Skip to content

Commit 4e46d03

Browse files
authored
fix: Remove unexpected value in log (#3224)
1 parent b8ba97b commit 4e46d03

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

packages/neuron-ui/src/components/ReplaceDuplicateWalletDialog/index.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { replaceWallet } from 'services/remote'
99
import styles from './replaceDuplicateWalletDialog.module.scss'
1010

1111
const useReplaceDuplicateWallet = () => {
12-
const [extendedKey, setExtendedKey] = useState('')
12+
const [duplicateWalletIds, setDuplicateWalletIds] = useState([])
1313
const [importedWalletId, setImportedWalletId] = useState('')
1414

1515
const onClose = useCallback(() => {
@@ -28,22 +28,22 @@ const useReplaceDuplicateWallet = () => {
2828
const msg = typeof message === 'string' ? '' : message.content
2929
if (msg) {
3030
const obj = JSON.parse(msg)
31-
setExtendedKey(obj.extendedKey)
31+
setDuplicateWalletIds(obj.duplicateWalletIds)
3232
setImportedWalletId(obj.id)
3333
}
3434
} catch (error) {
3535
onClose()
3636
}
3737
}
3838

39-
const show = useMemo(() => !!extendedKey && !!importedWalletId, [importedWalletId, extendedKey])
39+
const show = useMemo(() => !!duplicateWalletIds.length && !!importedWalletId, [importedWalletId, duplicateWalletIds])
4040

4141
return {
4242
onImportingExitingWalletError,
4343
dialogProps: {
4444
show,
4545
onClose,
46-
extendedKey,
46+
duplicateWalletIds,
4747
importedWalletId,
4848
},
4949
}
@@ -52,12 +52,12 @@ const useReplaceDuplicateWallet = () => {
5252
const ReplaceDuplicateWalletDialog = ({
5353
show,
5454
onClose,
55-
extendedKey,
55+
duplicateWalletIds,
5656
importedWalletId,
5757
}: {
5858
show: boolean
5959
onClose: () => void
60-
extendedKey: string
60+
duplicateWalletIds: string[]
6161
importedWalletId: string
6262
}) => {
6363
const {
@@ -68,7 +68,10 @@ const ReplaceDuplicateWalletDialog = ({
6868
const [selectedId, setSelectedId] = useState('')
6969
const [t] = useTranslation()
7070

71-
const group = useMemo(() => wallets.filter(item => item.extendedKey === extendedKey), [wallets, extendedKey])
71+
const group = useMemo(
72+
() => wallets.filter(item => duplicateWalletIds.includes(item.id)),
73+
[wallets, duplicateWalletIds]
74+
)
7275

7376
const handleGroupChange = useCallback(
7477
(checked: string) => {

packages/neuron-ui/src/containers/Main/hooks.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,15 +325,15 @@ export const useSubscription = ({
325325
break
326326
case 'import-exist-xpubkey': {
327327
if (payload) {
328-
const { existWalletIsWatchOnly, existingWalletId, id: importedWalletId } = JSON.parse(payload)
329-
if (existWalletIsWatchOnly) {
328+
const { duplicateWatchedWalletIds, id: importedWalletId } = JSON.parse(payload)
329+
if (duplicateWatchedWalletIds.length) {
330330
showGlobalAlertDialog({
331331
type: 'warning',
332332
message: t('main.import-exist-xpubkey-dialog.replace-tip'),
333333
action: 'all',
334334
onOk: () => {
335335
replaceWallet({
336-
existingWalletId,
336+
existingWalletId: duplicateWatchedWalletIds[0],
337337
importedWalletId,
338338
}).then(res => {
339339
if (isSuccessResponse(res)) {

packages/neuron-wallet/src/services/wallets.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -405,16 +405,17 @@ export default class WalletService {
405405
wallet.saveKeystore(props.keystore!)
406406
}
407407

408-
const existWalletInfo = this.getAll().find(item => item.extendedKey === props.extendedKey)
409-
if (existWalletInfo) {
410-
const existWallet = FileKeystoreWallet.fromJSON(existWalletInfo)
411-
const existWalletIsWatchOnly = existWallet.isHDWallet() && existWallet.loadKeystore().isEmpty()
408+
const existWalletsProperties = this.getAll().filter(item => item.extendedKey === props.extendedKey)
409+
if (existWalletsProperties.length) {
410+
const existWallets = existWalletsProperties.map(v => this.get(v.id))
411+
const duplicateWatchedWalletIds = existWallets
412+
.filter(v => v.isHDWallet() && v.loadKeystore().isEmpty())
413+
.map(v => v.id)
412414
this.importedWallet = wallet
413415
throw new DuplicateImportWallet(
414416
JSON.stringify({
415-
extendedKey: props.extendedKey,
416-
existWalletIsWatchOnly,
417-
existingWalletId: existWallet.id,
417+
duplicateWalletIds: existWallets.map(v => v.id),
418+
duplicateWatchedWalletIds,
418419
id,
419420
})
420421
)

packages/neuron-wallet/tests/services/wallets.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,9 @@ describe('wallet service', () => {
525525
try {
526526
walletService.create(wallet5)
527527
} catch (error) {
528-
const { extendedKey, id } = JSON.parse(error.message)
528+
const { duplicateWalletIds, id } = JSON.parse(error.message)
529529
await walletService.replace(createdWallet2.id, id)
530-
expect(extendedKey).toBe(prefixWith0x('b'.repeat(66) + '2'.repeat(64)))
530+
expect(duplicateWalletIds).toStrictEqual([createdWallet2.id])
531531
expect(() => walletService.get(createdWallet2.id)).toThrowError()
532532
expect(walletService.get(id).name).toBe(wallet5.name)
533533
}

0 commit comments

Comments
 (0)