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

Add Nomspace integration #621

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,5 +211,9 @@
"not ie 11",
"not dead",
"not op_mini all"
]
],
"dependencies": {

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 to dependencies considering their team hasn't added anything there

"@ensdomains/ensjs": "^2.0.1",
"ethers": "^5.5.4"
}
}
10 changes: 9 additions & 1 deletion src/components/AccountDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface AccountDetailsProps {
pendingTransactions: string[]
confirmedTransactions: string[]
ENSName?: string
nom?: string
openOptions: () => void
}

Expand All @@ -31,6 +32,7 @@ const AccountDetails: FC<AccountDetailsProps> = ({
pendingTransactions,
confirmedTransactions,
ENSName,
nom,
openOptions,
}) => {
const { i18n } = useLingui()
Expand Down Expand Up @@ -82,7 +84,13 @@ const AccountDetails: FC<AccountDetailsProps> = ({
/>
</div>
<Typography weight={700} variant="lg" className="text-white">
{ENSName ? ENSName : account && shortenAddress(account)}
{nom && ENSName

Choose a reason for hiding this comment

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

Let's do it in this priority:

ENSName ? ENSName : nom ? nom : account && shortenAddress(account)

? ENSName + ' (' + nom + ')'
: ENSName
? ENSName
: nom
? account && shortenAddress(account) + ' (' + nom + ')'
: account && shortenAddress(account)}
</Typography>
</div>
<div className="flex items-center gap-2 space-x-3">
Expand Down
14 changes: 9 additions & 5 deletions src/components/Web3Status/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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>

Choose a reason for hiding this comment

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

I think it's probably ok to just do nom instead of shortenAddress(account) + ' (' + nom + ')'

<Davatar
size={20}
address={account}
Expand Down Expand Up @@ -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(() => {
Expand All @@ -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}
/>
</>
)
}
13 changes: 11 additions & 2 deletions src/features/portfolio/HeaderDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
Expand All @@ -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

Choose a reason for hiding this comment

The 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>
Expand Down
23 changes: 22 additions & 1 deletion src/hooks/useENSName.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
// @ts-ignore

Choose a reason for hiding this comment

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

Don't use @ts-ignore. Add @ensdomains/ensjs declaration to a .d.ts file

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 {
Expand All @@ -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]
Expand All @@ -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,
}
}
4 changes: 3 additions & 1 deletion src/modals/WalletModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ interface WalletModal {
pendingTransactions: string[] // hashes of pending
confirmedTransactions: string[] // hashes of confirmed
ENSName?: string
nom?: string
}

const WalletModal: FC<WalletModal> = ({ pendingTransactions, confirmedTransactions, ENSName }) => {
const WalletModal: FC<WalletModal> = ({ pendingTransactions, confirmedTransactions, ENSName, nom }) => {
const { active, account, connector, activate, error, deactivate } = useWeb3React()
const { i18n } = useLingui()
const [walletView, setWalletView] = useState(WALLET_VIEWS.ACCOUNT)
Expand Down Expand Up @@ -227,6 +228,7 @@ const WalletModal: FC<WalletModal> = ({ pendingTransactions, confirmedTransactio
pendingTransactions={pendingTransactions}
confirmedTransactions={confirmedTransactions}
ENSName={ENSName}
nom={nom}
openOptions={() => setWalletView(WALLET_VIEWS.OPTIONS)}
/>
) : (
Expand Down
Loading