diff --git a/flows/README.md b/flows/README.md index 93ff93459..3e75a092a 100644 --- a/flows/README.md +++ b/flows/README.md @@ -2,6 +2,16 @@ This directory contains end-to-end UI automation flows for the Keeper app using Maestro. +## USDT Settings route smoke check + +`usdt-settings-routes.yaml` starts on Home in an authenticated, disposable development app on TESTNET. It checks Settings > Keys & Wallets > Add USDT Wallet, opens the creation form and the seed import form, and returns without submitting either form. It does not create wallets or make transaction, recovery or backup requests. + +```bash +maestro --udid test flows/usdt-settings-routes.yaml +``` + +The default app ID is `io.hexawallet.hexakeeper.dev`; override it with `-e APP_ID=` when testing a different development package. Do not run against a funded/customer profile. Production USDT entry uses MAINNET; this smoke flow is intended for the development TESTNET fixture. + ## Instructions Use these flows to validate onboarding, wallet, RGB assets, settings, backup, and recovery journeys on development builds. diff --git a/flows/usdt-settings-routes.yaml b/flows/usdt-settings-routes.yaml new file mode 100644 index 000000000..7ceee05f8 --- /dev/null +++ b/flows/usdt-settings-routes.yaml @@ -0,0 +1,43 @@ +appId: ${APP_ID} +env: + APP_ID: io.hexawallet.hexakeeper.dev +--- +# Start with an authenticated disposable development/testnet app on Home. +# This check never submits a wallet, seed, send or backup request. +- runFlow: + when: + visible: "Protect Your Recovery Key" + commands: + - tapOn: "Skip for Now" + - extendedWaitUntil: + visible: "Skip Backup" + timeout: 20000 + - tapOn: "Skip Backup" +- assertVisible: "More" +- tapOn: "More" +- scrollUntilVisible: + element: + id: "btn_setting_Add USDT Wallet" + direction: DOWN + timeout: 20000 +- tapOn: + id: "btn_setting_Add USDT Wallet" +- assertVisible: ".*Create a new USDT wallet.*" +- assertVisible: ".*Import Wallet.*" +- tapOn: ".*Create a new USDT wallet.*" +- extendedWaitUntil: + visible: "Add Your Wallet Details" + timeout: 20000 +- assertVisible: "Enter wallet name" +- assertVisible: "Create Your Wallet" +- tapOn: + id: btn_back +- tapOn: + id: "btn_setting_Add USDT Wallet" +- tapOn: ".*Import Wallet.*" +- extendedWaitUntil: + visible: "Enter Seed Words" + timeout: 20000 +- assertVisible: "Next" +- tapOn: + id: btn_back diff --git a/openspec/specs/settings/spec.md b/openspec/specs/settings/spec.md index 6bd7f7222..7a46c1552 100644 --- a/openspec/specs/settings/spec.md +++ b/openspec/specs/settings/spec.md @@ -30,6 +30,24 @@ Settings grouping should separate: ## Requirements +### Requirement: USDT wallet creation entry point + +Settings > Keys & Wallets MUST show "Add USDT Wallet" when the active Bitcoin network matches `USDTWalletSupportedNetwork` (testnet in development mode, mainnet otherwise). It MUST open the existing USDT create/import choice. On the unsupported network, the entry point MUST be absent. Moving this entry point MUST NOT remove existing USDT wallets or change their send, receive, GasFree, backup, or management behavior. + +#### Scenario: Open USDT wallet creation from Settings + +- GIVEN the user is on `USDTWalletSupportedNetwork` +- WHEN the user opens Settings > Keys & Wallets and taps "Add USDT Wallet" +- THEN the user can choose "Create Wallet" or "Import Wallet" + +#### Scenario: USDT creation unavailable on the unsupported network + +- GIVEN the active network differs from `USDTWalletSupportedNetwork` +- WHEN the user opens Settings > Keys & Wallets +- THEN "Add USDT Wallet" is not shown + +--- + ### Requirement: Node Configuration The app MUST allow the user to add, connect, disconnect, and delete custom Electrum diff --git a/openspec/specs/usdt/spec.md b/openspec/specs/usdt/spec.md index ff8efe379..a26a04911 100644 --- a/openspec/specs/usdt/spec.md +++ b/openspec/specs/usdt/spec.md @@ -20,19 +20,26 @@ visually and functionally distinct from all Bitcoin and multi-key entities. ### Requirement: USDT Wallet Availability -The app MUST only offer USDT wallet creation and import when the active Bitcoin network is mainnet. On testnet the USDT wallet option MUST NOT be shown in the wallet-type picker. +The app MUST offer USDT wallet creation and import from Settings > Keys & Wallets only when the active Bitcoin network matches `USDTWalletSupportedNetwork` (testnet in development mode, mainnet otherwise). The home Add Wallet control and onboarding MUST lead to Bitcoin wallet flows without a currency picker. Moving this entry point MUST NOT delete or migrate existing USDT wallets. -#### Scenario: USDT option shown on mainnet (happy path) +#### Scenario: USDT entry point shown on the supported network (happy path) -- GIVEN the user is authenticated and the app is configured for mainnet -- WHEN the user taps the "Add Wallet" control on the home screen -- THEN a currency-type picker appears offering both a Bitcoin wallet option and a USDT (Dollar) wallet option +- GIVEN the user is authenticated and the active network matches `USDTWalletSupportedNetwork` +- WHEN the user opens Settings > Keys & Wallets +- THEN an "Add USDT Wallet" item opens a choice to create or import a USDT wallet -#### Scenario: USDT option hidden on testnet +#### Scenario: USDT entry point hidden on the unsupported network -- GIVEN the user is authenticated and the app is configured for testnet -- WHEN the user taps the "Add Wallet" control on the home screen -- THEN the currency-type picker shows only the Bitcoin wallet option and the USDT wallet option is absent +- GIVEN the user is authenticated and the active network differs from `USDTWalletSupportedNetwork` +- WHEN the user opens Settings > Keys & Wallets +- THEN the "Add USDT Wallet" item is absent + +#### Scenario: Add Wallet remains Bitcoin focused + +- GIVEN the user is on the home screen on either network +- WHEN the user taps "Add Wallet" +- THEN the Bitcoin wallet create, import, and collaborative wallet choices appear directly +- AND no USDT choice appears in that flow --- @@ -42,7 +49,7 @@ The app MUST allow the user to create a new USDT wallet by supplying a name and #### Scenario: Create a new USDT wallet (happy path) -- GIVEN the user selects the USDT wallet option and then "Create wallet" from the wallet-type picker +- GIVEN the user opens "Add USDT Wallet" in Settings and selects "Create Wallet" - WHEN the user enters a valid wallet name (up to 18 characters) and optionally a description, then confirms - THEN a new USDT wallet is created and appears in the home-screen wallet list - AND the wallet's creation is persisted to the relay server as part of the app image backup @@ -67,7 +74,7 @@ The app MUST allow the user to import an existing USDT wallet by providing its B #### Scenario: Import a USDT wallet via mnemonic (happy path) -- GIVEN the user selects the USDT wallet option and then "Import wallet" from the wallet-type picker +- GIVEN the user opens "Add USDT Wallet" in Settings and selects "Import Wallet" - WHEN the user enters the correct seed phrase for an existing USDT wallet - THEN the wallet is imported and appears in the home-screen wallet list with its corresponding Tron address diff --git a/openspec/specs/wallets/spec.md b/openspec/specs/wallets/spec.md index f621d7e3f..dcce30297 100644 --- a/openspec/specs/wallets/spec.md +++ b/openspec/specs/wallets/spec.md @@ -308,19 +308,19 @@ A watch-only or zero-balance wallet that is hidden MUST be deletable from the wa ### Requirement: USDT Wallet Distinction -The app MUST distinguish USDT wallets from Bitcoin wallets at every level of the interface. USDT wallets MUST NOT appear in the Bitcoin wallet list on the home screen and MUST be accessible from a dedicated USDT section. +The app MUST distinguish USDT wallets from Bitcoin wallets at every level of the interface. Existing visible USDT wallets MUST remain in the unified home wallet list with a distinct USDT identity. Their creation and import entry point is in Settings > Keys & Wallets. -#### Scenario: USDT wallet absent from Bitcoin home list +#### Scenario: USDT wallet remains visible on home - GIVEN the user has both a Bitcoin wallet and a USDT wallet - WHEN the user views the main home screen wallet list -- THEN the USDT wallet does not appear alongside Bitcoin wallets +- THEN the USDT wallet appears alongside Bitcoin wallets with a distinct USDT identifier and balance unit -#### Scenario: USDT wallet accessible from dedicated section +#### Scenario: USDT wallet detail remains accessible - GIVEN the user has a USDT wallet -- WHEN the user navigates to the USDT section of the home screen -- THEN the USDT wallet is listed there with its balance and transaction history +- WHEN the user taps the USDT wallet card on the home screen +- THEN the USDT wallet detail opens with its balance and transaction history --- @@ -334,7 +334,7 @@ The app MUST distinguish USDT wallets from Bitcoin wallets at every level of the - Watch-only wallet shows: "This wallet can show balances and transactions, but cannot send bitcoin." - Buy, Sell, Swap, Acquire entry points are absent from wallet creation and management. - No subscription/tier gating. -- USDT wallets are in a distinct section (not the Bitcoin wallet list). +- Existing USDT wallets remain visible in the unified home wallet list with distinct USDT identity. --- diff --git a/src/context/Localization/language/en.json b/src/context/Localization/language/en.json index 962b29aee..4975f8787 100644 --- a/src/context/Localization/language/en.json +++ b/src/context/Localization/language/en.json @@ -486,6 +486,7 @@ "restoreExistingWallet": "Restore an existing wallet", "walletWithFamily": "Create wallet with family and friends", "addNewWallet": "Add a New Wallet", + "AddUSDTWallet": "Add USDT Wallet", "createOrImportWallet": "Create a new wallet or import existing one", "collaborativeSessionExists": "Collaborative wallet setup session already exists", "collaborativeSessionExistsDesc": "You already have a collaborative wallet setup session in progress, would you like to continue the session or start a new one?", @@ -2218,4 +2219,4 @@ "disclaimerLearnMore": "Learn more about Ask Keeper", "disclaimerCta": "Got it" } -} \ No newline at end of file +} diff --git a/src/context/Localization/language/es.json b/src/context/Localization/language/es.json index a59ae5abd..d47890682 100644 --- a/src/context/Localization/language/es.json +++ b/src/context/Localization/language/es.json @@ -474,6 +474,7 @@ "restoreExistingWallet": "Restore an existing wallet", "walletWithFamily": "Create wallet with family and friends", "addNewWallet": "Add a New Wallet", + "AddUSDTWallet": "Add USDT Wallet", "createOrImportWallet": "Create a new wallet or import existing one", "collaborativeSessionExists": "Collaborative wallet setup session already exists", "collaborativeSessionExistsDesc": "You already have a collaborative wallet setup session in progress, would you like to continue the session or start a new one?", @@ -2199,4 +2200,4 @@ "disclaimerLearnMore": "Learn more about Ask Keeper", "disclaimerCta": "Got it" } -} \ No newline at end of file +} diff --git a/src/screens/Home/components/Settings/USDTWalletCreationModal.tsx b/src/screens/Home/components/Settings/USDTWalletCreationModal.tsx new file mode 100644 index 000000000..db5b72431 --- /dev/null +++ b/src/screens/Home/components/Settings/USDTWalletCreationModal.tsx @@ -0,0 +1,128 @@ +import { Box, useColorMode } from '@gluestack-ui/themed-native-base'; +import { CommonActions, useNavigation } from '@react-navigation/native'; +import React, { useContext } from 'react'; +import { StyleSheet, TouchableOpacity } from 'react-native'; +import ImportWalletIcon from 'src/assets/images/import.svg'; +import NewWalletIcon from 'src/assets/images/wallet-white-small.svg'; +import TickIcon from 'src/assets/images/icon_tick.svg'; +import ToastErrorIcon from 'src/assets/images/toast_error.svg'; +import CircleIconWrapper from 'src/components/CircleIconWrapper'; +import KeeperModal from 'src/components/KeeperModal'; +import Text from 'src/components/KeeperText'; +import { hp, wp } from 'src/constants/responsive'; +import { LocalizationContext } from 'src/context/Localization/LocContext'; +import useToastMessage from 'src/hooks/useToastMessage'; +import { useUSDTWallets } from 'src/hooks/useUSDTWallets'; +import { USDTWalletType } from 'src/services/wallets/factories/USDTWalletFactory'; + +const USDTWalletCreationModal = ({ visible, close }: { visible: boolean; close: () => void }) => { + const { colorMode } = useColorMode(); + const navigation = useNavigation(); + const { translations } = useContext(LocalizationContext); + const { wallet: walletText, home } = translations; + const { createWallet } = useUSDTWallets(); + const { showToast } = useToastMessage(); + + const importUSDTWallet = async (mnemonic) => { + try { + const { newWallet, error } = await createWallet({ + type: USDTWalletType.IMPORTED, + name: 'USDT Wallet', + description: 'Imported USDT Wallet', + importDetails: { mnemonic }, + }); + + if (!newWallet) throw new Error(error); + + showToast('USDT wallet imported successfully!', ); + setTimeout(() => { + navigation.dispatch( + CommonActions.navigate({ name: 'Home', params: { selectedOption: 'Wallets' } }) + ); + }, 900); + } catch (err) { + showToast(`Failed to import USDT wallet: ${err.message}`, ); + } + }; + + const options = [ + { + title: walletText.createWallet, + subtitle: 'Create a new USDT wallet', + icon: , + onPress: () => { + close(); + navigation.dispatch(CommonActions.navigate('addUsdtWallet')); + }, + }, + { + title: home.ImportWallet, + subtitle: walletText.restoreExistingWallet, + icon: , + onPress: () => { + close(); + navigation.dispatch( + CommonActions.navigate({ + name: 'EnterSeedScreen', + params: { isImport: true, isUSDTWallet: true, importSeedCta: importUSDTWallet }, + }) + ); + }, + }, + ]; + + return ( + ( + + {options.map((option) => ( + + + + + + {option.title} + + + {option.subtitle} + + + + + ))} + + )} + /> + ); +}; + +export default USDTWalletCreationModal; + +const styles = StyleSheet.create({ + optionsList: { gap: wp(15), marginBottom: hp(10) }, + option: { + flexDirection: 'row', + paddingHorizontal: wp(15), + paddingVertical: hp(22), + alignItems: 'center', + gap: wp(16), + borderRadius: 12, + borderWidth: 1, + }, + optionText: { flex: 1, flexShrink: 1 }, +}); diff --git a/src/screens/Home/components/Settings/keeperSettings.tsx b/src/screens/Home/components/Settings/keeperSettings.tsx index 65b0c2843..1589a87a7 100644 --- a/src/screens/Home/components/Settings/keeperSettings.tsx +++ b/src/screens/Home/components/Settings/keeperSettings.tsx @@ -1,5 +1,5 @@ import { Box, ScrollView, useColorMode } from '@gluestack-ui/themed-native-base'; -import React, { useContext, useEffect } from 'react'; +import React, { useContext, useEffect, useState } from 'react'; import Colors from 'src/theme/Colors'; import PlebContainer from './Component/PlebContainer'; import { LocalizationContext } from 'src/context/Localization/LocContext'; @@ -24,12 +24,22 @@ import { useAppSelector } from 'src/store/hooks'; import { setShowTipModal } from 'src/store/reducers/settings'; import { useDispatch } from 'react-redux'; import SupportDeveloperIcon from 'src/assets/images/supportDeveloper.svg'; +import UsdtWalletLogo from 'src/assets/images/usdt-wallet-logo.svg'; +import { USDTWalletSupportedNetwork } from 'src/services/wallets/factories/USDTWalletFactory'; +import USDTWalletCreationModal from './USDTWalletCreationModal'; const KeeperSettings = ({ route }) => { const { colorMode } = useColorMode(); const navigation = useNavigation(); const { translations } = useContext(LocalizationContext); - const { signer: signerText, inheritancePlanning, settings, common } = translations; + const { + signer: signerText, + inheritancePlanning, + settings, + common, + wallet: walletText, + } = translations; + const [createUsdtWallet, setCreateUsdtWallet] = useState(false); const { BackAndRecovery, General, @@ -52,6 +62,7 @@ const KeeperSettings = ({ route }) => { }, []); // Empty dependency array means this runs once on mount const { backupAllLoading } = useAppSelector((state) => state.bhr); + const { bitcoinNetworkType } = useAppSelector((state) => state.settings); const dispatch = useDispatch(); return ( @@ -87,7 +98,18 @@ const KeeperSettings = ({ route }) => { subtitleColor={`${colorMode}.balanceText`} backgroundColor={`${colorMode}.textInputBackground`} borderColor={`${colorMode}.separator`} - items={keysAndwallet} + items={[ + ...keysAndwallet, + ...(bitcoinNetworkType === USDTWalletSupportedNetwork + ? [ + { + title: walletText.AddUSDTWallet, + icon: , + onPress: () => setCreateUsdtWallet(true), + }, + ] + : []), + ]} /> { /> {DeleteBackupModal} + setCreateUsdtWallet(false)} + /> ); }; diff --git a/src/screens/Home/components/Wallet/HomeWallet.tsx b/src/screens/Home/components/Wallet/HomeWallet.tsx index f277a0b79..95978a000 100644 --- a/src/screens/Home/components/Wallet/HomeWallet.tsx +++ b/src/screens/Home/components/Wallet/HomeWallet.tsx @@ -1,7 +1,6 @@ import { Box, useColorMode, View } from '@gluestack-ui/themed-native-base'; import React, { useContext, useState, useEffect } from 'react'; import { FlatList, StyleSheet, TouchableOpacity } from 'react-native'; -import DashedCta from 'src/components/DashedCta'; import WalletCard from './WalletCard'; import Colors from 'src/theme/Colors'; import useWallets from 'src/hooks/useWallets'; @@ -10,11 +9,11 @@ import { Wallet } from 'src/services/wallets/interfaces/wallet'; import { Vault } from 'src/services/wallets/interfaces/vault'; import useWalletAsset from 'src/hooks/useWalletAsset'; -import { EntityKind, VisibilityType, WalletType } from 'src/services/wallets/enums'; -import { useNavigation, useFocusEffect, CommonActions } from '@react-navigation/native'; +import { EntityKind, VisibilityType } from 'src/services/wallets/enums'; +import { useNavigation } from '@react-navigation/native'; import KeeperModal from 'src/components/KeeperModal'; import Text from 'src/components/KeeperText'; -import { hp, windowWidth, wp } from 'src/constants/responsive'; +import { hp, wp } from 'src/constants/responsive'; import NewWalletIcon from 'src/assets/images/wallet-white-small.svg'; import ImportWalletIcon from 'src/assets/images/import.svg'; @@ -23,26 +22,18 @@ import CollaborativeWalletIcon from 'src/assets/images/collaborative_vault_white import { useAppSelector } from 'src/store/hooks'; import { resetCollaborativeSession } from 'src/store/reducers/vaults'; import { useDispatch } from 'react-redux'; -import { autoSyncWallets, refreshWallets } from 'src/store/sagaActions/wallets'; +import { autoSyncWallets } from 'src/store/sagaActions/wallets'; import { RefreshControl } from 'react-native'; import { ELECTRUM_CLIENT } from 'src/services/electrum/client'; import ActivityIndicatorView from 'src/components/AppActivityIndicator/ActivityIndicatorView'; import CircleIconWrapper from 'src/components/CircleIconWrapper'; -import ThemedColor from 'src/components/ThemedColor/ThemedColor'; -import ThemedSvg from 'src/components/ThemedSvg.tsx/ThemedSvg'; import { LocalizationContext } from 'src/context/Localization/LocContext'; -import BitCoinWalletLogo from 'src/assets/images/bitcoin-wallet-logo.svg'; -import UsdtWalletLogo from 'src/assets/images/usdt-wallet-logo.svg'; import { useUSDTWallets } from 'src/hooks/useUSDTWallets'; import { getAvailableBalanceUSDTWallet, USDTWallet, - USDTWalletSupportedNetwork, - USDTWalletType, } from 'src/services/wallets/factories/USDTWalletFactory'; import useToastMessage from 'src/hooks/useToastMessage'; -import TickIcon from 'src/assets/images/icon_tick.svg'; -import ToastErrorIcon from 'src/assets/images/toast_error.svg'; import Fab from 'src/components/Fab'; import AddIcon from 'src/assets/images/add_white.svg'; import { useUTXOSpendability } from 'src/hooks/useUTXOSpendability'; @@ -105,28 +96,24 @@ function WalletCardItem({ const HomeWallet = () => { const { colorMode } = useColorMode(); - const isDarkMode = colorMode === 'dark'; const navigation = useNavigation(); const { wallets } = useWallets({ getAll: true }); const { translations } = useContext(LocalizationContext); - const { wallet: walletText, home, common, usdtWalletText } = translations; + const { wallet: walletText, home, common } = translations; const { getWalletCardGradient, getWalletTags } = useWalletAsset(); const { allVaults } = useVault({ includeArchived: false, getFirst: true, getHiddenWallets: false, }); - const { usdtWallets, createWallet } = useUSDTWallets(); + const { usdtWallets } = useUSDTWallets(); const { collaborativeSession } = useAppSelector((state) => state.vault); - const { bitcoinNetworkType } = useAppSelector((state) => state.settings); const dispatch = useDispatch(); const [showAddWalletModal, setShowAddWalletModal] = useState(false); const [collabSessionExistsModalVisible, setCollabSessionExistsModalVisible] = useState(false); const [pullRefresh, setPullRefresh] = useState(false); const { walletSyncing } = useAppSelector((state) => state.wallet); - const [pickWalletType, setPickWalletType] = useState(false); - const [createUsdtWallet, setCreateUsdtWallet] = useState(false); const syncing = ELECTRUM_CLIENT.isClientConnected && Object.values(walletSyncing).some((isSyncing) => isSyncing); @@ -140,12 +127,6 @@ const HomeWallet = () => { ...usdtWallets, ].filter((item) => item !== null); const [isShowAmount, setIsShowAmount] = useState(false); - const DashedCta_hexagonBackgroundColor = ThemedColor({ - name: 'DashedCta_hexagonBackgroundColor', - }); - const dashed_CTA_background = ThemedColor({ - name: 'dashed_CTA_background', - }); const { showToast } = useToastMessage(); const pendingDustToast = useAppSelector((state: any) => state.utxos.pendingDustToast); @@ -176,35 +157,6 @@ const HomeWallet = () => { setPullRefresh(false); }; - const importUSDTWallet = async (mnemonic) => { - try { - const { newWallet, error } = await createWallet({ - type: USDTWalletType.IMPORTED, - name: 'USDT Wallet', - description: 'Imported USDT Wallet', - importDetails: { - mnemonic, - }, - }); - - if (newWallet) { - showToast('USDT wallet imported successfully!', ); - setTimeout(() => { - navigation.dispatch( - CommonActions.navigate({ - name: 'Home', - params: { selectedOption: 'Wallets' }, - }) - ); - }, 900); - } else { - throw new Error(error); - } - } catch (err) { - showToast(`Failed to import USDT wallet: ${err.message}`, ); - } - }; - const CREATE_WALLET_OPTIONS = [ { title: walletText.createWallet, @@ -234,38 +186,6 @@ const HomeWallet = () => { id: 'collaborativeWallet', }, ]; - const CREATE_USDT_WALLET_OPTIONS = [ - { - title: walletText.createWallet, - subtitle: 'Create a new USDT wallet', - icon: , - onPress: () => { - navigation.navigate('addUsdtWallet'); - setCreateUsdtWallet(false); - }, - id: 'usdtnewWallet', - }, - { - title: home.ImportWallet, - subtitle: walletText.restoreExistingWallet, - icon: , - onPress: () => { - setCreateUsdtWallet(false); - navigation.dispatch( - CommonActions.navigate({ - name: 'EnterSeedScreen', - params: { - isImport: true, - isUSDTWallet: true, - importSeedCta: importUSDTWallet, - }, - }) - ); - }, - id: 'usdtimportWallet', - }, - ]; - const renderWalletCard = ({ item }: { item: Wallet | Vault | USDTWallet }) => ( { } - onPress={() => setPickWalletType(true)} + onPress={() => setShowAddWalletModal(true)} /> { )} /> - setCreateUsdtWallet(false)} - textColor={`${colorMode}.textGreen`} - subTitleColor={`${colorMode}.modalSubtitleBlack`} - showCloseIcon - Content={() => ( - - {CREATE_USDT_WALLET_OPTIONS.map((option, index) => ( - - ))} - - )} - /> setCollabSessionExistsModalVisible(false)} @@ -343,63 +247,6 @@ const HomeWallet = () => { navigation.navigate('SetupCollaborativeWallet'); }} /> - setPickWalletType(false)} - title={usdtWalletText.pickWalletType} - subTitle={usdtWalletText.selectCurrency} - textColor={`${colorMode}.textGreen`} - subTitleColor={`${colorMode}.modalSubtitleBlack`} - modalBackground={`${colorMode}.modalWhiteBackground`} - Content={() => ( - - { - setShowAddWalletModal(true); - setPickWalletType(false); - }} - > - - } - backgroundColor={Colors.BrightOrange} - /> - - {usdtWalletText.bitcoinWallet} - - - - {bitcoinNetworkType === USDTWalletSupportedNetwork ? ( - { - setCreateUsdtWallet(true); - setPickWalletType(false); - }} - > - - } - backgroundColor={Colors.DesaturatedTeal} - /> - - {usdtWalletText.dollarWallet} - - - - ) : null} - - )} - /> ); }; @@ -457,26 +304,4 @@ const styles = StyleSheet.create({ borderRadius: 12, borderWidth: 1, }, - customStyle: { - marginBottom: hp(10), - }, - DashedCtaStyle: { - width: windowWidth * 0.88, - }, - walletTypeContainer: { - gap: wp(15), - marginBottom: hp(10), - flexDirection: 'row', - justifyContent: 'center', - alignContent: 'center', - }, - typeCard: { - width: wp(148), - height: hp(104), - alignItems: 'center', - borderWidth: 1, - justifyContent: 'center', - borderRadius: 12, - gap: wp(10), - }, }); diff --git a/src/screens/USDT/UsdtAddWallet.tsx b/src/screens/USDT/UsdtAddWallet.tsx index abc66e173..de7b3a283 100644 --- a/src/screens/USDT/UsdtAddWallet.tsx +++ b/src/screens/USDT/UsdtAddWallet.tsx @@ -134,14 +134,14 @@ const AddUsdtWallet = () => { {usdtWalletText.UsdtPowerdBy} Linking.openURL('https://gasfree.io/home')} > {'GasFree.io'} {' '} {usdtWalletText.keeperDontControl}{' '} Linking.openURL('https://gasfree.io/home')} > diff --git a/tests/components/USDTWalletEntryPoints.test.tsx b/tests/components/USDTWalletEntryPoints.test.tsx new file mode 100644 index 000000000..5803e868d --- /dev/null +++ b/tests/components/USDTWalletEntryPoints.test.tsx @@ -0,0 +1,377 @@ +import React from 'react'; +import { act, fireEvent, render } from '@testing-library/react-native'; +import { useQuery } from '@realm/react'; +import { CommonActions } from '@react-navigation/native'; +import { NetworkType, EntityKind, VisibilityType } from 'src/services/wallets/enums'; +import KeeperSettings from 'src/screens/Home/components/Settings/keeperSettings'; +import USDTWalletCreationModal from 'src/screens/Home/components/Settings/USDTWalletCreationModal'; +import HomeWallet from 'src/screens/Home/components/Wallet/HomeWallet'; +import AddUsdtWallet from 'src/screens/USDT/UsdtAddWallet'; +import UsdtDetails from 'src/screens/USDT/UsdtDetails'; +import RecieveUsdt from 'src/screens/USDT/RecieveUsdt'; +import translations from 'src/context/Localization/language/en.json'; + +const mockDispatch = jest.fn(); +const mockNavigate = jest.fn(); +const mockCreateWallet = jest.fn(); +const mockShowToast = jest.fn(); +let mockNetwork = NetworkType.TESTNET; +const mockWallet = { + id: 'disposable-usdt-wallet', + entityKind: EntityKind.USDT_WALLET, + networkType: NetworkType.TESTNET, + presentationData: { + name: 'Existing USDT', + description: 'Preserved wallet', + visibility: VisibilityType.DEFAULT, + }, + specs: { balance: 0, transactions: [] }, + accountStatus: { gasFreeAddress: 'disposable-gasfree-address', frozen: 0 }, +}; + +jest.mock('@react-navigation/native', () => ({ + ...jest.requireActual('@react-navigation/native'), + useNavigation: () => ({ dispatch: mockDispatch, navigate: mockNavigate, setParams: jest.fn() }), +})); +jest.mock('@gluestack-ui/themed-native-base', () => { + const { View, ScrollView } = require('react-native'); + return { + Box: View, + View, + HStack: View, + VStack: View, + ScrollView, + useColorMode: () => ({ colorMode: 'light' }), + }; +}); +jest.mock('src/context/Localization/LocContext', () => ({ + LocalizationContext: require('react').createContext({ + translations: require('src/context/Localization/language/en.json'), + }), +})); +jest.mock('src/hooks/useUSDTWallets', () => ({ + useUSDTWallets: () => ({ + createWallet: mockCreateWallet, + usdtWallets: [mockWallet], + getWalletById: (id) => (id === mockWallet.id ? mockWallet : null), + }), +})); +jest.mock('src/services/wallets/factories/USDTWalletFactory', () => ({ + USDTWalletSupportedNetwork: 'TESTNET', + USDTWalletType: { DEFAULT: 'DEFAULT', IMPORTED: 'IMPORTED' }, + getAvailableBalanceUSDTWallet: (wallet) => wallet.specs.balance - wallet.accountStatus.frozen, +})); +jest.mock('src/store/hooks', () => ({ + useAppSelector: (select) => + select({ + settings: { bitcoinNetworkType: mockNetwork }, + bhr: { backupAllLoading: false }, + vault: { collaborativeSession: { signers: {} } }, + wallet: { walletSyncing: {} }, + utxos: { pendingDustToast: null }, + }), +})); +jest.mock('react-redux', () => ({ useDispatch: () => jest.fn() })); +jest.mock('src/hooks/useToastMessage', () => ({ + __esModule: true, + default: () => ({ showToast: mockShowToast }), +})); +jest.mock('src/hooks/useSettingKeeper', () => ({ + useSettingKeeper: () => ({ + BackAndRecovery: [], + General: [], + keysAndwallet: [], + Tips: [], + setConfirmPass: jest.fn(), + }), +})); +jest.mock('src/hooks/useWallets', () => ({ __esModule: true, default: () => ({ wallets: [] }) })); +jest.mock('src/hooks/useVault', () => ({ __esModule: true, default: () => ({ allVaults: [] }) })); +jest.mock('src/hooks/useWalletAsset', () => ({ + __esModule: true, + default: () => ({ getWalletCardGradient: () => [], getWalletTags: () => [] }), +})); +jest.mock('src/hooks/useUTXOSpendability', () => ({ + useUTXOSpendability: () => ({ hasDoNotSpendUTXOs: false }), +})); +jest.mock('src/store/reducers/settings', () => ({ setShowTipModal: jest.fn() })); +jest.mock('src/store/reducers/vaults', () => ({ resetCollaborativeSession: jest.fn() })); +jest.mock('src/store/reducers/utxos', () => ({ clearDustToast: jest.fn() })); +jest.mock('src/store/sagaActions/wallets', () => ({ autoSyncWallets: jest.fn() })); +jest.mock('src/services/electrum/client', () => ({ + ELECTRUM_CLIENT: { isClientConnected: false }, +})); +jest.mock('src/utils/service-utilities/config', () => ({ + __esModule: true, + default: { ADDRESS: { settings: '' } }, + KEEPER_WEBSITE_BASE_URL: '', +})); +jest.mock('src/utils/OpenLink', () => jest.fn()); +jest.mock( + 'src/components/KeeperText', + () => + ({ children, ...props }) => + require('react').createElement(require('react-native').Text, props, children) +); +jest.mock( + 'src/components/KeeperTextInput', + () => (props) => require('react').createElement(require('react-native').TextInput, props) +); +jest.mock('src/components/ScreenWrapper', () => ({ children }) => <>{children}); +jest.mock('src/components/CircleIconWrapper', () => () => null); +jest.mock( + 'src/components/WalletHeader', + () => + ({ title }) => + require('react').createElement(require('react-native').Text, null, title) +); +jest.mock('src/components/ThemedSvg.tsx/ThemedSvg', () => () => null); +jest.mock('src/components/ThemedColor/ThemedColor', () => () => '#000'); +jest.mock('src/components/NavButton', () => () => null); +jest.mock('src/components/AppActivityIndicator/ActivityIndicatorView', () => () => null); +jest.mock( + 'src/components/KeeperModal', + () => + ({ visible, title, Content }) => + visible ? ( + <> + {require('react').createElement(require('react-native').Text, null, title)} + {Content && } + + ) : null +); +jest.mock( + 'src/components/Buttons', + () => + ({ primaryText, primaryCallback, primaryDisable }) => + require('react').createElement( + require('react-native').Pressable, + { onPress: primaryCallback, disabled: primaryDisable }, + require('react').createElement(require('react-native').Text, null, primaryText) + ) +); +jest.mock( + 'src/components/Fab', + () => + ({ onPress }) => + require('react').createElement(require('react-native').Pressable, { + onPress, + testID: 'add_wallet', + }) +); +jest.mock('src/screens/Home/components/Settings/Component/PlebContainer', () => () => null); +jest.mock('src/screens/Home/components/Settings/Component/SettingModal', () => () => null); +jest.mock('src/screens/Home/components/Settings/Component/SettingCard', () => ({ items }) => ( + <> + {items.map((item) => + require('react').createElement( + require('react-native').Pressable, + { key: item.title, onPress: item.onPress }, + require('react').createElement(require('react-native').Text, null, item.title) + ) + )} + +)); +jest.mock( + 'src/screens/Home/components/Wallet/WalletCard', + () => + ({ title }) => + require('react').createElement(require('react-native').Text, null, title) +); +jest.mock( + 'src/screens/WalletDetails/components/WalletDetailHeader', + () => + ({ title }) => + require('react').createElement(require('react-native').Text, null, title) +); +jest.mock( + 'src/screens/WalletDetails/components/DetailCards', + () => + ({ sendCallback, receiveCallback }) => + ( + <> + {require('react').createElement( + require('react-native').Pressable, + { onPress: sendCallback }, + require('react').createElement(require('react-native').Text, null, 'Send USDT') + )} + {require('react').createElement( + require('react-native').Pressable, + { onPress: receiveCallback }, + require('react').createElement(require('react-native').Text, null, 'Receive USDT') + )} + + ) +); +jest.mock('src/screens/WalletDetails/components/Transactions', () => () => null); +jest.mock('src/screens/WalletDetails/components/MoreCard', () => () => null); +jest.mock( + 'src/components/KeeperQRCode', + () => + ({ qrData }) => + require('react').createElement(require('react-native').Text, { testID: 'receive_qr' }, qrData) +); +jest.mock( + 'src/components/WalletCopiableData', + () => + ({ data }) => + require('react').createElement( + require('react-native').Text, + { testID: 'receive_address' }, + data + ) +); + +jest.mock('src/assets/images/import.svg', () => () => null); +jest.mock('src/assets/images/wallet-white-small.svg', () => () => null); +jest.mock('src/assets/images/icon_tick.svg', () => () => null); +jest.mock('src/assets/images/toast_error.svg', () => () => null); +jest.mock('src/assets/images/Twitter.svg', () => () => null); +jest.mock('src/assets/images/Twitter-white.svg', () => () => null); +jest.mock('src/assets/images/noster.svg', () => () => null); +jest.mock('src/assets/images/noster-white.svg', () => () => null); +jest.mock('src/assets/images/Telegram.svg', () => () => null); +jest.mock('src/assets/images/Telegram-white.svg', () => () => null); +jest.mock('src/assets/images/supportDeveloper.svg', () => () => null); +jest.mock('src/assets/images/usdt-wallet-logo.svg', () => () => null); +jest.mock('src/assets/images/collaborative_vault_white.svg', () => () => null); +jest.mock('src/assets/images/add_white.svg', () => () => null); +jest.mock('src/assets/images/addWallet_illustration.svg', () => () => null); +jest.mock('src/assets/images/swap.svg', () => () => null); + +describe('USDT Settings entry and existing wallets', () => { + beforeEach(() => { + jest.clearAllMocks(); + jest.useFakeTimers(); + mockNetwork = NetworkType.TESTNET; + (useQuery as jest.Mock).mockReturnValue([{ primaryMnemonic: 'disposable-test-fixture' }]); + }); + afterEach(() => jest.useRealTimers()); + + it('opens create/import from Settings on the supported network', () => { + const screen = render(); + fireEvent.press(screen.getByText(translations.wallet.AddUSDTWallet)); + expect(screen.getByText('Create a new USDT wallet')).toBeTruthy(); + expect(screen.getByText(translations.home.ImportWallet)).toBeTruthy(); + }); + + it('hides the Settings entry on the unsupported network', () => { + mockNetwork = NetworkType.MAINNET; + const screen = render(); + expect(screen.queryByText(translations.wallet.AddUSDTWallet)).toBeNull(); + }); + + it('Home keeps existing USDT wallets accessible while Add Wallet has only Bitcoin choices', () => { + const screen = render(); + fireEvent.press(screen.getByTestId(`wallet_item_${mockWallet.id}`)); + expect(mockNavigate).toHaveBeenCalledWith('usdtDetails', { usdtWalletId: mockWallet.id }); + fireEvent.press(screen.getByTestId('add_wallet')); + expect(screen.getByText(translations.wallet.createWalletDesc)).toBeTruthy(); + expect(screen.getByText(translations.common.collaborativeWallet)).toBeTruthy(); + expect(screen.queryByText(translations.wallet.AddUSDTWallet)).toBeNull(); + expect(screen.queryByText('Create a new USDT wallet')).toBeNull(); + }); + + it('Create dismisses the choice modal and dispatches the registered creation route', () => { + const close = jest.fn(); + const screen = render(); + fireEvent.press(screen.getByText(translations.wallet.createWallet)); + expect(close).toHaveBeenCalledTimes(1); + expect(mockDispatch).toHaveBeenCalledWith(CommonActions.navigate('addUsdtWallet')); + expect(mockCreateWallet).not.toHaveBeenCalled(); + }); + + it('the creation form renders from a valid KeeperApp fixture and creates using its mnemonic', async () => { + mockCreateWallet.mockResolvedValueOnce({ newWallet: mockWallet }); + const screen = render(); + expect(screen.getByText(translations.usdtWalletText.addWalletDetails)).toBeTruthy(); + fireEvent.changeText(screen.getByTestId('input_wallet_name'), ' New USDT '); + await act(async () => fireEvent.press(screen.getByText(translations.wallet.createYourWallet))); + expect(mockCreateWallet).toHaveBeenCalledWith({ + type: 'DEFAULT', + name: 'New USDT', + description: 'USDT wallet', + primaryMnemonic: 'disposable-test-fixture', + }); + act(() => jest.advanceTimersByTime(900)); + expect(mockDispatch).toHaveBeenCalledWith( + CommonActions.navigate({ name: 'Home', params: { selectedOption: 'Wallets' } }) + ); + }); + + it('creation failure remains on the form and shows an error', async () => { + mockCreateWallet.mockResolvedValueOnce({ error: 'Disposable backend unavailable' }); + const screen = render(); + fireEvent.changeText(screen.getByTestId('input_wallet_name'), 'New USDT'); + await act(async () => fireEvent.press(screen.getByText(translations.wallet.createYourWallet))); + expect(mockShowToast).toHaveBeenCalledWith( + 'Failed to create wallet: Disposable backend unavailable', + expect.anything() + ); + expect(mockDispatch).not.toHaveBeenCalled(); + expect(screen.getByText(translations.wallet.createYourWallet)).toBeTruthy(); + }); + + it('Import keeps the USDT seed flow and returns to wallets after success', async () => { + const close = jest.fn(); + mockCreateWallet.mockResolvedValueOnce({ newWallet: mockWallet }); + const screen = render(); + fireEvent.press(screen.getByText(translations.home.ImportWallet)); + const action = mockDispatch.mock.calls[0][0]; + expect(close).toHaveBeenCalledTimes(1); + expect(action.payload.name).toBe('EnterSeedScreen'); + expect(action.payload.params).toMatchObject({ isImport: true, isUSDTWallet: true }); + await act(async () => action.payload.params.importSeedCta('disposable-import-fixture')); + expect(mockCreateWallet).toHaveBeenCalledWith({ + type: 'IMPORTED', + name: 'USDT Wallet', + description: 'Imported USDT Wallet', + importDetails: { mnemonic: 'disposable-import-fixture' }, + }); + act(() => jest.advanceTimersByTime(900)); + expect(mockDispatch).toHaveBeenLastCalledWith( + CommonActions.navigate({ name: 'Home', params: { selectedOption: 'Wallets' } }) + ); + }); + + it('failed import shows an error and does not navigate to Home', async () => { + mockCreateWallet.mockResolvedValueOnce({ + error: 'USDT wallet already exists with the same ID', + }); + const screen = render(); + fireEvent.press(screen.getByText(translations.home.ImportWallet)); + await act(async () => + mockDispatch.mock.calls[0][0].payload.params.importSeedCta('disposable-import-fixture') + ); + act(() => jest.advanceTimersByTime(900)); + expect(mockDispatch).toHaveBeenCalledTimes(1); + expect(mockShowToast).toHaveBeenCalledWith( + 'Failed to import USDT wallet: USDT wallet already exists with the same ID', + expect.anything() + ); + }); + + it('existing wallet details retain send/receive routes and pass the existing wallet', () => { + const screen = render(); + fireEvent.press(screen.getByText('Send USDT')); + fireEvent.press(screen.getByText('Receive USDT')); + expect(mockDispatch).toHaveBeenCalledWith( + CommonActions.navigate('sendUsdt', { usdtWallet: mockWallet }) + ); + expect(mockDispatch).toHaveBeenCalledWith( + CommonActions.navigate('usdtReceive', { usdtWallet: mockWallet }) + ); + }); + + it('receive still uses the GasFree address for the displayed address and QR', () => { + const screen = render(); + expect(screen.getByTestId('receive_qr').props.children).toBe( + mockWallet.accountStatus.gasFreeAddress + ); + expect(screen.getByTestId('receive_address').props.children).toBe( + mockWallet.accountStatus.gasFreeAddress + ); + expect(screen.getByText(translations.usdtWalletText.sendOnlyUsdt)).toBeTruthy(); + expect(mockCreateWallet).not.toHaveBeenCalled(); + }); +});