Skip to content

Commit

Permalink
fix: Remove unexpected value in log (#3224)
Browse files Browse the repository at this point in the history
  • Loading branch information
yanguoyu authored Aug 7, 2024
1 parent b8ba97b commit 4e46d03
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 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
6 changes: 3 additions & 3 deletions packages/neuron-ui/src/containers/Main/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,15 @@ export const useSubscription = ({
break
case 'import-exist-xpubkey': {
if (payload) {
const { existWalletIsWatchOnly, existingWalletId, id: importedWalletId } = JSON.parse(payload)
if (existWalletIsWatchOnly) {
const { duplicateWatchedWalletIds, id: importedWalletId } = JSON.parse(payload)
if (duplicateWatchedWalletIds.length) {
showGlobalAlertDialog({
type: 'warning',
message: t('main.import-exist-xpubkey-dialog.replace-tip'),
action: 'all',
onOk: () => {
replaceWallet({
existingWalletId,
existingWalletId: duplicateWatchedWalletIds[0],
importedWalletId,
}).then(res => {
if (isSuccessResponse(res)) {
Expand Down
15 changes: 8 additions & 7 deletions packages/neuron-wallet/src/services/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,16 +405,17 @@ 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 existWalletsProperties = this.getAll().filter(item => item.extendedKey === props.extendedKey)
if (existWalletsProperties.length) {
const existWallets = existWalletsProperties.map(v => this.get(v.id))
const duplicateWatchedWalletIds = existWallets
.filter(v => v.isHDWallet() && v.loadKeystore().isEmpty())
.map(v => v.id)
this.importedWallet = wallet
throw new DuplicateImportWallet(
JSON.stringify({
extendedKey: props.extendedKey,
existWalletIsWatchOnly,
existingWalletId: existWallet.id,
duplicateWalletIds: existWallets.map(v => v.id),
duplicateWatchedWalletIds,
id,
})
)
Expand Down
4 changes: 2 additions & 2 deletions packages/neuron-wallet/tests/services/wallets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,9 @@ describe('wallet service', () => {
try {
walletService.create(wallet5)
} catch (error) {
const { extendedKey, id } = JSON.parse(error.message)
const { duplicateWalletIds, id } = JSON.parse(error.message)
await walletService.replace(createdWallet2.id, id)
expect(extendedKey).toBe(prefixWith0x('b'.repeat(66) + '2'.repeat(64)))
expect(duplicateWalletIds).toStrictEqual([createdWallet2.id])
expect(() => walletService.get(createdWallet2.id)).toThrowError()
expect(walletService.get(id).name).toBe(wallet5.name)
}
Expand Down

3 comments on commit 4e46d03

@github-actions
Copy link
Contributor

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 10280002427

@github-actions
Copy link
Contributor

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 10280002568

@github-actions
Copy link
Contributor

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 10297744264

Please sign in to comment.