diff --git a/packages/neuron-ui/src/components/DetectDuplicateWalletDialog/index.tsx b/packages/neuron-ui/src/components/DetectDuplicateWalletDialog/index.tsx index 96df267317..efd5277ed3 100644 --- a/packages/neuron-ui/src/components/DetectDuplicateWalletDialog/index.tsx +++ b/packages/neuron-ui/src/components/DetectDuplicateWalletDialog/index.tsx @@ -4,7 +4,6 @@ import Dialog from 'widgets/Dialog' import RadioGroup from 'widgets/RadioGroup' import { useState as useGlobalState, useDispatch, AppActions } from 'states' import { requestPassword } from 'services/remote' -import PasswordRequest from 'components/PasswordRequest' import styles from './detectDuplicateWalletDialog.module.scss' const DetectDuplicateWalletDialog = ({ onClose }: { onClose: () => void }) => { @@ -84,35 +83,32 @@ const DetectDuplicateWalletDialog = ({ onClose }: { onClose: () => void }) => { }, [wallets, deletableWallets, requestPassword, onClose, dispatch]) return ( - <> - -
-

{t('settings.wallet-manager.detected-duplicate.detail')}

-
- {groups.map(group => ( - ({ - value: `${wallet.extendedKey}_${wallet.id}`, - label: {wallet.name}, - }))} - /> - ))} -
+ +
+

{t('settings.wallet-manager.detected-duplicate.detail')}

+
+ {groups.map(group => ( + ({ + value: `${wallet.extendedKey}_${wallet.id}`, + label: {wallet.name}, + }))} + /> + ))}
-
- - +
+
) } diff --git a/packages/neuron-ui/src/components/ReplaceDuplicateWalletDialog/index.tsx b/packages/neuron-ui/src/components/ReplaceDuplicateWalletDialog/index.tsx index 263cd35920..0ba08b2ba3 100644 --- a/packages/neuron-ui/src/components/ReplaceDuplicateWalletDialog/index.tsx +++ b/packages/neuron-ui/src/components/ReplaceDuplicateWalletDialog/index.tsx @@ -10,11 +10,11 @@ import styles from './replaceDuplicateWalletDialog.module.scss' const useReplaceDuplicateWallet = () => { const [extendedKey, setExtendedKey] = useState('') - const [tmpId, setTmpId] = useState('') + const [importedWalletId, setImportedWalletId] = useState('') const onClose = useCallback(() => { - setTmpId('') - }, [setTmpId]) + setImportedWalletId('') + }, [setImportedWalletId]) const onImportingExitingWalletError = ( message: @@ -29,14 +29,14 @@ const useReplaceDuplicateWallet = () => { if (msg) { const obj = JSON.parse(msg) setExtendedKey(obj.extendedKey) - setTmpId(obj.id) + setImportedWalletId(obj.id) } } catch (error) { onClose() } } - const show = useMemo(() => !!extendedKey && !!tmpId, [tmpId, extendedKey]) + const show = useMemo(() => !!extendedKey && !!importedWalletId, [importedWalletId, extendedKey]) return { onImportingExitingWalletError, @@ -44,7 +44,7 @@ const useReplaceDuplicateWallet = () => { show, onClose, extendedKey, - tmpId, + importedWalletId, }, } } @@ -53,12 +53,12 @@ const ReplaceDuplicateWalletDialog = ({ show, onClose, extendedKey, - tmpId, + importedWalletId, }: { show: boolean onClose: () => void extendedKey: string - tmpId: string + importedWalletId: string }) => { const { settings: { wallets = [] }, @@ -79,8 +79,8 @@ const ReplaceDuplicateWalletDialog = ({ const onConfirm = useCallback(async () => { replaceWallet({ - id: selectedId, - tmpId, + existingWalletId: selectedId, + importedWalletId, }) .then(res => { if (isSuccessResponse(res)) { diff --git a/packages/neuron-ui/src/types/Controller/index.d.ts b/packages/neuron-ui/src/types/Controller/index.d.ts index 31d3b380d3..816a0b6591 100644 --- a/packages/neuron-ui/src/types/Controller/index.d.ts +++ b/packages/neuron-ui/src/types/Controller/index.d.ts @@ -49,8 +49,8 @@ declare namespace Controller { } interface ReplaceWalletParams { - id: string - tmpId: string + existingWalletId: string + importedWalletId: string } interface BackupWalletParams { diff --git a/packages/neuron-ui/src/widgets/RadioGroup/index.tsx b/packages/neuron-ui/src/widgets/RadioGroup/index.tsx index 0355b90693..0268abc203 100644 --- a/packages/neuron-ui/src/widgets/RadioGroup/index.tsx +++ b/packages/neuron-ui/src/widgets/RadioGroup/index.tsx @@ -12,8 +12,8 @@ export interface RadioGroupOptions { export interface RadioGroupProps { options: RadioGroupOptions[] onChange?: (arg: string) => void - defaultValue?: string | number - value?: string | number + defaultValue?: string + value?: string itemClassName?: string className?: string inputIdPrefix?: string diff --git a/packages/neuron-wallet/src/controllers/api.ts b/packages/neuron-wallet/src/controllers/api.ts index 127ff43dc6..2cdeec6aa5 100644 --- a/packages/neuron-wallet/src/controllers/api.ts +++ b/packages/neuron-wallet/src/controllers/api.ts @@ -349,8 +349,8 @@ export default class ApiController { return this.#walletsController.delete({ id, password }) }) - handle('replace-wallet', async (_, { id = '', tmpId = '' }) => { - return this.#walletsController.replaceWallet(id, tmpId) + handle('replace-wallet', async (_, { existingWalletId = '', importedWalletId = '' }) => { + return this.#walletsController.replaceWallet(existingWalletId, importedWalletId) }) handle('backup-wallet', async (_, { id = '', password = '' }) => { diff --git a/packages/neuron-wallet/src/controllers/wallets.ts b/packages/neuron-wallet/src/controllers/wallets.ts index 1c867519d3..61b972a0b4 100644 --- a/packages/neuron-wallet/src/controllers/wallets.ts +++ b/packages/neuron-wallet/src/controllers/wallets.ts @@ -632,9 +632,9 @@ export default class WalletsController { } } - public async replaceWallet(id: string, tmpId: string): Promise> { + public async replaceWallet(existingWalletId: string, importedWalletId: string): Promise> { const walletsService = WalletsService.getInstance() - await walletsService.replace(id, tmpId) + await walletsService.replace(existingWalletId, importedWalletId) return { status: ResponseCode.Success, diff --git a/packages/neuron-wallet/src/services/wallets.ts b/packages/neuron-wallet/src/services/wallets.ts index 19be776ade..8dc3900402 100644 --- a/packages/neuron-wallet/src/services/wallets.ts +++ b/packages/neuron-wallet/src/services/wallets.ts @@ -277,7 +277,7 @@ export default class WalletService { private listStore: Store // Save wallets (meta info except keystore, which is persisted separately) private walletsKey = 'wallets' private currentWalletKey = 'current' - private tmpWallet: Wallet | undefined + private importedWallet: Wallet | undefined public static getInstance = () => { if (!WalletService.instance) { @@ -384,7 +384,7 @@ export default class WalletService { } if (this.getAll().find(item => item.extendedKey === props.extendedKey)) { - this.tmpWallet = wallet + this.importedWallet = wallet throw new ImportingExitingWallet(JSON.stringify({ extendedKey: props.extendedKey, id })) } @@ -394,35 +394,30 @@ export default class WalletService { return wallet } - public replace = async (id: string, tmpId: string) => { - const wallet = this.get(id) - if (!wallet || !this.tmpWallet) { - throw new WalletNotFound(id) + public replace = async (existingWalletId: string, importedWalletId: string) => { + const wallet = this.get(existingWalletId) + if (!wallet || !this.importedWallet) { + throw new WalletNotFound(existingWalletId) } - const tmp = this.tmpWallet?.toJSON() - if (tmpId !== tmp.id) { - throw new WalletNotFound(tmpId) + const newWallet = this.importedWallet?.toJSON() + if (importedWalletId !== newWallet.id) { + throw new WalletNotFound(importedWalletId) } - if (wallet.toJSON().extendedKey !== tmp.extendedKey) { + if (wallet.toJSON().extendedKey !== newWallet.extendedKey) { throw new Error('The wallets are not the same and cannot be replaced.') } const wallets = this.getAll() - this.listStore.writeSync(this.walletsKey, [...wallets, tmp]) + this.listStore.writeSync(this.walletsKey, [...wallets, newWallet]) - const current = this.getCurrent() - const currentID = current ? current.id : '' + this.setCurrent(newWallet.id) - if (currentID === id) { - this.setCurrent(tmp.id) - } - - await AddressService.deleteByWalletId(id) + await AddressService.deleteByWalletId(existingWalletId) - const newWallets = wallets.filter(w => w.id !== id) - this.listStore.writeSync(this.walletsKey, [...newWallets, tmp]) + const newWallets = wallets.filter(w => w.id !== existingWalletId) + this.listStore.writeSync(this.walletsKey, [...newWallets, newWallet]) if (!wallet.isHardware()) { wallet.deleteKeystore()