Skip to content

Commit

Permalink
fix: mf-4966 there might be duplicate wallet name (#10404)
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleBill committed Aug 16, 2023
1 parent e681f91 commit 359136d
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions packages/mask/src/extension/popups/hook/useContactsContext.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useMemo, useState } from 'react'
import { createContainer } from 'unstated-next'
import { NetworkPluginID, type Wallet } from '@masknet/shared-base'
import { useContacts, useChainContext, useLookupAddress, useWallets, useAddressType } from '@masknet/web3-hooks-base'
import { useAddressType, useChainContext, useContacts, useLookupAddress, useWallets } from '@masknet/web3-hooks-base'
import { GoPlusLabs } from '@masknet/web3-providers'
import { isSameAddress, type Contact } from '@masknet/web3-shared-base'
import { AddressType, isValidAddress, isValidDomain } from '@masknet/web3-shared-evm'
import { useI18N } from '../../../utils/index.js'
import { type Contact } from '@masknet/web3-shared-base'
import { useMemo, useState } from 'react'
import { useAsync } from 'react-use'
import { GoPlusLabs } from '@masknet/web3-providers'
import { createContainer } from 'unstated-next'
import { useI18N } from '../../../utils/index.js'

interface ContextOptions {
defaultName: string
Expand All @@ -31,9 +31,15 @@ function useContactsContext({ defaultName, defaultAddress }: ContextOptions = {
}
if (isValidAddress(userInput)) return userInput
// UserInput is wallet name
const contact: Wallet | Contact | undefined = [...wallets, ...contacts].find((x) => x.name === userInput)
return contact?.address
}, [userInput, registeredAddress, contacts, wallets])
const matches = [...wallets, ...contacts].filter((x) => x.name === userInput)
if (!matches.length) return defaultAddress
const contact: Wallet | Contact =
matches.length > 1
? // There might be wallets or contacts with the same name
matches.find((x) => isSameAddress(x.address, defaultAddress)) || matches[0]
: matches[0]
return contact.address
}, [userInput, defaultAddress, registeredAddress, contacts, wallets])

const { value: addressType } = useAddressType(NetworkPluginID.PLUGIN_EVM, address, {
chainId,
Expand Down

0 comments on commit 359136d

Please sign in to comment.