Skip to content

Commit

Permalink
fix: identity resolution (#2124)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris13524 authored Apr 15, 2024
1 parent 1ea3762 commit 92996c4
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 46 deletions.
3 changes: 1 addition & 2 deletions packages/core/src/controllers/BlockchainApiController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,10 @@ const api = new FetchUtil({ baseUrl })

// -- Controller ---------------------------------------- //
export const BlockchainApiController = {
fetchIdentity({ caipChainId, address }: BlockchainApiIdentityRequest) {
fetchIdentity({ address }: BlockchainApiIdentityRequest) {
return api.get<BlockchainApiIdentityResponse>({
path: `/v1/identity/${address}`,
params: {
chainId: caipChainId,
projectId: OptionsController.state.projectId
}
})
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/utils/TypeUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ export interface ThemeVariables {

// -- BlockchainApiController Types ---------------------------------------------
export interface BlockchainApiIdentityRequest {
caipChainId: CaipNetworkId
address: string
}

Expand Down
34 changes: 21 additions & 13 deletions packages/ethers/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -879,20 +879,28 @@ export class Web3Modal extends Web3ModalScaffold {
private async syncProfile(address: Address) {
const chainId = EthersStoreUtil.state.chainId

if (chainId === 1) {
const ensProvider = new InfuraProvider('mainnet')
const name = await ensProvider.lookupAddress(address)
const avatar = await ensProvider.getAvatar(address)

if (name) {
this.setProfileName(name)
}
if (avatar) {
this.setProfileImage(avatar)
try {
const { name, avatar } = await this.fetchIdentity({
address
})
this.setProfileName(name)
this.setProfileImage(avatar)
} catch {
if (chainId === 1) {
const ensProvider = new InfuraProvider('mainnet')
const name = await ensProvider.lookupAddress(address)
const avatar = await ensProvider.getAvatar(address)

if (name) {
this.setProfileName(name)
}
if (avatar) {
this.setProfileImage(avatar)
}
} else {
this.setProfileName(null)
this.setProfileImage(null)
}
} else {
this.setProfileName(null)
this.setProfileImage(null)
}
}

Expand Down
34 changes: 21 additions & 13 deletions packages/ethers5/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -765,20 +765,28 @@ export class Web3Modal extends Web3ModalScaffold {
private async syncProfile(address: Address) {
const chainId = EthersStoreUtil.state.chainId

if (chainId === 1) {
const ensProvider = new ethers.providers.InfuraProvider('mainnet')
const name = await ensProvider.lookupAddress(address)
const avatar = await ensProvider.getAvatar(address)

if (name) {
this.setProfileName(name)
}
if (avatar) {
this.setProfileImage(avatar)
try {
const { name, avatar } = await this.fetchIdentity({
address
})
this.setProfileName(name)
this.setProfileImage(avatar)
} catch {
if (chainId === 1) {
const ensProvider = new ethers.providers.InfuraProvider('mainnet')
const name = await ensProvider.lookupAddress(address)
const avatar = await ensProvider.getAvatar(address)

if (name) {
this.setProfileName(name)
}
if (avatar) {
this.setProfileImage(avatar)
}
} else {
this.setProfileName(null)
this.setProfileImage(null)
}
} else {
this.setProfileName(null)
this.setProfileImage(null)
}
}

Expand Down
31 changes: 14 additions & 17 deletions packages/wagmi/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,31 +288,28 @@ export class Web3Modal extends Web3ModalScaffold {
}

private async syncProfile(address: Hex, chainId: Chain['id']) {
if (chainId !== mainnet.id) {
this.setProfileName(null)
this.setProfileImage(null)

return
}

try {
const { name, avatar } = await this.fetchIdentity({
caipChainId: `${ConstantsUtil.EIP155}:${chainId}`,
address
})
this.setProfileName(name)
this.setProfileImage(avatar)
} catch {
const profileName = await getEnsName(this.wagmiConfig, { address, chainId })
if (profileName) {
this.setProfileName(profileName)
const profileImage = await getEnsAvatar(this.wagmiConfig, {
name: profileName,
chainId
})
if (profileImage) {
this.setProfileImage(profileImage)
if (chainId === mainnet.id) {
const profileName = await getEnsName(this.wagmiConfig, { address, chainId })
if (profileName) {
this.setProfileName(profileName)
const profileImage = await getEnsAvatar(this.wagmiConfig, {
name: profileName,
chainId
})
if (profileImage) {
this.setProfileImage(profileImage)
}
}
} else {
this.setProfileName(null)
this.setProfileImage(null)
}
}
}
Expand Down

0 comments on commit 92996c4

Please sign in to comment.