Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: identity resolution #2124

Merged
merged 5 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
glitch-txs marked this conversation as resolved.
Show resolved Hide resolved
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)
}
chris13524 marked this conversation as resolved.
Show resolved Hide resolved
} 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
Loading