-
Notifications
You must be signed in to change notification settings - Fork 44
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
Space id integration #1578
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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'; | ||
|
@@ -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) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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); | ||
|
||
|
@@ -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( | ||
|
@@ -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]); | ||
|
@@ -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); | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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