diff --git a/packages/plugins/EVM/src/state/IdentityService.ts b/packages/plugins/EVM/src/state/IdentityService.ts index d482cffd80f..2635e42e0c5 100644 --- a/packages/plugins/EVM/src/state/IdentityService.ts +++ b/packages/plugins/EVM/src/state/IdentityService.ts @@ -21,8 +21,8 @@ import { ChainbaseResolver } from './NameService/Chainbase.js' import { Web3StateSettings } from '../settings/index.js' import { SpaceID_Resolver } from './NameService/SpaceID.js' -const ENS_RE = /[^\s()[\]]{1,256}\.(eth|kred|xyz|luxe)\b/i -const SID_RE = /[^\t\n\v()[\]]{1,256}\.bnb\b/i +const ENS_RE = /[^\s()[\]]{1,256}\.(eth|kred|xyz|luxe)\b/gi +const SID_RE = /[^\t\n\v()[\]]{1,256}\.bnb\b/gi const ADDRESS_FULL = /0x\w{40,}/i const RSS3_URL_RE = /https?:\/\/(?[\w.]+)\.(rss3|cheers)\.bio/ const RSS3_RNS_RE = /(?[\w.]+)\.rss3/ @@ -30,9 +30,7 @@ const LENS_RE = /[^\s()[\]]{1,256}\.lens\b/i const LENS_URL_RE = /https?:\/\/.+\/(\w+\.lens)/ function getENSNames(userId: string, nickname: string, bio: string) { - return [userId.match(ENS_RE), nickname.match(ENS_RE), bio.match(ENS_RE)] - .map((result) => result?.[0] ?? '') - .filter(Boolean) + return [userId.match(ENS_RE), nickname.match(ENS_RE), bio.match(ENS_RE)].flatMap((result) => result ?? []) } function getLensNames(nickname: string, bio: string, homepage: string) { @@ -42,9 +40,7 @@ function getLensNames(nickname: string, bio: string, homepage: string) { } function getSIDNames(userId: string, nickname: string, bio: string) { - return [userId.match(SID_RE), nickname.match(SID_RE), bio.match(SID_RE)] - .map((result) => result?.[0] ?? '') - .filter(Boolean) + return [userId.match(SID_RE), nickname.match(SID_RE), bio.match(SID_RE)].flatMap((result) => result ?? []) } function getRSS3Ids(nickname: string, profileURL: string, bio: string) { @@ -189,7 +185,9 @@ export class IdentityService extends IdentityServiceState { return this.createSocialAddress(SocialAddressType.ENS, address, name) }), ) - return compact(allSettled.map((x) => (x.status === 'fulfilled' ? x.value : undefined)).filter(Boolean)) + return uniqBy(compact(allSettled.map((x) => (x.status === 'fulfilled' ? x.value : undefined))), (x) => + x.address.toLowerCase(), + ) } private async getSocialAddressFromSpaceID({ identifier, nickname = '', bio = '' }: SocialIdentity) { @@ -205,7 +203,9 @@ export class IdentityService extends IdentityServiceState { return this.createSocialAddress(SocialAddressType.SPACE_ID, address, name, ChainId.BSC) }), ) - return compact(allSettled.map((x) => (x.status === 'fulfilled' ? x.value : undefined)).filter(Boolean)) + return uniqBy(compact(allSettled.map((x) => (x.status === 'fulfilled' ? x.value : undefined))), (x) => + x.address.toLowerCase(), + ) } private async getSocialAddressFromLens({ nickname = '', bio = '', homepage = '' }: SocialIdentity) { diff --git a/packages/web3-hooks/base/src/useSocialAddressesAll.ts b/packages/web3-hooks/base/src/useSocialAddressesAll.ts index c66ad818378..39f8a99d038 100644 --- a/packages/web3-hooks/base/src/useSocialAddressesAll.ts +++ b/packages/web3-hooks/base/src/useSocialAddressesAll.ts @@ -1,4 +1,3 @@ -import LRUCache from 'lru-cache' import { useAsyncRetry } from 'react-use' import { EMPTY_LIST, NetworkPluginID } from '@masknet/shared-base' import type { SocialAddress, SocialAddressType, SocialIdentity } from '@masknet/web3-shared-base' @@ -6,12 +5,6 @@ import type { Web3Helper } from '@masknet/web3-helpers' import { useWeb3State } from './useWeb3State.js' type AddressList = Array> -type CacheValue = Promise>> - -const addressCache = new LRUCache({ - max: 500, - ttl: 2 * 60 * 1000, -}) /** * Get all social addresses across all networks.