diff --git a/packages/neuron-ui/src/components/ReplaceDuplicateWalletDialog/index.tsx b/packages/neuron-ui/src/components/ReplaceDuplicateWalletDialog/index.tsx index c644a496e9..133c7067d4 100644 --- a/packages/neuron-ui/src/components/ReplaceDuplicateWalletDialog/index.tsx +++ b/packages/neuron-ui/src/components/ReplaceDuplicateWalletDialog/index.tsx @@ -9,7 +9,7 @@ import { replaceWallet } from 'services/remote' import styles from './replaceDuplicateWalletDialog.module.scss' const useReplaceDuplicateWallet = () => { - const [extendedKey, setExtendedKey] = useState('') + const [duplicateWalletIds, setDuplicateWalletIds] = useState([]) const [importedWalletId, setImportedWalletId] = useState('') const onClose = useCallback(() => { @@ -28,7 +28,7 @@ const useReplaceDuplicateWallet = () => { const msg = typeof message === 'string' ? '' : message.content if (msg) { const obj = JSON.parse(msg) - setExtendedKey(obj.extendedKey) + setDuplicateWalletIds(obj.duplicateWalletIds) setImportedWalletId(obj.id) } } catch (error) { @@ -36,14 +36,14 @@ const useReplaceDuplicateWallet = () => { } } - const show = useMemo(() => !!extendedKey && !!importedWalletId, [importedWalletId, extendedKey]) + const show = useMemo(() => !!duplicateWalletIds.length && !!importedWalletId, [importedWalletId, duplicateWalletIds]) return { onImportingExitingWalletError, dialogProps: { show, onClose, - extendedKey, + duplicateWalletIds, importedWalletId, }, } @@ -52,12 +52,12 @@ const useReplaceDuplicateWallet = () => { const ReplaceDuplicateWalletDialog = ({ show, onClose, - extendedKey, + duplicateWalletIds, importedWalletId, }: { show: boolean onClose: () => void - extendedKey: string + duplicateWalletIds: string[] importedWalletId: string }) => { const { @@ -68,7 +68,10 @@ const ReplaceDuplicateWalletDialog = ({ const [selectedId, setSelectedId] = useState('') const [t] = useTranslation() - const group = useMemo(() => wallets.filter(item => item.extendedKey === extendedKey), [wallets, extendedKey]) + const group = useMemo( + () => wallets.filter(item => duplicateWalletIds.includes(item.id)), + [wallets, duplicateWalletIds] + ) const handleGroupChange = useCallback( (checked: string) => { diff --git a/packages/neuron-wallet/src/services/wallets.ts b/packages/neuron-wallet/src/services/wallets.ts index 6121bca49b..224d08de76 100644 --- a/packages/neuron-wallet/src/services/wallets.ts +++ b/packages/neuron-wallet/src/services/wallets.ts @@ -405,16 +405,14 @@ export default class WalletService { wallet.saveKeystore(props.keystore!) } - const existWalletInfo = this.getAll().find(item => item.extendedKey === props.extendedKey) - if (existWalletInfo) { - const existWallet = FileKeystoreWallet.fromJSON(existWalletInfo) - const existWalletIsWatchOnly = existWallet.isHDWallet() && existWallet.loadKeystore().isEmpty() + const existWallets = this.getAll().filter(item => item.extendedKey === props.extendedKey) + if (existWallets.length) { + const existWalletIsWatchOnly = existWallets.some(v => v.isHDWallet && !v.keystore) this.importedWallet = wallet throw new DuplicateImportWallet( JSON.stringify({ - extendedKey: props.extendedKey, + duplicateWalletIds: existWallets.map(v => v.id), existWalletIsWatchOnly, - existingWalletId: existWallet.id, id, }) )