Skip to content

Commit

Permalink
fix: ethers SDK not using identity API
Browse files Browse the repository at this point in the history
  • Loading branch information
chris13524 committed Apr 12, 2024
1 parent 0bade3e commit 564e2a8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 26 deletions.
34 changes: 21 additions & 13 deletions packages/ethers/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

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

0 comments on commit 564e2a8

Please sign in to comment.