diff --git a/packages/platform-clients/ens-utils.ts b/packages/platform-clients/ens-utils.ts index b57fd180f1..4fddf31967 100644 --- a/packages/platform-clients/ens-utils.ts +++ b/packages/platform-clients/ens-utils.ts @@ -12,7 +12,7 @@ export type ENSRes = { } class ENSUtils implements IENSUtils { - async getEnsEntry(address: string): Promise { + async getEnsEntry(address: string): Promise { const ensRes = await fetch( `https://api.ensideas.com/ens/resolve/${address}`, { @@ -24,33 +24,24 @@ class ENSUtils implements IENSUtils { } ) - const res: ENSRes = await ensRes.json() + if (ensRes.status === 200) return ensRes.json() - if (res.error) { - console.error(`Error requesting ens from address: ${res.error}`) - - throw new Error(res.error) - } - - return res + console.error(`ENSIdeasError: ${await ensRes.text()}`) } - async getENSDisplayName(addressOrEns: string): Promise { - const { displayName } = await this.getEnsEntry(addressOrEns) - - return displayName + async getENSDisplayName(addressOrEns: string): Promise { + const profile = await this.getEnsEntry(addressOrEns) + return profile?.displayName || '' } async getENSAddress(addressOrEns: string): Promise { - const { address } = await this.getEnsEntry(addressOrEns) - - return address + const profile = await this.getEnsEntry(addressOrEns) + return profile?.address || '' } - async getENSAddressAvatar(addressOrEns: string): Promise { - const { avatar } = await this.getEnsEntry(addressOrEns) - - return avatar + async getENSAddressAvatar(addressOrEns: string): Promise { + const profile = await this.getEnsEntry(addressOrEns) + return profile?.avatar || '' } } diff --git a/platform/account/src/jsonrpc/methods/getIdentityByAlias.ts b/platform/account/src/jsonrpc/methods/getIdentityByAlias.ts index 11662bdfe3..e2e24964c9 100644 --- a/platform/account/src/jsonrpc/methods/getIdentityByAlias.ts +++ b/platform/account/src/jsonrpc/methods/getIdentityByAlias.ts @@ -28,7 +28,8 @@ export const getIdentityByAliasMethod = async ({ }): Promise => { let alias = input.alias if (input.provider === 'eth' && input.alias.endsWith('.eth')) { - alias = (await new ENSUtils().getEnsEntry(input.alias)).address + const addressFromENS = await new ENSUtils().getENSAddress(input.alias) + if (addressFromENS) alias = addressFromENS } const caller = router.createCaller(ctx) diff --git a/platform/account/src/jsonrpc/middlewares/checkCryptoNode.ts b/platform/account/src/jsonrpc/middlewares/checkCryptoNode.ts index 036da891fc..c4cd52fb58 100644 --- a/platform/account/src/jsonrpc/middlewares/checkCryptoNode.ts +++ b/platform/account/src/jsonrpc/middlewares/checkCryptoNode.ts @@ -33,8 +33,9 @@ export const checkCryptoNodes: BaseMiddlewareFunction = async ({ if (alias && alias.endsWith('.eth')) { const ensClient = new ENSUtils() const response = await ensClient.getEnsEntry(alias) - const { address: ethAddress } = response + if (!response) return next({ ctx }) + const { address: ethAddress } = response const hash = generateHashedIDRef(CryptoAccountType.ETH, ethAddress) if (hash !== hashedIdref) { diff --git a/platform/account/src/nodes/crypto.ts b/platform/account/src/nodes/crypto.ts index 3f0a6be8e4..e91f56173b 100644 --- a/platform/account/src/nodes/crypto.ts +++ b/platform/account/src/nodes/crypto.ts @@ -110,12 +110,12 @@ const getCryptoAccountProfile = async ( address: string ): Promise => { const ensClient = new ENSUtils() - const { avatar, displayName } = await ensClient.getEnsEntry(address) + const profile = await ensClient.getEnsEntry(address) return { address, - title: displayName || '', - icon: avatar || '', + title: profile?.displayName || '', + icon: profile?.avatar || '', type: CryptoAccountType.ETH, } }