From f15325e3e45d23900f284c79a2e5fb1f54ecc05c Mon Sep 17 00:00:00 2001 From: Max Voloshinskii Date: Thu, 16 May 2024 20:19:38 +0300 Subject: [PATCH] fix(mobile): Join TG step (#864) * fix(mobile): Join TG step * fix amount * fix amount --- packages/@core-js/src/utils/State.ts | 22 ++++++++++- packages/mobile/src/config/index.ts | 5 +++ .../mobile/src/modals/BurnVouchersModal.tsx | 2 +- .../Wallet/components/FinishSetupList.tsx | 37 +++++++++++++++++-- packages/mobile/src/wallet/Wallet/Wallet.ts | 8 ++++ .../shared/i18n/locales/tonkeeper/en.json | 1 + .../shared/i18n/locales/tonkeeper/ru-RU.json | 1 + 7 files changed, 70 insertions(+), 6 deletions(-) diff --git a/packages/@core-js/src/utils/State.ts b/packages/@core-js/src/utils/State.ts index a1a40c589..06bd6a11f 100644 --- a/packages/@core-js/src/utils/State.ts +++ b/packages/@core-js/src/utils/State.ts @@ -9,6 +9,8 @@ export interface StatePersistOptions { storage: Storage; partialize?: (data: TData) => Partial; rehydrated?: (data: TData) => void; + version?: number; + onUpdate?: (prevVersion: number | undefined, prevData: any) => Partial; } export class State { @@ -29,7 +31,13 @@ export class State { const { key, storage, partialize } = this.persistOptions; try { - const data = partialize ? partialize(this.data) : this.data; + const data: Partial & { __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); @@ -58,6 +66,18 @@ export class State { 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); } diff --git a/packages/mobile/src/config/index.ts b/packages/mobile/src/config/index.ts index 4f5612c62..a997ff7c1 100644 --- a/packages/mobile/src/config/index.ts +++ b/packages/mobile/src/config/index.ts @@ -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; @@ -117,6 +119,9 @@ const defaultConfig: Partial = { 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, diff --git a/packages/mobile/src/modals/BurnVouchersModal.tsx b/packages/mobile/src/modals/BurnVouchersModal.tsx index 05d454890..9657fe1e3 100644 --- a/packages/mobile/src/modals/BurnVouchersModal.tsx +++ b/packages/mobile/src/modals/BurnVouchersModal.tsx @@ -73,7 +73,7 @@ export const BurnVouchersModal = memo((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) diff --git a/packages/mobile/src/tabs/Wallet/components/FinishSetupList.tsx b/packages/mobile/src/tabs/Wallet/components/FinishSetupList.tsx index 7163a3fef..da4f0a447 100644 --- a/packages/mobile/src/tabs/Wallet/components/FinishSetupList.tsx +++ b/packages/mobile/src/tabs/Wallet/components/FinishSetupList.tsx @@ -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 { @@ -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(); @@ -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, @@ -109,13 +129,21 @@ 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 @@ -123,9 +151,10 @@ export const FinishSetupList = memo(() => { setTimeout(() => handleDone(), 300); } }, [ - biometry.isEnabled, biometry.isAvailable, + biometry.isEnabled, handleDone, + hasOpenedTelegramChannel, lastBackupAt, notifications.isAvailable, notifications.isSubscribed, diff --git a/packages/mobile/src/wallet/Wallet/Wallet.ts b/packages/mobile/src/wallet/Wallet/Wallet.ts index d90c85f0a..c6b934fd8 100644 --- a/packages/mobile/src/wallet/Wallet/Wallet.ts +++ b/packages/mobile/src/wallet/Wallet/Wallet.ts @@ -17,6 +17,7 @@ export interface WalletStatusState { export interface WalletSetupState { lastBackupAt: number | null; setupDismissed: boolean; + hasOpenedTelegramChannel: boolean; } export class Wallet extends WalletContent { @@ -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; @@ -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(); @@ -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(); diff --git a/packages/shared/i18n/locales/tonkeeper/en.json b/packages/shared/i18n/locales/tonkeeper/en.json index 64250b922..750bf7b4d 100644 --- a/packages/shared/i18n/locales/tonkeeper/en.json +++ b/packages/shared/i18n/locales/tonkeeper/en.json @@ -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", diff --git a/packages/shared/i18n/locales/tonkeeper/ru-RU.json b/packages/shared/i18n/locales/tonkeeper/ru-RU.json index b3e63f975..08427a79c 100644 --- a/packages/shared/i18n/locales/tonkeeper/ru-RU.json +++ b/packages/shared/i18n/locales/tonkeeper/ru-RU.json @@ -1305,6 +1305,7 @@ "done_button": "Готово" }, "finish_setup": { + "join_tg": "Присоединяйтесь к каналу Tonkeeper", "header_title": "Завершить установку", "use_biometry": "Включите %{name} для подтверждения транзакций", "enable_notifications": "Включите уведомления о транзакциях",