diff --git a/apps/web/src/app/(routes)/layout.tsx b/apps/web/src/app/(routes)/layout.tsx index 4a3b8211..75c9f968 100644 --- a/apps/web/src/app/(routes)/layout.tsx +++ b/apps/web/src/app/(routes)/layout.tsx @@ -110,8 +110,6 @@ function RootLayout({ children }: { children: React.ReactNode }) {
{children}
- {/* - */}
diff --git a/apps/web/src/app/(routes)/providers.tsx b/apps/web/src/app/(routes)/providers.tsx index 5e5561d1..b339f6c5 100644 --- a/apps/web/src/app/(routes)/providers.tsx +++ b/apps/web/src/app/(routes)/providers.tsx @@ -1,20 +1,13 @@ "use client"; import { - type Chain, - // type Chain, - // goerli as starknetGoerli, mainnet as starknetMainnet, + sepolia as starknetSepolia, } from "@starknet-react/chains"; -import { - StarknetConfig, - jsonRpcProvider, - // publicProvider, - // publicProvider, -} from "@starknet-react/core"; +import { StarknetConfig, jsonRpcProvider } from "@starknet-react/core"; import { ThemeProvider } from "next-themes"; import { WagmiProvider, createConfig, http } from "wagmi"; -import { mainnet } from "wagmi/chains"; +import { mainnet, sepolia } from "wagmi/chains"; import { WalletModalsProvider } from "../_components/WalletModals/WalletModalsContext"; import { @@ -23,21 +16,21 @@ import { } from "../_lib/utils/connectors"; const wagmiConfig = createConfig({ - // chains: [goerli], - chains: [mainnet], + chains: [sepolia], + // chains: [mainnet], connectors: ethereumConnectors, ssr: false, transports: { - [mainnet.id]: http( + [sepolia.id]: http( process.env.NEXT_PUBLIC_ALCHEMY_ETHEREUM_RPC_ENDPOINT ?? "" ), + // [mainnet.id]: http( + // process.env.NEXT_PUBLIC_ALCHEMY_ETHEREUM_RPC_ENDPOINT ?? "" + // ), }, }); -function starknetRpc(chain: Chain) { - if (chain.network === "goerli") - return { nodeUrl: `https://juno.testnet.arkproject.dev/` }; - +function starknetRpc() { return { nodeUrl: process.env.NEXT_PUBLIC_ALCHEMY_STARKNET_RPC_ENDPOINT ?? "", }; @@ -53,8 +46,8 @@ export default function Providers({ children }: ProvidersProps) { return ( { if ( diff --git a/apps/web/src/server/api/routers/bridgeRequest.ts b/apps/web/src/server/api/routers/bridgeRequest.ts index 727ed8ef..f40f1207 100644 --- a/apps/web/src/server/api/routers/bridgeRequest.ts +++ b/apps/web/src/server/api/routers/bridgeRequest.ts @@ -1,15 +1,20 @@ -import { Alchemy, Network, type Nft } from "alchemy-sdk"; +import { Alchemy, Network } from "alchemy-sdk"; import { z } from "zod"; import { type Chain } from "~/app/_types"; import { createTRPCRouter, publicProcedure } from "~/server/api/trpc"; +import { getMediaObjectFromAlchemyMedia } from "../helpers/l1nfts"; +import { + getL2NftsMetadataBatch, + getMediaObjectFromUrl, +} from "../helpers/l2nfts"; import { type NftMedia } from "../types"; const alchemy = new Alchemy({ apiKey: process.env.ALCHEMY_API_KEY, - network: Network.ETH_MAINNET, - // network: Network.ETH_GOERLI, + // network: Network.ETH_MAINNET, + network: Network.ETH_SEPOLIA, }); export type BridgeRequestEventStatus = @@ -96,27 +101,66 @@ export const bridgeRequestRouter = createTRPCRouter({ }; } - let requestMetadata: Array = []; + let requestMetadataByReqHash: Record< + string, + { contractName: string; media: NftMedia } + > = {}; + if (bridgeRequests[0]?.req.chain_src === "eth") { - requestMetadata = await alchemy.nft.getNftMetadataBatch( + const requestMetadatas = await alchemy.nft.getNftMetadataBatch( bridgeRequests.reverse().map((bridgeRequest) => ({ contractAddress: bridgeRequest.req.collection_src, tokenId: bridgeRequest.token_ids[0], })) ); + + requestMetadataByReqHash = requestMetadatas.reduce((acc, current) => { + return { + ...acc, + [`${current.tokenId}`]: { + contractName: current.contract.name, + media: getMediaObjectFromAlchemyMedia(current.media[0]), + }, + }; + }, {}); + } else { + const requestMetadatas = await getL2NftsMetadataBatch( + bridgeRequests.map((bridgeRequest) => ({ + contract_address: bridgeRequest.req.collection_src, + token_id: bridgeRequest.token_ids[0], + })) + ); + requestMetadataByReqHash = requestMetadatas.result.reduce( + (acc, current) => { + return { + ...acc, + [`${current.token_id}`]: { + contractName: current.contract_name, + media: getMediaObjectFromUrl( + current.metadata?.normalized.image + ), + }, + }; + }, + {} + ); } const bridgeRequestsWithMetadata = bridgeRequests.map( - (bridgeRequest, index) => { + (bridgeRequest) => { const lastBridgeRequestEvent = bridgeRequest.events[bridgeRequest.events.length - 1]; const isArrived = lastBridgeRequestEvent?.label === "withdraw_available_l1" || lastBridgeRequestEvent?.label === "withdraw_completed_l1" || lastBridgeRequestEvent?.label === "withdraw_completed_l2"; - const media = requestMetadata[index]?.media[0]; - const mediaSrc = media?.gateway ?? media?.thumbnail ?? media?.raw; - const mediaFormat = media?.format === "mp4" ? "video" : "image"; + const requestMetadata = + requestMetadataByReqHash[`${bridgeRequest.token_ids[0]}`]; + const collectionMedia = requestMetadata?.media ?? { + format: "image", + src: undefined, + }; + const collectionName = requestMetadata?.contractName ?? "Unknown"; return { arrivalAddress: bridgeRequest.req.to, @@ -127,8 +171,8 @@ export const bridgeRequestRouter = createTRPCRouter({ arrivalTimestamp: isArrived ? lastBridgeRequestEvent?.block_timestamp : undefined, - collectionMedia: { format: mediaFormat, src: mediaSrc }, - collectionName: requestMetadata[index]?.contract.name ?? "", + collectionMedia, + collectionName, collectionSourceAddress: bridgeRequest.req.collection_src, requestContent: JSON.parse( bridgeRequest.req.content diff --git a/apps/web/src/server/api/routers/l1Nfts.ts b/apps/web/src/server/api/routers/l1Nfts.ts index 6e4b8d67..af0f3b2b 100644 --- a/apps/web/src/server/api/routers/l1Nfts.ts +++ b/apps/web/src/server/api/routers/l1Nfts.ts @@ -1,6 +1,6 @@ import { Alchemy, Network, NftFilters } from "alchemy-sdk"; import { createClient, getContract, http } from "viem"; -import { mainnet } from "viem/chains"; +import { mainnet, sepolia } from "viem/chains"; import { z } from "zod"; import { createTRPCRouter, publicProcedure } from "~/server/api/trpc"; @@ -10,7 +10,8 @@ import { getMediaObjectFromAlchemyMedia } from "../helpers/l1nfts"; import { type Collection, type Nft } from "../types"; const viemClient = createClient({ - chain: mainnet, + // chain: mainnet, + chain: sepolia, transport: http(process.env.NEXT_PUBLIC_ALCHEMY_ETHEREUM_RPC_ENDPOINT ?? ""), }); @@ -22,8 +23,8 @@ const bridgeL1Contract = getContract({ const alchemy = new Alchemy({ apiKey: process.env.ALCHEMY_API_KEY, - network: Network.ETH_MAINNET, - // network: Network.ETH_GOERLI, + // network: Network.ETH_MAINNET, + network: Network.ETH_SEPOLIA, }); export const l1NftsRouter = createTRPCRouter({