Skip to content

Commit

Permalink
feat: add support for ens names
Browse files Browse the repository at this point in the history
  • Loading branch information
marthendalnunes committed Apr 12, 2024
1 parent 0aa3ee1 commit 7eea41f
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { useCallback, useMemo, useState } from "react"
import Image from "next/image"
import { ENS_CONTRACT_ADDRESS } from "@/data/constants"
import { type Address } from "viem"

import { type Nft } from "@/lib/hooks/web3/use-nfts-for-owner"
Expand Down Expand Up @@ -31,6 +32,12 @@ export function Erc721TokenIdSelector({
},
[setSelectedTokenId]
)

const isEnsContract = useMemo(
() => contractAddress === ENS_CONTRACT_ADDRESS,
[contractAddress]
)

const filteredTokenList = useMemo(
() =>
nfts?.filter(
Expand Down Expand Up @@ -63,35 +70,37 @@ export function Erc721TokenIdSelector({
return (
<div
className={cn(
"grid max-h-[380px] w-full grid-cols-1 gap-4 overflow-y-auto rounded-xl border border-primary/10 p-3 sm:grid-cols-2",
"grid max-h-[380px] w-full grid-cols-1 gap-2 overflow-y-auto rounded-xl border border-primary/10 p-3",
className
)}
>
{filteredTokenList?.map((nft) => (
<Card
className={cn(
"flex h-fit cursor-pointer items-center gap-x-6 border-2 p-4 transition duration-200",
"flex h-fit cursor-pointer w-full items-center gap-x-4 border-2 p-4 transition duration-200",
selectedTokenId === nft.tokenId
? "border-primary"
: "hover:border-primary/25"
)}
onClick={() => handleSelect(nft.tokenId)}
key={nft.tokenId}
>
<div className="relative h-[60px] w-[60px]">
<div className="relative h-[64px] min-w-[64px]">
{imageLoaded ? null : (
<Skeleton className="absolute h-[60px] w-[60px] rounded-md" />
<Skeleton className="absolute h-[64px] w-[64px] rounded-md" />
)}
<Image
width={60}
height={60}
width={64}
height={64}
className={cn("absolute rounded-md", !imageLoaded && "invisible")}
alt={`${nft.tokenId} image`}
src={nft.imageUrl ?? "/logo.svg"}
onLoad={() => setImageLoaded(true)}
/>
</div>
<div className="text-2xl font-semibold">#{nft.tokenId}</div>
<div className="text-xl overflow-x-auto font-semibold">
{isEnsContract ? nft.name : "#" + nft.tokenId}
</div>
</Card>
))}
</div>
Expand Down
11 changes: 9 additions & 2 deletions apps/website/components/forms/form-L1-to-L2-bridge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { useEffect, useMemo, useState, type HTMLAttributes } from "react"
import Image from "next/image"
import { l1Erc721BridgeAbi } from "@/data/abis"
import { ENS_CONTRACT_ADDRESS } from "@/data/constants"
import { l1NetworkOptions, l2NetworksOptions } from "@/data/networks/options"
import { type Address, type BaseError } from "viem"
import {
Expand Down Expand Up @@ -69,6 +70,10 @@ export function FormL1ToL2Bridge({
})

const { chainId: currentChainId } = useAccount()
const isEnsContract = useMemo(
() => localToken === ENS_CONTRACT_ADDRESS,
[localToken]
)

// ERC721 Approve
const readErc721GetApproved = useReadErc721GetApproved({
Expand Down Expand Up @@ -189,7 +194,7 @@ export function FormL1ToL2Bridge({
<Label>Item</Label>
{nft ? (
<div className="flex items-center gap-x-5 p-2">
<div className="relative h-[80px] w-[80px]">
<div className="relative h-[80px] min-w-[80px]">
{imageLoaded ? null : (
<Skeleton className="absolute h-[80px] w-[80px] rounded-md" />
)}
Expand All @@ -205,7 +210,9 @@ export function FormL1ToL2Bridge({
onLoad={() => setImageLoaded(true)}
/>
</div>
<div className="text-3xl font-semibold">#{nft.tokenId}</div>
<div className="text-3xl overflow-x-auto font-semibold">
{isEnsContract ? nft.name : "#" + nft.tokenId}
</div>
</div>
) : (
<Skeleton className="h-16 w-full" />
Expand Down
15 changes: 9 additions & 6 deletions apps/website/components/forms/form-select-erc721-token-l1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,20 @@ export function FormSelectErc721TokenL1({
})

const onSubmit: SubmitHandler<FormData> = (data) => {
const remoteToken = tokenList.tokens.find(
const selectedToken = tokenList.tokens.find(
({ address }) => address.toLowerCase() === data.localToken.toLowerCase()
)?.extensions?.bridgeInfo?.[data?.destinationNetwork]
?.tokenAddress as Address
)
const remoteTokenAddress = selectedToken?.extensions?.bridgeInfo?.[
data?.destinationNetwork
]?.tokenAddress as Address

onTokenSelected?.({
destinationNetwork: data.destinationNetwork,
remoteToken: data.remoteToken ?? remoteToken,
remoteToken: data.remoteToken ?? remoteTokenAddress,
localToken: data.localToken,
tokenId: data.tokenId,
name: data.name ?? "",
logoURI: data.logoURI ?? "/logo.svg",
name: data.name ?? selectedToken?.name ?? "",
logoURI: data.logoURI ?? selectedToken?.logoURI ?? "/logo.svg",
})
}

Expand Down
7 changes: 2 additions & 5 deletions apps/website/components/ui/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ const Card = React.forwardRef<
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn(
"rounded-xl border bg-card text-card-foreground shadow",
className
)}
className={cn("rounded-xl border text-card-foreground shadow", className)}
{...props}
/>
))
Expand Down Expand Up @@ -73,4 +70,4 @@ const CardFooter = React.forwardRef<
))
CardFooter.displayName = "CardFooter"

export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent }
export { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle }
1 change: 1 addition & 0 deletions apps/website/data/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const ENS_CONTRACT_ADDRESS = "0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85"
2 changes: 1 addition & 1 deletion apps/website/lib/hooks/web3/use-nfts-for-owner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ export function useNftsForOwner({ owner, contractAddresses, chainId }: Params) {
...nft,
// Adds a convenience property that gets fallback image from the NFT metadata
imageUrl:
nft.image.cachedUrl ??
nft.image.pngUrl ??
nft.image.originalUrl ??
nft.image.cachedUrl ??
nft.contract.openSeaMetadata?.imageUrl,
}))
return allNfts
Expand Down
1 change: 1 addition & 0 deletions apps/website/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "./env.mjs"
const nextConfig = {
reactStrictMode: true,
images: {
dangerouslyAllowSVG: true,
remotePatterns: [
{
protocol: "https",
Expand Down

0 comments on commit 7eea41f

Please sign in to comment.