Skip to content

Commit

Permalink
fix: check whether tron is enabled or not when new wallets are creating
Browse files Browse the repository at this point in the history
  • Loading branch information
siandreev committed Dec 27, 2024
1 parent 56b37a0 commit 0468bb1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/entries/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class AccountTonMnemonic extends TonMnemonic {
activeTonWalletId: WalletId;
tonWallets: TonWalletStandard[];
mnemonicType: MnemonicType;
networks: {
networks?: {
tron: TronWallet;
};
}) {
Expand Down
14 changes: 10 additions & 4 deletions packages/core/src/service/walletService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export const createStandardTonAccountByMnemonic = async (
options: {
versions?: WalletVersion[];
auth: AuthPassword | Omit<AuthKeychain, 'keychainStoreKey'>;
generateTronWallet?: boolean;
}
) => {
const { name, emoji, publicKey, walletAuth, walletIdToActivate, wallets, tronWallet } =
Expand All @@ -255,9 +256,11 @@ export const createStandardTonAccountByMnemonic = async (
activeTonWalletId: walletIdToActivate,
tonWallets: wallets,
mnemonicType,
networks: {
tron: tronWallet
}
networks: options?.generateTronWallet
? {
tron: tronWallet
}
: undefined
});
};

Expand Down Expand Up @@ -549,6 +552,7 @@ export const createMAMAccountByMnemonic = async (
options: {
selectedDerivations?: number[];
auth: AuthPassword | Omit<AuthKeychain, 'keychainStoreKey'>;
generateTronWallet?: boolean;
}
) => {
const rootAccount = await TonKeychainRoot.fromMnemonic(rootMnemonic, {
Expand Down Expand Up @@ -617,7 +621,9 @@ export const createMAMAccountByMnemonic = async (
index: w.derivationIndex,
tonWallets,
activeTonWalletId: tonWallets[0].id,
tronWallet: await tronWalletByTonMnemonic(w.tonAccount.mnemonics)
tronWallet: options?.generateTronWallet
? await tronWalletByTonMnemonic(w.tonAccount.mnemonics)
: undefined
},
shouldAdd: w.shouldAdd
};
Expand Down
9 changes: 6 additions & 3 deletions packages/uikit/src/pages/import/ImportExistingWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { FinalView } from './Password';
import { Subscribe } from './Subscribe';
import {
useAccountsState,
useActiveTonNetwork,
useCreateAccountMAM,
useCreateAccountMnemonic,
useMutateRenameAccount,
Expand Down Expand Up @@ -44,12 +43,14 @@ import {
} from '@tonkeeper/core/dist/service/mnemonicService';
import { MnemonicType } from '@tonkeeper/core/dist/entries/password';
import { Network } from '@tonkeeper/core/dist/entries/network';
import { useIsTronEnabledGlobally } from '../../state/tron/tron';

const useProcessMnemonic = () => {
const context = useAppContext();
const fiat = useUserFiat();
const sdk = useAppSdk();
const accounts = useAccountsState();
const isTronEnabled = useIsTronEnabledGlobally();

return useMutation<
{
Expand Down Expand Up @@ -123,7 +124,8 @@ const useProcessMnemonic = () => {
WalletVersion.V4R2,
WalletVersion.V3R2,
WalletVersion.V3R1
]
],
generateTronWallet: isTronEnabled
}
);

Expand Down Expand Up @@ -171,7 +173,8 @@ const useProcessMnemonic = () => {
WalletVersion.V4R2,
WalletVersion.V3R2,
WalletVersion.V3R1
]
],
generateTronWallet: isTronEnabled
}
);

Expand Down
22 changes: 16 additions & 6 deletions packages/uikit/src/state/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ import {
getTonWalletStandard,
getWalletAddress,
mamAccountToMamAccountWithTron,
standardTonAccountToAccountWithTron
standardTonAccountToAccountWithTron,
tronWalletByTonMnemonic
} from '@tonkeeper/core/dist/service/walletService';
import { Account as TonapiAccount, AccountsApi } from '@tonkeeper/core/dist/tonApiV2';
import { seeIfValidTonAddress } from '@tonkeeper/core/dist/utils/common';
Expand All @@ -64,6 +65,7 @@ import { useGlobalPreferences } from './global-preferences';
import { useDeleteFolder } from './folders';
import { useRemoveAccountTwoFAData } from './two-fa';
import { assertUnreachable } from '@tonkeeper/core/dist/utils/types';
import { useIsTronEnabledGlobally } from './tron/tron';

export { useAccountsStateQuery, useAccountsState };

Expand Down Expand Up @@ -215,6 +217,7 @@ export const useCreateMAMAccountDerivation = () => {
const appContext = useAppContext();
const network = useActiveTonNetwork();
const { mutateAsync: checkTouchId } = useCheckTouchId();
const isTronEnabled = useIsTronEnabledGlobally();

return useMutation<void, Error, { accountId: AccountId }>(async ({ accountId }) => {
const account = await storage.getAccount(accountId);
Expand Down Expand Up @@ -247,7 +250,8 @@ export const useCreateMAMAccountDerivation = () => {
emoji: account.emoji,
index: newDerivationIndex,
tonWallets,
activeTonWalletId: tonWallets[0].id
activeTonWalletId: tonWallets[0].id,
tronWallet: isTronEnabled ? await tronWalletByTonMnemonic(mnemonic) : undefined
});

await storage.updateAccountInState(account);
Expand Down Expand Up @@ -509,6 +513,7 @@ export const useCreateAccountMnemonic = () => {
const context = useAppContext();
const { mutateAsync: addAccountToState } = useAddAccountToStateMutation();
const { mutateAsync: selectAccountMutation } = useMutateActiveAccount();
const isTronEnabled = useIsTronEnabledGlobally();

return useMutation<
AccountTonMnemonic,
Expand Down Expand Up @@ -536,7 +541,8 @@ export const useCreateAccountMnemonic = () => {
auth: {
kind: 'keychain'
},
versions
versions,
generateTronWallet: isTronEnabled
}
);

Expand Down Expand Up @@ -567,7 +573,8 @@ export const useCreateAccountMnemonic = () => {
kind: 'password',
encryptedMnemonic
},
versions
versions,
generateTronWallet: isTronEnabled
}
);

Expand All @@ -584,6 +591,7 @@ export const useCreateAccountMAM = () => {
const context = useAppContext();
const { mutateAsync: addAccountToState } = useAddAccountToStateMutation();
const { mutateAsync: selectAccountMutation } = useMutateActiveAccount();
const isTronEnabled = useIsTronEnabledGlobally();

return useMutation<
AccountMAM,
Expand All @@ -600,7 +608,8 @@ export const useCreateAccountMAM = () => {
selectedDerivations,
auth: {
kind: 'keychain'
}
},
generateTronWallet: isTronEnabled
});

await sdk.keychain.setPassword(
Expand All @@ -625,7 +634,8 @@ export const useCreateAccountMAM = () => {
auth: {
kind: 'password',
encryptedMnemonic
}
},
generateTronWallet: isTronEnabled
});

await addAccountToState(account);
Expand Down

0 comments on commit 0468bb1

Please sign in to comment.