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

added space-id #1579

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@testing-library/user-event": "^7.1.2",
"@uniswap/widgets": "^2.47.3",
"@unstoppabledomains/resolution": "8.5.0",
"@web3-name-sdk/core": "^0.1.18",
"@web3-onboard/coinbase": "^2.2.5",
"@web3-onboard/core": "2.21.6",
"@web3-onboard/injected-wallets": "2.10.16",
Expand Down
42 changes: 21 additions & 21 deletions src/hooks/useResolveWeb3Name.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// React + Web3 Essentials
import { ethers } from 'ethers';
import { useContext, useEffect, useState } from 'react';
import { createWeb3Name } from '@web3-name-sdk/core';

// Internal Components
import { caip10ToWallet } from 'helpers/w2w';
Expand All @@ -13,21 +14,23 @@ import { AppContextType } from 'types/context';
import { appConfig } from '../config/index.js';
import { getUdResolver } from 'helpers/w2w/udResolver';

const getEnsName = async (
provider: ethers.providers.BaseProvider | any,
checksumWallet: string,
setWeb3NameList: any
) => {
let ensName: string = '';
provider.lookupAddress(checksumWallet).then(async (ens) => {
if (ens) {
ensName = ens;
setWeb3NameList((prev) => ({ ...prev, [checksumWallet]: ens }));
} else {
ensName = null;
}
});
return ensName;
const getDomainName = async (checksumWallet: string, setWeb3NameList: any) => {
let domainName: string | null = '';
const web3NameClient = createWeb3Name();
web3NameClient
.getDomainName({
address: checksumWallet,
queryChainIdList: appConfig.allowedNetworks,
})
.then(async (domain) => {
if (domain) {
domainName = domain;
setWeb3NameList((prev) => ({ ...prev, [checksumWallet]: domain }));
} else {
domainName = null;
}
});
return domainName;
};

const getUnstoppableName = async (checksumWallet: string, setWeb3NameList: any) => {
Expand All @@ -45,7 +48,7 @@ const getUnstoppableName = async (checksumWallet: string, setWeb3NameList: any)
};

export function useResolveWeb3Name(address?: string) {
const [web3Name, setWeb3Name] = useState<string>(null);
const [web3Name, setWeb3Name] = useState<string | null>(null);

const ctx: ContextType = useContext<ContextType>(Context);

Expand All @@ -54,7 +57,6 @@ export function useResolveWeb3Name(address?: string) {
useEffect(() => {
(async () => {
setWeb3Name(null);
let provider = new ethers.providers.InfuraProvider(appConfig.coreContractChain, appConfig.infuraAPIKey);
if (address) {
const walletLowercase = address.includes(':nft')
? caip10ToWallet(
Expand All @@ -68,8 +70,6 @@ export function useResolveWeb3Name(address?: string) {
const checksumWallet = ethers.utils.getAddress(walletLowercase);
if (ethers.utils.isAddress(checksumWallet)) {
try {
// attempt ENS name resolution first, with a fallback to Unstoppable Domains if
// a value is not found from ENS.
Object.keys(web3NameList).forEach((element) => {
if (web3NameList[checksumWallet]) {
setWeb3Name(web3NameList[checksumWallet]);
Expand All @@ -78,15 +78,15 @@ export function useResolveWeb3Name(address?: string) {
});

let web3Response =
(await getEnsName(provider, checksumWallet, setWeb3NameList)) ||
(await getDomainName(checksumWallet, setWeb3NameList)) ||
(await getUnstoppableName(checksumWallet, setWeb3NameList));
// store result
if (web3Response) {
setWeb3Name(web3Response);
return;
}
} catch (e) {
// console.error('Error fetching web3 name from indexDB', e);
console.debug('Error fetching web3 name from indexDB', e);
}
}
}
Expand Down
34 changes: 33 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ __metadata:
languageName: node
linkType: hard

"@adraffy/ens-normalize@npm:^1.10.0":
version: 1.10.1
resolution: "@adraffy/ens-normalize@npm:1.10.1"
checksum: 10/4cb938c4abb88a346d50cb0ea44243ab3574330c81d4f5aaaf9dfee584b96189d0faa404de0fcbef5a1b73909ea4ebc3e63d84bd23f9949e5c8d4085207a5091
languageName: node
linkType: hard

"@ampproject/remapping@npm:^2.2.0":
version: 2.3.0
resolution: "@ampproject/remapping@npm:2.3.0"
Expand Down Expand Up @@ -982,6 +989,13 @@ __metadata:
languageName: node
linkType: hard

"@ensdomains/ens-validation@npm:^0.1.0":
version: 0.1.0
resolution: "@ensdomains/ens-validation@npm:0.1.0"
checksum: 10/689d57543c871fce3ed4d67b66861405f477073bdab703b3fabad1a21153375c37122a0ae4bd3a130abe7da1d854642724b2aad392f4e5e63681e03cd9a6315d
languageName: node
linkType: hard

"@esbuild/aix-ppc64@npm:0.19.12":
version: 0.19.12
resolution: "@esbuild/aix-ppc64@npm:0.19.12"
Expand Down Expand Up @@ -7272,6 +7286,23 @@ __metadata:
languageName: node
linkType: hard

"@web3-name-sdk/core@npm:^0.1.18":
version: 0.1.18
resolution: "@web3-name-sdk/core@npm:0.1.18"
dependencies:
"@adraffy/ens-normalize": "npm:^1.10.0"
"@ensdomains/ens-validation": "npm:^0.1.0"
viem: "npm:^1.20"
peerDependencies:
"@bonfida/spl-name-service": ^1.4.0
"@sei-js/core": ^3.1.0
"@siddomains/injective-sidjs": 0.0.2-beta
"@siddomains/sei-sidjs": ^0.0.4
"@solana/web3.js": ^1.75.0
checksum: 10/eebbc7f28ae67cf92c558dc61fae28e5242386416a5d225082f8091eab8ad958257e9a534defc42218d00aa5ca9d04700226e16fa992da28e2e8e77af932337c
languageName: node
linkType: hard

"@web3-onboard/coinbase@npm:^2.2.5":
version: 2.2.7
resolution: "@web3-onboard/coinbase@npm:2.2.7"
Expand Down Expand Up @@ -17719,6 +17750,7 @@ __metadata:
"@uniswap/widgets": "npm:^2.47.3"
"@unstoppabledomains/resolution": "npm:8.5.0"
"@vitejs/plugin-react": "npm:^4.2.1"
"@web3-name-sdk/core": "npm:^0.1.18"
"@web3-onboard/coinbase": "npm:^2.2.5"
"@web3-onboard/core": "npm:2.21.6"
"@web3-onboard/injected-wallets": "npm:2.10.16"
Expand Down Expand Up @@ -21356,7 +21388,7 @@ __metadata:
languageName: node
linkType: hard

"viem@npm:^1.20.3":
"viem@npm:^1.20, viem@npm:^1.20.3":
version: 1.21.4
resolution: "viem@npm:1.21.4"
dependencies:
Expand Down
Loading