Skip to content

Commit

Permalink
fix: Remove unexpected value in log
Browse files Browse the repository at this point in the history
  • Loading branch information
yanguoyu committed Aug 6, 2024
1 parent b8ba97b commit 0c4c534
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -28,22 +28,22 @@ 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) {
onClose()
}
}

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

return {
onImportingExitingWalletError,
dialogProps: {
show,
onClose,
extendedKey,
duplicateWalletIds,
importedWalletId,
},
}
Expand All @@ -52,12 +52,12 @@ const useReplaceDuplicateWallet = () => {
const ReplaceDuplicateWalletDialog = ({
show,
onClose,
extendedKey,
duplicateWalletIds,
importedWalletId,
}: {
show: boolean
onClose: () => void
extendedKey: string
duplicateWalletIds: string[]
importedWalletId: string
}) => {
const {
Expand All @@ -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) => {
Expand Down
10 changes: 4 additions & 6 deletions packages/neuron-wallet/src/services/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
)
Expand Down

1 comment on commit 0c4c534

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Packaging for test is done in 10259782054

Please sign in to comment.