-
Notifications
You must be signed in to change notification settings - Fork 708
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
Add Nomspace integration #621
base: master
Are you sure you want to change the base?
Changes from 2 commits
bfdd7dd
3005e48
a115a4e
a464579
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 |
---|---|---|
|
@@ -23,6 +23,7 @@ interface AccountDetailsProps { | |
pendingTransactions: string[] | ||
confirmedTransactions: string[] | ||
ENSName?: string | ||
nom?: string | ||
openOptions: () => void | ||
} | ||
|
||
|
@@ -31,6 +32,7 @@ const AccountDetails: FC<AccountDetailsProps> = ({ | |
pendingTransactions, | ||
confirmedTransactions, | ||
ENSName, | ||
nom, | ||
openOptions, | ||
}) => { | ||
const { i18n } = useLingui() | ||
|
@@ -82,7 +84,13 @@ const AccountDetails: FC<AccountDetailsProps> = ({ | |
/> | ||
</div> | ||
<Typography weight={700} variant="lg" className="text-white"> | ||
{ENSName ? ENSName : account && shortenAddress(account)} | ||
{nom && ENSName | ||
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. Let's do it in this priority:
|
||
? ENSName + ' (' + nom + ')' | ||
: ENSName | ||
? ENSName | ||
: nom | ||
? account && shortenAddress(account) + ' (' + nom + ')' | ||
: account && shortenAddress(account)} | ||
</Typography> | ||
</div> | ||
<div className="flex items-center gap-2 space-x-3"> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,7 +96,7 @@ function Web3StatusInner() { | |
const { i18n } = useLingui() | ||
const { account, connector, library } = useWeb3React() | ||
|
||
const { ENSName } = useENSName(account ?? undefined) | ||
const { ENSName, nom } = useENSName(account ?? undefined) | ||
|
||
const allTransactions = useAllTransactions() | ||
|
||
|
@@ -127,7 +127,7 @@ function Web3StatusInner() { | |
</div> | ||
) : ( | ||
<div className="flex items-center gap-2"> | ||
<div>{ENSName || shortenAddress(account)}</div> | ||
<div>{ENSName ? ENSName : nom ? shortenAddress(account) + ' (' + nom + ')' : shortenAddress(account)}</div> | ||
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. I think it's probably ok to just do |
||
<Davatar | ||
size={20} | ||
address={account} | ||
|
@@ -155,8 +155,7 @@ export default function Web3Status() { | |
const { active, account } = useWeb3React() | ||
const contextNetwork = useWeb3React(NetworkContextName) | ||
|
||
const { ENSName } = useENSName(account ?? undefined) | ||
|
||
const { ENSName, nom } = useENSName(account ?? undefined) | ||
const allTransactions = useAllTransactions() | ||
|
||
const sortedRecentTransactions = useMemo(() => { | ||
|
@@ -174,7 +173,12 @@ export default function Web3Status() { | |
return ( | ||
<> | ||
<Web3StatusInner /> | ||
<WalletModal ENSName={ENSName ?? undefined} pendingTransactions={pending} confirmedTransactions={confirmed} /> | ||
<WalletModal | ||
ENSName={ENSName ?? undefined} | ||
pendingTransactions={pending} | ||
confirmedTransactions={confirmed} | ||
nom={nom ?? undefined} | ||
/> | ||
</> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ interface HeaderDropdownProps { | |
const HeaderDropdown: FC<HeaderDropdownProps> = ({ account, hideAccount = false }) => { | ||
const { library, chainId } = useActiveWeb3React() | ||
const [show, setShow] = useState<boolean>(false) | ||
const { ENSName } = useENSName(account ?? undefined) | ||
const { ENSName, nom } = useENSName(account ?? undefined) | ||
|
||
return ( | ||
<> | ||
|
@@ -42,7 +42,16 @@ const HeaderDropdown: FC<HeaderDropdownProps> = ({ account, hideAccount = false | |
className="text-high-emphesis flex gap-1 cursor-pointer hover:text-blue-100" | ||
weight={700} | ||
> | ||
{ENSName ? ENSName : account ? shortenAddress(account) : ''} <LinkIcon width={20} /> | ||
{nom && ENSName | ||
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. ditto with last similar comment |
||
? ENSName + ' (' + nom + ')' | ||
: ENSName | ||
? ENSName | ||
: nom | ||
? shortenAddress(account) + ' (' + nom + ')' | ||
: account | ||
? shortenAddress(account) | ||
: ''} | ||
<LinkIcon width={20} /> | ||
</Typography> | ||
</a> | ||
</Link> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,29 @@ | ||
// @ts-ignore | ||
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. Don't use |
||
import ENS from '@ensdomains/ensjs' | ||
import { isAddress } from '@ethersproject/address' | ||
import { namehash } from '@ethersproject/hash' | ||
import { useMemo } from 'react' | ||
import { providers } from 'ethers' | ||
import { useEffect, useMemo, useState } from 'react' | ||
|
||
import { isZero } from '../functions' | ||
import { useSingleCallResult } from '../state/multicall/hooks' | ||
import { useENSRegistrarContract, useENSResolverContract } from './useContract' | ||
import useDebounce from './useDebounce' | ||
const NOM_REGISTRY_ADDRESS = '0x3DE51c3960400A0F752d3492652Ae4A0b2A36FB3' | ||
|
||
/** | ||
* Does a reverse lookup for an address to find its ENS name. | ||
* Note this is not the same as looking up an ENS name to find an address. | ||
*/ | ||
export default function useENSName(address?: string): { | ||
ENSName: string | null | ||
nom: string | null | ||
loading: boolean | ||
} { | ||
const debouncedAddress = useDebounce(address, 200) | ||
const provider = new providers.JsonRpcProvider('https://forno.celo.org') | ||
const [nom, setNom] = useState<string | null>(null) | ||
|
||
const ensNodeArgument = useMemo(() => { | ||
if (!debouncedAddress || !isAddress(debouncedAddress)) return [undefined] | ||
try { | ||
|
@@ -24,6 +32,18 @@ export default function useENSName(address?: string): { | |
return [undefined] | ||
} | ||
}, [debouncedAddress]) | ||
|
||
useEffect(() => { | ||
;(async () => { | ||
const nom = new ENS({ provider, ensAddress: NOM_REGISTRY_ADDRESS }) | ||
try { | ||
const { name } = await nom.getName(address) | ||
if (name) setNom(`${name}.nom`) | ||
} catch (e) { | ||
console.error('Could not fetch nom data', e) | ||
} | ||
})() | ||
}, [address, provider]) | ||
const registrarContract = useENSRegistrarContract(false) | ||
const resolverAddress = useSingleCallResult(registrarContract, 'resolver', ensNodeArgument) | ||
const resolverAddressResult = resolverAddress.result?.[0] | ||
|
@@ -36,6 +56,7 @@ export default function useENSName(address?: string): { | |
const changed = debouncedAddress !== address | ||
return { | ||
ENSName: changed ? null : name.result?.[0] ?? null, | ||
nom, | ||
loading: changed || resolverAddress.loading || name.loading, | ||
} | ||
} |
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.
Does it work to move these deps to
devDependencies
? Let's avoid adding stuff todependencies
considering their team hasn't added anything there