From 11338089a397594de666e459140ca3353abcac98 Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Thu, 16 Jan 2025 00:09:47 +0100 Subject: [PATCH 01/34] [skip ci] wip: new wallet flow for native --- src/assets/translations/en/main.json | 7 ++ .../WalletProvider/NativeWallet/config.ts | 2 +- .../NewWalletViews/NewWalletViewsSwitch.tsx | 3 + .../wallets/native/NativeStart.tsx | 74 +++++++++++++++++++ 4 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 src/context/WalletProvider/NewWalletViews/wallets/native/NativeStart.tsx diff --git a/src/assets/translations/en/main.json b/src/assets/translations/en/main.json index ecdc73bf8d2..0fac1544536 100644 --- a/src/assets/translations/en/main.json +++ b/src/assets/translations/en/main.json @@ -1871,6 +1871,13 @@ "onboarding": { "skip": "Skip", "shapeshiftWallet": "ShapeShift Wallet", + "createNewWallet": "Create a new wallet", + "haveAKeystore": "Have a keystore?", + "importExisting": "Import existing", + "importFromKeystore": "Import from keystore", + "whatIsShapeshiftWallet": "What is ShapeShift Wallet?", + "yourDecentralizedGateway": "Your decentralization gateway. Trade and earn Bitcoin, Ethereum, Solana and more from a single, secure wallet.", + "crossChainFreedom": "Cross chain freedom. Access the best rates across multiple decentralized exchanges, no middleman required", "selfCustody": { "title": "Your ShapeShift Wallet is Self-Custody", "subTitle": "You hold the keys and you're the only one who can access it.", diff --git a/src/context/WalletProvider/NativeWallet/config.ts b/src/context/WalletProvider/NativeWallet/config.ts index 8d588ebb8ca..1b0d5fdef4c 100644 --- a/src/context/WalletProvider/NativeWallet/config.ts +++ b/src/context/WalletProvider/NativeWallet/config.ts @@ -1,5 +1,5 @@ import type { NativeAdapter } from '@shapeshiftoss/hdwallet-native' -import { FoxIcon } from 'components/Icons/FoxIcon' // Ensure the import path is correct +import { FoxIcon } from 'components/Icons/FoxIcon' import type { SupportedWalletInfo } from 'context/WalletProvider/config' type NativeConfigType = Omit, 'routes'> diff --git a/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx b/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx index 111d91307b5..0e08f648e21 100644 --- a/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx +++ b/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx @@ -23,6 +23,7 @@ import { SnapUpdate } from '../MetaMask/components/SnapUpdate' import { NativeWalletRoutes } from '../types' import { InstalledWalletsSection } from './sections/InstalledWalletsSection' import { MipdBody } from './wallets/mipd/MipdBody' +import { NativeStart } from './wallets/native/NativeStart' const sectionsWidth = { base: 'full', md: '300px' } const containerWidth = { @@ -50,6 +51,8 @@ const RightPanelContent = ({ state: { modalType, isMipdProvider }, } = useWallet() + if (!modalType) return + if (isMipdProvider && modalType) { return ( diff --git a/src/context/WalletProvider/NewWalletViews/wallets/native/NativeStart.tsx b/src/context/WalletProvider/NewWalletViews/wallets/native/NativeStart.tsx new file mode 100644 index 00000000000..74dc6f36bc0 --- /dev/null +++ b/src/context/WalletProvider/NewWalletViews/wallets/native/NativeStart.tsx @@ -0,0 +1,74 @@ +import { Box, Button, Flex, Text as CText, useColorModeValue } from '@chakra-ui/react' +import { useCallback } from 'react' +import { useTranslate } from 'react-polyglot' +import { FoxIcon } from 'components/Icons/FoxIcon' +import { Text } from 'components/Text' + +export const NativeStart = () => { + const translate = useTranslate() + + const headingColor = useColorModeValue('gray.800', 'whiteAlpha.800') + const bodyColor = useColorModeValue('gray.600', 'whiteAlpha.600') + const keystoreBgColor = useColorModeValue('blackAlpha.100', 'whiteAlpha.100') + const mainTextColor = useColorModeValue('gray.700', 'whiteAlpha.800') + + const handleCreateClick = useCallback(() => console.log('TODO: handle create wallet'), []) + const handleImportClick = useCallback(() => console.log('TODO: handle import wallet'), []) + const handleImportKeystoreClick = useCallback( + () => console.log('TODO: handle import from keystore'), + [], + ) + + return ( + + + + + + + + + + + + + {translate('walletProvider.shapeShift.onboarding.haveAKeystore')}{' '} + + + + + + + + + ) +} From 6da6baa6a8592c00556563a2d5a269104e963d3a Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Thu, 16 Jan 2025 00:11:19 +0100 Subject: [PATCH 02/34] [skip ci] feat: handlers --- .../NewWalletViews/wallets/native/NativeStart.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/context/WalletProvider/NewWalletViews/wallets/native/NativeStart.tsx b/src/context/WalletProvider/NewWalletViews/wallets/native/NativeStart.tsx index 74dc6f36bc0..9d14a035154 100644 --- a/src/context/WalletProvider/NewWalletViews/wallets/native/NativeStart.tsx +++ b/src/context/WalletProvider/NewWalletViews/wallets/native/NativeStart.tsx @@ -1,22 +1,28 @@ import { Box, Button, Flex, Text as CText, useColorModeValue } from '@chakra-ui/react' import { useCallback } from 'react' import { useTranslate } from 'react-polyglot' +import { useHistory } from 'react-router-dom' import { FoxIcon } from 'components/Icons/FoxIcon' import { Text } from 'components/Text' +import { NativeWalletRoutes } from 'context/WalletProvider/types' export const NativeStart = () => { const translate = useTranslate() + const history = useHistory() const headingColor = useColorModeValue('gray.800', 'whiteAlpha.800') const bodyColor = useColorModeValue('gray.600', 'whiteAlpha.600') const keystoreBgColor = useColorModeValue('blackAlpha.100', 'whiteAlpha.100') const mainTextColor = useColorModeValue('gray.700', 'whiteAlpha.800') - const handleCreateClick = useCallback(() => console.log('TODO: handle create wallet'), []) - const handleImportClick = useCallback(() => console.log('TODO: handle import wallet'), []) + const handleCreateClick = useCallback(() => history.push(NativeWalletRoutes.Create), [history]) + const handleImportClick = useCallback( + () => history.push(NativeWalletRoutes.ImportSelect), + [history], + ) const handleImportKeystoreClick = useCallback( - () => console.log('TODO: handle import from keystore'), - [], + () => history.push(NativeWalletRoutes.ImportKeystore), + [history], ) return ( From d7b51a1256e3cee7bf9333f66322e8cbdd9495bb Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Thu, 16 Jan 2025 01:25:24 +0100 Subject: [PATCH 03/34] feat: stopping point --- .../components/NativePassword.tsx | 8 +- .../NativeWallet/components/NativeRename.tsx | 5 +- .../NativeWallet/components/NativeSuccess.tsx | 5 +- .../components/NativeTestPhrase.tsx | 8 +- .../WalletProvider/NativeWallet/types.ts | 13 -- .../NewWalletViews/NewWalletViewsSwitch.tsx | 59 +++++++- .../sections/SavedWalletsSection.tsx | 134 ++++++++++++++++++ .../wallets/native/NativeStart.tsx | 2 +- .../WalletProvider/WalletViewsSwitch.tsx | 5 + 9 files changed, 216 insertions(+), 23 deletions(-) create mode 100644 src/context/WalletProvider/NewWalletViews/sections/SavedWalletsSection.tsx diff --git a/src/context/WalletProvider/NativeWallet/components/NativePassword.tsx b/src/context/WalletProvider/NativeWallet/components/NativePassword.tsx index 61be77a68c0..f36a50a13d4 100644 --- a/src/context/WalletProvider/NativeWallet/components/NativePassword.tsx +++ b/src/context/WalletProvider/NativeWallet/components/NativePassword.tsx @@ -17,12 +17,16 @@ import type { FieldValues } from 'react-hook-form' import { useForm } from 'react-hook-form' import { FaEye, FaEyeSlash } from 'react-icons/fa' import { useTranslate } from 'react-polyglot' +import type { RouteComponentProps } from 'react-router-dom' import { Text } from 'components/Text' import { NativeWalletRoutes } from 'context/WalletProvider/types' -import type { NativeSetupProps, NativeWalletValues } from '../types' +import type { LocationState, NativeWalletValues } from '../types' -export const NativePassword = ({ history, location }: NativeSetupProps) => { +export const NativePassword = ({ + history, + location, +}: RouteComponentProps<{}, any, LocationState>) => { const translate = useTranslate() const [showPw, setShowPw] = useState(false) const [showConfirmPw, setShowConfirmPw] = useState(false) diff --git a/src/context/WalletProvider/NativeWallet/components/NativeRename.tsx b/src/context/WalletProvider/NativeWallet/components/NativeRename.tsx index 665d0bf163f..f1da1d70f16 100644 --- a/src/context/WalletProvider/NativeWallet/components/NativeRename.tsx +++ b/src/context/WalletProvider/NativeWallet/components/NativeRename.tsx @@ -14,11 +14,12 @@ import type { FieldValues } from 'react-hook-form' import { useForm } from 'react-hook-form' import { FaEye, FaEyeSlash } from 'react-icons/fa' import { useTranslate } from 'react-polyglot' +import type { RouteComponentProps } from 'react-router-dom' import { Text } from 'components/Text' -import type { NativeSetupProps, NativeWalletValues } from '../types' +import type { NativeWalletValues } from '../types' -export const NativeRename = ({ history, location }: NativeSetupProps) => { +export const NativeRename = ({ history, location }: RouteComponentProps) => { const translate = useTranslate() const [showPw, setShowPw] = useState(false) diff --git a/src/context/WalletProvider/NativeWallet/components/NativeSuccess.tsx b/src/context/WalletProvider/NativeWallet/components/NativeSuccess.tsx index 124e0df011c..d5a439c2395 100644 --- a/src/context/WalletProvider/NativeWallet/components/NativeSuccess.tsx +++ b/src/context/WalletProvider/NativeWallet/components/NativeSuccess.tsx @@ -1,10 +1,11 @@ import { Box, ModalBody, ModalHeader } from '@chakra-ui/react' +import type { RouteComponentProps } from 'react-router-dom' import { Text } from 'components/Text' import { useNativeSuccess } from '../hooks/useNativeSuccess' -import type { NativeSetupProps } from '../types' +import type { LocationState } from '../types' -export const NativeSuccess = ({ location }: NativeSetupProps) => { +export const NativeSuccess = ({ location }: RouteComponentProps<{}, any, LocationState>) => { const { isSuccessful } = useNativeSuccess({ vault: location.state.vault }) return ( diff --git a/src/context/WalletProvider/NativeWallet/components/NativeTestPhrase.tsx b/src/context/WalletProvider/NativeWallet/components/NativeTestPhrase.tsx index 638bf9d83f4..0acf8f38aa3 100644 --- a/src/context/WalletProvider/NativeWallet/components/NativeTestPhrase.tsx +++ b/src/context/WalletProvider/NativeWallet/components/NativeTestPhrase.tsx @@ -7,9 +7,10 @@ import slice from 'lodash/slice' import uniq from 'lodash/uniq' import { useCallback, useEffect, useState } from 'react' import { useTranslate } from 'react-polyglot' +import type { RouteComponentProps } from 'react-router-dom' import { RawText, Text } from 'components/Text' -import type { NativeSetupProps } from '../types' +import type { LocationState } from '../types' const Revocable = Default.Revocable const revocable = Default.revocable @@ -26,7 +27,10 @@ type TestState = { correctAnswerIndex: number } -export const NativeTestPhrase = ({ history, location }: NativeSetupProps) => { +export const NativeTestPhrase = ({ + history, + location, +}: RouteComponentProps<{}, any, LocationState>) => { const translate = useTranslate() const [testState, setTestState] = useState(null) const [hasAlreadySaved, setHasAlreadySaved] = useState(false) diff --git a/src/context/WalletProvider/NativeWallet/types.ts b/src/context/WalletProvider/NativeWallet/types.ts index f8adc9d889a..d2a392aa4a2 100644 --- a/src/context/WalletProvider/NativeWallet/types.ts +++ b/src/context/WalletProvider/NativeWallet/types.ts @@ -1,7 +1,4 @@ import type { Vault } from '@shapeshiftoss/hdwallet-native-vault' -import type React from 'react' -import type { RouteComponentProps } from 'react-router-dom' -import type { ActionTypes } from 'context/WalletProvider/actions' export type NativeWalletValues = { name: string @@ -21,13 +18,3 @@ export interface LocationState { message: string } } - -export interface NativeSetupProps - extends RouteComponentProps< - {}, - any, // history - LocationState - > { - vault: Vault - dispatch: React.Dispatch -} diff --git a/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx b/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx index 0e08f648e21..d7da665132f 100644 --- a/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx +++ b/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx @@ -13,15 +13,23 @@ import { import { useCallback, useEffect, useMemo, useState } from 'react' import { isMobile } from 'react-device-detect' import { useTranslate } from 'react-polyglot' -import { Route, Switch, useHistory } from 'react-router-dom' +import type { RouteComponentProps } from 'react-router-dom' +import { Route, Switch, useHistory, useLocation } from 'react-router-dom' import { Text } from 'components/Text' import { WalletActions } from 'context/WalletProvider/actions' import { useWallet } from 'hooks/useWallet/useWallet' import { SnapInstall } from '../MetaMask/components/SnapInstall' import { SnapUpdate } from '../MetaMask/components/SnapUpdate' +import { EnterPassword } from '../NativeWallet/components/EnterPassword' +import { NativeCreate } from '../NativeWallet/components/NativeCreate' +import { NativeImportKeystore } from '../NativeWallet/components/NativeImportKeystore' +import { NativePassword } from '../NativeWallet/components/NativePassword' +import { NativeSuccess } from '../NativeWallet/components/NativeSuccess' +import type { LocationState } from '../NativeWallet/types' import { NativeWalletRoutes } from '../types' import { InstalledWalletsSection } from './sections/InstalledWalletsSection' +import { SavedWalletsSection } from './sections/SavedWalletsSection' import { MipdBody } from './wallets/mipd/MipdBody' import { NativeStart } from './wallets/native/NativeStart' @@ -51,6 +59,54 @@ const RightPanelContent = ({ state: { modalType, isMipdProvider }, } = useWallet() + const location = useLocation() + + if (location.pathname.startsWith('/native')) { + return ( + + } + /> + + + + ( + )} /> + )} + /> + + + + + ( + )} /> + )} + /> + + ) + } + + // No modal type, and no in-flight native routes - assume enpty state if (!modalType) return if (isMipdProvider && modalType) { @@ -175,6 +231,7 @@ export const NewWalletViewsSwitch = () => { () => ( + void +} + +const WalletCard = ({ wallet, onClick }: WalletCardProps) => { + const handleClick = useCallback(() => onClick(wallet), [onClick, wallet]) + return ( + + + + + + + {wallet.name} + + + + ) +} + +export const SavedWalletsSection = () => { + const [wallets, setWallets] = useState([]) + const localWallet = useLocalWallet() + const { getAdapter, dispatch } = useWallet() + + // TODO(gomes): let's use this PR as an opportunity to remove this digusting IIAFE from copypasta, yes it works but pls + useEffect(() => { + ;(async () => { + const Vault = await import('@shapeshiftoss/hdwallet-native-vault').then(m => m.Vault) + try { + const vaultIds = await Vault.list() + const storedWallets: VaultInfo[] = await Promise.all( + vaultIds.map(async id => { + const meta = await Vault.meta(id) + const name = String(meta?.get('name') ?? id) + return { id, name } + }), + ) + setWallets(storedWallets) + } catch (e) { + console.error(e) + setWallets([]) + } + })() + }, []) + + const handleWalletSelect = useCallback( + async (wallet: VaultInfo) => { + const adapter = await getAdapter(KeyManager.Native) + const deviceId = wallet.id + if (adapter) { + const { name, icon } = NativeConfig + try { + dispatch({ + type: WalletActions.SET_NATIVE_PENDING_DEVICE_ID, + payload: deviceId, + }) + + const walletInstance = await adapter.pairDevice(deviceId) + if (!(await walletInstance?.isInitialized())) { + await walletInstance?.initialize() + } else { + dispatch({ + type: WalletActions.SET_WALLET, + payload: { + wallet: walletInstance, + name, + icon, + deviceId, + meta: { label: wallet.name }, + connectedType: KeyManager.Native, + }, + }) + dispatch({ + type: WalletActions.SET_IS_CONNECTED, + payload: true, + }) + dispatch({ type: WalletActions.RESET_NATIVE_PENDING_DEVICE_ID }) + dispatch({ type: WalletActions.SET_WALLET_MODAL, payload: false }) + } + + localWallet.setLocalWallet({ type: KeyManager.Native, deviceId }) + localWallet.setLocalNativeWalletName(wallet.name) + } catch (e) { + console.error(e) + } + } + }, + [dispatch, getAdapter, localWallet], + ) + + if (!wallets.length) return null + + return ( + + + {wallets.map(wallet => ( + + ))} + + ) +} diff --git a/src/context/WalletProvider/NewWalletViews/wallets/native/NativeStart.tsx b/src/context/WalletProvider/NewWalletViews/wallets/native/NativeStart.tsx index 9d14a035154..fca79d2a44e 100644 --- a/src/context/WalletProvider/NewWalletViews/wallets/native/NativeStart.tsx +++ b/src/context/WalletProvider/NewWalletViews/wallets/native/NativeStart.tsx @@ -69,7 +69,7 @@ export const NativeStart = () => { From b95c538d29729238ca41fbd67c417c8d2976a86d Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Thu, 16 Jan 2025 19:16:23 +0100 Subject: [PATCH 21/34] fix: tests with flag on --- .../WalletProvider/WalletProvider.test.tsx | 7 +++++++ src/test/TestProviders.tsx | 17 +++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/context/WalletProvider/WalletProvider.test.tsx b/src/context/WalletProvider/WalletProvider.test.tsx index 6fe622ca385..69a1c74f4e5 100644 --- a/src/context/WalletProvider/WalletProvider.test.tsx +++ b/src/context/WalletProvider/WalletProvider.test.tsx @@ -34,6 +34,13 @@ vi.mock('@shapeshiftoss/hdwallet-metamask-multichain', () => ({ }, })) +vi.mock('@shapeshiftoss/hdwallet-native-vault', () => ({ + Vault: { + list: vi.fn().mockResolvedValue([]), + meta: vi.fn(), + }, +})) + vi.mock('./useEip1993EventHandler', () => ({ useEip1993EventHandler: vi.fn(), })) diff --git a/src/test/TestProviders.tsx b/src/test/TestProviders.tsx index 3e6822be8a1..0dbb9c9a6f0 100644 --- a/src/test/TestProviders.tsx +++ b/src/test/TestProviders.tsx @@ -1,3 +1,4 @@ +import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import type { PropsWithChildren } from 'react' import React from 'react' import { I18n } from 'react-polyglot' @@ -8,11 +9,15 @@ import { store } from 'state/store' const locale: string = navigator?.language?.split('-')[0] ?? 'en' const messages = translations['en'] +const queryClient = new QueryClient() + export const TestProviders: React.FC = ({ children }) => ( - - - {/* @ts-ignore remove warning */} - {children} - - + + + + {/* @ts-ignore remove warning */} + {children} + + + ) From 2e8d38215c3ec73a22f782d4f3f07df5df3e79a0 Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Thu, 16 Jan 2025 19:24:34 +0100 Subject: [PATCH 22/34] feat: more progress more ion --- src/assets/translations/en/main.json | 3 ++- .../NewWalletViews/NewWalletViewsSwitch.tsx | 2 +- .../sections/InstalledWalletsSection.tsx | 7 +---- .../sections/SavedWalletsSection.tsx | 27 ++++++++++--------- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/assets/translations/en/main.json b/src/assets/translations/en/main.json index d40ffcf3bef..4000be1e93d 100644 --- a/src/assets/translations/en/main.json +++ b/src/assets/translations/en/main.json @@ -188,7 +188,8 @@ "activeAccount": "Active Account", "update": "Update", "apy": "APY", - "tbd": "TBD" + "tbd": "TBD", + "installed": "Installed" }, "consentBanner": { "body": { diff --git a/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx b/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx index 293fb249f6d..6c836520dc5 100644 --- a/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx +++ b/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx @@ -247,11 +247,11 @@ export const NewWalletViewsSwitch = () => { const sections = useMemo( () => ( - + - + {filteredProviders.map(provider => { const isSelected = selectedWalletId === provider.info.rdns return ( diff --git a/src/context/WalletProvider/NewWalletViews/sections/SavedWalletsSection.tsx b/src/context/WalletProvider/NewWalletViews/sections/SavedWalletsSection.tsx index 70288f8c471..0587e25aa27 100644 --- a/src/context/WalletProvider/NewWalletViews/sections/SavedWalletsSection.tsx +++ b/src/context/WalletProvider/NewWalletViews/sections/SavedWalletsSection.tsx @@ -133,20 +133,21 @@ export const SavedWalletsSection = ({ if (!nativeVaultsQuery.data?.length) return null return ( - + <> - {nativeVaultsQuery.data.map(wallet => ( - - ))} - + + {nativeVaultsQuery.data.map(wallet => ( + + ))} + + ) } From 17adcab56a38a200a455f260b6c434c287618163 Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Thu, 16 Jan 2025 19:29:08 +0100 Subject: [PATCH 23/34] feat: add divider --- .../WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx b/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx index 6c836520dc5..34964a4a0f6 100644 --- a/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx +++ b/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx @@ -1,6 +1,7 @@ import { ArrowBackIcon } from '@chakra-ui/icons' import { Box, + Divider, Flex, IconButton, Modal, @@ -251,6 +252,7 @@ export const NewWalletViewsSwitch = () => { selectedWalletId={selectedWalletId} onWalletSelect={handleWalletSelect} /> + Date: Thu, 16 Jan 2025 19:32:01 +0100 Subject: [PATCH 24/34] fix: scrolly bits --- .../WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx b/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx index 34964a4a0f6..77c305fc8af 100644 --- a/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx +++ b/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx @@ -247,7 +247,7 @@ export const NewWalletViewsSwitch = () => { const sections = useMemo( () => ( - + Date: Thu, 16 Jan 2025 19:37:51 +0100 Subject: [PATCH 25/34] feat: truncate long-ass wallet names --- .../NewWalletViews/sections/SavedWalletsSection.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/context/WalletProvider/NewWalletViews/sections/SavedWalletsSection.tsx b/src/context/WalletProvider/NewWalletViews/sections/SavedWalletsSection.tsx index 0587e25aa27..08c4eeefcad 100644 --- a/src/context/WalletProvider/NewWalletViews/sections/SavedWalletsSection.tsx +++ b/src/context/WalletProvider/NewWalletViews/sections/SavedWalletsSection.tsx @@ -43,7 +43,9 @@ const WalletCard = ({ wallet, onClick, isSelected }: WalletCardProps) => { - {wallet.name} + + {wallet.name} + From 50cfde364148b808110f1622b37e11bbbcdaf9aa Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Thu, 16 Jan 2025 19:47:07 +0100 Subject: [PATCH 26/34] feat: slightly adjust styles --- .../WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx b/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx index 77c305fc8af..c7a47fc6e6d 100644 --- a/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx +++ b/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx @@ -247,7 +247,7 @@ export const NewWalletViewsSwitch = () => { const sections = useMemo( () => ( - + { > - + {/* Always display sections for the root route, no matter the viewport */} From e945fcb7d8b144091086bc6af427cafd7af49548 Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Thu, 16 Jan 2025 22:23:58 +0100 Subject: [PATCH 27/34] feat: almost there --- src/assets/translations/en/main.json | 1 + .../NewWalletViews/NewWalletViewsSwitch.tsx | 2 +- .../sections/SavedWalletsSection.tsx | 28 ++++- .../wallets/native/NativeStart.tsx | 104 ++++++++++-------- 4 files changed, 89 insertions(+), 46 deletions(-) diff --git a/src/assets/translations/en/main.json b/src/assets/translations/en/main.json index 4000be1e93d..b38e7119936 100644 --- a/src/assets/translations/en/main.json +++ b/src/assets/translations/en/main.json @@ -1874,6 +1874,7 @@ "shapeshiftWallet": "ShapeShift Wallet", "createNewWallet": "Create a new wallet", "shapeshiftNative": "ShapeShift Native", + "addNewWallet": "Add new wallet", "comingFromThorswap": "Coming from THORSwap?", "importExisting": "Import existing", "importFromKeystore": "Import from keystore", diff --git a/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx b/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx index c7a47fc6e6d..c30c6fd93fb 100644 --- a/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx +++ b/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx @@ -252,7 +252,7 @@ export const NewWalletViewsSwitch = () => { selectedWalletId={selectedWalletId} onWalletSelect={handleWalletSelect} /> - + void }) => { + const buttonBgColor = useColorModeValue('blackAlpha.50', 'whiteAlpha.50') + const localWallet = useLocalWallet() const { getAdapter, dispatch } = useWallet() @@ -132,6 +134,10 @@ export const SavedWalletsSection = ({ [dispatch, getAdapter, localWallet, onWalletSelect], ) + const handleAddNewWalletClick = useCallback(() => { + console.log('TODO') + }, []) + if (!nativeVaultsQuery.data?.length) return null return ( @@ -149,6 +155,24 @@ export const SavedWalletsSection = ({ isSelected={selectedWalletId === wallet.id} /> ))} + + + + + + + + ) diff --git a/src/context/WalletProvider/NewWalletViews/wallets/native/NativeStart.tsx b/src/context/WalletProvider/NewWalletViews/wallets/native/NativeStart.tsx index f817953f8e8..287ec6f97e1 100644 --- a/src/context/WalletProvider/NewWalletViews/wallets/native/NativeStart.tsx +++ b/src/context/WalletProvider/NewWalletViews/wallets/native/NativeStart.tsx @@ -1,5 +1,15 @@ -import { Box, Button, Flex, Text as CText, useColorModeValue } from '@chakra-ui/react' +import { + Box, + Button, + Divider, + Flex, + Icon, + Stack, + Text as CText, + useColorModeValue, +} from '@chakra-ui/react' import { useCallback } from 'react' +import { FaArrowRight } from 'react-icons/fa' import { useTranslate } from 'react-polyglot' import { useHistory } from 'react-router-dom' import { FoxIcon } from 'components/Icons/FoxIcon' @@ -12,7 +22,6 @@ export const NativeStart = () => { const headingColor = useColorModeValue('gray.800', 'whiteAlpha.800') const bodyColor = useColorModeValue('gray.600', 'whiteAlpha.600') - const keystoreBgColor = useColorModeValue('blackAlpha.100', 'whiteAlpha.100') const mainTextColor = useColorModeValue('gray.700', 'whiteAlpha.800') const handleCreateClick = useCallback(() => history.push(NativeWalletRoutes.Create), [history]) @@ -26,55 +35,64 @@ export const NativeStart = () => { ) return ( - - - - + + + + + + + - + + - - + - + + + + {translate('walletProvider.shapeShift.onboarding.comingFromThorswap')}{' '} - - - - - - + ) } From 381c8a229ae28f542eae40677580fa49827f15ce Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Thu, 16 Jan 2025 23:02:17 +0100 Subject: [PATCH 28/34] feat: here we fuarking go --- .../NewWalletViews/NewWalletViewsSwitch.tsx | 21 ++- .../sections/SavedWalletsSection.tsx | 7 +- .../wallets/native/NativeIntro.tsx | 98 ++++++++++++ .../wallets/native/NativeStart.tsx | 149 ++++++++---------- 4 files changed, 182 insertions(+), 93 deletions(-) create mode 100644 src/context/WalletProvider/NewWalletViews/wallets/native/NativeIntro.tsx diff --git a/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx b/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx index c30c6fd93fb..3e9ef9096d7 100644 --- a/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx +++ b/src/context/WalletProvider/NewWalletViews/NewWalletViewsSwitch.tsx @@ -37,6 +37,7 @@ import { NativeWalletRoutes } from '../types' import { InstalledWalletsSection } from './sections/InstalledWalletsSection' import { SavedWalletsSection } from './sections/SavedWalletsSection' import { MipdBody } from './wallets/mipd/MipdBody' +import { NativeIntro } from './wallets/native/NativeIntro' import { NativeStart } from './wallets/native/NativeStart' const sectionsWidth = { base: 'full', md: '300px' } @@ -58,6 +59,13 @@ type RightPanelContentProps = { const nativeRoutes = ( + } + /> } @@ -76,7 +83,6 @@ const nativeRoutes = ( } @@ -87,22 +93,16 @@ const nativeRoutes = ( } /> - + } @@ -110,7 +110,6 @@ const nativeRoutes = ( } @@ -132,7 +131,7 @@ const RightPanelContent = ({ if (location.pathname.startsWith('/native')) return nativeRoutes // No modal type, and no in-flight native routes - assume enpty state - if (!modalType || modalType === 'native' || location.pathname === '/') return + if (!modalType || modalType === 'native' || location.pathname === '/') return if (isMipdProvider && modalType) { return ( diff --git a/src/context/WalletProvider/NewWalletViews/sections/SavedWalletsSection.tsx b/src/context/WalletProvider/NewWalletViews/sections/SavedWalletsSection.tsx index f4eb7eb6609..512b27fda63 100644 --- a/src/context/WalletProvider/NewWalletViews/sections/SavedWalletsSection.tsx +++ b/src/context/WalletProvider/NewWalletViews/sections/SavedWalletsSection.tsx @@ -2,12 +2,14 @@ import { Box, Button, Flex, Icon, Stack, Text as CText, useColorModeValue } from import { useQuery } from '@tanstack/react-query' import { useCallback } from 'react' import { FaPlus, FaWallet } from 'react-icons/fa' +import { useHistory } from 'react-router-dom' import { FoxIcon } from 'components/Icons/FoxIcon' import { Text } from 'components/Text' import { WalletActions } from 'context/WalletProvider/actions' import { KeyManager } from 'context/WalletProvider/KeyManager' import { useLocalWallet } from 'context/WalletProvider/local-wallet' import { NativeConfig } from 'context/WalletProvider/NativeWallet/config' +import { NativeWalletRoutes } from 'context/WalletProvider/types' import { useWallet } from 'hooks/useWallet/useWallet' type VaultInfo = { @@ -61,6 +63,7 @@ export const SavedWalletsSection = ({ }) => { const buttonBgColor = useColorModeValue('blackAlpha.50', 'whiteAlpha.50') + const history = useHistory() const localWallet = useLocalWallet() const { getAdapter, dispatch } = useWallet() @@ -135,8 +138,8 @@ export const SavedWalletsSection = ({ ) const handleAddNewWalletClick = useCallback(() => { - console.log('TODO') - }, []) + history.push(NativeWalletRoutes.Connect) + }, [history]) if (!nativeVaultsQuery.data?.length) return null diff --git a/src/context/WalletProvider/NewWalletViews/wallets/native/NativeIntro.tsx b/src/context/WalletProvider/NewWalletViews/wallets/native/NativeIntro.tsx new file mode 100644 index 00000000000..89a193831cd --- /dev/null +++ b/src/context/WalletProvider/NewWalletViews/wallets/native/NativeIntro.tsx @@ -0,0 +1,98 @@ +import { + Box, + Button, + Divider, + Flex, + Icon, + Stack, + Text as CText, + useColorModeValue, +} from '@chakra-ui/react' +import { useCallback } from 'react' +import { FaArrowRight } from 'react-icons/fa' +import { useTranslate } from 'react-polyglot' +import { useHistory } from 'react-router-dom' +import { FoxIcon } from 'components/Icons/FoxIcon' +import { Text } from 'components/Text' +import { NativeWalletRoutes } from 'context/WalletProvider/types' + +export const NativeIntro = () => { + const translate = useTranslate() + const history = useHistory() + + const headingColor = useColorModeValue('gray.800', 'whiteAlpha.800') + const bodyColor = useColorModeValue('gray.600', 'whiteAlpha.600') + const mainTextColor = useColorModeValue('gray.700', 'whiteAlpha.800') + + const handleCreateClick = useCallback(() => history.push(NativeWalletRoutes.Create), [history]) + const handleImportClick = useCallback( + () => history.push(NativeWalletRoutes.ImportSelect), + [history], + ) + const handleImportKeystoreClick = useCallback( + () => history.push(NativeWalletRoutes.ImportKeystore), + [history], + ) + + return ( + + + + + + + + + + + + + + + + + + + {translate('walletProvider.shapeShift.onboarding.comingFromThorswap')}{' '} + + + + + ) +} diff --git a/src/context/WalletProvider/NewWalletViews/wallets/native/NativeStart.tsx b/src/context/WalletProvider/NewWalletViews/wallets/native/NativeStart.tsx index 287ec6f97e1..2d1cab2c1d8 100644 --- a/src/context/WalletProvider/NewWalletViews/wallets/native/NativeStart.tsx +++ b/src/context/WalletProvider/NewWalletViews/wallets/native/NativeStart.tsx @@ -1,98 +1,87 @@ -import { - Box, - Button, - Divider, - Flex, - Icon, - Stack, - Text as CText, - useColorModeValue, -} from '@chakra-ui/react' +import { ArrowForwardIcon } from '@chakra-ui/icons' +import type { ResponsiveValue } from '@chakra-ui/react' +import { Button, Divider, Flex, ModalBody, ModalHeader, Stack } from '@chakra-ui/react' +import type { Property } from 'csstype' import { useCallback } from 'react' -import { FaArrowRight } from 'react-icons/fa' import { useTranslate } from 'react-polyglot' -import { useHistory } from 'react-router-dom' -import { FoxIcon } from 'components/Icons/FoxIcon' +import type { RouteComponentProps } from 'react-router' import { Text } from 'components/Text' import { NativeWalletRoutes } from 'context/WalletProvider/types' +import { useFeatureFlag } from 'hooks/useFeatureFlag/useFeatureFlag' -export const NativeStart = () => { - const translate = useTranslate() - const history = useHistory() +const directionProp: ResponsiveValue = ['column', 'row'] +const mlProp = [0, 1.5] +const arrowForwardIcon = - const headingColor = useColorModeValue('gray.800', 'whiteAlpha.800') - const bodyColor = useColorModeValue('gray.600', 'whiteAlpha.600') - const mainTextColor = useColorModeValue('gray.700', 'whiteAlpha.800') +export const NativeStart = ({ history }: RouteComponentProps) => { + const isShapeShiftMobileWalletEnabled = useFeatureFlag('ShapeShiftMobileWallet') + const translate = useTranslate() - const handleCreateClick = useCallback(() => history.push(NativeWalletRoutes.Create), [history]) + const handleCreate = useCallback(() => history.push(NativeWalletRoutes.Create), [history]) const handleImportClick = useCallback( () => history.push(NativeWalletRoutes.ImportSelect), [history], ) - const handleImportKeystoreClick = useCallback( - () => history.push(NativeWalletRoutes.ImportKeystore), - [history], - ) + const handleLogin = useCallback(() => history.push(NativeWalletRoutes.LegacyLogin), [history]) return ( - - - - - - - - - - - - - - - - - - - {translate('walletProvider.shapeShift.onboarding.comingFromThorswap')}{' '} + <> + + + + + + + + - - - + {isShapeShiftMobileWalletEnabled && ( + <> + + + + + + + )} + + + ) } From 1604511a3824074746a4c1c0d438e17d33e20c3c Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Thu, 16 Jan 2025 23:54:11 +0100 Subject: [PATCH 29/34] feat: cleanup --- .../wallets/native/NativeStart.tsx | 35 +------------------ 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/src/context/WalletProvider/NewWalletViews/wallets/native/NativeStart.tsx b/src/context/WalletProvider/NewWalletViews/wallets/native/NativeStart.tsx index 2d1cab2c1d8..efd167bb49d 100644 --- a/src/context/WalletProvider/NewWalletViews/wallets/native/NativeStart.tsx +++ b/src/context/WalletProvider/NewWalletViews/wallets/native/NativeStart.tsx @@ -1,28 +1,18 @@ import { ArrowForwardIcon } from '@chakra-ui/icons' -import type { ResponsiveValue } from '@chakra-ui/react' -import { Button, Divider, Flex, ModalBody, ModalHeader, Stack } from '@chakra-ui/react' -import type { Property } from 'csstype' +import { Button, Divider, ModalBody, ModalHeader, Stack } from '@chakra-ui/react' import { useCallback } from 'react' -import { useTranslate } from 'react-polyglot' import type { RouteComponentProps } from 'react-router' import { Text } from 'components/Text' import { NativeWalletRoutes } from 'context/WalletProvider/types' -import { useFeatureFlag } from 'hooks/useFeatureFlag/useFeatureFlag' -const directionProp: ResponsiveValue = ['column', 'row'] -const mlProp = [0, 1.5] const arrowForwardIcon = export const NativeStart = ({ history }: RouteComponentProps) => { - const isShapeShiftMobileWalletEnabled = useFeatureFlag('ShapeShiftMobileWallet') - const translate = useTranslate() - const handleCreate = useCallback(() => history.push(NativeWalletRoutes.Create), [history]) const handleImportClick = useCallback( () => history.push(NativeWalletRoutes.ImportSelect), [history], ) - const handleLogin = useCallback(() => history.push(NativeWalletRoutes.LegacyLogin), [history]) return ( <> @@ -57,29 +47,6 @@ export const NativeStart = ({ history }: RouteComponentProps) => { > - {isShapeShiftMobileWalletEnabled && ( - <> - - - - - - - )} From 84191d75bb13654b10f5d3391773f31ca48fb2af Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Thu, 16 Jan 2025 23:54:50 +0100 Subject: [PATCH 30/34] feat: more cleanup --- .../WalletProvider/NewWalletViews/wallets/mipd/MipdBody.tsx | 1 - .../NewWalletViews/wallets/native/NativeStart.tsx | 2 -- 2 files changed, 3 deletions(-) diff --git a/src/context/WalletProvider/NewWalletViews/wallets/mipd/MipdBody.tsx b/src/context/WalletProvider/NewWalletViews/wallets/mipd/MipdBody.tsx index 84f05efe634..5535a4430b2 100644 --- a/src/context/WalletProvider/NewWalletViews/wallets/mipd/MipdBody.tsx +++ b/src/context/WalletProvider/NewWalletViews/wallets/mipd/MipdBody.tsx @@ -211,7 +211,6 @@ export const MipdBody = ({ rdns, isLoading, error, setIsLoading, setError }: Mip loadingText={translate('common.pairing')} spinner={spinner} onClick={pairDevice} - data-test='wallet-pair-button' > {translate('walletProvider.mipd.connect.button')} diff --git a/src/context/WalletProvider/NewWalletViews/wallets/native/NativeStart.tsx b/src/context/WalletProvider/NewWalletViews/wallets/native/NativeStart.tsx index efd167bb49d..b5765bd2b4d 100644 --- a/src/context/WalletProvider/NewWalletViews/wallets/native/NativeStart.tsx +++ b/src/context/WalletProvider/NewWalletViews/wallets/native/NativeStart.tsx @@ -31,7 +31,6 @@ export const NativeStart = ({ history }: RouteComponentProps) => { justifyContent='space-between' rightIcon={arrowForwardIcon} onClick={handleCreate} - data-test='wallet-native-create-button' > @@ -43,7 +42,6 @@ export const NativeStart = ({ history }: RouteComponentProps) => { justifyContent='space-between' rightIcon={arrowForwardIcon} onClick={handleImportClick} - data-test='wallet-native-import-button' > From c46c1eefa6b1a04b160e17a1a8ca7f6b8fcc0e3d Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Thu, 16 Jan 2025 23:58:04 +0100 Subject: [PATCH 31/34] feat: more cleanup --- src/context/WalletProvider/WalletViewsSwitch.tsx | 5 ----- src/test/TestProviders.tsx | 1 - 2 files changed, 6 deletions(-) diff --git a/src/context/WalletProvider/WalletViewsSwitch.tsx b/src/context/WalletProvider/WalletViewsSwitch.tsx index b9704077bba..65a2566231a 100644 --- a/src/context/WalletProvider/WalletViewsSwitch.tsx +++ b/src/context/WalletProvider/WalletViewsSwitch.tsx @@ -92,11 +92,6 @@ export const WalletViewsSwitch = () => { await cancelWalletRequests() }, [cancelWalletRequests, dispatch, history]) - useEffect(() => { - // Reset on mount - dispatch({ type: WalletActions.SET_INITIAL_ROUTE, payload: '' }) - }, [dispatch]) - useEffect(() => { if (initialRoute) { history.push(initialRoute) diff --git a/src/test/TestProviders.tsx b/src/test/TestProviders.tsx index 0dbb9c9a6f0..cc2d31f6a99 100644 --- a/src/test/TestProviders.tsx +++ b/src/test/TestProviders.tsx @@ -15,7 +15,6 @@ export const TestProviders: React.FC = ({ children }) => ( - {/* @ts-ignore remove warning */} {children} From 78485394d1bb00898f5bc4426e6ab315c2349a2d Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Thu, 16 Jan 2025 23:59:14 +0100 Subject: [PATCH 32/34] feat: last cleanup i swear --- src/theme/semanticTokens.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/theme/semanticTokens.ts b/src/theme/semanticTokens.ts index f5b7f0915b5..7e6aa3c2a2d 100644 --- a/src/theme/semanticTokens.ts +++ b/src/theme/semanticTokens.ts @@ -65,11 +65,11 @@ export const semanticTokens = { _dark: 'darkNeutral.900', }, hover: { - default: 'gray.150', + default: 'gray.50', _dark: 'darkNeutral.800', }, pressed: { - default: 'gray.250', + default: 'gray.150', _dark: 'darkNeutral.900', }, }, From f7b4b16f1b5245a11a77f076cae0a242120004c0 Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Fri, 17 Jan 2025 00:03:10 +0100 Subject: [PATCH 33/34] Revert "feat: last cleanup i swear" This reverts commit 78485394d1bb00898f5bc4426e6ab315c2349a2d. --- src/theme/semanticTokens.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/theme/semanticTokens.ts b/src/theme/semanticTokens.ts index 7e6aa3c2a2d..f5b7f0915b5 100644 --- a/src/theme/semanticTokens.ts +++ b/src/theme/semanticTokens.ts @@ -65,11 +65,11 @@ export const semanticTokens = { _dark: 'darkNeutral.900', }, hover: { - default: 'gray.50', + default: 'gray.150', _dark: 'darkNeutral.800', }, pressed: { - default: 'gray.150', + default: 'gray.250', _dark: 'darkNeutral.900', }, }, From 3234de0c84060f155fd82794057399e3cd854705 Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Fri, 17 Jan 2025 14:07:05 +0100 Subject: [PATCH 34/34] feat: extract hdwalletNativeVaultsList queryKey / queryFn --- .../NativeWallet/components/NativeSuccess.tsx | 5 ++++- .../sections/SavedWalletsSection.tsx | 18 ++---------------- src/react-queries/queries/common.ts | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/context/WalletProvider/NativeWallet/components/NativeSuccess.tsx b/src/context/WalletProvider/NativeWallet/components/NativeSuccess.tsx index ee6340f477c..9c1538bc8d2 100644 --- a/src/context/WalletProvider/NativeWallet/components/NativeSuccess.tsx +++ b/src/context/WalletProvider/NativeWallet/components/NativeSuccess.tsx @@ -1,5 +1,6 @@ import { Box, ModalBody, ModalHeader } from '@chakra-ui/react' import { useQueryClient } from '@tanstack/react-query' +import { reactQueries } from 'react-queries' import { Text } from 'components/Text' import { useNativeSuccess } from '../hooks/useNativeSuccess' @@ -9,7 +10,9 @@ export const NativeSuccess = ({ location }: NativeSetupProps) => { const queryClient = useQueryClient() const { isSuccessful } = useNativeSuccess({ vault: location.state.vault }) - queryClient.invalidateQueries({ queryKey: ['hdwalletNativeVaultsList'] }) + queryClient.invalidateQueries({ + queryKey: reactQueries.common.hdwalletNativeVaultsList().queryKey, + }) return ( <> diff --git a/src/context/WalletProvider/NewWalletViews/sections/SavedWalletsSection.tsx b/src/context/WalletProvider/NewWalletViews/sections/SavedWalletsSection.tsx index 512b27fda63..5b859765fdf 100644 --- a/src/context/WalletProvider/NewWalletViews/sections/SavedWalletsSection.tsx +++ b/src/context/WalletProvider/NewWalletViews/sections/SavedWalletsSection.tsx @@ -2,6 +2,7 @@ import { Box, Button, Flex, Icon, Stack, Text as CText, useColorModeValue } from import { useQuery } from '@tanstack/react-query' import { useCallback } from 'react' import { FaPlus, FaWallet } from 'react-icons/fa' +import { reactQueries } from 'react-queries' import { useHistory } from 'react-router-dom' import { FoxIcon } from 'components/Icons/FoxIcon' import { Text } from 'components/Text' @@ -68,22 +69,7 @@ export const SavedWalletsSection = ({ const { getAdapter, dispatch } = useWallet() const nativeVaultsQuery = useQuery({ - queryKey: ['hdwalletNativeVaultsList'], - queryFn: async () => { - const Vault = await import('@shapeshiftoss/hdwallet-native-vault').then(m => m.Vault) - - const storedWallets: VaultInfo[] = await Vault.list().then(vaultIds => - Promise.all( - vaultIds.map(async id => { - const meta = await Vault.meta(id) - const name = String(meta?.get('name') ?? id) - return { id, name } - }), - ), - ) - - return storedWallets - }, + ...reactQueries.common.hdwalletNativeVaultsList(), refetchOnMount: true, }) diff --git a/src/react-queries/queries/common.ts b/src/react-queries/queries/common.ts index e3d7c0d888d..aba30e56f12 100644 --- a/src/react-queries/queries/common.ts +++ b/src/react-queries/queries/common.ts @@ -101,4 +101,22 @@ export const common = createQueryKeys('common', { }) => ({ queryKey: ['evmFees', to, chainId, data, value, from], }), + hdwalletNativeVaultsList: () => ({ + queryKey: ['hdwalletNativeVaultsList'], + queryFn: async () => { + const Vault = await import('@shapeshiftoss/hdwallet-native-vault').then(m => m.Vault) + + const storedWallets = await Vault.list().then(vaultIds => + Promise.all( + vaultIds.map(async id => { + const meta = await Vault.meta(id) + const name = String(meta?.get('name') ?? id) + return { id, name } + }), + ), + ) + + return storedWallets + }, + }), })