Skip to content

Commit

Permalink
fix(mobile): Join TG step (#864)
Browse files Browse the repository at this point in the history
* fix(mobile): Join TG step

* fix amount

* fix amount
  • Loading branch information
voloshinskii authored May 16, 2024
1 parent 4138e28 commit f15325e
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 6 deletions.
22 changes: 21 additions & 1 deletion packages/@core-js/src/utils/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export interface StatePersistOptions<TData extends DefaultStateData> {
storage: Storage;
partialize?: (data: TData) => Partial<TData>;
rehydrated?: (data: TData) => void;
version?: number;
onUpdate?: (prevVersion: number | undefined, prevData: any) => Partial<TData>;
}

export class State<TData extends DefaultStateData> {
Expand All @@ -29,7 +31,13 @@ export class State<TData extends DefaultStateData> {
const { key, storage, partialize } = this.persistOptions;

try {
const data = partialize ? partialize(this.data) : this.data;
const data: Partial<TData> & { __version?: number } = partialize
? partialize(this.data)
: this.data;

// We should keep last version in storage
data.__version = this.persistOptions.version;

await storage.setItem(key, JSON.stringify(data));
} catch (err) {
console.log('[State]: error persist for key', key, err);
Expand Down Expand Up @@ -58,6 +66,18 @@ export class State<TData extends DefaultStateData> {

this.data = { ...this.data, ...parsedData };

if (
this.persistOptions.onUpdate &&
this.persistOptions.version &&
(!parsedData.__version || this.persistOptions.version > parsedData.__version)
) {
this.data = {
...this.data,
...this.persistOptions.onUpdate(parsedData.__version, this.data),
};
this.storeIfNeeded();
}

if (rehydrated) {
rehydrated(this.data);
}
Expand Down
5 changes: 5 additions & 0 deletions packages/mobile/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export type AppConfigVars = {
tonNFTsMarketplaceEndpoint: string;
tonapiMainnetHost: string;
accountExplorer: string;
telegram_ru: string;
telegram_global: string;
subscriptionsHost: string;
cachedMediaEndpoint: string;
cachedMediaKey: string;
Expand Down Expand Up @@ -117,6 +119,9 @@ const defaultConfig: Partial<AppConfigVars> = {
disable_battery_crypto_recharge_module: false,
disable_signer: true,

telegram_global: 'https://t.me/tonkeeper_news',
telegram_ru: 'https://t.me/tonkeeper_ru',

disable_show_unverified_token: false,
disable_tonstakers: false,
disable_holders_cards: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/mobile/src/modals/BurnVouchersModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const BurnVouchersModal = memo<BurnVouchersModalProps>((props) => {
valid_until,
messages: selectedNfts.map((nft) => ({
address: nft.address,
amount: Ton.toNano('0.07'),
amount: Ton.toNano('0.1'),
payload: beginCell()
.storeUint(OpCodes.NFT_TRANSFER, 32)
.storeUint(ContractService.getWalletQueryId(), 64)
Expand Down
37 changes: 33 additions & 4 deletions packages/mobile/src/tabs/Wallet/components/FinishSetupList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ import {
View,
} from '@tonkeeper/uikit';
import { memo, useCallback, useEffect, useMemo } from 'react';
import { t } from '@tonkeeper/shared/i18n';
import { i18n, t } from '@tonkeeper/shared/i18n';
import { useBiometrySettings, useWallet, useWalletSetup } from '@tonkeeper/shared/hooks';
import { useNavigation } from '@tonkeeper/router';
import { useNotificationsSwitch } from '$hooks/useNotificationsSwitch';
import { LayoutAnimation, Linking } from 'react-native';
import { getBiometryIcon, getBiometryName } from '$utils';
import { config } from '$config';
import { tk } from '$wallet';

enum SetupItemType {
Backup = 'Backup',
Notifications = 'Notifications',
Biometry = 'Biometry',
JoinTonkeeper = 'JoinTonkeeper',
}

interface SetupItem {
Expand All @@ -32,7 +35,7 @@ interface SetupItem {
}

export const FinishSetupList = memo(() => {
const { lastBackupAt, setupDismissed } = useWalletSetup();
const { lastBackupAt, setupDismissed, hasOpenedTelegramChannel } = useWalletSetup();
const wallet = useWallet();
const nav = useNavigation();

Expand Down Expand Up @@ -98,6 +101,23 @@ export const FinishSetupList = memo(() => {
});
}

if (!hasOpenedTelegramChannel) {
list.push({
type: SetupItemType.JoinTonkeeper,
iconName: 'ic-telegram-28',
title: t('finish_setup.join_tg'),
switch: null,
onPress: () => {
tk.wallet.toggleTgJoined();
Linking.openURL(
i18n.locale === 'ru'
? config.get('telegram_ru')
: config.get('telegram_global'),
).catch((e) => console.log(e));
},
});
}

if (lastBackupAt === null) {
list.push({
type: SetupItemType.Backup,
Expand All @@ -109,23 +129,32 @@ export const FinishSetupList = memo(() => {
}

return list;
}, [biometry, initialItems, lastBackupAt, nav, notifications]);
}, [
biometry,
initialItems,
lastBackupAt,
nav,
notifications,
hasOpenedTelegramChannel,
]);

useEffect(() => {
const notificationsEnabled = !notifications.isAvailable || notifications.isSubscribed;
const biometryEnabled = !biometry.isAvailable || biometry.isEnabled;
if (
!setupDismissed &&
hasOpenedTelegramChannel &&
biometryEnabled &&
notificationsEnabled &&
lastBackupAt !== null
) {
setTimeout(() => handleDone(), 300);
}
}, [
biometry.isEnabled,
biometry.isAvailable,
biometry.isEnabled,
handleDone,
hasOpenedTelegramChannel,
lastBackupAt,
notifications.isAvailable,
notifications.isSubscribed,
Expand Down
8 changes: 8 additions & 0 deletions packages/mobile/src/wallet/Wallet/Wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface WalletStatusState {
export interface WalletSetupState {
lastBackupAt: number | null;
setupDismissed: boolean;
hasOpenedTelegramChannel: boolean;
}

export class Wallet extends WalletContent {
Expand All @@ -29,6 +30,7 @@ export class Wallet extends WalletContent {
static readonly INITIAL_SETUP_STATE: WalletSetupState = {
lastBackupAt: null,
setupDismissed: false,
hasOpenedTelegramChannel: false,
};

private stopListenTransactions: Function | null = null;
Expand Down Expand Up @@ -58,6 +60,8 @@ export class Wallet extends WalletContent {
this.setup.persist({
storage: this.storage,
key: `${this.persistPath}/setup`,
version: 1,
onUpdate: (lastVersion, prevData) => ({ ...prevData, setupDismissed: false }),
});

this.listenTransactions();
Expand All @@ -72,6 +76,10 @@ export class Wallet extends WalletContent {
this.setup.set({ setupDismissed: true });
}

public toggleTgJoined() {
this.setup.set({ hasOpenedTelegramChannel: true });
}

public async rehydrate() {
await super.rehydrate();

Expand Down
1 change: 1 addition & 0 deletions packages/shared/i18n/locales/tonkeeper/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,7 @@
"done_button": "Done"
},
"finish_setup": {
"join_tg": "Join Tonkeeper channel",
"header_title": "Finish setting up",
"use_biometry": "Use %{name} to approve transaction",
"enable_notifications": "Enable transaction notifications",
Expand Down
1 change: 1 addition & 0 deletions packages/shared/i18n/locales/tonkeeper/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -1305,6 +1305,7 @@
"done_button": "Готово"
},
"finish_setup": {
"join_tg": "Присоединяйтесь к каналу Tonkeeper",
"header_title": "Завершить установку",
"use_biometry": "Включите %{name} для подтверждения транзакций",
"enable_notifications": "Включите уведомления о транзакциях",
Expand Down

0 comments on commit f15325e

Please sign in to comment.