Skip to content

Commit

Permalink
feat: add unstoppable domains support (#431)
Browse files Browse the repository at this point in the history
* feat: add unstoppable support

* clean up code according to review comments

* remove support for polygon UD names

* rename methods
  • Loading branch information
fionnachan authored Sep 15, 2022
1 parent 64ebb9b commit 1264f6a
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 15 deletions.
1 change: 1 addition & 0 deletions packages/arb-token-bridge-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"@sentry/tracing": "^7.9.0",
"@tailwindcss/forms": "^0.3.3",
"@tippyjs/react": "^4.2.6",
"@unstoppabledomains/resolution": "^8.3.3",
"@walletconnect/web3-provider": "^1.6.5",
"axios": "^0.21.4",
"boring-avatars": "^1.7.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useWallet } from '@arbitrum/use-wallet'
import { Popover, Tab } from '@headlessui/react'
import { ExternalLinkIcon, LogoutIcon } from '@heroicons/react/outline'
import { JsonRpcProvider } from '@ethersproject/providers'
import { Resolution } from '@unstoppabledomains/resolution';
import BoringAvatar from 'boring-avatars'

import { Transition } from './Transition'
Expand All @@ -25,6 +26,9 @@ import { ReactComponent as CustomClipboardCopyIcon } from '../../assets/copy.svg
type ENSInfo = { name: string | null; avatar: string | null }
const ensInfoDefaults: ENSInfo = { name: null, avatar: null }

type UDInfo = { name: string | null }
const udInfoDefaults: UDInfo = { name: null }

function getTransactionsDataStatus(
pwLoadedState: PendingWithdrawalsLoadedState
): TransactionsDataStatus {
Expand Down Expand Up @@ -55,7 +59,31 @@ function isDeposit(tx: MergedTransaction) {
return tx.direction === 'deposit' || tx.direction === 'deposit-l1'
}

async function tryLookupAddress(
async function tryLookupUDName(provider: JsonRpcProvider, address: string) {
const UDresolution = Resolution.fromEthersProvider({uns: {
// TODO => remove Layer2 config when UD lib supports our use case
// Layer2 (polygon) is required in the object type but we only want to use Layer1
// This is a hack to only support Ethereum Mainnet UD names
// https://github.com/unstoppabledomains/resolution/issues/229
locations: {
Layer1: {
network: 'mainnet',
provider
},
Layer2: {
network: 'mainnet',
provider
}
}
}});
try {
return await UDresolution.reverse(address)
} catch (error) {
return null
}
}

async function tryLookupENSName(
provider: JsonRpcProvider,
address: string
): Promise<string | null> {
Expand All @@ -66,7 +94,7 @@ async function tryLookupAddress(
}
}

async function tryGetAvatar(
async function tryLookupENSAvatar(
provider: JsonRpcProvider,
address: string
): Promise<string | null> {
Expand All @@ -87,20 +115,22 @@ export function HeaderAccountPopover() {

const [showCopied, setShowCopied] = useState(false)
const [ensInfo, setENSInfo] = useState<ENSInfo>(ensInfoDefaults)
const [udInfo, setUDInfo] = useState<UDInfo>(udInfoDefaults)

useEffect(() => {
async function resolveENSInfo() {
async function resolveNameServiceInfo() {
if (account && l1.signer) {
const [name, avatar] = await Promise.all([
tryLookupAddress(l1.signer.provider, account),
tryGetAvatar(l1.signer.provider, account)
const [ensName, avatar, udName] = await Promise.all([
tryLookupENSName(l1.signer.provider, account),
tryLookupENSAvatar(l1.signer.provider, account),
tryLookupUDName(l1.signer.provider, account)
])

setENSInfo({ name, avatar })
setENSInfo({ name: ensName, avatar })
setUDInfo({ name: udName })
}
}

resolveENSInfo()
resolveNameServiceInfo()
}, [account, l1.signer])

const [deposits, withdrawals] = useMemo(() => {
Expand Down Expand Up @@ -159,7 +189,7 @@ export function HeaderAccountPopover() {
fallback={<CustomBoringAvatar size={32} name={account} />}
/>
<span className="text-2xl font-medium text-white lg:text-base lg:font-normal">
{ensInfo.name || accountShort}
{ensInfo.name ?? udInfo.name ?? accountShort}
</span>
</div>
</div>
Expand All @@ -175,7 +205,7 @@ export function HeaderAccountPopover() {
</Transition>
<button
className="arb-hover hidden flex-row items-center space-x-4 rounded-full lg:flex"
onClick={() => copy(ensInfo.name || account || '')}
onClick={() => copy(ensInfo.name ?? udInfo.name ?? account ?? '')}
>
<SafeImage
src={ensInfo.avatar || undefined}
Expand All @@ -184,7 +214,7 @@ export function HeaderAccountPopover() {
/>
<div className="flex flex-row items-center space-x-3">
<span className="text-2xl font-normal text-white">
{ensInfo.name || accountShort}
{ensInfo.name ?? udInfo.name ?? accountShort}
</span>
<CustomClipboardCopyIcon className="h-6 w-6 text-white" />
</div>
Expand Down
29 changes: 26 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1546,7 +1546,7 @@
"@ethersproject/properties" "^5.6.0"
"@ethersproject/strings" "^5.6.0"

"@ethersproject/[email protected]", "@ethersproject/abi@^5.0.0", "@ethersproject/abi@^5.6.3", "@ethersproject/abi@^5.7.0":
"@ethersproject/[email protected]", "@ethersproject/abi@^5.0.0", "@ethersproject/abi@^5.0.1", "@ethersproject/abi@^5.6.3", "@ethersproject/abi@^5.7.0":
version "5.7.0"
resolved "https://registry.yarnpkg.com/@ethersproject/abi/-/abi-5.7.0.tgz#b3f3e045bbbeed1af3947335c247ad625a44e449"
integrity sha512-351ktp42TiRcYB3H1OP8yajPeAQstMW/yCFokj/AthP9bLHzQFPlOrxOcwYEDkUAICmOHljvN4K39OMTMUa9RA==
Expand Down Expand Up @@ -2872,7 +2872,7 @@
penpal "3.0.7"
pocket-js-core "0.0.3"

"@rehooks/local-storage@^2.3.0":
"@rehooks/local-storage@2.4.0", "@rehooks/local-storage@^2.3.0":
version "2.4.0"
resolved "https://registry.yarnpkg.com/@rehooks/local-storage/-/local-storage-2.4.0.tgz#fb884b2b657cad5f77aa6ab60bb3532f0e0725d2"
integrity sha512-LoXDbEHsuIckVgBsFAv8SuU/M7memjyfWut9Zf36TQXqqCHBRFv8bweg9PymQCa1aWIMjNrZQflFdo55FDlXYg==
Expand Down Expand Up @@ -4260,6 +4260,17 @@
resolved "https://registry.yarnpkg.com/@uniswap/token-lists/-/token-lists-1.0.0-beta.28.tgz#76bb6ec25e76ae6bece9efc11b9b68079b2b9402"
integrity sha512-MmVeoOd/HlZYOn5NT2mlDoOUYjnZb+3V7aCD5/YwSgsqeDRXZmKfKHafEEhiZoMvXuZdqSBg4L/ythvzAf9cwA==

"@unstoppabledomains/resolution@^8.3.3":
version "8.3.3"
resolved "https://registry.yarnpkg.com/@unstoppabledomains/resolution/-/resolution-8.3.3.tgz#599c5e2f068a36e24bd19c0f9e2f753036264a3b"
integrity sha512-jQ9757Lvx/xqU7Lg7JT4L9WQZuElHkMiJmtph0e6TSwfguIlkv1i5UgzURgVXDvVizVKpDejGS60kuvICkz9ZQ==
dependencies:
"@ethersproject/abi" "^5.0.1"
bn.js "^4.4.0"
cross-fetch "^3.1.4"
crypto-js "^4.1.1"
elliptic "^6.5.4"

"@walletconnect/browser-utils@^1.7.7":
version "1.7.7"
resolved "https://registry.yarnpkg.com/@walletconnect/browser-utils/-/browser-utils-1.7.7.tgz#4ae0db1ddf49be179ea556af842db3b7afce973d"
Expand Down Expand Up @@ -8022,6 +8033,13 @@ cross-fetch@^2.1.1:
node-fetch "^2.6.7"
whatwg-fetch "^2.0.4"

cross-fetch@^3.1.4:
version "3.1.5"
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.1.5.tgz#e1389f44d9e7ba767907f7af8454787952ab534f"
integrity sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==
dependencies:
node-fetch "2.6.7"

[email protected], cross-spawn@^7.0.0, cross-spawn@^7.0.1, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
version "7.0.3"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
Expand Down Expand Up @@ -8077,6 +8095,11 @@ [email protected], crypto-browserify@^3.11.0:
randombytes "^2.0.0"
randomfill "^1.0.3"

crypto-js@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.1.1.tgz#9e485bcf03521041bd85844786b83fb7619736cf"
integrity sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw==

crypto-random-string@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/crypto-random-string/-/crypto-random-string-1.0.0.tgz#a230f64f568310e1498009940790ec99545bca7e"
Expand Down Expand Up @@ -15634,7 +15657,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==

node-fetch@^2.6.0, node-fetch@^2.6.1, node-fetch@^2.6.7:
node-fetch@2.6.7, node-fetch@^2.6.0, node-fetch@^2.6.1, node-fetch@^2.6.7:
version "2.6.7"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
Expand Down

1 comment on commit 1264f6a

@vercel
Copy link

@vercel vercel bot commented on 1264f6a Sep 15, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.