Skip to content

Commit

Permalink
fix: mf-2818 match multiple ENS and Space Id (#8359)
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleBill committed Dec 27, 2022
1 parent 0bc6ce7 commit caa1b7b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
20 changes: 10 additions & 10 deletions packages/plugins/EVM/src/state/IdentityService.ts
Expand Up @@ -21,18 +21,16 @@ 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?:\/\/(?<name>[\w.]+)\.(rss3|cheers)\.bio/
const RSS3_RNS_RE = /(?<name>[\w.]+)\.rss3/
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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -189,7 +185,9 @@ export class IdentityService extends IdentityServiceState<ChainId> {
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) {
Expand All @@ -205,7 +203,9 @@ export class IdentityService extends IdentityServiceState<ChainId> {
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) {
Expand Down
7 changes: 0 additions & 7 deletions packages/web3-hooks/base/src/useSocialAddressesAll.ts
@@ -1,17 +1,10 @@
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'
import type { Web3Helper } from '@masknet/web3-helpers'
import { useWeb3State } from './useWeb3State.js'

type AddressList = Array<SocialAddress<Web3Helper.ChainIdAll>>
type CacheValue = Promise<Array<PromiseSettledResult<AddressList>>>

const addressCache = new LRUCache<string, CacheValue>({
max: 500,
ttl: 2 * 60 * 1000,
})

/**
* Get all social addresses across all networks.
Expand Down

0 comments on commit caa1b7b

Please sign in to comment.