Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update testnet accounts #319

Merged
merged 6 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions packages/core/src/service/tonConnect/connectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,21 +385,36 @@ export const tonDisconnectRequest = async (options: { storage: IStorage; webView
await disconnectAccountConnection({ ...options, wallet: connection.wallet });
};

const getMaxMessages = (account: Account) => {
if (account.type === 'ledger') {
return 1;
}

const wallet = account.activeTonWallet;

return isStandardTonWallet(wallet) && wallet.version === WalletVersion.V5R1 ? 255 : 4;
};

export const saveWalletTonConnect = async (options: {
storage: IStorage;
wallet: TonContract;
account: Account;
manifest: DAppManifest;
params: TonConnectParams;
replyItems: ConnectItemReply[];
appVersion: string;
webViewUrl?: string;
}): Promise<ConnectEvent> => {
await saveAccountConnection(options);
const wallet = options.account.activeTonWallet;
await saveAccountConnection({
storage: options.storage,
wallet,
manifest: options.manifest,
params: options.params,
webViewUrl: options.webViewUrl
});

const maxMessages = getMaxMessages(options.account);

const maxMessages =
isStandardTonWallet(options.wallet) && options.wallet.version === WalletVersion.V5R1
? 255
: 4;
return {
id: Date.now(),
event: 'connect',
Expand Down
5 changes: 4 additions & 1 deletion packages/uikit/src/components/account/AccountBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ export const AccountAndWalletBadgesGroup: FC<{
return <AccountBadge className={className} size={size} accountType={account.type} />;
}

if (account.type === 'mnemonic' && account.tonWallets.length > 1) {
if (
(account.type === 'mnemonic' || account.type === 'testnet') &&
account.tonWallets.length > 1
) {
const wallet = account.tonWallets.find(w => w.id === walletId);
if (wallet) {
return (
Expand Down
2 changes: 1 addition & 1 deletion packages/uikit/src/components/connect/connectHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const useResponseConnectionMutation = () => {
if (replyItems && manifest && data) {
const response = await saveWalletTonConnect({
storage: sdk.storage,
wallet: data.activeTonWallet,
account: data,
manifest,
params,
replyItems,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ export const AddWalletNotificationControlled = () => {

const navigateHome = useMemo(
() =>
!params?.walletType
selectedMethod
? () => {
setSelectedMethod(undefined);
}
: undefined,
[params?.walletType]
[selectedMethod]
);

return (
Expand Down
11 changes: 8 additions & 3 deletions packages/uikit/src/components/settings/AccountSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import {
import { SettingsItem, SettingsList } from './SettingsList';
import {
isAccountTonWalletStandard,
isAccountVersionEditable
isAccountVersionEditable,
isMnemonicAndPassword
} from '@tonkeeper/core/dist/entries/account';
import { useBatteryEnabledConfig } from '../../state/battery';

Expand Down Expand Up @@ -81,7 +82,11 @@ const SingleAccountSettings = () => {
});
}

if (account.type === 'mnemonic' || account.type === 'ton-only') {
if (
account.type === 'mnemonic' ||
account.type === 'testnet' ||
account.type === 'ton-only'
) {
items.push({
name: t('settings_wallet_version'),
icon: walletVersionText(account.activeTonWallet.version),
Expand Down Expand Up @@ -197,7 +202,7 @@ const MultipleAccountSettings = () => {
const mainItems = useMemo<SettingsItem[]>(() => {
const items: SettingsItem[] = [];

if (account.type === 'mnemonic' || account.type === 'mam') {
if (isMnemonicAndPassword(account)) {
items.push({
name: t('settings_recovery_phrase'),
icon: <RecoveryPhraseIcon />,
Expand Down
4 changes: 2 additions & 2 deletions packages/uikit/src/pages/settings/Recovery.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AccountId } from '@tonkeeper/core/dist/entries/account';
import { AccountId, isMnemonicAndPassword } from '@tonkeeper/core/dist/entries/account';
import { WalletId } from '@tonkeeper/core/dist/entries/wallet';
import { FC, useCallback, useEffect, useMemo, useState } from 'react';
import { Navigate, useNavigate, useParams, useSearchParams } from 'react-router-dom';
Expand All @@ -12,7 +12,7 @@ import { useAccountState, useActiveAccount } from '../../state/wallet';

export const ActiveRecovery = () => {
const account = useActiveAccount();
if (account.type === 'mnemonic' || account.type === 'mam') {
if (isMnemonicAndPassword(account)) {
return <RecoveryContent accountId={account.id} />;
} else {
return <Navigate to="../" replace={true} />;
Expand Down
7 changes: 3 additions & 4 deletions packages/uikit/src/state/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
getNetworkByAccount,
getWalletById,
isAccountTonWalletStandard,
isAccountVersionEditable
isAccountVersionEditable,
isMnemonicAndPassword
} from '@tonkeeper/core/dist/entries/account';
import { Network } from '@tonkeeper/core/dist/entries/network';
import { AuthKeychain, MnemonicType } from '@tonkeeper/core/dist/entries/password';
Expand Down Expand Up @@ -690,9 +691,7 @@ export const useMutateDeleteAll = () => {

export const useIsPasswordSet = () => {
const wallets = useAccountsState();
return (wallets || []).some(
acc => (acc.type === 'mnemonic' || acc.type === 'mam') && acc.auth.kind === 'password'
);
return (wallets || []).some(acc => isMnemonicAndPassword(acc) && acc.auth.kind === 'password');
};

export const useMutateLogOut = () => {
Expand Down
Loading