From 564e2a875ebe67b1049a9a13dca4c9d3f7204b1b Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Sat, 6 Apr 2024 12:11:34 -0400 Subject: [PATCH] fix: ethers SDK not using identity API --- packages/ethers/src/client.ts | 34 +++++++++++++++++++++------------- packages/ethers5/src/client.ts | 34 +++++++++++++++++++++------------- 2 files changed, 42 insertions(+), 26 deletions(-) diff --git a/packages/ethers/src/client.ts b/packages/ethers/src/client.ts index 86282a0b07..ae5576489a 100644 --- a/packages/ethers/src/client.ts +++ b/packages/ethers/src/client.ts @@ -880,20 +880,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) } }