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

Space id integration #1578

Merged
merged 3 commits into from
May 30, 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
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",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mishramonalisha76 the ticket description says resolved the domain name using space id package, but where is the space id package used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"@web3-name-sdk/core" this the space id package

"@web3-onboard/core": "2.21.6",
"@web3-onboard/injected-wallets": "2.10.16",
Expand Down
43 changes: 21 additions & 22 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 { AppContext } from 'contexts/AppContext';
Expand All @@ -13,22 +14,23 @@ import { AppContextType } from 'types/context';
import { getUdResolver } from 'helpers/w2w/udResolver';
import { appConfig } from '../config/index.js';

// TODO This is causing multiple errors constantly on timeout
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) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have this functionality inside the sdk library then why not use it from there and avoid installing the space id library here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why its not getting installed from the sdk itself, even though its mentioned in dependencies in uiweb package

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;
};

// TODO This is causing multiple errors constantly on timeout
Expand All @@ -47,7 +49,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 @@ -56,7 +58,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 @@ -70,8 +71,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 @@ -80,15 +79,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
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7332,7 +7332,7 @@ __metadata:
languageName: node
linkType: hard

"@web3-name-sdk/core@npm:^0.1.15":
"@web3-name-sdk/core@npm:^0.1.15, @web3-name-sdk/core@npm:^0.1.18":
version: 0.1.18
resolution: "@web3-name-sdk/core@npm:0.1.18"
dependencies:
Expand Down Expand Up @@ -17698,6 +17698,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
Loading