From 92996c4fa54ed43bf320b63550b36ffb1cd71e89 Mon Sep 17 00:00:00 2001 From: Chris Smith <1979423+chris13524@users.noreply.github.com> Date: Mon, 15 Apr 2024 17:03:53 -0400 Subject: [PATCH] fix: identity resolution (#2124) --- .../controllers/BlockchainApiController.ts | 3 +- packages/core/src/utils/TypeUtil.ts | 1 - packages/ethers/src/client.ts | 34 ++++++++++++------- packages/ethers5/src/client.ts | 34 ++++++++++++------- packages/wagmi/src/client.ts | 31 ++++++++--------- 5 files changed, 57 insertions(+), 46 deletions(-) diff --git a/packages/core/src/controllers/BlockchainApiController.ts b/packages/core/src/controllers/BlockchainApiController.ts index a75641b6f5..50adec3860 100644 --- a/packages/core/src/controllers/BlockchainApiController.ts +++ b/packages/core/src/controllers/BlockchainApiController.ts @@ -95,11 +95,10 @@ const api = new FetchUtil({ baseUrl }) // -- Controller ---------------------------------------- // export const BlockchainApiController = { - fetchIdentity({ caipChainId, address }: BlockchainApiIdentityRequest) { + fetchIdentity({ address }: BlockchainApiIdentityRequest) { return api.get({ path: `/v1/identity/${address}`, params: { - chainId: caipChainId, projectId: OptionsController.state.projectId } }) diff --git a/packages/core/src/utils/TypeUtil.ts b/packages/core/src/utils/TypeUtil.ts index 016a2d1464..26e4396e60 100644 --- a/packages/core/src/utils/TypeUtil.ts +++ b/packages/core/src/utils/TypeUtil.ts @@ -139,7 +139,6 @@ export interface ThemeVariables { // -- BlockchainApiController Types --------------------------------------------- export interface BlockchainApiIdentityRequest { - caipChainId: CaipNetworkId address: string } diff --git a/packages/ethers/src/client.ts b/packages/ethers/src/client.ts index 65bee0328b..03027274c3 100644 --- a/packages/ethers/src/client.ts +++ b/packages/ethers/src/client.ts @@ -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) } } diff --git a/packages/ethers5/src/client.ts b/packages/ethers5/src/client.ts index 0202fa8407..c46d9e1f0e 100644 --- a/packages/ethers5/src/client.ts +++ b/packages/ethers5/src/client.ts @@ -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) } } diff --git a/packages/wagmi/src/client.ts b/packages/wagmi/src/client.ts index c020df814c..32318d5aaf 100644 --- a/packages/wagmi/src/client.ts +++ b/packages/wagmi/src/client.ts @@ -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) } } }