Skip to content

Commit

Permalink
Update Nomspace integration
Browse files Browse the repository at this point in the history
  • Loading branch information
muiux committed Jan 20, 2022
1 parent 040d085 commit b24fe91
Show file tree
Hide file tree
Showing 4 changed files with 1,182 additions and 800 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
"@celo/contractkit": "^1.2.0",
"@celo/utils": "^1.2.1",
"@craco/craco": "^6.1.2",
"@ensdomains/ensjs": "^2.0.1",
"@ethersproject/abi": "^5.3.1",
"@ethersproject/abstract-signer": "^5.3.0",
"@ethersproject/address": "^5.3.0",
Expand All @@ -127,7 +128,6 @@
"@ethersproject/providers": "^5.3.1",
"@ethersproject/strings": "^5.3.0",
"@ethersproject/units": "^5.5.0",
"@nomspace/nomspace": "^1.0.6",
"@ramp-network/ramp-instant-sdk": "^2.5.0",
"@sentry/react": "^6.9.0",
"@sentry/tracing": "^6.16.1",
Expand Down
12 changes: 7 additions & 5 deletions src/hooks/useAccountSummary.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AccountsWrapper } from '@celo/contractkit/lib/wrappers/Accounts'
import { useContractKit } from '@celo-tools/use-contractkit'
import { NomKit } from '@nomspace/nomspace'
import { useContractKit, useProvider } from '@celo-tools/use-contractkit'
import ENS from '@ensdomains/ensjs'
import { useEffect, useState } from 'react'

type AsyncReturnType<T extends (...args: any) => any> = T extends (...args: any) => Promise<infer U>
Expand All @@ -22,6 +22,7 @@ export default function useAccountSummary(address?: string | null): {
const [summary, setSummary] = useState<AccountSummary | null>(null)
const [nom, setNom] = useState<string | null>(null)
const { kit } = useContractKit()
const provider = useProvider()

useEffect(() => {
;(async () => {
Expand All @@ -36,14 +37,15 @@ export default function useAccountSummary(address?: string | null): {
console.error('Could not fetch account summary', e)
}

const nomKit = new NomKit(kit as any, '0xABf8faBbC071F320F222A526A2e1fBE26429344d')
const nom = new ENS({ provider, ensAddress: '0x3DE51c3960400A0F752d3492652Ae4A0b2A36FB3' })
try {
setNom(await nomKit.allNamesForResolution(address).then((n) => (n[0] ? `${n[0]}.nom` : null)))
const { name } = await nom.getName(address)
if (name) setNom(`${name}.nom`)
} catch (e) {
console.error('Could not fetch nom data', e)
}
})()
}, [address, kit])
}, [address, kit, provider])

return { summary, nom, loading: summary === null }
}
2 changes: 2 additions & 0 deletions src/react-app-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ declare module 'multihashes' {
declare function decode(buff: Uint8Array): { code: number; name: string; length: number; digest: Uint8Array }
declare function toB58String(hash: Uint8Array): string
}

declare module '@ensdomains/ensjs'
Loading

0 comments on commit b24fe91

Please sign in to comment.