diff --git a/.yarn/install-state.gz b/.yarn/install-state.gz index a93457d..aa2e6e1 100644 Binary files a/.yarn/install-state.gz and b/.yarn/install-state.gz differ diff --git a/components/mint/MintStep1.tsx b/components/mint/MintStep1.tsx index 07bf400..a25227e 100644 --- a/components/mint/MintStep1.tsx +++ b/components/mint/MintStep1.tsx @@ -5,6 +5,7 @@ import { formatW3BucketCapacity } from "@lib/utils"; import classNames from "classnames"; import React, { useEffect, useMemo } from "react"; import { OnNext } from "./type"; +import { useNetwork } from "wagmi"; export interface MintStep1Props { editions: BucketEdition[]; @@ -17,10 +18,12 @@ function fmtPrices(prices: BucketEdition["prices"]) { export const MintStep1 = React.memo((p: MintStep1Props) => { const { editions, onNext } = p; + const { chain } = useNetwork(); + const chainId = chain && chain.id; const [mintData, updateMint] = useMintData(); useEffect(() => { if (mintData.editionId === undefined && editions.length) { - updateMint({ editionId: editions[0].id, price: editions[0].prices[0] }); + updateMint({ chainId: chainId, editionId: editions[0].id, price: editions[0].prices[0] }); } }, [mintData, updateMint, editions]); const currentEditionId = mintData.editionId; @@ -58,7 +61,7 @@ export const MintStep1 = React.memo((p: MintStep1Props) => { } )} onClick={() => { - updateMint({ editionId: item.id, price: item.prices[0] }); + updateMint({ chainId: chainId, editionId: item.id, price: item.prices[0] }); }} /> {`${fmtPrices( diff --git a/components/mint/MintStep2.tsx b/components/mint/MintStep2.tsx index 46d12e9..3f2837d 100644 --- a/components/mint/MintStep2.tsx +++ b/components/mint/MintStep2.tsx @@ -298,7 +298,12 @@ export const MintStep2 = React.memo((p: MintStep2Props) => { axios .post>( genUrl("/auth/ipns/gen"), - { editionId: "" + mintData.editionId }, + { + bucketInfo: JSON.stringify({ + chainId: mintData.chainId, + editionId: mintData.editionId + }) + }, { headers: { Authorization: `Bearer ${auth}` }, } diff --git a/components/mint/MintStep3.tsx b/components/mint/MintStep3.tsx index 77d111e..e70d022 100644 --- a/components/mint/MintStep3.tsx +++ b/components/mint/MintStep3.tsx @@ -20,7 +20,7 @@ import classNames from "classnames"; import { ContractTransaction, ethers } from "ethers"; import React, { useMemo } from "react"; import { useNavigate } from "react-router-dom"; -import { erc20ABI, useAccount, useSigner } from "wagmi"; +import { erc20ABI, useAccount, useNetwork, useSigner } from "wagmi"; import { getContract } from "wagmi/actions"; import { OnNext } from "./type"; @@ -53,6 +53,8 @@ export interface MintStep3Props { export const MintStep3 = React.memo((p: MintStep3Props) => { const { editions, onNext } = p; + const { chain } = useNetwork(); + const chainId = chain && chain.id; const [mintData, updateMint] = useMintData(); const currentEditionId = mintData.editionId; const currentEdition = useMemo( @@ -201,14 +203,14 @@ export const MintStep3 = React.memo((p: MintStep3Props) => { data={[ "W3Bucket NFT Token ID", mintData.tokenId, - bucketEtherscanUrl(mintData.tokenId), + bucketEtherscanUrl(chainId, mintData.tokenId), ]} /> diff --git a/components/modals/ConnectWallet.tsx b/components/modals/ConnectWallet.tsx index 7643efa..c73aaa6 100644 --- a/components/modals/ConnectWallet.tsx +++ b/components/modals/ConnectWallet.tsx @@ -1,9 +1,12 @@ import { IconMetaMask } from "@components/common/icons"; -import { SupportChain } from "@lib/config"; +import { SupportChain, SupportId2Chain } from "@lib/config"; import { useOn } from "@lib/hooks/tools"; import React from "react"; import { useNavigate } from "react-router-dom"; import { useConnect, useSwitchNetwork } from "wagmi"; +import { ethers } from "ethers"; +import detectEthereumProvider from "@metamask/detect-provider"; +import { MetaMaskConnector } from "@wagmi/core/connectors/metaMask"; import { Modal, ModalHead } from "./Modal"; export const ConnectWallet = React.memo((p: { onClose: () => void }) => { @@ -13,14 +16,29 @@ export const ConnectWallet = React.memo((p: { onClose: () => void }) => { const push = useNavigate() const onConnect = useOn(async () => { try { + const chainId = await (async () => { + const provider: any = await detectEthereumProvider(); + if (provider && provider.isMetaMask) { + await provider.request({ method: "eth_requestAccounts" }); + const web3Provider = new ethers.providers.Web3Provider(provider); + const signer = web3Provider.getSigner(); + const id = await signer.getChainId(); + if (SupportId2Chain.has(id)) return id; + } + console.warn(`Cannot get chainId from provider or unsupported chain, use ${SupportChain[0].id}`); + return SupportChain[0].id; + })(); + const connector = new MetaMaskConnector({ + chains: [SupportId2Chain.get(chainId)] + }) console.info("data:", data); console.info("cts:", connectors); if ((!data || data.chain.unsupported) && switchNetworkAsync) { - await switchNetworkAsync(SupportChain[0].id); + await switchNetworkAsync(chainId); } else { await connectAsync({ - chainId: SupportChain[0].id, - connector: connectors[0], + chainId: chainId, + connector: connector, }); } push('/buckets') diff --git a/components/pages/main/Buckets.tsx b/components/pages/main/Buckets.tsx index c81eb5b..06f1e4d 100644 --- a/components/pages/main/Buckets.tsx +++ b/components/pages/main/Buckets.tsx @@ -18,12 +18,13 @@ import moment from "moment"; import React, { useCallback, useMemo } from "react"; import { useNavigate } from "react-router-dom"; import { useAsync } from "react-use"; -import { useAccount } from "wagmi"; +import { useAccount, useNetwork } from "wagmi"; import { MainLayout } from "./MainLayout"; import classnames from "classnames"; const BucketCard = React.memo((p: { data: BucketDTO,className?:string }) => { const { data,className } = p; + const { chain } = useNetwork(); const push = useNavigate(); const capacityInGb = useMemo( () => data.maxStorageSize / 1024 / 1024 / 1024, @@ -72,7 +73,7 @@ const BucketCard = React.memo((p: { data: BucketDTO,className?:string }) => { View NFT Contract diff --git a/components/pages/main/MainLayout.tsx b/components/pages/main/MainLayout.tsx index 004fa3a..c026c55 100644 --- a/components/pages/main/MainLayout.tsx +++ b/components/pages/main/MainLayout.tsx @@ -39,7 +39,6 @@ export const MainLayout = React.memo( const { menuId, children, ...props } = p; const { address: account } = useAccount(); const { chain } = useNetwork(); - const chainId = chain && chain.id; const isConnected = useConnected(); const menus: Menu[] = useMemo(() => { return [ @@ -82,10 +81,10 @@ export const MainLayout = React.memo(
- {chainId === 1 ? "Mainnet" : "Goerli"} + {chain.name.replace(' ', '')}
)} diff --git a/lib/abi/w3bucket.abi.ts b/lib/abi/w3bucket.abi.ts index 62e430c..805c909 100644 --- a/lib/abi/w3bucket.abi.ts +++ b/lib/abi/w3bucket.abi.ts @@ -1,849 +1,12 @@ -export const abi = [ - { "inputs": [], "stateMutability": "nonpayable", "type": "constructor" }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "previousAdmin", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "newAdmin", - "type": "address" - } - ], - "name": "AdminChanged", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "owner", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "approved", - "type": "address" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "Approval", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "owner", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "operator", - "type": "address" - }, - { - "indexed": false, - "internalType": "bool", - "name": "approved", - "type": "bool" - } - ], - "name": "ApprovalForAll", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "beacon", - "type": "address" - } - ], - "name": "BeaconUpgraded", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "editionId", - "type": "uint256" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "capacityInGigabytes", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "address", - "name": "currency", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "price", - "type": "uint256" - } - ], - "name": "BucketMinted", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "uint256", - "name": "editionId", - "type": "uint256" - }, - { - "indexed": true, - "internalType": "address", - "name": "currency", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "price", - "type": "uint256" - } - ], - "name": "EditionPriceUpdated", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "uint256", - "name": "editionId", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "capacityInGigabytes", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "maxMintableSupply", - "type": "uint256" - } - ], - "name": "EditionUpdated", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint8", - "name": "version", - "type": "uint8" - } - ], - "name": "Initialized", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "Paused", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "string", - "name": "_value", - "type": "string" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "_id", - "type": "uint256" - } - ], - "name": "PermanentURI", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "bytes32", - "name": "role", - "type": "bytes32" - }, - { - "indexed": true, - "internalType": "bytes32", - "name": "previousAdminRole", - "type": "bytes32" - }, - { - "indexed": true, - "internalType": "bytes32", - "name": "newAdminRole", - "type": "bytes32" - } - ], - "name": "RoleAdminChanged", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "bytes32", - "name": "role", - "type": "bytes32" - }, - { - "indexed": true, - "internalType": "address", - "name": "account", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "sender", - "type": "address" - } - ], - "name": "RoleGranted", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "bytes32", - "name": "role", - "type": "bytes32" - }, - { - "indexed": true, - "internalType": "address", - "name": "account", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "sender", - "type": "address" - } - ], - "name": "RoleRevoked", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "from", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "Transfer", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "Unpaused", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "implementation", - "type": "address" - } - ], - "name": "Upgraded", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "currency", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "Withdraw", - "type": "event" - }, - { - "inputs": [], - "name": "DEFAULT_ADMIN_ROLE", - "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "EDITIONS_ADMIN_ROLE", - "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "EDITION_MAX_MINTABLE_SUPPLY", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "EDITION_TOKEN_ID_FACTOR", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "MAX_EDITION_ID", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "MIN_EDITION_ID", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "PAUSER_ROLE", - "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "UPGRADER_ROLE", - "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "WITHDRAWER_ROLE", - "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "to", "type": "address" }, - { "internalType": "uint256", "name": "tokenId", "type": "uint256" } - ], - "name": "approve", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "owner", "type": "address" } - ], - "name": "balanceOf", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "uint256", "name": "tokenId", "type": "uint256" } - ], - "name": "burn", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "uint256", "name": "tokenId", "type": "uint256" } - ], - "name": "getApproved", - "outputs": [{ "internalType": "address", "name": "", "type": "address" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "uint256", "name": "editionId", "type": "uint256" } - ], - "name": "getBucketEditionPrices", - "outputs": [ - { - "components": [ - { "internalType": "address", "name": "currency", "type": "address" }, - { "internalType": "uint256", "name": "price", "type": "uint256" } - ], - "internalType": "struct BucketEditionUpgradable.EditionPrice[]", - "name": "", - "type": "tuple[]" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "bool", "name": "activeOnly", "type": "bool" } - ], - "name": "getBucketEditions", - "outputs": [ - { - "components": [ - { "internalType": "uint256", "name": "editionId", "type": "uint256" }, - { "internalType": "bool", "name": "active", "type": "bool" }, - { - "internalType": "uint256", - "name": "capacityInGigabytes", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxMintableSupply", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "currentSupplyMinted", - "type": "uint256" - } - ], - "internalType": "struct BucketEditionUpgradable.BucketEdition[]", - "name": "", - "type": "tuple[]" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "bytes32", "name": "role", "type": "bytes32" } - ], - "name": "getRoleAdmin", - "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "bytes32", "name": "role", "type": "bytes32" }, - { "internalType": "uint256", "name": "index", "type": "uint256" } - ], - "name": "getRoleMember", - "outputs": [{ "internalType": "address", "name": "", "type": "address" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "bytes32", "name": "role", "type": "bytes32" } - ], - "name": "getRoleMemberCount", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "bytes32", "name": "role", "type": "bytes32" }, - { "internalType": "address", "name": "account", "type": "address" } - ], - "name": "grantRole", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "bytes32", "name": "role", "type": "bytes32" }, - { "internalType": "address", "name": "account", "type": "address" } - ], - "name": "hasRole", - "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "string", "name": "name", "type": "string" }, - { "internalType": "string", "name": "symbol", "type": "string" } - ], - "name": "initialize", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "owner", "type": "address" }, - { "internalType": "address", "name": "operator", "type": "address" } - ], - "name": "isApprovedForAll", - "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "to", "type": "address" }, - { "internalType": "uint256", "name": "editionId", "type": "uint256" }, - { "internalType": "address", "name": "currency", "type": "address" }, - { "internalType": "string", "name": "uri", "type": "string" } - ], - "name": "mint", - "outputs": [], - "stateMutability": "payable", - "type": "function" - }, - { - "inputs": [], - "name": "name", - "outputs": [{ "internalType": "string", "name": "", "type": "string" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "uint256", "name": "tokenId", "type": "uint256" } - ], - "name": "ownerOf", - "outputs": [{ "internalType": "address", "name": "", "type": "address" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "pause", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "paused", - "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "proxiableUUID", - "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "bytes32", "name": "role", "type": "bytes32" }, - { "internalType": "address", "name": "account", "type": "address" } - ], - "name": "renounceRole", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "bytes32", "name": "role", "type": "bytes32" }, - { "internalType": "address", "name": "account", "type": "address" } - ], - "name": "revokeRole", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "from", "type": "address" }, - { "internalType": "address", "name": "to", "type": "address" }, - { "internalType": "uint256", "name": "tokenId", "type": "uint256" } - ], - "name": "safeTransferFrom", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "from", "type": "address" }, - { "internalType": "address", "name": "to", "type": "address" }, - { "internalType": "uint256", "name": "tokenId", "type": "uint256" }, - { "internalType": "bytes", "name": "data", "type": "bytes" } - ], - "name": "safeTransferFrom", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "operator", "type": "address" }, - { "internalType": "bool", "name": "approved", "type": "bool" } - ], - "name": "setApprovalForAll", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "uint256", "name": "editionId", "type": "uint256" }, - { - "components": [ - { "internalType": "address", "name": "currency", "type": "address" }, - { "internalType": "uint256", "name": "price", "type": "uint256" } - ], - "internalType": "struct BucketEditionUpgradable.EditionPrice[]", - "name": "prices", - "type": "tuple[]" - } - ], - "name": "setBucketEditionPrices", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "components": [ - { "internalType": "uint256", "name": "editionId", "type": "uint256" }, - { - "internalType": "uint256", - "name": "capacityInGigabytes", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxMintableSupply", - "type": "uint256" - } - ], - "internalType": "struct BucketEditionUpgradable.BucketEditionParams[]", - "name": "editions", - "type": "tuple[]" - } - ], - "name": "setBucketEditions", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "bytes4", "name": "interfaceId", "type": "bytes4" } - ], - "name": "supportsInterface", - "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "symbol", - "outputs": [{ "internalType": "string", "name": "", "type": "string" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "uint256", "name": "index", "type": "uint256" } - ], - "name": "tokenByIndex", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "owner", "type": "address" }, - { "internalType": "uint256", "name": "index", "type": "uint256" } - ], - "name": "tokenOfOwnerByIndex", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "uint256", "name": "tokenId", "type": "uint256" } - ], - "name": "tokenURI", - "outputs": [{ "internalType": "string", "name": "", "type": "string" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "totalSupply", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "from", "type": "address" }, - { "internalType": "address", "name": "to", "type": "address" }, - { "internalType": "uint256", "name": "tokenId", "type": "uint256" } - ], - "name": "transferFrom", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "unpause", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "newImplementation", - "type": "address" - } - ], - "name": "upgradeTo", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "newImplementation", - "type": "address" - }, - { "internalType": "bytes", "name": "data", "type": "bytes" } - ], - "name": "upgradeToAndCall", - "outputs": [], - "stateMutability": "payable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "to", "type": "address" }, - { "internalType": "address", "name": "currency", "type": "address" } - ], - "name": "withdraw", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { "stateMutability": "payable", "type": "receive" } - ] as const - \ No newline at end of file +import arbitrumABI from './w3bucket.arbitrum.abi.json'; +import ethABI from './w3bucket.abi.json'; +import { chain } from "wagmi"; + +export function setABI(chainId: number) { + if (chainId === chain.arbitrumGoerli.id || chainId === chain.arbitrum.id) { + abi = arbitrumABI; + } + abi = ethABI; +} + +export let abi = [] \ No newline at end of file diff --git a/lib/abi/w3bucket.arbitrum.abi.json b/lib/abi/w3bucket.arbitrum.abi.json new file mode 100644 index 0000000..58512d2 --- /dev/null +++ b/lib/abi/w3bucket.arbitrum.abi.json @@ -0,0 +1,1235 @@ +[ + { + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "previousAdmin", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "newAdmin", + "type": "address" + } + ], + "name": "AdminChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "approved", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "operator", + "type": "address" + }, + { + "indexed": false, + "internalType": "bool", + "name": "approved", + "type": "bool" + } + ], + "name": "ApprovalForAll", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "beacon", + "type": "address" + } + ], + "name": "BeaconUpgraded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "editionId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "capacityInGigabytes", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "address", + "name": "currency", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "price", + "type": "uint256" + } + ], + "name": "BucketMinted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "editionId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "currency", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "price", + "type": "uint256" + } + ], + "name": "EditionPriceUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "editionId", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "capacityInGigabytes", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "maxMintableSupply", + "type": "uint256" + } + ], + "name": "EditionUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint8", + "name": "version", + "type": "uint8" + } + ], + "name": "Initialized", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "Paused", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "string", + "name": "_value", + "type": "string" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "_id", + "type": "uint256" + } + ], + "name": "PermanentURI", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "previousAdminRole", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "newAdminRole", + "type": "bytes32" + } + ], + "name": "RoleAdminChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "RoleGranted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "RoleRevoked", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "Unpaused", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "implementation", + "type": "address" + } + ], + "name": "Upgraded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "currency", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "Withdraw", + "type": "event" + }, + { + "inputs": [], + "name": "DEFAULT_ADMIN_ROLE", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "EDITIONS_ADMIN_ROLE", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "EDITION_MAX_MINTABLE_SUPPLY", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "EDITION_TOKEN_ID_FACTOR", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAX_EDITION_ID", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MIN_EDITION_ID", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "PAUSER_ROLE", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "UPGRADER_ROLE", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "WITHDRAWER_ROLE", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "burn", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "getApproved", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "editionId", + "type": "uint256" + } + ], + "name": "getBucketEditionPrices", + "outputs": [ + { + "components": [ + { + "internalType": "address", + "name": "currency", + "type": "address" + }, + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + } + ], + "internalType": "struct BucketEditionUpgradable.EditionPrice[]", + "name": "", + "type": "tuple[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bool", + "name": "activeOnly", + "type": "bool" + } + ], + "name": "getBucketEditions", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "editionId", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "active", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "capacityInGigabytes", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxMintableSupply", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "currentSupplyMinted", + "type": "uint256" + } + ], + "internalType": "struct BucketEditionUpgradable.BucketEdition[]", + "name": "", + "type": "tuple[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + } + ], + "name": "getRoleAdmin", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + } + ], + "name": "getRoleMember", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + } + ], + "name": "getRoleMemberCount", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "grantRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "hasRole", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "name", + "type": "string" + }, + { + "internalType": "string", + "name": "symbol", + "type": "string" + } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "address", + "name": "operator", + "type": "address" + } + ], + "name": "isApprovedForAll", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "editionId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "currency", + "type": "address" + }, + { + "internalType": "string", + "name": "uri", + "type": "string" + } + ], + "name": "mint", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "ownerOf", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "pause", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "paused", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "proxiableUUID", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "renounceRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "revokeRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "safeTransferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "safeTransferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "operator", + "type": "address" + }, + { + "internalType": "bool", + "name": "approved", + "type": "bool" + } + ], + "name": "setApprovalForAll", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "editionId", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "address", + "name": "currency", + "type": "address" + }, + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + } + ], + "internalType": "struct BucketEditionUpgradable.EditionPrice[]", + "name": "prices", + "type": "tuple[]" + } + ], + "name": "setBucketEditionPrices", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "editionId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "capacityInGigabytes", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxMintableSupply", + "type": "uint256" + } + ], + "internalType": "struct BucketEditionUpgradable.BucketEditionParams[]", + "name": "editions", + "type": "tuple[]" + } + ], + "name": "setBucketEditions", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes4", + "name": "interfaceId", + "type": "bytes4" + } + ], + "name": "supportsInterface", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + } + ], + "name": "tokenByIndex", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + } + ], + "name": "tokenOfOwnerByIndex", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "tokenURI", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalSupply", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "unpause", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newImplementation", + "type": "address" + } + ], + "name": "upgradeTo", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newImplementation", + "type": "address" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "upgradeToAndCall", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "address", + "name": "currency", + "type": "address" + } + ], + "name": "withdraw", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "stateMutability": "payable", + "type": "receive" + } +] diff --git a/lib/config.ts b/lib/config.ts index 5120ded..54c7125 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -3,13 +3,29 @@ import { chain } from "wagmi"; import { IS_DEV } from "./env"; export const GA_ID = IS_DEV ? "-" : "-"; -export const W3Bucket_Adress: `0x${string}` = - IS_DEV || IS_TEST - ? "0x398663842680332A1AbA3B03bd6dB47aE984994C" - : "0x587ad7a26C5acae69D683fE923fD3f5B0700f3Ef"; +export let W3Bucket_Adress: `0x${string}` = "0x"; + +const chainId2ContractAddress = new Map([ + [chain.mainnet.id, "0x587ad7a26C5acae69D683fE923fD3f5B0700f3Ef"], + [chain.goerli.id, "0x398663842680332A1AbA3B03bd6dB47aE984994C"], + [chain.arbitrum.id, "0xe42719cDA4CCa7Abd2243e18604372C6B1c5790c"], + [chain.arbitrumGoerli.id, "0x1f0C5b696da48f5E93B1c3b3220E42b11b9a9E96"], +]); + +export function setW3BucketAddress(chainId: number) { + W3Bucket_Adress = chainId2ContractAddress.get(chainId); +} export const SupportChain = - IS_DEV || IS_TEST ? [chain.goerli] : [chain.mainnet]; + IS_DEV || IS_TEST ? [chain.goerli, chain.arbitrumGoerli] : [chain.mainnet, chain.arbitrum]; + +export const SupportId2Chain = (() => { + const res = new Map(); + for (const chain of SupportChain) { + res.set(chain.id, chain); + } + return res; +})() export interface AuthIpfsEndpoint { name?: string; diff --git a/lib/hooks/useConnected.ts b/lib/hooks/useConnected.ts index 88cccb7..a7e6d0a 100644 --- a/lib/hooks/useConnected.ts +++ b/lib/hooks/useConnected.ts @@ -1,14 +1,18 @@ import { useAccount } from "wagmi"; -import { IS_DEV, IS_TEST } from "@lib/env"; import { useMemo } from "react"; import { useNetwork } from "wagmi"; +import { SupportId2Chain, setW3BucketAddress } from "@lib/config"; +import { setABI } from "@lib/abi/w3bucket.abi"; export function useConnected() { const { chain } = useNetwork(); const chainId = chain && chain.id; const { address } = useAccount(); + if (chainId) { + setW3BucketAddress(chainId); + setABI(chainId); + } return useMemo(() => { - if (IS_DEV || IS_TEST) return address && chainId === 5; - return address && chainId === 1; + return address && SupportId2Chain.has(chainId); }, [address, chainId]); } diff --git a/lib/hooks/useGetAuth.ts b/lib/hooks/useGetAuth.ts index 22127cd..97e3762 100644 --- a/lib/hooks/useGetAuth.ts +++ b/lib/hooks/useGetAuth.ts @@ -39,7 +39,7 @@ export function useGetAuth( const getToken = useOn(async (tokenId?: string) => { const old = localStorage.getItem(key) || ""; - if (!signTypedDataAsync || !address || !chainId || unsupported) throw "not connect wallet"; + if (!signTypedDataAsync || !address || !chainId) throw "not connect wallet"; const current = moment().unix(); if (cache && old) { const lastAuth = JSON.parse(window.atob(old)).data; diff --git a/lib/type.d.ts b/lib/type.d.ts index 9020127..55c0b99 100644 --- a/lib/type.d.ts +++ b/lib/type.d.ts @@ -82,6 +82,7 @@ export interface CrustOrder { export interface MintData { color: MintColorType; qrcode: QRCODE_STYLE; + chainId?: number; editionId?: number; price?: Price; ipns?: string; diff --git a/lib/utils.ts b/lib/utils.ts index 50f0493..1b178e5 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -5,7 +5,8 @@ import isMobile from "ismobilejs"; import _ from "lodash"; import {utc} from "moment"; import numbro from "numbro"; -import {IS_DEV, IS_LOCAL, IS_TEST} from "./env"; +import { IS_LOCAL } from "./env"; +import { chain as chains } from "wagmi"; export const IS_MOBILE = isMobile(window.navigator).phone; @@ -117,21 +118,32 @@ export function sleep(t: number) { return new Promise((resolve) => setTimeout(resolve, t)); } -export function etherscanBase() { - const base = - IS_DEV || IS_TEST ? "https://goerli.etherscan.io" : "https://etherscan.io"; - return base; +export function etherscanBase(chainId: number) { + switch (chainId) { + case chains.mainnet.id: + return "https://etherscan.io"; + case chains.goerli.id: + return "https://goerli.etherscan.io"; + case chains.arbitrum.id: + return "https://arbiscan.io"; + case chains.arbitrumGoerli.id: + return "https://goerli.arbiscan.io"; + default: + console.warn(`chainId:${chainId} not supported.`) + } + return "https://etherscan.io"; } -export function bucketEtherscanUrl(tokenId: string | number) { - return `${etherscanBase()}/token/${W3Bucket_Adress}?a=${tokenId}`; + +export function bucketEtherscanUrl(chainId: number, tokenId: string | number) { + return `${etherscanBase(chainId)}/token/${W3Bucket_Adress}?a=${tokenId}`; } -export function etherscanTx(tx: string) { - return `${etherscanBase()}/tx/${tx}`; +export function etherscanTx(chainId: number, tx: string) { + return `${etherscanBase(chainId)}/tx/${tx}`; } -export function etherscanAddress(address: string) { - return `${etherscanBase()}/address/${address}`; +export function etherscanAddress(chainId: number, address: string) { + return `${etherscanBase(chainId)}/address/${address}`; } export function formatW3BucketCapacity(