Skip to content

Commit

Permalink
fix: Hardware activeate aptos token (#1649)
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteZhang1024 authored Sep 27, 2022
1 parent 354322e commit 6e1507c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const Done: FC<EnableLocalAuthenticationProps> = ({
const navigation = useNavigation();

useEffect(() => {
if (password) {
if (accountId && networkId && tokenId) {
(async () => {
try {
const result = await backgroundApiProxy.engine.activateToken(
Expand Down Expand Up @@ -73,7 +73,7 @@ type NavigationProps = NativeStackScreenProps<

const ActivateTokenAuthModal: FC<NavigationProps> = ({ route }) => {
const intl = useIntl();
const { accountId, networkId, tokenId, onSuccess, onFailure } =
const { walletId, accountId, networkId, tokenId, onSuccess, onFailure } =
route.params || {};

return (
Expand All @@ -86,7 +86,7 @@ const ActivateTokenAuthModal: FC<NavigationProps> = ({ route }) => {
hidePrimaryAction
>
<Protected
walletId={null}
walletId={walletId}
skipSavePassword
field={ValidationFields.Payment}
>
Expand Down
17 changes: 14 additions & 3 deletions packages/kit/src/views/ManageTokens/AddToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<NavigationProps>();
const { address, logoURI } = useRouteParams();
Expand Down Expand Up @@ -278,6 +281,7 @@ function AddTokenModal() {
);
if (vaultSettings?.activateTokenRequired) {
navigation.navigate(ManageTokenRoutes.ActivateToken, {
walletId,
accountId: activeAccount?.id,
networkId: activeNetwork?.id,
tokenId: address,
Expand All @@ -289,7 +293,14 @@ function AddTokenModal() {
addAccountToken();
}
}
}, [activeAccount, activeNetwork, addAccountToken, address, navigation]);
}, [
activeAccount,
activeNetwork,
addAccountToken,
address,
navigation,
walletId,
]);

return (
<ViewTokenModal
Expand Down
10 changes: 7 additions & 3 deletions packages/kit/src/views/ManageTokens/CustomToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ export const AddCustomToken: FC<NavigationProps> = ({ 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();
Expand Down Expand Up @@ -116,6 +119,7 @@ export const AddCustomToken: FC<NavigationProps> = ({ route }) => {
params: {
screen: ManageTokenRoutes.ActivateToken,
params: {
walletId,
accountId: $accountId,
networkId: $networkId,
tokenId,
Expand All @@ -130,7 +134,7 @@ export const AddCustomToken: FC<NavigationProps> = ({ route }) => {
}
}
},
[activeNetwork, activeAccount, navigation, onAddToken],
[activeNetwork, activeAccount, navigation, walletId, onAddToken],
);

const onSearch = useCallback(
Expand Down
12 changes: 10 additions & 2 deletions packages/kit/src/views/ManageTokens/Listing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ const ListRenderToken: FC<ListRenderTokenProps> = ({
const intl = useIntl();
const toast = useToast();
const navigation = useNavigation<NavigationProps>();
const { accountId, networkId } = useActiveWalletAccount();
const { walletId, accountId, networkId } = useActiveWalletAccount();
const accountTokens = useAccountTokens(networkId, accountId);
const hideSmallBalance = useAppSelector((s) => s.settings.hideSmallBalance);

Expand Down Expand Up @@ -348,6 +348,7 @@ const ListRenderToken: FC<ListRenderTokenProps> = ({
);
if (vaultSettings?.activateTokenRequired) {
navigation.navigate(ManageTokenRoutes.ActivateToken, {
walletId,
accountId,
networkId,
tokenId: item.tokenIdOnNetwork,
Expand All @@ -359,7 +360,14 @@ const ListRenderToken: FC<ListRenderTokenProps> = ({
onAddToken();
}
}
}, [accountId, item.tokenIdOnNetwork, navigation, networkId, onAddToken]);
}, [
walletId,
accountId,
item.tokenIdOnNetwork,
navigation,
networkId,
onAddToken,
]);

const onDetail = useCallback(() => {
const routeName = isOwned
Expand Down
1 change: 1 addition & 0 deletions packages/kit/src/views/ManageTokens/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type ManageTokenRoutesParams = {
}
| { query: string };
[ManageTokenRoutes.ActivateToken]: {
walletId: string;
accountId: string;
networkId: string;
tokenId: string;
Expand Down

0 comments on commit 6e1507c

Please sign in to comment.