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 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
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@commitlint/cli": "^13.0.0",
"@commitlint/config-conventional": "^13.0.0",
"@davatar/react": "^1.8.1",
"@ensdomains/ensjs": "^2.0.1",
"@ethereumjs/common": "^2.4.0",
"@ethereumjs/tx": "^3.3.0",
"@ethersproject/abi": "^5.4.0",
Expand Down Expand Up @@ -136,6 +137,7 @@
"eslint-plugin-simple-import-sort": "^7.0.0",
"eslint-plugin-unused-imports": "^1.1.5",
"eth-permit": "^0.2.1",
"ethers": "^5.5.4",
"fast-json-stable-stringify": "^2.1.0",
"fuse.js": "^6.4.6",
"graphql": "^15.5.3",
Expand Down
4 changes: 3 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,7 @@ const AccountDetails: FC<AccountDetailsProps> = ({
/>
</div>
<Typography weight={700} variant="lg" className="text-white">
{ENSName ? ENSName : account && shortenAddress(account)}
{ENSName ? ENSName : nom ? 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 ? nom : shortenAddress(account)}</div>
<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}
/>
</>
)
}
5 changes: 3 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,8 @@ 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} />
{ENSName ? ENSName : nom ? 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 TYPE NEEDS FIXING
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