From 6e1507cc2bde89bdabd646a530afc257c304e509 Mon Sep 17 00:00:00 2001 From: ByteZhang Date: Tue, 27 Sep 2022 16:49:42 +0800 Subject: [PATCH] fix: Hardware activeate aptos token (#1649) --- .../ManageTokens/ActivateTokenAuthModal.tsx | 6 +++--- .../kit/src/views/ManageTokens/AddToken.tsx | 17 ++++++++++++++--- .../kit/src/views/ManageTokens/CustomToken.tsx | 10 +++++++--- packages/kit/src/views/ManageTokens/Listing.tsx | 12 ++++++++++-- packages/kit/src/views/ManageTokens/types.ts | 1 + 5 files changed, 35 insertions(+), 11 deletions(-) diff --git a/packages/kit/src/views/ManageTokens/ActivateTokenAuthModal.tsx b/packages/kit/src/views/ManageTokens/ActivateTokenAuthModal.tsx index e608959e898..bf2f81cfae8 100644 --- a/packages/kit/src/views/ManageTokens/ActivateTokenAuthModal.tsx +++ b/packages/kit/src/views/ManageTokens/ActivateTokenAuthModal.tsx @@ -35,7 +35,7 @@ const Done: FC = ({ const navigation = useNavigation(); useEffect(() => { - if (password) { + if (accountId && networkId && tokenId) { (async () => { try { const result = await backgroundApiProxy.engine.activateToken( @@ -73,7 +73,7 @@ type NavigationProps = NativeStackScreenProps< const ActivateTokenAuthModal: FC = ({ route }) => { const intl = useIntl(); - const { accountId, networkId, tokenId, onSuccess, onFailure } = + const { walletId, accountId, networkId, tokenId, onSuccess, onFailure } = route.params || {}; return ( @@ -86,7 +86,7 @@ const ActivateTokenAuthModal: FC = ({ route }) => { hidePrimaryAction > diff --git a/packages/kit/src/views/ManageTokens/AddToken.tsx b/packages/kit/src/views/ManageTokens/AddToken.tsx index 393beee2e90..d02e4230fc9 100644 --- a/packages/kit/src/views/ManageTokens/AddToken.tsx +++ b/packages/kit/src/views/ManageTokens/AddToken.tsx @@ -234,8 +234,11 @@ function ViewTokenModal(props: IViewTokenModalProps) { function AddTokenModal() { const toast = useToast(); - const { account: activeAccount, network: activeNetwork } = - useActiveWalletAccount(); + const { + walletId, + account: activeAccount, + network: activeNetwork, + } = useActiveWalletAccount(); const intl = useIntl(); const navigation = useNavigation(); const { address, logoURI } = useRouteParams(); @@ -278,6 +281,7 @@ function AddTokenModal() { ); if (vaultSettings?.activateTokenRequired) { navigation.navigate(ManageTokenRoutes.ActivateToken, { + walletId, accountId: activeAccount?.id, networkId: activeNetwork?.id, tokenId: address, @@ -289,7 +293,14 @@ function AddTokenModal() { addAccountToken(); } } - }, [activeAccount, activeNetwork, addAccountToken, address, navigation]); + }, [ + activeAccount, + activeNetwork, + addAccountToken, + address, + navigation, + walletId, + ]); return ( = ({ route }) => { const navigation = useNavigation(); const [isSearching, setSearching] = useState(false); const [inputDisabled, setInputDisabled] = useState(false); - const { account: activeAccount, network: defaultNetwork } = - useActiveWalletAccount(); + const { + walletId, + account: activeAccount, + network: defaultNetwork, + } = useActiveWalletAccount(); const activeNetwork = useNetwork(networkId ?? null) ?? defaultNetwork; const { accountTokensMap } = useManageTokens(); const isSmallScreen = useIsVerticalLayout(); @@ -116,6 +119,7 @@ export const AddCustomToken: FC = ({ route }) => { params: { screen: ManageTokenRoutes.ActivateToken, params: { + walletId, accountId: $accountId, networkId: $networkId, tokenId, @@ -130,7 +134,7 @@ export const AddCustomToken: FC = ({ route }) => { } } }, - [activeNetwork, activeAccount, navigation, onAddToken], + [activeNetwork, activeAccount, navigation, walletId, onAddToken], ); const onSearch = useCallback( diff --git a/packages/kit/src/views/ManageTokens/Listing.tsx b/packages/kit/src/views/ManageTokens/Listing.tsx index c9118837c48..89eae2bd05c 100644 --- a/packages/kit/src/views/ManageTokens/Listing.tsx +++ b/packages/kit/src/views/ManageTokens/Listing.tsx @@ -265,7 +265,7 @@ const ListRenderToken: FC = ({ const intl = useIntl(); const toast = useToast(); const navigation = useNavigation(); - const { accountId, networkId } = useActiveWalletAccount(); + const { walletId, accountId, networkId } = useActiveWalletAccount(); const accountTokens = useAccountTokens(networkId, accountId); const hideSmallBalance = useAppSelector((s) => s.settings.hideSmallBalance); @@ -348,6 +348,7 @@ const ListRenderToken: FC = ({ ); if (vaultSettings?.activateTokenRequired) { navigation.navigate(ManageTokenRoutes.ActivateToken, { + walletId, accountId, networkId, tokenId: item.tokenIdOnNetwork, @@ -359,7 +360,14 @@ const ListRenderToken: FC = ({ onAddToken(); } } - }, [accountId, item.tokenIdOnNetwork, navigation, networkId, onAddToken]); + }, [ + walletId, + accountId, + item.tokenIdOnNetwork, + navigation, + networkId, + onAddToken, + ]); const onDetail = useCallback(() => { const routeName = isOwned diff --git a/packages/kit/src/views/ManageTokens/types.ts b/packages/kit/src/views/ManageTokens/types.ts index cd5b096bc90..36051182ba3 100644 --- a/packages/kit/src/views/ManageTokens/types.ts +++ b/packages/kit/src/views/ManageTokens/types.ts @@ -26,6 +26,7 @@ export type ManageTokenRoutesParams = { } | { query: string }; [ManageTokenRoutes.ActivateToken]: { + walletId: string; accountId: string; networkId: string; tokenId: string;