Skip to content

Commit

Permalink
fix(mobile): Add battery beta label (#791)
Browse files Browse the repository at this point in the history
* fix(mobile): Add battery beta label

* fix reservedBalance
  • Loading branch information
voloshinskii authored Apr 11, 2024
1 parent a35a916 commit 8450105
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/mobile/src/config/AppConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type AppConfigOptions<TConfig> = {
};

export class AppConfig<TConfig = {}> {
static readonly CONFIG_VERSION = 2; // change it, if config needs to be force updated
static readonly CONFIG_VERSION = 3; // change it, if config needs to be force updated

private clientConfigStorageKey = `__client-config__v${AppConfig.CONFIG_VERSION}`;
private serverConfigStorageKey = `__server-config__v${AppConfig.CONFIG_VERSION}`;
Expand Down
8 changes: 6 additions & 2 deletions packages/mobile/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export type AppConfigVars = {
aptabaseEndpoint: string;
aptabaseAppKey: string;
disable_battery: boolean;
battery_beta: boolean;
disable_battery_iap_module: boolean;
disable_battery_send: boolean;
disable_show_unverified_token: boolean;
Expand Down Expand Up @@ -86,16 +87,19 @@ const defaultConfig: Partial<AppConfigVars> = {
holdersService: 'https://card-dev.whales-api.com',
tronapiHost: 'https://tron.tonkeeper.com',
tronapiTestnetHost: 'https://testnet-tron.tonkeeper.com',

batteryHost: 'https://battery.tonkeeper.com',
batteryTestnetHost: 'https://testnet-battery.tonkeeper.com',
batteryMeanFees: '0.0055',
batteryReservedAmount: '0.3',
batteryMeanPrice_swap: '0.22',
batteryMeanPrice_jetton: '0.06',
batteryMeanPrice_nft: '0.03',
disable_battery: true,
battery_beta: true,
disable_battery: false,
disable_battery_send: false,
disable_battery_iap_module: Platform.OS !== 'android', // Enable for iOS, disable for Android
disable_battery_send: true,

disable_show_unverified_token: false,
disable_tonstakers: false,
disable_holders_cards: true,
Expand Down
4 changes: 3 additions & 1 deletion packages/mobile/src/core/Settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,9 @@ export const Settings: FC = () => {
name={'ic-battery-28'}
/>
}
title={t('battery.settings')}
title={t('battery.settings', {
betaLabel: config.get('battery_beta') ? '(Beta)' : '',
})}
onPress={handleBattery}
/>
)}
Expand Down
13 changes: 11 additions & 2 deletions packages/mobile/src/wallet/managers/BatteryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ export enum BatterySupportedTransaction {
export interface BatteryState {
isLoading: boolean;
balance?: string;
reservedBalance?: string;
supportedTransactions: Record<BatterySupportedTransaction, boolean>;
}

export class BatteryManager {
public state = new State<BatteryState>({
isLoading: false,
balance: undefined,
reservedBalance: '0',
supportedTransactions: {
[BatterySupportedTransaction.Swap]: true,
[BatterySupportedTransaction.Jetton]: true,
Expand All @@ -37,8 +39,9 @@ export class BatteryManager {
private storage: Storage,
) {
this.state.persist({
partialize: ({ balance, supportedTransactions }) => ({
partialize: ({ balance, reservedBalance, supportedTransactions }) => ({
balance,
reservedBalance,
supportedTransactions,
}),
storage: this.storage,
Expand All @@ -61,7 +64,13 @@ export class BatteryManager {
},
},
);
this.state.set({ isLoading: false, balance: data.balance });

this.state.set({
isLoading: false,
balance: data.balance,
// @ts-expect-error reservedAmount will be implemented in API later. Remove then
reservedBalance: data.reservedBalance ?? '0',
});
} catch (err) {
this.state.set({ isLoading: false });
return null;
Expand Down
9 changes: 8 additions & 1 deletion packages/shared/components/BatteryIcon/BatteryIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ const hitSlop = { top: 12, bottom: 12, right: 24, left: 8 };
export const BatteryIcon = memo(() => {
const { balance } = useBatteryBalance();
const isViewedBatteryScreen = useBatteryUIStore((state) => state.isViewedBatteryScreen);
if (config.get('disable_battery')) return null;
if (config.get('disable_battery')) {
return null;
}

// Hide battery icon if it's empty and beta is enabled
if (config.get('battery_beta') && (!balance || balance === '0')) {
return null;
}

return (
<TouchableOpacity onPress={openRefillBatteryModal} hitSlop={hitSlop}>
Expand Down
7 changes: 7 additions & 0 deletions packages/shared/components/RefillBattery/RefillBattery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { RestorePurchases } from './RestorePurchases';
import { RefillBatterySettingsWidget } from './RefillBatterySettingsWidget';
import Animated from 'react-native-reanimated';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { Tag } from '@tonkeeper/mobile/src/uikit';

export interface RefillBatteryProps {
navigateToTransactions: () => void;
Expand Down Expand Up @@ -56,6 +57,12 @@ export const RefillBattery = memo<RefillBatteryProps>((props) => {
</View>
)}
<Spacer y={16} />
{config.get('battery_beta') && (
<>
<Tag type="warning">Beta</Tag>
<Spacer y={4} />
</>
)}
<Text textAlign="center" type="h2">
{t(`battery.title`)}
</Text>
Expand Down
11 changes: 10 additions & 1 deletion packages/shared/components/RefillBattery/RefillBatteryIAP.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export const RefillBatteryIAP = memo(() => {
tk.wallet.battery.state,
(state) => state.balance,
);
const reservedBalance = useExternalState(
tk.wallet.battery.state,
(state) => state.reservedBalance,
);

useEffect(() => {
getProducts({
Expand Down Expand Up @@ -144,7 +148,12 @@ export const RefillBatteryIAP = memo(() => {
{t(`battery.packages.subtitle`, {
count: new BigNumber(item.userProceed)
.div(tonPriceInUsd)
.minus(!batteryBalance ? config.get('batteryReservedAmount') : 0)
.minus(
reservedBalance === '0' &&
(!batteryBalance || batteryBalance === '0')
? config.get('batteryReservedAmount')
: 0,
)
.div(config.get('batteryMeanFees'))
.decimalPlaces(0)
.toNumber(),
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/i18n/locales/tonkeeper/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
},
"refilled": "Battery refilled",
"screen_title": "Battery",
"settings": "Battery",
"settings": "Battery %{betaLabel}",
"ok": "OK",
"title": "Tonkeeper Battery",
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/i18n/locales/tonkeeper/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@
},
"refilled": "Батарейка заряжена",
"screen_title": "Батарейка",
"settings": "Батарейка",
"settings": "Батарейка %{betaLabel}",
"ok": "OK",
"title": "Батарейка Tonkeeper",
"description": {
Expand Down

0 comments on commit 8450105

Please sign in to comment.