From 17df803e07437ea68f05e9c379ced232c33ffa09 Mon Sep 17 00:00:00 2001 From: arjanjohan Date: Tue, 9 Jul 2024 15:56:12 +0200 Subject: [PATCH 1/6] networks added --- README.md | 5 +- package.json | 4 - packages/nextjs/app/bio/page.tsx | 11 +- .../ScaffoldEthAppWithProviders.tsx | 4 - .../CustomConnectButton/NetworkOptions.tsx | 8 +- .../scaffold-move/WalletContext.tsx | 2 +- .../hooks/scaffold-eth/useTargetNetwork.ts | 15 +- .../scaffold-move/useSubmitTransaction.ts | 15 +- .../hooks/scaffold-move/useTargetNetwork.ts | 23 + packages/nextjs/scaffold.config.ts | 21 +- packages/nextjs/services/store/store.ts | 8 +- packages/nextjs/services/web3/wagmiConfig.tsx | 30 - .../nextjs/services/web3/wagmiConnectors.tsx | 2 +- .../scaffold-eth/fetchPriceFromUniswap.ts | 70 -- packages/nextjs/utils/scaffold-eth/index.ts | 1 - .../nextjs/utils/scaffold-eth/networks.ts | 122 +-- .../nextjs/utils/scaffold-move/aptosClient.ts | 20 + packages/nextjs/utils/scaffold-move/chains.ts | 38 + yarn.lock | 781 +++++++++++++++++- 19 files changed, 891 insertions(+), 289 deletions(-) create mode 100644 packages/nextjs/hooks/scaffold-move/useTargetNetwork.ts delete mode 100644 packages/nextjs/services/web3/wagmiConfig.tsx delete mode 100644 packages/nextjs/utils/scaffold-eth/fetchPriceFromUniswap.ts create mode 100644 packages/nextjs/utils/scaffold-move/aptosClient.ts create mode 100644 packages/nextjs/utils/scaffold-move/chains.ts diff --git a/README.md b/README.md index e258bd6..bc7b97c 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,10 @@ For this hackathon I kept the scope small due to the time constraints. I build o - Styling of connect button - Store Aptos/Movement network data in scaffold-config - Debug page - - Msg for no result on view methods + - Msg for no result on view methods + error msg + - Formatting of input types + - Styling for resources tab + - Group contracts under address in list - Fix colors for dark mode - Ensure export default deployedContracts satisfies GenericContractsDeclaration - Add block explorer page diff --git a/package.json b/package.json index 412a647..35191d4 100644 --- a/package.json +++ b/package.json @@ -34,9 +34,5 @@ }, "engines": { "node": ">=18.17.0" - }, - "dependencies": { - "aptos": "^1.21.0", - "js-yaml": "^4.1.0" } } diff --git a/packages/nextjs/app/bio/page.tsx b/packages/nextjs/app/bio/page.tsx index dfdb70c..016529b 100644 --- a/packages/nextjs/app/bio/page.tsx +++ b/packages/nextjs/app/bio/page.tsx @@ -8,15 +8,10 @@ import { InputBase } from "~~/components/scaffold-eth"; import deployedModules from "~~/contracts/deployedModules"; import useSubmitTransaction from "~~/hooks/scaffold-move/useSubmitTransaction"; import { useGetAccountModules } from "~~/hooks/scaffold-move/useGetAccountModules"; +import { aptosClient } from "~~/utils/scaffold-move/aptosClient"; -// TODO: move this somewhere global -const aptosConfig = new AptosConfig({ - network: Network.CUSTOM, - fullnode: "https://aptos.devnet.m1.movementlabs.xyz", - indexer: "https://indexer.devnet.m1.movementlabs.xyz/", - faucet: "https://faucet2.movementlabs.xyz", -}); -const aptos = new Aptos(aptosConfig); + +const aptos = aptosClient("devnet"); const ONCHAIN_BIO = deployedModules.devnet.onchain_bio.abi; diff --git a/packages/nextjs/components/ScaffoldEthAppWithProviders.tsx b/packages/nextjs/components/ScaffoldEthAppWithProviders.tsx index 9c76e15..dddd424 100644 --- a/packages/nextjs/components/ScaffoldEthAppWithProviders.tsx +++ b/packages/nextjs/components/ScaffoldEthAppWithProviders.tsx @@ -2,12 +2,10 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import { Toaster } from "react-hot-toast"; -import { WagmiProvider } from "wagmi"; import { Footer } from "~~/components/Footer"; import { Header } from "~~/components/Header"; import { ProgressBar } from "~~/components/scaffold-eth/ProgressBar"; import { WalletProvider } from "~~/components/scaffold-move/WalletContext"; -import { wagmiConfig } from "~~/services/web3/wagmiConfig"; const ScaffoldEthApp = ({ children }: { children: React.ReactNode }) => { return ( @@ -32,7 +30,6 @@ export const queryClient = new QueryClient({ export const ScaffoldEthAppWithProviders = ({ children }: { children: React.ReactNode }) => { return ( - @@ -40,6 +37,5 @@ export const ScaffoldEthAppWithProviders = ({ children }: { children: React.Reac {children} - ); }; diff --git a/packages/nextjs/components/scaffold-move/CustomConnectButton/NetworkOptions.tsx b/packages/nextjs/components/scaffold-move/CustomConnectButton/NetworkOptions.tsx index ee75438..bf78e94 100644 --- a/packages/nextjs/components/scaffold-move/CustomConnectButton/NetworkOptions.tsx +++ b/packages/nextjs/components/scaffold-move/CustomConnectButton/NetworkOptions.tsx @@ -1,5 +1,4 @@ import { useTheme } from "next-themes"; -import { useAccount, useSwitchChain } from "wagmi"; import { ArrowsRightLeftIcon } from "@heroicons/react/24/solid"; import { getTargetNetworks } from "~~/utils/scaffold-eth"; @@ -10,22 +9,21 @@ type NetworkOptionsProps = { }; export const NetworkOptions = ({ hidden = false }: NetworkOptionsProps) => { - const { switchChain } = useSwitchChain(); - const { chain } = useAccount(); + const chain = "devnet"; // TODO: Get this from wallet? const { resolvedTheme } = useTheme(); const isDarkMode = resolvedTheme === "dark"; return ( <> {allowedNetworks - .filter(allowedNetwork => allowedNetwork.id !== chain?.id) + .filter(allowedNetwork => allowedNetwork.id !== chain) // TODO: DELETE .map(allowedNetwork => (
  • - + {accountHasBio && !transactionInProcess && ( -
    -
    {currentName}
    -
    {currentBio}
    +
    +
    + Name: +
    +
    + {currentName} +
    +
    + Bio: +
    +
    + {currentBio} +
    )} +
    + ); diff --git a/packages/nextjs/app/debug/_components/contract/ContractUI.tsx b/packages/nextjs/app/debug/_components/contract/ContractUI.tsx index 95605e0..5d8ed7a 100644 --- a/packages/nextjs/app/debug/_components/contract/ContractUI.tsx +++ b/packages/nextjs/app/debug/_components/contract/ContractUI.tsx @@ -3,12 +3,12 @@ // @refresh reset import { ContractReadMethods } from "./ContractReadMethods"; import { ModuleResources } from "./ModuleResources"; -import { ContractVariables } from "./ContractVariables"; import { ContractWriteMethods } from "./ContractWriteMethods"; import { Address, Balance} from "~~/components/scaffold-move"; import { useDeployedContractInfo } from "~~/hooks/scaffold-move"; import { ContractName } from "~~/utils/scaffold-eth/contract"; +import { useTargetNetwork } from "~~/hooks/scaffold-move/useTargetNetwork"; type ContractUIProps = { contractName: ContractName; @@ -19,8 +19,7 @@ type ContractUIProps = { * UI component to interface with deployed contracts. **/ export const ContractUI = ({ contractName, className = "" }: ContractUIProps) => { - // const { targetNetwork } = useTargetNetwork(); - const targetNetwork = "devnet" + const { targetNetwork } = useTargetNetwork(); const { data: deployedContractData, isLoading: deployedContractLoading } = useDeployedContractInfo(contractName); if (deployedContractLoading) { @@ -33,7 +32,7 @@ export const ContractUI = ({ contractName, className = "" }: ContractUIProps) => if (!deployedContractData || !deployedContractData.abi) { return (

    - {`No contract found by the name of "${contractName}" on chain "${targetNetwork}"!`} + {`No contract found by the name of "${String(contractName)}" on chain "${targetNetwork}"!`}

    ); } @@ -45,7 +44,7 @@ export const ContractUI = ({ contractName, className = "" }: ContractUIProps) =>
    - {contractName} + {String(contractName)}
    Balance: @@ -56,7 +55,7 @@ export const ContractUI = ({ contractName, className = "" }: ContractUIProps) => {targetNetwork && (

    Network:{" "} - {targetNetwork} + {String(targetNetwork.name)}

    )}
    diff --git a/packages/nextjs/app/debug/_components/contract/FunctionForm.tsx b/packages/nextjs/app/debug/_components/contract/FunctionForm.tsx index 6a218f7..0db3e16 100644 --- a/packages/nextjs/app/debug/_components/contract/FunctionForm.tsx +++ b/packages/nextjs/app/debug/_components/contract/FunctionForm.tsx @@ -3,7 +3,7 @@ import { Types } from "aptos"; import { parseTypeTag } from "@aptos-labs/ts-sdk"; import { - InputTransactionData, + InputTransactionData, useWallet } from "@aptos-labs/wallet-adapter-react"; import { useState } from "react"; @@ -46,8 +46,9 @@ export const FunctionForm = ({ const [viewInProcess, setViewInProcess] = useState(false); const [result, setResult] = useState(); const [data, setData] = useState({ typeArgs: [], args: [] }); - // const [state] = useGlobalState(); - const state = {network_value: "https://aptos.devnet.m1.movementlabs.xyz"} + + const { account } = useWallet(); + const state = { network_value: "https://aptos.devnet.m1.movementlabs.xyz" } const fnParams = removeSignerParam(fn, write); @@ -154,7 +155,6 @@ export const FunctionForm = ({ {fn.name}

    {fnParams.map((param, i) => { - // const isOption = param.startsWith("0x1::option::Option"); return (
    @@ -179,7 +179,7 @@ export const FunctionForm = ({
    - {transactionResponse !== null && transactionResponse?.transactionSubmitted && ( + {transactionResponse !== null && transactionResponse?.transactionSubmitted && (

    Result:

    {transactionResponse.success ? "✅ transaction successful" : "❌ transaction failed"}
    @@ -189,7 +189,7 @@ export const FunctionForm = ({ {/* {displayedTxResult ? : null} */}
    - diff --git a/packages/nextjs/app/debug/_components/contract/utilsDisplay.tsx b/packages/nextjs/app/debug/_components/contract/utilsDisplay.tsx index 3148aff..fab99eb 100644 --- a/packages/nextjs/app/debug/_components/contract/utilsDisplay.tsx +++ b/packages/nextjs/app/debug/_components/contract/utilsDisplay.tsx @@ -1,7 +1,7 @@ import { ReactElement, useState } from "react"; import { TransactionBase, TransactionReceipt, formatEther, isAddress, isHex } from "viem"; import { ArrowsRightLeftIcon } from "@heroicons/react/24/solid"; -import { Address } from "~~/components/scaffold-eth"; +import { Address } from "~~/components/scaffold-move"; import { replacer } from "~~/utils/scaffold-eth/common"; type DisplayContent = diff --git a/packages/nextjs/components/Footer.tsx b/packages/nextjs/components/Footer.tsx index bd5c976..96ee138 100644 --- a/packages/nextjs/components/Footer.tsx +++ b/packages/nextjs/components/Footer.tsx @@ -1,18 +1,17 @@ import React from "react"; -import Link from "next/link"; -import { hardhat } from "viem/chains"; -import { MagnifyingGlassIcon } from "@heroicons/react/24/outline"; +// import Link from "next/link"; +// import { MagnifyingGlassIcon } from "@heroicons/react/24/outline"; import { HeartIcon } from "@heroicons/react/24/outline"; import { SwitchTheme } from "~~/components/SwitchTheme"; // import { Faucet } from "~~/components/scaffold-eth"; -import { useTargetNetwork } from "~~/hooks/scaffold-eth/useTargetNetwork"; +import { useTargetNetwork } from "~~/hooks/scaffold-move/useTargetNetwork"; /** * Site footer */ export const Footer = () => { const { targetNetwork } = useTargetNetwork(); - const isLocalNetwork = targetNetwork.id === hardhat.id; + const isLocalNetwork = targetNetwork.id === "local"; return (
    diff --git a/packages/nextjs/components/Header.tsx b/packages/nextjs/components/Header.tsx index 1290aeb..193d002 100644 --- a/packages/nextjs/components/Header.tsx +++ b/packages/nextjs/components/Header.tsx @@ -4,7 +4,6 @@ import React, { useRef, useState } from "react"; import Image from "next/image"; import Link from "next/link"; import { usePathname } from "next/navigation"; -import { WalletSelector } from "@aptos-labs/wallet-adapter-ant-design"; import { Bars3Icon, BugAntIcon } from "@heroicons/react/24/outline"; // import { FaucetButton } from "~~/components/scaffold-eth"; // import { useOutsideClick } from "~~/hooks/scaffold-eth"; diff --git a/packages/nextjs/components/scaffold-eth/Address.tsx b/packages/nextjs/components/scaffold-eth/Address.tsx deleted file mode 100644 index f24b459..0000000 --- a/packages/nextjs/components/scaffold-eth/Address.tsx +++ /dev/null @@ -1,141 +0,0 @@ -"use client"; - -import { useEffect, useState } from "react"; -import Link from "next/link"; -import { CopyToClipboard } from "react-copy-to-clipboard"; -import { Address as AddressType, getAddress, isAddress } from "viem"; -import { hardhat } from "viem/chains"; -import { normalize } from "viem/ens"; -import { useEnsAvatar, useEnsName } from "wagmi"; -import { CheckCircleIcon, DocumentDuplicateIcon } from "@heroicons/react/24/outline"; -import { BlockieAvatar } from "~~/components/scaffold-eth"; -import { useTargetNetwork } from "~~/hooks/scaffold-eth/useTargetNetwork"; -import { getBlockExplorerAddressLink } from "~~/utils/scaffold-eth"; - -type AddressProps = { - address?: AddressType; - disableAddressLink?: boolean; - format?: "short" | "long"; - size?: "xs" | "sm" | "base" | "lg" | "xl" | "2xl" | "3xl"; -}; - -const blockieSizeMap = { - xs: 6, - sm: 7, - base: 8, - lg: 9, - xl: 10, - "2xl": 12, - "3xl": 15, -}; - -/** - * Displays an address (or ENS) with a Blockie image and option to copy address. - */ -export const Address = ({ address, disableAddressLink, format, size = "base" }: AddressProps) => { - const [ens, setEns] = useState(); - const [ensAvatar, setEnsAvatar] = useState(); - const [addressCopied, setAddressCopied] = useState(false); - const checkSumAddress = address ? getAddress(address) : undefined; - - const { targetNetwork } = useTargetNetwork(); - - const { data: fetchedEns } = useEnsName({ - address: checkSumAddress, - chainId: 1, - query: { - enabled: isAddress(checkSumAddress ?? ""), - }, - }); - const { data: fetchedEnsAvatar } = useEnsAvatar({ - name: fetchedEns ? normalize(fetchedEns) : undefined, - chainId: 1, - query: { - enabled: Boolean(fetchedEns), - gcTime: 30_000, - }, - }); - - // We need to apply this pattern to avoid Hydration errors. - useEffect(() => { - setEns(fetchedEns); - }, [fetchedEns]); - - useEffect(() => { - setEnsAvatar(fetchedEnsAvatar); - }, [fetchedEnsAvatar]); - - // Skeleton UI - if (!checkSumAddress) { - return ( -
    -
    -
    -
    -
    -
    - ); - } - - if (!isAddress(checkSumAddress)) { - return Wrong address; - } - - const blockExplorerAddressLink = getBlockExplorerAddressLink(targetNetwork, checkSumAddress); - let displayAddress = checkSumAddress?.slice(0, 6) + "..." + checkSumAddress?.slice(-4); - - if (ens) { - displayAddress = ens; - } else if (format === "long") { - displayAddress = checkSumAddress; - } - - return ( -
    -
    - -
    - {disableAddressLink ? ( - {displayAddress} - ) : targetNetwork.id === hardhat.id ? ( - - {displayAddress} - - ) : ( - - {displayAddress} - - )} - {addressCopied ? ( -
    - ); -}; diff --git a/packages/nextjs/components/scaffold-eth/index.tsx b/packages/nextjs/components/scaffold-eth/index.tsx index 5475153..be66d76 100644 --- a/packages/nextjs/components/scaffold-eth/index.tsx +++ b/packages/nextjs/components/scaffold-eth/index.tsx @@ -1,3 +1 @@ -export * from "./Address"; -export * from "./BlockieAvatar"; export * from "./Input"; diff --git a/packages/nextjs/components/scaffold-move/Address.tsx b/packages/nextjs/components/scaffold-move/Address.tsx index 298c489..ab200e7 100644 --- a/packages/nextjs/components/scaffold-move/Address.tsx +++ b/packages/nextjs/components/scaffold-move/Address.tsx @@ -3,10 +3,9 @@ import { useState } from "react"; import Link from "next/link"; import { CopyToClipboard } from "react-copy-to-clipboard"; -import { hardhat } from "viem/chains"; import { CheckCircleIcon, DocumentDuplicateIcon } from "@heroicons/react/24/outline"; -import { BlockieAvatar } from "~~/components/scaffold-eth"; -import { useTargetNetwork } from "~~/hooks/scaffold-eth/useTargetNetwork"; +import { BlockieAvatar } from "~~/components/scaffold-move"; +import { useTargetNetwork } from "~~/hooks/scaffold-move/useTargetNetwork"; import { getBlockExplorerAddressLink } from "~~/utils/scaffold-eth"; type AddressProps = { @@ -95,7 +94,7 @@ export const Address = ({ address, disableAddressLink, format, size = "base" }:
    {disableAddressLink ? ( {displayAddress} - ) : targetNetwork.id === hardhat.id ? ( + ) : targetNetwork.id === "local" ? ( {displayAddress} diff --git a/packages/nextjs/components/scaffold-eth/BlockieAvatar.tsx b/packages/nextjs/components/scaffold-move/BlockieAvatar.tsx similarity index 100% rename from packages/nextjs/components/scaffold-eth/BlockieAvatar.tsx rename to packages/nextjs/components/scaffold-move/BlockieAvatar.tsx diff --git a/packages/nextjs/components/scaffold-move/CustomConnectButton/AddressInfoDropdown.tsx b/packages/nextjs/components/scaffold-move/CustomConnectButton/AddressInfoDropdown.tsx index 4f74b5d..365c356 100644 --- a/packages/nextjs/components/scaffold-move/CustomConnectButton/AddressInfoDropdown.tsx +++ b/packages/nextjs/components/scaffold-move/CustomConnectButton/AddressInfoDropdown.tsx @@ -10,7 +10,7 @@ import { DocumentDuplicateIcon, QrCodeIcon, } from "@heroicons/react/24/outline"; -import { BlockieAvatar, isENS } from "~~/components/scaffold-eth"; +import { BlockieAvatar, isENS } from "~~/components/scaffold-move"; import { useOutsideClick } from "~~/hooks/scaffold-move"; import { getTargetNetworks } from "~~/utils/scaffold-eth"; import { diff --git a/packages/nextjs/components/scaffold-move/CustomConnectButton/index.tsx b/packages/nextjs/components/scaffold-move/CustomConnectButton/index.tsx index e3dcbc2..2308379 100644 --- a/packages/nextjs/components/scaffold-move/CustomConnectButton/index.tsx +++ b/packages/nextjs/components/scaffold-move/CustomConnectButton/index.tsx @@ -1,10 +1,9 @@ "use client"; -import { useEffect, useState } from "react"; import { Balance } from "../Balance"; import { AddressInfoDropdown } from "./AddressInfoDropdown"; -import { WrongNetworkDropdown } from "./WrongNetworkDropdown"; -import { useTargetNetwork } from "~~/hooks/scaffold-eth/useTargetNetwork"; +// import { WrongNetworkDropdown } from "./WrongNetworkDropdown"; +import { useTargetNetwork } from "~~/hooks/scaffold-move/useTargetNetwork"; import { getBlockExplorerAddressLink } from "~~/utils/scaffold-eth"; import { WalletSelector } from "@aptos-labs/wallet-adapter-ant-design"; @@ -15,8 +14,8 @@ import { export const CustomConnectButton = () => { const { targetNetwork } = useTargetNetwork(); - // const [account, setAccount] = useState(null); const chain = {name: "devnet"}; // TODO: replace + const { account, connected} = useWallet(); @@ -37,13 +36,13 @@ export const CustomConnectButton = () => { : ( <>
    - {/* */} - {chain ? chain.name : "Loading..."} + + {chain ? targetNetwork.name : "Loading..."}
    diff --git a/packages/nextjs/components/scaffold-move/Input/index.ts b/packages/nextjs/components/scaffold-move/Input/index.ts new file mode 100644 index 0000000..edafec3 --- /dev/null +++ b/packages/nextjs/components/scaffold-move/Input/index.ts @@ -0,0 +1,3 @@ +"use client"; + +export * from "./utils"; diff --git a/packages/nextjs/components/scaffold-move/Input/utils.ts b/packages/nextjs/components/scaffold-move/Input/utils.ts new file mode 100644 index 0000000..519f535 --- /dev/null +++ b/packages/nextjs/components/scaffold-move/Input/utils.ts @@ -0,0 +1,3 @@ +// Treat any dot-separated string as a potential ENS name +const ensRegex = /.+\..+/; +export const isENS = (address = "") => ensRegex.test(address); diff --git a/packages/nextjs/components/scaffold-move/WalletContext.tsx b/packages/nextjs/components/scaffold-move/WalletContext.tsx index 35e0305..44af9cc 100644 --- a/packages/nextjs/components/scaffold-move/WalletContext.tsx +++ b/packages/nextjs/components/scaffold-move/WalletContext.tsx @@ -1,4 +1,4 @@ -import { ReactNode, createContext, useContext } from "react"; +import { ReactNode } from "react"; import { AptosWalletAdapterProvider } from "@aptos-labs/wallet-adapter-react"; import { PetraWallet, } from "petra-plugin-wallet-adapter"; diff --git a/packages/nextjs/components/scaffold-move/index.tsx b/packages/nextjs/components/scaffold-move/index.tsx index 8064f6b..b2e7789 100644 --- a/packages/nextjs/components/scaffold-move/index.tsx +++ b/packages/nextjs/components/scaffold-move/index.tsx @@ -1,3 +1,5 @@ export * from "./Address"; export * from "./Balance"; export * from "./CustomConnectButton"; +export * from "./BlockieAvatar"; +export * from "./Input"; \ No newline at end of file diff --git a/packages/nextjs/hooks/scaffold-eth/index.ts b/packages/nextjs/hooks/scaffold-eth/index.ts deleted file mode 100644 index 6f79f41..0000000 --- a/packages/nextjs/hooks/scaffold-eth/index.ts +++ /dev/null @@ -1,15 +0,0 @@ -export * from "./useAnimationConfig"; -// export * from "./useBurnerWallet"; -// export * from "./useContractLogs"; -// export * from "./useDeployedContractInfo"; -// export * from "./useFetchBlocks"; -// export * from "./useNetworkColor"; -// export * from "./useOutsideClick"; -// // export * from "./useScaffoldContract"; -// // export * from "./useScaffoldEventHistory"; -// export * from "./useScaffoldReadContract"; -// // export * from "./useScaffoldWatchContractEvent"; -// export * from "./useScaffoldWriteContract"; -export * from "./useTargetNetwork"; -// export * from "./useTransactor"; -// export * from "./useWatchBalance"; diff --git a/packages/nextjs/hooks/scaffold-eth/useAnimationConfig.ts b/packages/nextjs/hooks/scaffold-eth/useAnimationConfig.ts deleted file mode 100644 index e0044fd..0000000 --- a/packages/nextjs/hooks/scaffold-eth/useAnimationConfig.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { useEffect, useState } from "react"; - -const ANIMATION_TIME = 2000; - -export function useAnimationConfig(data: any) { - const [showAnimation, setShowAnimation] = useState(false); - const [prevData, setPrevData] = useState(); - - useEffect(() => { - if (prevData !== undefined && prevData !== data) { - setShowAnimation(true); - setTimeout(() => setShowAnimation(false), ANIMATION_TIME); - } - setPrevData(data); - }, [data, prevData]); - - return { - showAnimation, - }; -} diff --git a/packages/nextjs/hooks/scaffold-eth/useTargetNetwork.ts b/packages/nextjs/hooks/scaffold-eth/useTargetNetwork.ts deleted file mode 100644 index 7d71e15..0000000 --- a/packages/nextjs/hooks/scaffold-eth/useTargetNetwork.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { useEffect, useMemo } from "react"; -import scaffoldConfig from "~~/scaffold.config"; -import { useGlobalState } from "~~/services/store/store"; -import { ChainWithAttributes } from "~~/utils/scaffold-eth"; -import { NETWORKS_EXTRA_DATA } from "~~/utils/scaffold-eth"; - -/** - * Retrieves the connected wallet's network from scaffold.config or defaults to the 0th network in the list if the wallet is not connected. - */ -export function useTargetNetwork(): { targetNetwork: ChainWithAttributes } { - const chain = "devnet"; - const targetNetwork = useGlobalState(({ targetNetwork }) => targetNetwork); - const setTargetNetwork = useGlobalState(({ setTargetNetwork }) => setTargetNetwork); - - // useEffect(() => { - // const newSelectedNetwork = scaffoldConfig.targetNetworks.find(targetNetwork => targetNetwork.id === chain?.id); - // if (newSelectedNetwork && newSelectedNetwork.id !== targetNetwork.id) { - // setTargetNetwork(newSelectedNetwork); - // } - // }, [chain?.id, setTargetNetwork, targetNetwork.id]); - - return useMemo( - () => ({ - targetNetwork: { - ...targetNetwork, - ...NETWORKS_EXTRA_DATA[targetNetwork.id], - }, - }), - [targetNetwork], - ); -} diff --git a/packages/nextjs/hooks/scaffold-move/useSubmitTransaction.ts b/packages/nextjs/hooks/scaffold-move/useSubmitTransaction.ts index 420517c..5697861 100644 --- a/packages/nextjs/hooks/scaffold-move/useSubmitTransaction.ts +++ b/packages/nextjs/hooks/scaffold-move/useSubmitTransaction.ts @@ -38,7 +38,7 @@ const useSubmitTransaction = () => { const network = useTargetNetwork(); - const aptos = aptosClient("devnet"); + const aptos = aptosClient("m1_devnet"); const state = {network_value: "https://aptos.devnet.m1.movementlabs.xyz", aptos_client: aptos} const {signAndSubmitTransaction} = useWallet(); diff --git a/packages/nextjs/utils/scaffold-eth/networks.ts b/packages/nextjs/utils/scaffold-eth/networks.ts index 0261665..ce8d6cb 100644 --- a/packages/nextjs/utils/scaffold-eth/networks.ts +++ b/packages/nextjs/utils/scaffold-eth/networks.ts @@ -15,7 +15,7 @@ export function getBlockExplorerTxLink(chainId: string, txnHash: string) { export function getBlockExplorerAddressLink(network: Chain, address: string) { const chainId = network.id; - return `https://explorer.${chainId}.m1.movementlabs.xyz/account/${address}?network=dev${chainId}net`; + return `https://explorer.${chainId}.m1.movementlabs.xyz/account/${address}?network=${chainId}`; } /** From b28ccddf6bbfc8248b2281032ec2d3edec6175ee Mon Sep 17 00:00:00 2001 From: arjanjohan Date: Tue, 9 Jul 2024 19:35:25 +0200 Subject: [PATCH 3/6] fix lint errors --- .../_components/contract/ModuleResource.tsx | 4 ++-- .../_components/contract/ModuleResources.tsx | 18 ++++++------------ .../AddressInfoDropdown.tsx | 2 +- .../CustomConnectButton/NetworkOptions.tsx | 3 --- 4 files changed, 9 insertions(+), 18 deletions(-) diff --git a/packages/nextjs/app/debug/_components/contract/ModuleResource.tsx b/packages/nextjs/app/debug/_components/contract/ModuleResource.tsx index cad9adf..5fe8749 100644 --- a/packages/nextjs/app/debug/_components/contract/ModuleResource.tsx +++ b/packages/nextjs/app/debug/_components/contract/ModuleResource.tsx @@ -11,8 +11,7 @@ type ModuleResourceProps = { const GROUP_ARRAYS_AFTER_LENGTH = 100; const COLLAPSE_STRINGS_AFTER_LENGTH = 80; -const MAX_CARD_HEIGHT = 500; - + export const ModuleResource = ({ key, resource, @@ -25,6 +24,7 @@ export const ModuleResource = ({ <>
    {resource.type}
    ; }) => { - if (!deployedContractData || deployedContractData.abi === undefined) { - return null; - } - const {isLoading, data, error} = useGetAccountResources(deployedContractData.abi!.address); - - const [accountResources, setAccountResources] = - useState(null); - + if (error) { + return <>Cannot fetch resources. + {error.type &&

    Error: {error.type}

    } + {error.message &&

    Error message: {error.message}

    } + ; + } if (!data?.length) { return <>No resources; diff --git a/packages/nextjs/components/scaffold-move/CustomConnectButton/AddressInfoDropdown.tsx b/packages/nextjs/components/scaffold-move/CustomConnectButton/AddressInfoDropdown.tsx index 365c356..1dea269 100644 --- a/packages/nextjs/components/scaffold-move/CustomConnectButton/AddressInfoDropdown.tsx +++ b/packages/nextjs/components/scaffold-move/CustomConnectButton/AddressInfoDropdown.tsx @@ -44,7 +44,7 @@ export const AddressInfoDropdown = ({ useOutsideClick(dropdownRef, closeDropdown); - const { disconnect, wallet } = useWallet(); + const { disconnect } = useWallet(); return ( <>
    diff --git a/packages/nextjs/components/scaffold-move/CustomConnectButton/NetworkOptions.tsx b/packages/nextjs/components/scaffold-move/CustomConnectButton/NetworkOptions.tsx index bf78e94..4078bde 100644 --- a/packages/nextjs/components/scaffold-move/CustomConnectButton/NetworkOptions.tsx +++ b/packages/nextjs/components/scaffold-move/CustomConnectButton/NetworkOptions.tsx @@ -1,4 +1,3 @@ -import { useTheme } from "next-themes"; import { ArrowsRightLeftIcon } from "@heroicons/react/24/solid"; import { getTargetNetworks } from "~~/utils/scaffold-eth"; @@ -10,8 +9,6 @@ type NetworkOptionsProps = { export const NetworkOptions = ({ hidden = false }: NetworkOptionsProps) => { const chain = "devnet"; // TODO: Get this from wallet? - const { resolvedTheme } = useTheme(); - const isDarkMode = resolvedTheme === "dark"; return ( <> From a4a0439a24a49885500d0a2c06b1a6e174158f9c Mon Sep 17 00:00:00 2001 From: arjanjohan Date: Tue, 9 Jul 2024 21:08:11 +0200 Subject: [PATCH 4/6] cleanup console logs --- packages/nextjs/app/bio/page.tsx | 4 ---- .../nextjs/app/debug/_components/contract/FunctionForm.tsx | 4 +--- .../nextjs/app/debug/_components/contract/ModuleResource.tsx | 2 -- .../nextjs/hooks/scaffold-move/useDeployedContractInfo.ts | 1 - packages/nextjs/hooks/scaffold-move/useSubmitTransaction.ts | 2 -- packages/nextjs/scaffold.config.ts | 2 +- 6 files changed, 2 insertions(+), 13 deletions(-) diff --git a/packages/nextjs/app/bio/page.tsx b/packages/nextjs/app/bio/page.tsx index 3787f55..f50921d 100644 --- a/packages/nextjs/app/bio/page.tsx +++ b/packages/nextjs/app/bio/page.tsx @@ -24,7 +24,6 @@ const OnchainBio: NextPage = () => { const [currentBio, setCurrentBio] = useState(null); const {data, isLoading, error} = useGetAccountModules(ONCHAIN_BIO.address); - console.log("useGetAccountModules", data, "isLoading", isLoading, "error", error); const {submitTransaction, transactionResponse, transactionInProcess} = @@ -32,7 +31,6 @@ const OnchainBio: NextPage = () => { const fetchBio = async () => { if (!account) { - console.log("No account"); return []; } try { @@ -44,13 +42,11 @@ const OnchainBio: NextPage = () => { }); setAccountHasBio(true); if (bioResource) { - console.log("Name:", bioResource.name, "Bio:", bioResource.bio); setCurrentName(bioResource.name); setCurrentBio(bioResource.bio); } else { setCurrentName(null); setCurrentBio(null); - console.log("no bio"); } } catch (e: any) { setAccountHasBio(false); diff --git a/packages/nextjs/app/debug/_components/contract/FunctionForm.tsx b/packages/nextjs/app/debug/_components/contract/FunctionForm.tsx index 0db3e16..1821ace 100644 --- a/packages/nextjs/app/debug/_components/contract/FunctionForm.tsx +++ b/packages/nextjs/app/debug/_components/contract/FunctionForm.tsx @@ -116,7 +116,6 @@ export const FunctionForm = ({ const handleView = async () => { let viewRequest: Types.ViewRequest; - console.log("viewRequest AVH", state.network_value, data.ledgerVersion); try { viewRequest = { @@ -132,7 +131,6 @@ export const FunctionForm = ({ } setViewInProcess(true); try { - console.log("viewRequest", viewRequest, state.network_value, data.ledgerVersion); const result = await view(viewRequest, state.network_value, data.ledgerVersion); setResult(result); console.log("function_interacted", fn.name, { txn_status: "success" }); @@ -143,7 +141,7 @@ export const FunctionForm = ({ error = error.substring(prefix.length).trim(); } setResult(undefined); - console.log("AVH function_interacted", fn.name, { txn_status: "failed" }); + console.log("function_interacted", fn.name, { txn_status: "failed" }); } setViewInProcess(false); }; diff --git a/packages/nextjs/app/debug/_components/contract/ModuleResource.tsx b/packages/nextjs/app/debug/_components/contract/ModuleResource.tsx index 5fe8749..c4ca7f5 100644 --- a/packages/nextjs/app/debug/_components/contract/ModuleResource.tsx +++ b/packages/nextjs/app/debug/_components/contract/ModuleResource.tsx @@ -18,8 +18,6 @@ export const ModuleResource = ({ collapsedByDefault }: ModuleResourceProps) => { - console.log("resource", resource); - return ( <>
    {resource.type}
    diff --git a/packages/nextjs/hooks/scaffold-move/useDeployedContractInfo.ts b/packages/nextjs/hooks/scaffold-move/useDeployedContractInfo.ts index 6e96446..e008ab9 100644 --- a/packages/nextjs/hooks/scaffold-move/useDeployedContractInfo.ts +++ b/packages/nextjs/hooks/scaffold-move/useDeployedContractInfo.ts @@ -10,7 +10,6 @@ export const useDeployedContractInfo = (cont const isMounted = useIsMounted(); const targetNetwork = "devnet"; const deployedContract = contracts?.[targetNetwork]?.[contractName.toString()] as Contract; - console.log("deployedContract", deployedContract); const [status, setStatus] = useState(ContractCodeStatus.LOADING); // const publicClient = usePublicClient({ chainId: targetNetwork.id }); diff --git a/packages/nextjs/hooks/scaffold-move/useSubmitTransaction.ts b/packages/nextjs/hooks/scaffold-move/useSubmitTransaction.ts index 5697861..edc8541 100644 --- a/packages/nextjs/hooks/scaffold-move/useSubmitTransaction.ts +++ b/packages/nextjs/hooks/scaffold-move/useSubmitTransaction.ts @@ -53,7 +53,6 @@ const useSubmitTransaction = () => { setTransactionInProcess(true); - console.log("submitting transaction", transaction); const signAndSubmitTransactionCall = async ( transaction: InputTransactionData, ): Promise => { @@ -64,7 +63,6 @@ const useSubmitTransaction = () => { let response; try { response = await signAndSubmitTransaction(transaction); - console.log("response", response); // transaction submit succeed if ("hash" in response) { diff --git a/packages/nextjs/scaffold.config.ts b/packages/nextjs/scaffold.config.ts index 9f00b70..539a25d 100644 --- a/packages/nextjs/scaffold.config.ts +++ b/packages/nextjs/scaffold.config.ts @@ -1,4 +1,4 @@ -import {Chain, defaultChains} from "../nextjs/utils/scaffold-move/chains"; +import {Chain, defaultChains} from "./utils/scaffold-move/chains"; export type ScaffoldConfig = { From a1218da8937dc3db205b77c3b0e5e314833fbb07 Mon Sep 17 00:00:00 2001 From: arjanjohan Date: Tue, 9 Jul 2024 21:16:36 +0200 Subject: [PATCH 5/6] yarn format --- packages/nextjs/app/bio/page.tsx | 39 +++++-------- .../app/debug/_components/DebugContracts.tsx | 1 - .../contract/ContractReadMethods.tsx | 19 ++----- .../debug/_components/contract/ContractUI.tsx | 21 +++---- .../contract/ContractWriteMethods.tsx | 18 ++---- .../_components/contract/FunctionForm.tsx | 49 +++++++--------- .../_components/contract/ModuleResource.tsx | 11 +--- .../_components/contract/ModuleResources.tsx | 32 +++++------ .../app/debug/_components/contract/index.tsx | 2 +- packages/nextjs/app/page.tsx | 12 ++-- packages/nextjs/components/Header.tsx | 3 +- .../ScaffoldEthAppWithProviders.tsx | 12 ++-- .../components/scaffold-move/Address.tsx | 3 +- .../components/scaffold-move/Balance.tsx | 4 +- .../AddressInfoDropdown.tsx | 8 +-- .../CustomConnectButton/NetworkOptions.tsx | 5 +- .../CustomConnectButton/index.tsx | 28 ++++------ .../scaffold-move/WalletContext.tsx | 4 +- .../nextjs/components/scaffold-move/index.tsx | 2 +- packages/nextjs/hooks/client.ts | 16 ++---- packages/nextjs/hooks/index.ts | 28 ++++------ packages/nextjs/hooks/scaffold-move/index.ts | 2 +- .../scaffold-move/useGetAccountAPTBalance.ts | 9 +-- .../scaffold-move/useGetAccountModules.ts | 20 +++---- .../scaffold-move/useGetAccountResources.ts | 15 ++--- .../hooks/scaffold-move/useGraphqlClient.tsx | 38 +++++-------- .../scaffold-move/useSubmitTransaction.ts | 47 +++++----------- .../hooks/scaffold-move/useTargetNetwork.ts | 3 +- packages/nextjs/scaffold.config.ts | 3 +- .../nextjs/utils/scaffold-eth/networks.ts | 1 - .../ContentValue/CurrencyValue.tsx | 35 ++---------- .../nextjs/utils/scaffold-move/aptosClient.ts | 30 +++++----- packages/nextjs/utils/scaffold-move/chains.ts | 56 +++++++++---------- .../nextjs/utils/scaffold-move/contract.ts | 9 +-- packages/nextjs/utils/utils.ts | 28 ++++------ 35 files changed, 225 insertions(+), 388 deletions(-) diff --git a/packages/nextjs/app/bio/page.tsx b/packages/nextjs/app/bio/page.tsx index f50921d..7d1fcc8 100644 --- a/packages/nextjs/app/bio/page.tsx +++ b/packages/nextjs/app/bio/page.tsx @@ -5,8 +5,8 @@ import { InputTransactionData, useWallet } from "@aptos-labs/wallet-adapter-reac import type { NextPage } from "next"; import { InputBase } from "~~/components/scaffold-eth"; import deployedModules from "~~/contracts/deployedModules"; -import useSubmitTransaction from "~~/hooks/scaffold-move/useSubmitTransaction"; import { useGetAccountModules } from "~~/hooks/scaffold-move/useGetAccountModules"; +import useSubmitTransaction from "~~/hooks/scaffold-move/useSubmitTransaction"; import { aptosClient } from "~~/utils/scaffold-move/aptosClient"; const aptos = aptosClient("m1_devnet"); @@ -23,18 +23,15 @@ const OnchainBio: NextPage = () => { const [currentName, setCurrentName] = useState(null); const [currentBio, setCurrentBio] = useState(null); - const {data, isLoading, error} = useGetAccountModules(ONCHAIN_BIO.address); - + const { data, isLoading, error } = useGetAccountModules(ONCHAIN_BIO.address); - const {submitTransaction, transactionResponse, transactionInProcess} = - useSubmitTransaction(); + const { submitTransaction, transactionResponse, transactionInProcess } = useSubmitTransaction(); const fetchBio = async () => { if (!account) { return []; } try { - const resourceName = "Bio"; const bioResource = await aptos.getAccountResource({ accountAddress: account?.address, @@ -133,25 +130,19 @@ const OnchainBio: NextPage = () => { Fetch Bio - - {accountHasBio && !transactionInProcess && ( -
    -
    - Name: -
    -
    - {currentName} -
    -
    - Bio: -
    -
    - {currentBio} -
    -
    - )} + {accountHasBio && !transactionInProcess && ( +
    +
    + Name: +
    +
    {currentName}
    +
    + Bio: +
    +
    {currentBio}
    +
    + )}
    -
    ); diff --git a/packages/nextjs/app/debug/_components/DebugContracts.tsx b/packages/nextjs/app/debug/_components/DebugContracts.tsx index 5ccaba5..a7e8100 100644 --- a/packages/nextjs/app/debug/_components/DebugContracts.tsx +++ b/packages/nextjs/app/debug/_components/DebugContracts.tsx @@ -11,7 +11,6 @@ const contractsData = getAllContracts(); const contractNames = Object.keys(contractsData) as ContractName[]; export function DebugContracts() { - const selectedContractStorageKey = "scaffoldEth2.selectedContract"; const [selectedContract, setSelectedContract] = useLocalStorage( diff --git a/packages/nextjs/app/debug/_components/contract/ContractReadMethods.tsx b/packages/nextjs/app/debug/_components/contract/ContractReadMethods.tsx index 2c4cefb..1d4564a 100644 --- a/packages/nextjs/app/debug/_components/contract/ContractReadMethods.tsx +++ b/packages/nextjs/app/debug/_components/contract/ContractReadMethods.tsx @@ -1,18 +1,12 @@ import { FunctionForm } from "~~/app/debug/_components/contract"; import { Contract, ContractName } from "~~/utils/scaffold-move/contract"; -export const ContractReadMethods = ({ - deployedContractData -}: { - deployedContractData: Contract -}) => { +export const ContractReadMethods = ({ deployedContractData }: { deployedContractData: Contract }) => { if (!deployedContractData || deployedContractData.abi === undefined) { return null; } - const functionsToDisplay = deployedContractData.abi.exposed_functions.filter((fn) => - fn.is_view, - ); + const functionsToDisplay = deployedContractData.abi.exposed_functions.filter(fn => fn.is_view); if (!functionsToDisplay.length) { return <>No view functions; @@ -20,15 +14,10 @@ export const ContractReadMethods = ({ return ( <> - {functionsToDisplay.map((fn, index) => (
    -
    + +
    ))} ); diff --git a/packages/nextjs/app/debug/_components/contract/ContractUI.tsx b/packages/nextjs/app/debug/_components/contract/ContractUI.tsx index 5d8ed7a..f5ac02d 100644 --- a/packages/nextjs/app/debug/_components/contract/ContractUI.tsx +++ b/packages/nextjs/app/debug/_components/contract/ContractUI.tsx @@ -2,13 +2,12 @@ // @refresh reset import { ContractReadMethods } from "./ContractReadMethods"; -import { ModuleResources } from "./ModuleResources"; import { ContractWriteMethods } from "./ContractWriteMethods"; -import { Address, Balance} from "~~/components/scaffold-move"; - +import { ModuleResources } from "./ModuleResources"; +import { Address, Balance } from "~~/components/scaffold-move"; import { useDeployedContractInfo } from "~~/hooks/scaffold-move"; +import { useTargetNetwork } from "~~/hooks/scaffold-move/useTargetNetwork"; import { ContractName } from "~~/utils/scaffold-eth/contract"; -import { useTargetNetwork } from "~~/hooks/scaffold-move/useTargetNetwork"; type ContractUIProps = { contractName: ContractName; @@ -48,18 +47,16 @@ export const ContractUI = ({ contractName, className = "" }: ContractUIProps) =>
    Balance: - +
    {targetNetwork && (

    - Network:{" "} - {String(targetNetwork.name)} + Network: {String(targetNetwork.name)}

    )}
    -
    @@ -82,9 +79,7 @@ export const ContractUI = ({ contractName, className = "" }: ContractUIProps) =>
    - +
    @@ -96,9 +91,7 @@ export const ContractUI = ({ contractName, className = "" }: ContractUIProps) =>
    - +
    diff --git a/packages/nextjs/app/debug/_components/contract/ContractWriteMethods.tsx b/packages/nextjs/app/debug/_components/contract/ContractWriteMethods.tsx index c21bfb1..d5efb83 100644 --- a/packages/nextjs/app/debug/_components/contract/ContractWriteMethods.tsx +++ b/packages/nextjs/app/debug/_components/contract/ContractWriteMethods.tsx @@ -1,18 +1,12 @@ import { FunctionForm } from "~~/app/debug/_components/contract"; import { Contract, ContractName } from "~~/utils/scaffold-move/contract"; -export const ContractWriteMethods = ({ - deployedContractData, -}: { - deployedContractData: Contract; -}) => { +export const ContractWriteMethods = ({ deployedContractData }: { deployedContractData: Contract }) => { if (!deployedContractData || deployedContractData.abi === undefined) { return null; } - const functionsToDisplay = deployedContractData.abi.exposed_functions.filter((fn) => - fn.is_entry, - ); + const functionsToDisplay = deployedContractData.abi.exposed_functions.filter(fn => fn.is_entry); if (!functionsToDisplay.length) { return <>No write functions; @@ -22,12 +16,8 @@ export const ContractWriteMethods = ({ <> {functionsToDisplay.map((fn, index) => (
    -
    + + ))} ); diff --git a/packages/nextjs/app/debug/_components/contract/FunctionForm.tsx b/packages/nextjs/app/debug/_components/contract/FunctionForm.tsx index 1821ace..fafbcc8 100644 --- a/packages/nextjs/app/debug/_components/contract/FunctionForm.tsx +++ b/packages/nextjs/app/debug/_components/contract/FunctionForm.tsx @@ -1,18 +1,14 @@ "use client"; -import { Types } from "aptos"; -import { parseTypeTag } from "@aptos-labs/ts-sdk"; -import { - InputTransactionData, useWallet -} from "@aptos-labs/wallet-adapter-react"; - import { useState } from "react"; -import useSubmitTransaction from "~~/hooks/scaffold-move/useSubmitTransaction"; import { encodeInputArgsForViewRequest } from "../../../../utils/utils"; -import { view } from "~~/hooks"; +import { parseTypeTag } from "@aptos-labs/ts-sdk"; +import { InputTransactionData, useWallet } from "@aptos-labs/wallet-adapter-react"; +import { Types } from "aptos"; // import { useGlobalState } from "../../../../global-config/GlobalConfig"; import { displayTxResult } from "~~/app/debug/_components/contract"; - +import { view } from "~~/hooks"; +import useSubmitTransaction from "~~/hooks/scaffold-move/useSubmitTransaction"; const zeroInputs = false; @@ -33,23 +29,17 @@ function removeSignerParam(fn: Types.MoveFunction, write: boolean) { if (!write) { return fn.params; } - return fn.params.filter((p) => p !== "signer" && p !== "&signer"); + return fn.params.filter(p => p !== "signer" && p !== "&signer"); } -export const FunctionForm = ({ - key, - module, - fn, - write, -}: FunctionFormProps) => { +export const FunctionForm = ({ key, module, fn, write }: FunctionFormProps) => { const { submitTransaction, transactionResponse, transactionInProcess } = useSubmitTransaction(); const [viewInProcess, setViewInProcess] = useState(false); const [result, setResult] = useState(); const [data, setData] = useState({ typeArgs: [], args: [] }); const { account } = useWallet(); - const state = { network_value: "https://aptos.devnet.m1.movementlabs.xyz" } - + const state = { network_value: "https://aptos.devnet.m1.movementlabs.xyz" }; const fnParams = removeSignerParam(fn, write); @@ -72,7 +62,7 @@ export const FunctionForm = ({ if (arg.startsWith("[")) { return JSON.parse(arg) as any[]; } else { - return arg.split(",").map((arg) => { + return arg.split(",").map(arg => { return arg.trim(); }); } @@ -149,9 +139,7 @@ export const FunctionForm = ({ return (
    -

    - {fn.name} -

    +

    {fn.name}

    {fnParams.map((param, i) => { return (
    @@ -162,7 +150,7 @@ export const FunctionForm = ({ { + onChange={e => { const newArgs = [...data.args]; newArgs[i] = e.target.value; setData({ ...data, args: newArgs }); @@ -176,23 +164,27 @@ export const FunctionForm = ({ {write && (
    - {transactionResponse !== null && transactionResponse?.transactionSubmitted && (

    Result:

    -
    {transactionResponse.success ? "✅ transaction successful" : "❌ transaction failed"}
    +
    +                    {transactionResponse.success ? "✅ transaction successful" : "❌ transaction failed"}
    +                  
    )} {/* TODO: Add TxReceipt for Move */} {/* {displayedTxResult ? : null} */}
    -
    - )} {!write && (
    @@ -210,11 +202,8 @@ export const FunctionForm = ({ Read 📡
    - )} -
    -
    ); }; diff --git a/packages/nextjs/app/debug/_components/contract/ModuleResource.tsx b/packages/nextjs/app/debug/_components/contract/ModuleResource.tsx index c4ca7f5..93aaf64 100644 --- a/packages/nextjs/app/debug/_components/contract/ModuleResource.tsx +++ b/packages/nextjs/app/debug/_components/contract/ModuleResource.tsx @@ -1,5 +1,4 @@ - -import {Types} from "aptos"; +import { Types } from "aptos"; import ReactJson from "react-json-view"; type ModuleResourceProps = { @@ -8,16 +7,10 @@ type ModuleResourceProps = { collapsedByDefault: boolean; }; - const GROUP_ARRAYS_AFTER_LENGTH = 100; const COLLAPSE_STRINGS_AFTER_LENGTH = 80; - -export const ModuleResource = ({ - key, - resource, - collapsedByDefault -}: ModuleResourceProps) => { +export const ModuleResource = ({ key, resource, collapsedByDefault }: ModuleResourceProps) => { return ( <>
    {resource.type}
    diff --git a/packages/nextjs/app/debug/_components/contract/ModuleResources.tsx b/packages/nextjs/app/debug/_components/contract/ModuleResources.tsx index 35f4ce2..c6c91e1 100644 --- a/packages/nextjs/app/debug/_components/contract/ModuleResources.tsx +++ b/packages/nextjs/app/debug/_components/contract/ModuleResources.tsx @@ -1,20 +1,18 @@ -import { Contract, ContractName } from "~~/utils/scaffold-move/contract"; -import {useGetAccountResources} from "~~/hooks/scaffold-move"; import { ModuleResource } from "./ModuleResource"; +import { useGetAccountResources } from "~~/hooks/scaffold-move"; +import { Contract, ContractName } from "~~/utils/scaffold-move/contract"; +export const ModuleResources = ({ deployedContractData }: { deployedContractData: Contract }) => { + const { isLoading, data, error } = useGetAccountResources(deployedContractData.abi!.address); -export const ModuleResources = ({ - deployedContractData, -}: { - deployedContractData: Contract; -}) => { - const {isLoading, data, error} = useGetAccountResources(deployedContractData.abi!.address); - if (error) { - return <>Cannot fetch resources. - {error.type &&

    Error: {error.type}

    } - {error.message &&

    Error message: {error.message}

    } - ; + return ( + <> + Cannot fetch resources. + {error.type &&

    Error: {error.type}

    } + {error.message &&

    Error message: {error.message}

    } + + ); } if (!data?.length) { @@ -26,12 +24,8 @@ export const ModuleResources = ({ {data.map((resource, index) => (
    -
    + +
    ))} ); diff --git a/packages/nextjs/app/debug/_components/contract/index.tsx b/packages/nextjs/app/debug/_components/contract/index.tsx index 2d5b26b..338472f 100644 --- a/packages/nextjs/app/debug/_components/contract/index.tsx +++ b/packages/nextjs/app/debug/_components/contract/index.tsx @@ -3,4 +3,4 @@ export * from "./ContractUI"; export * from "./TxReceipt"; export * from "./utilsContract"; export * from "./utilsDisplay"; -export * from "./FunctionForm" +export * from "./FunctionForm"; diff --git a/packages/nextjs/app/page.tsx b/packages/nextjs/app/page.tsx index 14dae44..b8c14a7 100644 --- a/packages/nextjs/app/page.tsx +++ b/packages/nextjs/app/page.tsx @@ -1,12 +1,10 @@ "use client"; import Link from "next/link"; +import { useWallet } from "@aptos-labs/wallet-adapter-react"; import type { NextPage } from "next"; import { BugAntIcon, MagnifyingGlassIcon } from "@heroicons/react/24/outline"; import { Address } from "~~/components/scaffold-move"; -import { - useWallet, -} from "@aptos-labs/wallet-adapter-react"; const Home: NextPage = () => { const { account: connectedAccount } = useWallet(); @@ -21,7 +19,7 @@ const Home: NextPage = () => {

    Connected Address:

    - +

    @@ -57,10 +55,8 @@ const Home: NextPage = () => {

    - Explore your local transactions with the{" "} - {/* */} - Block Explorer {" "} - {/* {" "} */} + Explore your local transactions with the {/* */} + Block Explorer {/* {" "} */} tab. Coming soon...

    diff --git a/packages/nextjs/components/Header.tsx b/packages/nextjs/components/Header.tsx index 193d002..ce8d5dc 100644 --- a/packages/nextjs/components/Header.tsx +++ b/packages/nextjs/components/Header.tsx @@ -7,8 +7,7 @@ import { usePathname } from "next/navigation"; import { Bars3Icon, BugAntIcon } from "@heroicons/react/24/outline"; // import { FaucetButton } from "~~/components/scaffold-eth"; // import { useOutsideClick } from "~~/hooks/scaffold-eth"; -import {CustomConnectButton} from "~~/components/scaffold-move"; - +import { CustomConnectButton } from "~~/components/scaffold-move"; type HeaderMenuLink = { label: string; diff --git a/packages/nextjs/components/ScaffoldEthAppWithProviders.tsx b/packages/nextjs/components/ScaffoldEthAppWithProviders.tsx index dddd424..b48ffd5 100644 --- a/packages/nextjs/components/ScaffoldEthAppWithProviders.tsx +++ b/packages/nextjs/components/ScaffoldEthAppWithProviders.tsx @@ -30,12 +30,12 @@ export const queryClient = new QueryClient({ export const ScaffoldEthAppWithProviders = ({ children }: { children: React.ReactNode }) => { return ( - - + + - - {children} - - + + {children} + + ); }; diff --git a/packages/nextjs/components/scaffold-move/Address.tsx b/packages/nextjs/components/scaffold-move/Address.tsx index ab200e7..7f37b53 100644 --- a/packages/nextjs/components/scaffold-move/Address.tsx +++ b/packages/nextjs/components/scaffold-move/Address.tsx @@ -72,13 +72,12 @@ export const Address = ({ address, disableAddressLink, format, size = "base" }: ); } - const blockExplorerAddressLink = getBlockExplorerAddressLink(targetNetwork, address); let displayAddress = address?.slice(0, 6) + "..." + address?.slice(-4); // if (ens) { // displayAddress = ens; - // } else + // } else if (format === "long") { displayAddress = address; } diff --git a/packages/nextjs/components/scaffold-move/Balance.tsx b/packages/nextjs/components/scaffold-move/Balance.tsx index e533712..3092c82 100644 --- a/packages/nextjs/components/scaffold-move/Balance.tsx +++ b/packages/nextjs/components/scaffold-move/Balance.tsx @@ -1,7 +1,7 @@ "use client"; -import {useGetAccountAPTBalance} from "~~/hooks/scaffold-move/useGetAccountAPTBalance"; -import {getFormattedBalanceStr} from "../../utils/scaffold-move/ContentValue/CurrencyValue" +import { getFormattedBalanceStr } from "../../utils/scaffold-move/ContentValue/CurrencyValue"; +import { useGetAccountAPTBalance } from "~~/hooks/scaffold-move/useGetAccountAPTBalance"; type BalanceProps = { address: string; diff --git a/packages/nextjs/components/scaffold-move/CustomConnectButton/AddressInfoDropdown.tsx b/packages/nextjs/components/scaffold-move/CustomConnectButton/AddressInfoDropdown.tsx index 1dea269..eb41d67 100644 --- a/packages/nextjs/components/scaffold-move/CustomConnectButton/AddressInfoDropdown.tsx +++ b/packages/nextjs/components/scaffold-move/CustomConnectButton/AddressInfoDropdown.tsx @@ -1,5 +1,6 @@ import { useRef, useState } from "react"; import { NetworkOptions } from "./NetworkOptions"; +import { useWallet } from "@aptos-labs/wallet-adapter-react"; import CopyToClipboard from "react-copy-to-clipboard"; import { ArrowLeftOnRectangleIcon, @@ -13,9 +14,6 @@ import { import { BlockieAvatar, isENS } from "~~/components/scaffold-move"; import { useOutsideClick } from "~~/hooks/scaffold-move"; import { getTargetNetworks } from "~~/utils/scaffold-eth"; -import { - useWallet -} from "@aptos-labs/wallet-adapter-react"; const allowedNetworks = getTargetNetworks(); @@ -32,7 +30,6 @@ export const AddressInfoDropdown = ({ displayName, blockExplorerAddressLink, }: AddressInfoDropdownProps) => { - const [addressCopied, setAddressCopied] = useState(false); const [selectingNetwork, setSelectingNetwork] = useState(false); @@ -43,7 +40,6 @@ export const AddressInfoDropdown = ({ }; useOutsideClick(dropdownRef, closeDropdown); - const { disconnect } = useWallet(); return ( <> @@ -120,7 +116,7 @@ export const AddressInfoDropdown = ({ Switch Network
  • - ) : null} + ) : null}
  • diff --git a/packages/nextjs/components/scaffold-move/CustomConnectButton/index.tsx b/packages/nextjs/components/scaffold-move/CustomConnectButton/index.tsx index 2308379..0a87f50 100644 --- a/packages/nextjs/components/scaffold-move/CustomConnectButton/index.tsx +++ b/packages/nextjs/components/scaffold-move/CustomConnectButton/index.tsx @@ -2,24 +2,17 @@ import { Balance } from "../Balance"; import { AddressInfoDropdown } from "./AddressInfoDropdown"; +import { WalletSelector } from "@aptos-labs/wallet-adapter-ant-design"; +import { useWallet } from "@aptos-labs/wallet-adapter-react"; // import { WrongNetworkDropdown } from "./WrongNetworkDropdown"; import { useTargetNetwork } from "~~/hooks/scaffold-move/useTargetNetwork"; import { getBlockExplorerAddressLink } from "~~/utils/scaffold-eth"; -import { WalletSelector } from "@aptos-labs/wallet-adapter-ant-design"; - - -import { - useWallet -} from "@aptos-labs/wallet-adapter-react"; export const CustomConnectButton = () => { const { targetNetwork } = useTargetNetwork(); - const chain = {name: "devnet"}; // TODO: replace - - - - const { account, connected} = useWallet(); + const chain = { name: "devnet" }; // TODO: replace + const { account, connected } = useWallet(); const blockExplorerAddressLink = account ? getBlockExplorerAddressLink(targetNetwork, account?.address) : undefined; @@ -27,16 +20,15 @@ export const CustomConnectButton = () => { <> {!connected ? (
    - +
    - ) - // : chainId !== targetNetwork.id ? ( - // - // ) - : ( + ) : ( + // : chainId !== targetNetwork.id ? ( + // + // ) <>
    - + {chain ? targetNetwork.name : "Loading..."}
    { const wallets = [new PetraWallet()]; diff --git a/packages/nextjs/components/scaffold-move/index.tsx b/packages/nextjs/components/scaffold-move/index.tsx index b2e7789..b930c90 100644 --- a/packages/nextjs/components/scaffold-move/index.tsx +++ b/packages/nextjs/components/scaffold-move/index.tsx @@ -2,4 +2,4 @@ export * from "./Address"; export * from "./Balance"; export * from "./CustomConnectButton"; export * from "./BlockieAvatar"; -export * from "./Input"; \ No newline at end of file +export * from "./Input"; diff --git a/packages/nextjs/hooks/client.ts b/packages/nextjs/hooks/client.ts index b199628..e51fde4 100644 --- a/packages/nextjs/hooks/client.ts +++ b/packages/nextjs/hooks/client.ts @@ -5,25 +5,21 @@ export enum ResponseErrorType { } export type ResponseError = - | {type: ResponseErrorType.NOT_FOUND; message?: string} - | {type: ResponseErrorType.UNHANDLED; message: string} - | {type: ResponseErrorType.TOO_MANY_REQUESTS; message?: string}; + | { type: ResponseErrorType.NOT_FOUND; message?: string } + | { type: ResponseErrorType.UNHANDLED; message: string } + | { type: ResponseErrorType.TOO_MANY_REQUESTS; message?: string }; export async function withResponseError(promise: Promise): Promise { - return await promise.catch((error) => { + return await promise.catch(error => { console.error("ERROR!", error, typeof error); if (typeof error == "object" && "status" in error) { // This is a request! error = error as Response; if (error.status === 404) { - throw {type: ResponseErrorType.NOT_FOUND}; + throw { type: ResponseErrorType.NOT_FOUND }; } } - if ( - error.message - .toLowerCase() - .includes(ResponseErrorType.TOO_MANY_REQUESTS.toLowerCase()) - ) { + if (error.message.toLowerCase().includes(ResponseErrorType.TOO_MANY_REQUESTS.toLowerCase())) { throw { type: ResponseErrorType.TOO_MANY_REQUESTS, }; diff --git a/packages/nextjs/hooks/index.ts b/packages/nextjs/hooks/index.ts index 502852e..e7b3112 100644 --- a/packages/nextjs/hooks/index.ts +++ b/packages/nextjs/hooks/index.ts @@ -1,5 +1,5 @@ -import {AptosClient, Types} from "aptos"; -import {withResponseError} from "./client"; +import { withResponseError } from "./client"; +import { AptosClient, Types } from "aptos"; // export async function getTransactions( // requestParameters: {start?: number; limit?: number}, @@ -95,18 +95,16 @@ import {withResponseError} from "./client"; // } export function getAccountResources( - requestParameters: {address: string; ledgerVersion?: number}, + requestParameters: { address: string; ledgerVersion?: number }, nodeUrl: string, ): Promise { const client = new AptosClient(nodeUrl); - const {address, ledgerVersion} = requestParameters; + const { address, ledgerVersion } = requestParameters; let ledgerVersionBig; if (ledgerVersion !== undefined) { ledgerVersionBig = BigInt(ledgerVersion); } - return withResponseError( - client.getAccountResources(address, {ledgerVersion: ledgerVersionBig}), - ); + return withResponseError(client.getAccountResources(address, { ledgerVersion: ledgerVersionBig })); } // export function getAccountResource( @@ -131,18 +129,16 @@ export function getAccountResources( // } export function getAccountModules( - requestParameters: {address: string; ledgerVersion?: number}, + requestParameters: { address: string; ledgerVersion?: number }, nodeUrl: string, ): Promise { const client = new AptosClient(nodeUrl); - const {address, ledgerVersion} = requestParameters; + const { address, ledgerVersion } = requestParameters; let ledgerVersionBig; if (ledgerVersion !== undefined) { ledgerVersionBig = BigInt(ledgerVersion); } - return withResponseError( - client.getAccountModules(address, {ledgerVersion: ledgerVersionBig}), - ); + return withResponseError(client.getAccountModules(address, { ledgerVersion: ledgerVersionBig })); } export function getAccountModule( @@ -154,7 +150,7 @@ export function getAccountModule( nodeUrl: string, ): Promise { const client = new AptosClient(nodeUrl); - const {address, moduleName, ledgerVersion} = requestParameters; + const { address, moduleName, ledgerVersion } = requestParameters; let ledgerVersionBig; if (ledgerVersion !== undefined) { ledgerVersionBig = BigInt(ledgerVersion); @@ -166,11 +162,7 @@ export function getAccountModule( ); } -export function view( - request: Types.ViewRequest, - nodeUrl: string, - ledgerVersion?: string, -): Promise { +export function view(request: Types.ViewRequest, nodeUrl: string, ledgerVersion?: string): Promise { const client = new AptosClient(nodeUrl); let parsedVersion = ledgerVersion; diff --git a/packages/nextjs/hooks/scaffold-move/index.ts b/packages/nextjs/hooks/scaffold-move/index.ts index b3ad99f..70c6df7 100644 --- a/packages/nextjs/hooks/scaffold-move/index.ts +++ b/packages/nextjs/hooks/scaffold-move/index.ts @@ -1,4 +1,4 @@ export * from "./useDeployedContractInfo"; export * from "./useGetAccountAPTBalance"; export * from "./useGetAccountResources"; -export * from "./useOutsideClick"; \ No newline at end of file +export * from "./useOutsideClick"; diff --git a/packages/nextjs/hooks/scaffold-move/useGetAccountAPTBalance.ts b/packages/nextjs/hooks/scaffold-move/useGetAccountAPTBalance.ts index 7b993b7..e1b9b8d 100644 --- a/packages/nextjs/hooks/scaffold-move/useGetAccountAPTBalance.ts +++ b/packages/nextjs/hooks/scaffold-move/useGetAccountAPTBalance.ts @@ -1,4 +1,4 @@ -import {useGetAccountResources} from "./useGetAccountResources"; +import { useGetAccountResources } from "./useGetAccountResources"; interface CoinStore { coin: { @@ -7,16 +7,13 @@ interface CoinStore { } export function useGetAccountAPTBalance(address: string) { - const {isLoading, data, error} = useGetAccountResources(address); + const { isLoading, data, error } = useGetAccountResources(address); if (isLoading || error || !data) { return null; } - const coinStore = data.find( - (resource) => - resource.type === "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>", - ); + const coinStore = data.find(resource => resource.type === "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>"); if (!coinStore) { return null; diff --git a/packages/nextjs/hooks/scaffold-move/useGetAccountModules.ts b/packages/nextjs/hooks/scaffold-move/useGetAccountModules.ts index 6120659..0c2e0be 100644 --- a/packages/nextjs/hooks/scaffold-move/useGetAccountModules.ts +++ b/packages/nextjs/hooks/scaffold-move/useGetAccountModules.ts @@ -1,18 +1,16 @@ -import {Types} from "aptos"; -import {useQuery, UseQueryResult} from "@tanstack/react-query"; -import {getAccountModules} from ".."; -import {ResponseError} from "../client"; +import { getAccountModules } from ".."; +import { ResponseError } from "../client"; +import { UseQueryResult, useQuery } from "@tanstack/react-query"; +import { Types } from "aptos"; + // import {useGlobalState} from "../../global-config/GlobalConfig"; -export function useGetAccountModules( - address: string, -): UseQueryResult { +export function useGetAccountModules(address: string): UseQueryResult { // const [state] = useGlobalState(); - const state = {network_value: "https://aptos.devnet.m1.movementlabs.xyz"} - + const state = { network_value: "https://aptos.devnet.m1.movementlabs.xyz" }; return useQuery, ResponseError>({ - queryKey: ["accountModules", {address}, state.network_value], - queryFn: () => getAccountModules({address}, state.network_value), + queryKey: ["accountModules", { address }, state.network_value], + queryFn: () => getAccountModules({ address }, state.network_value), }); } diff --git a/packages/nextjs/hooks/scaffold-move/useGetAccountResources.ts b/packages/nextjs/hooks/scaffold-move/useGetAccountResources.ts index ff88ef1..a7ddb23 100644 --- a/packages/nextjs/hooks/scaffold-move/useGetAccountResources.ts +++ b/packages/nextjs/hooks/scaffold-move/useGetAccountResources.ts @@ -1,7 +1,8 @@ -import {Types} from "aptos"; -import {useQuery, UseQueryResult} from "@tanstack/react-query"; -import {getAccountResources} from ".."; -import {ResponseError} from "../client"; +import { getAccountResources } from ".."; +import { ResponseError } from "../client"; +import { UseQueryResult, useQuery } from "@tanstack/react-query"; +import { Types } from "aptos"; + // import {useGlobalState} from "../../global-config/GlobalConfig"; export function useGetAccountResources( @@ -11,11 +12,11 @@ export function useGetAccountResources( }, ): UseQueryResult { // const [state] = useGlobalState(); - const state = {network_value: "https://aptos.devnet.m1.movementlabs.xyz"} + const state = { network_value: "https://aptos.devnet.m1.movementlabs.xyz" }; const test = useQuery, ResponseError>({ - queryKey: ["accountResources", {address}, state.network_value], - queryFn: () => getAccountResources({address}, state.network_value), + queryKey: ["accountResources", { address }, state.network_value], + queryFn: () => getAccountResources({ address }, state.network_value), retry: options?.retry ?? false, }); return test; diff --git a/packages/nextjs/hooks/scaffold-move/useGraphqlClient.tsx b/packages/nextjs/hooks/scaffold-move/useGraphqlClient.tsx index 0a131c7..1893270 100644 --- a/packages/nextjs/hooks/scaffold-move/useGraphqlClient.tsx +++ b/packages/nextjs/hooks/scaffold-move/useGraphqlClient.tsx @@ -1,13 +1,8 @@ import React from "react"; -import { - ApolloClient, - InMemoryCache, - ApolloProvider, - HttpLink, - NormalizedCacheObject, -} from "@apollo/client"; -import {useEffect, useState} from "react"; -import {Network, NetworkName} from "../../constants"; +import { useEffect, useState } from "react"; +import { Network, NetworkName } from "../../constants"; +import { ApolloClient, ApolloProvider, HttpLink, InMemoryCache, NormalizedCacheObject } from "@apollo/client"; + // import {useGlobalState} from "../../global-config/GlobalConfig"; function getIsGraphqlClientSupportedFor(networkName: NetworkName): boolean { @@ -32,9 +27,7 @@ export function getGraphqlURI(networkName: NetworkName): string | undefined { } } -function getGraphqlClient( - networkName: NetworkName, -): ApolloClient { +function getGraphqlClient(networkName: NetworkName): ApolloClient { return new ApolloClient({ link: new HttpLink({ uri: getGraphqlURI(networkName), @@ -45,11 +38,11 @@ function getGraphqlClient( export function useGetGraphqlClient() { // const [state] = useGlobalState(); - const state = {network_name: Network.DEVNET, network_value: "https://aptos.devnet.m1.movementlabs.xyz"} + const state = { network_name: Network.DEVNET, network_value: "https://aptos.devnet.m1.movementlabs.xyz" }; - const [graphqlClient, setGraphqlClient] = useState< - ApolloClient - >(getGraphqlClient(state.network_name)); + const [graphqlClient, setGraphqlClient] = useState>( + getGraphqlClient(state.network_name), + ); useEffect(() => { setGraphqlClient(getGraphqlClient(state.network_name)); @@ -62,7 +55,7 @@ type GraphqlClientProviderProps = { children: React.ReactNode; }; -export function GraphqlClientProvider({children}: GraphqlClientProviderProps) { +export function GraphqlClientProvider({ children }: GraphqlClientProviderProps) { const graphqlClient = useGetGraphqlClient(); return {children}; @@ -70,15 +63,14 @@ export function GraphqlClientProvider({children}: GraphqlClientProviderProps) { export function useGetIsGraphqlClientSupported(): boolean { // const [state] = useGlobalState(); - const state = {network_name: Network.DEVNET, network_value: "https://aptos.devnet.m1.movementlabs.xyz"} + const state = { network_name: Network.DEVNET, network_value: "https://aptos.devnet.m1.movementlabs.xyz" }; - const [isGraphqlClientSupported, setIsGraphqlClientSupported] = - useState(getIsGraphqlClientSupportedFor(state.network_name)); + const [isGraphqlClientSupported, setIsGraphqlClientSupported] = useState( + getIsGraphqlClientSupportedFor(state.network_name), + ); useEffect(() => { - setIsGraphqlClientSupported( - getIsGraphqlClientSupportedFor(state.network_name), - ); + setIsGraphqlClientSupported(getIsGraphqlClientSupportedFor(state.network_name)); }, [state.network_name]); return isGraphqlClientSupported; diff --git a/packages/nextjs/hooks/scaffold-move/useSubmitTransaction.ts b/packages/nextjs/hooks/scaffold-move/useSubmitTransaction.ts index edc8541..3a473b0 100644 --- a/packages/nextjs/hooks/scaffold-move/useSubmitTransaction.ts +++ b/packages/nextjs/hooks/scaffold-move/useSubmitTransaction.ts @@ -1,18 +1,11 @@ -import {FailedTransactionError} from "aptos"; -import {useEffect, useState} from "react"; -import { - useWallet, - InputTransactionData, -} from "@aptos-labs/wallet-adapter-react"; +import { useEffect, useState } from "react"; +import { InputTransactionData, useWallet } from "@aptos-labs/wallet-adapter-react"; +import { FailedTransactionError } from "aptos"; +import { useTargetNetwork } from "~~/hooks/scaffold-move/useTargetNetwork"; // import {useGlobalState} from "../../global-config/GlobalConfig"; import { aptosClient } from "~~/utils/scaffold-move/aptosClient"; -import { useTargetNetwork } from "~~/hooks/scaffold-move/useTargetNetwork"; - - -export type TransactionResponse = - | TransactionResponseOnSubmission - | TransactionResponseOnError; +export type TransactionResponse = TransactionResponseOnSubmission | TransactionResponseOnError; // "submission" here means that the transaction is posted on chain and gas is paid. // However, the status of the transaction might not be "success". @@ -29,19 +22,15 @@ export type TransactionResponseOnError = { }; const useSubmitTransaction = () => { - const [transactionResponse, setTransactionResponse] = - useState(null); - const [transactionInProcess, setTransactionInProcess] = - useState(false); + const [transactionResponse, setTransactionResponse] = useState(null); + const [transactionInProcess, setTransactionInProcess] = useState(false); // const [state] = useGlobalState(); - - const network = useTargetNetwork(); const aptos = aptosClient("m1_devnet"); - const state = {network_value: "https://aptos.devnet.m1.movementlabs.xyz", aptos_client: aptos} + const state = { network_value: "https://aptos.devnet.m1.movementlabs.xyz", aptos_client: aptos }; - const {signAndSubmitTransaction} = useWallet(); + const { signAndSubmitTransaction } = useWallet(); useEffect(() => { if (transactionResponse !== null) { @@ -50,12 +39,8 @@ const useSubmitTransaction = () => { }, [transactionResponse]); async function submitTransaction(transaction: InputTransactionData) { - - setTransactionInProcess(true); - const signAndSubmitTransactionCall = async ( - transaction: InputTransactionData, - ): Promise => { + const signAndSubmitTransactionCall = async (transaction: InputTransactionData): Promise => { const responseOnError: TransactionResponseOnError = { transactionSubmitted: false, message: "Unknown Error", @@ -69,9 +54,9 @@ const useSubmitTransaction = () => { // await state.aptos_client.waitForTransaction(response["hash"], { // checkSuccess: true, // }); - + await state.aptos_client.waitForTransaction(response["hash"]); - + return { transactionSubmitted: true, transactionHash: response["hash"], @@ -79,7 +64,7 @@ const useSubmitTransaction = () => { }; } // transaction failed - return {...responseOnError, message: response.message}; + return { ...responseOnError, message: response.message }; } catch (error) { if (error instanceof FailedTransactionError) { return { @@ -89,15 +74,13 @@ const useSubmitTransaction = () => { success: false, }; } else if (error instanceof Error) { - return {...responseOnError, message: error.message}; + return { ...responseOnError, message: error.message }; } } return responseOnError; }; - await signAndSubmitTransactionCall(transaction).then( - setTransactionResponse, - ); + await signAndSubmitTransactionCall(transaction).then(setTransactionResponse); } function clearTransactionResponse() { diff --git a/packages/nextjs/hooks/scaffold-move/useTargetNetwork.ts b/packages/nextjs/hooks/scaffold-move/useTargetNetwork.ts index 8f563fe..9841c87 100644 --- a/packages/nextjs/hooks/scaffold-move/useTargetNetwork.ts +++ b/packages/nextjs/hooks/scaffold-move/useTargetNetwork.ts @@ -18,6 +18,5 @@ export function useTargetNetwork(): { targetNetwork: Chain } { } }, [chain, setTargetNetwork, targetNetwork.id]); - return {targetNetwork}; - + return { targetNetwork }; } diff --git a/packages/nextjs/scaffold.config.ts b/packages/nextjs/scaffold.config.ts index 539a25d..5980e67 100644 --- a/packages/nextjs/scaffold.config.ts +++ b/packages/nextjs/scaffold.config.ts @@ -1,5 +1,4 @@ -import {Chain, defaultChains} from "./utils/scaffold-move/chains"; - +import { Chain, defaultChains } from "./utils/scaffold-move/chains"; export type ScaffoldConfig = { targetNetworks: readonly Chain[]; diff --git a/packages/nextjs/utils/scaffold-eth/networks.ts b/packages/nextjs/utils/scaffold-eth/networks.ts index ce8d6cb..27a523c 100644 --- a/packages/nextjs/utils/scaffold-eth/networks.ts +++ b/packages/nextjs/utils/scaffold-eth/networks.ts @@ -13,7 +13,6 @@ export function getBlockExplorerTxLink(chainId: string, txnHash: string) { * Defaults to Etherscan if no (wagmi) block explorer is configured for the network. */ export function getBlockExplorerAddressLink(network: Chain, address: string) { - const chainId = network.id; return `https://explorer.${chainId}.m1.movementlabs.xyz/account/${address}?network=${chainId}`; } diff --git a/packages/nextjs/utils/scaffold-move/ContentValue/CurrencyValue.tsx b/packages/nextjs/utils/scaffold-move/ContentValue/CurrencyValue.tsx index 8c2836b..19fbc4a 100644 --- a/packages/nextjs/utils/scaffold-move/ContentValue/CurrencyValue.tsx +++ b/packages/nextjs/utils/scaffold-move/ContentValue/CurrencyValue.tsx @@ -9,11 +9,7 @@ function trimRight(rightSide: string) { return rightSide; } -export function getFormattedBalanceStr( - balance: string, - decimals?: number, - fixedDecimalPlaces?: number, -): string { +export function getFormattedBalanceStr(balance: string, decimals?: number, fixedDecimalPlaces?: number): string { // If balance is zero or decimals is 0, just return it if (balance == "0" || (decimals !== undefined && decimals === 0)) { return balance; @@ -28,9 +24,7 @@ export function getFormattedBalanceStr( } // Otherwise, insert decimal point at len - decimals - const leftSide = BigInt(balance.slice(0, len - decimals)).toLocaleString( - "en-US", - ); + const leftSide = BigInt(balance.slice(0, len - decimals)).toLocaleString("en-US"); let rightSide = balance.slice(len - decimals); if (BigInt(rightSide) == BigInt(0)) { return leftSide; @@ -38,10 +32,7 @@ export function getFormattedBalanceStr( // remove trailing 0s rightSide = trimRight(rightSide); - if ( - fixedDecimalPlaces !== undefined && - rightSide.length > fixedDecimalPlaces - ) { + if (fixedDecimalPlaces !== undefined && rightSide.length > fixedDecimalPlaces) { rightSide = rightSide.slice(0, fixedDecimalPlaces - rightSide.length); } @@ -59,12 +50,7 @@ type CurrencyValueProps = { currencyCode?: string | React.ReactNode; }; -export default function CurrencyValue({ - amount, - decimals, - fixedDecimalPlaces, - currencyCode, -}: CurrencyValueProps) { +export default function CurrencyValue({ amount, decimals, fixedDecimalPlaces, currencyCode }: CurrencyValueProps) { const number = getFormattedBalanceStr(amount, decimals, fixedDecimalPlaces); if (currencyCode) { return ( @@ -77,21 +63,12 @@ export default function CurrencyValue({ } } -export function APTCurrencyValue({ - amount: amountStr, - decimals, - fixedDecimalPlaces, -}: CurrencyValueProps) { +export function APTCurrencyValue({ amount: amountStr, decimals, fixedDecimalPlaces }: CurrencyValueProps) { // remove leading "-" when it's a negative number let amount = amountStr; if (amountStr.startsWith("-")) { amount = amountStr.substring(1); } - return ( - - ); + return ; } diff --git a/packages/nextjs/utils/scaffold-move/aptosClient.ts b/packages/nextjs/utils/scaffold-move/aptosClient.ts index 003fe77..1b0c434 100644 --- a/packages/nextjs/utils/scaffold-move/aptosClient.ts +++ b/packages/nextjs/utils/scaffold-move/aptosClient.ts @@ -1,20 +1,20 @@ -import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk"; import { defaultChains } from "./chains"; +import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk"; export function aptosClient(chainId: string) { - const chain = defaultChains[chainId]; - if (!chain) { - throw new Error(`Chain with id ${chainId} not found`); - } + const chain = defaultChains[chainId]; + if (!chain) { + throw new Error(`Chain with id ${chainId} not found`); + } - const aptosConfig = new AptosConfig({ - network: chain.network, - ...(chain.network === Network.CUSTOM && { - fullnode: chain.fullnode, - indexer: chain.indexer, - faucet: chain.faucet, - }), - }); + const aptosConfig = new AptosConfig({ + network: chain.network, + ...(chain.network === Network.CUSTOM && { + fullnode: chain.fullnode, + indexer: chain.indexer, + faucet: chain.faucet, + }), + }); - return new Aptos(aptosConfig); -} \ No newline at end of file + return new Aptos(aptosConfig); +} diff --git a/packages/nextjs/utils/scaffold-move/chains.ts b/packages/nextjs/utils/scaffold-move/chains.ts index be599b6..d2bb5ef 100644 --- a/packages/nextjs/utils/scaffold-move/chains.ts +++ b/packages/nextjs/utils/scaffold-move/chains.ts @@ -1,38 +1,36 @@ - import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk"; export type Chain = { - id: string; - name: string; - network: Network; - fullnode?: string; - indexer?: string; - faucet?: string; + id: string; + name: string; + network: Network; + fullnode?: string; + indexer?: string; + faucet?: string; }; type Chains = { - [key: string]: Chain; + [key: string]: Chain; }; export const defaultChains: Chains = { - m1_devnet: { - id: 'devnet', - name: 'M1 Devnet', - network: Network.CUSTOM, - fullnode: 'https://aptos.devnet.m1.movementlabs.xyz', - indexer: 'https://indexer.devnet.m1.movementlabs.xyz/', - faucet: 'https://faucet2.movementlabs.xyz', - }, - // m1_testnet: { - // id: 'testnet', - // name: 'M1 Testnet', - // network: Network.CUSTOM, - // rpcUrl: 'https://devnet.m1.movementlabs.xyz/', - // }, - aptos_testnet: { - id: 'testnet', - name: 'Aptos Testnet', - network: Network.TESTNET, - }, - -}; \ No newline at end of file + m1_devnet: { + id: "devnet", + name: "M1 Devnet", + network: Network.CUSTOM, + fullnode: "https://aptos.devnet.m1.movementlabs.xyz", + indexer: "https://indexer.devnet.m1.movementlabs.xyz/", + faucet: "https://faucet2.movementlabs.xyz", + }, + // m1_testnet: { + // id: 'testnet', + // name: 'M1 Testnet', + // network: Network.CUSTOM, + // rpcUrl: 'https://devnet.m1.movementlabs.xyz/', + // }, + aptos_testnet: { + id: "testnet", + name: "Aptos Testnet", + network: Network.TESTNET, + }, +}; diff --git a/packages/nextjs/utils/scaffold-move/contract.ts b/packages/nextjs/utils/scaffold-move/contract.ts index c2b2ef6..546fbae 100644 --- a/packages/nextjs/utils/scaffold-move/contract.ts +++ b/packages/nextjs/utils/scaffold-move/contract.ts @@ -1,9 +1,8 @@ +import { Types } from "aptos"; import type { MergeDeepRecord } from "type-fest/source/merge-deep"; import deployedContractsData from "~~/contracts/deployedModules"; import externalContractsData from "~~/contracts/externalModules"; import scaffoldConfig from "~~/scaffold.config"; -import { Types } from "aptos"; - type AddExternalFlag = { [ChainId in keyof T]: { @@ -70,7 +69,7 @@ export type GenericContractAbi = { friends: string[]; //TODO: check which type? exposed_functions: MoveFunction[]; structs: MoveStruct[]; -} +}; export type GenericContractsDeclaration = { [chainId: string]: { [contractName: string]: GenericContract; @@ -79,7 +78,6 @@ export type GenericContractsDeclaration = { export const contracts = contractsData as GenericContractsDeclaration | null; - type ConfiguredChainId = (typeof scaffoldConfig)["targetNetworks"][0]["id"]; type IsContractDeclarationMissing = typeof contractsData extends { [key in ConfiguredChainId]: any } @@ -90,12 +88,9 @@ type ContractsDeclaration = IsContractDeclarationMissing = Contracts[TContractName]; - - export enum ContractCodeStatus { "LOADING", "DEPLOYED", diff --git a/packages/nextjs/utils/utils.ts b/packages/nextjs/utils/utils.ts index db9513b..827c33e 100644 --- a/packages/nextjs/utils/utils.ts +++ b/packages/nextjs/utils/utils.ts @@ -1,4 +1,5 @@ -import {HexString, Types} from "aptos"; +import { HexString, Types } from "aptos"; + // import pako from "pako"; // import {Statsig} from "statsig-react"; /** @@ -160,18 +161,15 @@ import {HexString, Types} from "aptos"; export function encodeInputArgsForViewRequest(type: string, value: string) { if (type.includes("vector")) { // when it's a vector, we support both hex and javascript array format - return value.trim().startsWith("0x") - ? value.trim() - : encodeVectorForViewRequest(type, value); + return value.trim().startsWith("0x") ? value.trim() : encodeVectorForViewRequest(type, value); } else if (type === "bool") { - if (value !== "true" && value !== "false") - throw new Error(`Invalid bool value: ${value}`); + if (value !== "true" && value !== "false") throw new Error(`Invalid bool value: ${value}`); return value === "true" ? true : false; } else if (["u8", "u16", "u32"].includes(type)) { return ensureNumber(value); } else if (type.startsWith("0x1::option::Option")) { - return {vec: [...(value ? [value] : [])]}; + return { vec: [...(value ? [value] : [])] }; } else return value; } @@ -197,23 +195,22 @@ function encodeVectorForViewRequest(type: string, value: string) { return ( HexString.fromUint8Array( new Uint8Array( - rawVector.map((v) => { + rawVector.map(v => { const result = ensureNumber(v.trim()); - if (result < 0 || result > 255) - throw new Error(`Invalid u8 value: ${result}`); + if (result < 0 || result > 255) throw new Error(`Invalid u8 value: ${result}`); return result; }), ), ) as any ).hexString; } else if (["u16", "u32"].includes(match[1])) { - return rawVector.map((v) => ensureNumber(v.trim())); + return rawVector.map(v => ensureNumber(v.trim())); } else if (["u64", "u128", "u256"].includes(match[1])) { // For bigint, not need to convert, only validation - rawVector.forEach((v) => ensureBigInt(v.trim())); + rawVector.forEach(v => ensureBigInt(v.trim())); return rawVector; } else if (match[1] === "bool") { - return rawVector.map((v) => ensureBoolean(v.trim())); + return rawVector.map(v => ensureBoolean(v.trim())); } else { // 1. Address type no need to convert // 2. Other complex types like Struct is not support yet. We just pass what user input. @@ -262,10 +259,7 @@ export function ensureBoolean(val: boolean | string): boolean { function assertType(val: any, types: string[] | string, message?: string) { if (!types?.includes(typeof val)) { throw new Error( - message || - `Invalid arg: ${val} type should be ${ - types instanceof Array ? types.join(" or ") : types - }`, + message || `Invalid arg: ${val} type should be ${types instanceof Array ? types.join(" or ") : types}`, ); } } From 6ef38577a5241cd689dd8368a42b0c78188cfd4d Mon Sep 17 00:00:00 2001 From: arjanjohan Date: Tue, 9 Jul 2024 22:22:53 +0200 Subject: [PATCH 6/6] removing many unused eth utils --- packages/nextjs/app/bio/page.tsx | 3 - .../app/debug/_components/DebugContracts.tsx | 10 +- .../_components/contract/ContractInput.tsx | 2 +- .../contract/ContractReadMethods.tsx | 5 +- .../debug/_components/contract/ContractUI.tsx | 5 +- .../contract/ContractWriteMethods.tsx | 5 +- .../app/debug/_components/contract/Tuple.tsx | 4 +- .../debug/_components/contract/TupleArray.tsx | 4 +- .../debug/_components/contract/TxReceipt.tsx | 2 +- .../_components/contract/utilsContract.tsx | 2 +- .../_components/contract/utilsDisplay.tsx | 2 +- packages/nextjs/app/debug/page.tsx | 2 +- packages/nextjs/app/layout.tsx | 2 +- .../components/scaffold-move/Address.tsx | 2 +- .../AddressInfoDropdown.tsx | 2 +- .../CustomConnectButton/NetworkOptions.tsx | 2 +- .../CustomConnectButton/index.tsx | 2 +- packages/nextjs/contracts/deployedModules.ts | 3 +- packages/nextjs/contracts/externalModules.ts | 3 +- .../nextjs/services/web3/wagmiConnectors.tsx | 43 --- packages/nextjs/utils/scaffold-eth/block.ts | 17 - .../nextjs/utils/scaffold-eth/contract.ts | 316 ------------------ .../utils/scaffold-eth/contractsData.ts | 7 - .../nextjs/utils/scaffold-eth/decodeTxData.ts | 61 ---- .../{scaffold-eth => scaffold-move}/common.ts | 0 .../nextjs/utils/scaffold-move/contract.ts | 34 +- .../getMetadata.ts | 0 .../getParsedError.ts | 0 .../{scaffold-eth => scaffold-move}/index.ts | 2 - .../networks.ts | 0 .../notification.tsx | 0 31 files changed, 40 insertions(+), 502 deletions(-) delete mode 100644 packages/nextjs/services/web3/wagmiConnectors.tsx delete mode 100644 packages/nextjs/utils/scaffold-eth/block.ts delete mode 100644 packages/nextjs/utils/scaffold-eth/contract.ts delete mode 100644 packages/nextjs/utils/scaffold-eth/contractsData.ts delete mode 100644 packages/nextjs/utils/scaffold-eth/decodeTxData.ts rename packages/nextjs/utils/{scaffold-eth => scaffold-move}/common.ts (100%) rename packages/nextjs/utils/{scaffold-eth => scaffold-move}/getMetadata.ts (100%) rename packages/nextjs/utils/{scaffold-eth => scaffold-move}/getParsedError.ts (100%) rename packages/nextjs/utils/{scaffold-eth => scaffold-move}/index.ts (62%) rename packages/nextjs/utils/{scaffold-eth => scaffold-move}/networks.ts (100%) rename packages/nextjs/utils/{scaffold-eth => scaffold-move}/notification.tsx (100%) diff --git a/packages/nextjs/app/bio/page.tsx b/packages/nextjs/app/bio/page.tsx index 7d1fcc8..3222aa9 100644 --- a/packages/nextjs/app/bio/page.tsx +++ b/packages/nextjs/app/bio/page.tsx @@ -5,7 +5,6 @@ import { InputTransactionData, useWallet } from "@aptos-labs/wallet-adapter-reac import type { NextPage } from "next"; import { InputBase } from "~~/components/scaffold-eth"; import deployedModules from "~~/contracts/deployedModules"; -import { useGetAccountModules } from "~~/hooks/scaffold-move/useGetAccountModules"; import useSubmitTransaction from "~~/hooks/scaffold-move/useSubmitTransaction"; import { aptosClient } from "~~/utils/scaffold-move/aptosClient"; @@ -23,8 +22,6 @@ const OnchainBio: NextPage = () => { const [currentName, setCurrentName] = useState(null); const [currentBio, setCurrentBio] = useState(null); - const { data, isLoading, error } = useGetAccountModules(ONCHAIN_BIO.address); - const { submitTransaction, transactionResponse, transactionInProcess } = useSubmitTransaction(); const fetchBio = async () => { diff --git a/packages/nextjs/app/debug/_components/DebugContracts.tsx b/packages/nextjs/app/debug/_components/DebugContracts.tsx index a7e8100..3b3f810 100644 --- a/packages/nextjs/app/debug/_components/DebugContracts.tsx +++ b/packages/nextjs/app/debug/_components/DebugContracts.tsx @@ -4,7 +4,7 @@ import { useEffect } from "react"; import { useLocalStorage } from "usehooks-ts"; import { BarsArrowUpIcon } from "@heroicons/react/20/solid"; import { ContractUI } from "~~/app/debug/_components/contract"; -import { ContractName } from "~~/utils/scaffold-eth/contract"; +import { ContractName } from "~~/utils/scaffold-move/contract"; import { getAllContracts } from "~~/utils/scaffold-move/contractsData"; const contractsData = getAllContracts(); @@ -40,11 +40,11 @@ export function DebugContracts() { ? "bg-base-300 hover:bg-base-300 no-animation" : "bg-base-100 hover:bg-secondary" }`} - key={contractName} + key={contractName as string} onClick={() => setSelectedContract(contractName)} > - {contractName} - {contractsData[contractName].external && ( + {contractName as string} + {contractsData[contractName as string].external && ( @@ -55,7 +55,7 @@ export function DebugContracts() { )} {contractNames.map(contractName => ( diff --git a/packages/nextjs/app/debug/_components/contract/ContractInput.tsx b/packages/nextjs/app/debug/_components/contract/ContractInput.tsx index 766431e..21c6840 100644 --- a/packages/nextjs/app/debug/_components/contract/ContractInput.tsx +++ b/packages/nextjs/app/debug/_components/contract/ContractInput.tsx @@ -12,7 +12,7 @@ import { IntegerInput, IntegerVariant, } from "~~/components/scaffold-eth"; -import { AbiParameterTuple } from "~~/utils/scaffold-eth/contract"; +import { AbiParameterTuple } from "~~/utils/scaffold-move/contract"; type ContractInputProps = { setForm: Dispatch>>; diff --git a/packages/nextjs/app/debug/_components/contract/ContractReadMethods.tsx b/packages/nextjs/app/debug/_components/contract/ContractReadMethods.tsx index 1d4564a..28aee9a 100644 --- a/packages/nextjs/app/debug/_components/contract/ContractReadMethods.tsx +++ b/packages/nextjs/app/debug/_components/contract/ContractReadMethods.tsx @@ -1,12 +1,13 @@ import { FunctionForm } from "~~/app/debug/_components/contract"; import { Contract, ContractName } from "~~/utils/scaffold-move/contract"; +import { Types } from "aptos"; export const ContractReadMethods = ({ deployedContractData }: { deployedContractData: Contract }) => { if (!deployedContractData || deployedContractData.abi === undefined) { return null; } - const functionsToDisplay = deployedContractData.abi.exposed_functions.filter(fn => fn.is_view); + const functionsToDisplay = deployedContractData.abi.exposed_functions.filter((fn: Types.MoveFunction) => fn.is_view); if (!functionsToDisplay.length) { return <>No view functions; @@ -14,7 +15,7 @@ export const ContractReadMethods = ({ deployedContractData }: { deployedContract return ( <> - {functionsToDisplay.map((fn, index) => ( + {functionsToDisplay.map((fn: Types.MoveFunction, index: number) => (
    diff --git a/packages/nextjs/app/debug/_components/contract/ContractUI.tsx b/packages/nextjs/app/debug/_components/contract/ContractUI.tsx index f5ac02d..75946f4 100644 --- a/packages/nextjs/app/debug/_components/contract/ContractUI.tsx +++ b/packages/nextjs/app/debug/_components/contract/ContractUI.tsx @@ -7,7 +7,7 @@ import { ModuleResources } from "./ModuleResources"; import { Address, Balance } from "~~/components/scaffold-move"; import { useDeployedContractInfo } from "~~/hooks/scaffold-move"; import { useTargetNetwork } from "~~/hooks/scaffold-move/useTargetNetwork"; -import { ContractName } from "~~/utils/scaffold-eth/contract"; +import { ContractName } from "~~/utils/scaffold-move/contract"; type ContractUIProps = { contractName: ContractName; @@ -91,7 +91,8 @@ export const ContractUI = ({ contractName, className = "" }: ContractUIProps) =>
    - + I disabled the Resources tab due to errors in the Vercel deployment, run the project locally to see it in action. + {/* */}
    diff --git a/packages/nextjs/app/debug/_components/contract/ContractWriteMethods.tsx b/packages/nextjs/app/debug/_components/contract/ContractWriteMethods.tsx index d5efb83..2088e6f 100644 --- a/packages/nextjs/app/debug/_components/contract/ContractWriteMethods.tsx +++ b/packages/nextjs/app/debug/_components/contract/ContractWriteMethods.tsx @@ -1,12 +1,13 @@ import { FunctionForm } from "~~/app/debug/_components/contract"; import { Contract, ContractName } from "~~/utils/scaffold-move/contract"; +import { Types } from "aptos"; export const ContractWriteMethods = ({ deployedContractData }: { deployedContractData: Contract }) => { if (!deployedContractData || deployedContractData.abi === undefined) { return null; } - const functionsToDisplay = deployedContractData.abi.exposed_functions.filter(fn => fn.is_entry); + const functionsToDisplay = deployedContractData.abi.exposed_functions.filter((fn : Types.MoveFunction) => fn.is_entry); if (!functionsToDisplay.length) { return <>No write functions; @@ -14,7 +15,7 @@ export const ContractWriteMethods = ({ deployedContractData }: { deployedContrac return ( <> - {functionsToDisplay.map((fn, index) => ( + {functionsToDisplay.map((fn: Types.MoveFunction, index: number) => (
    diff --git a/packages/nextjs/app/debug/_components/contract/Tuple.tsx b/packages/nextjs/app/debug/_components/contract/Tuple.tsx index 0e3175d..7f4745f 100644 --- a/packages/nextjs/app/debug/_components/contract/Tuple.tsx +++ b/packages/nextjs/app/debug/_components/contract/Tuple.tsx @@ -1,8 +1,8 @@ import { Dispatch, SetStateAction, useEffect, useState } from "react"; import { ContractInput } from "./ContractInput"; import { getFunctionInputKey, getInitalTupleFormState } from "./utilsContract"; -import { replacer } from "~~/utils/scaffold-eth/common"; -import { AbiParameterTuple } from "~~/utils/scaffold-eth/contract"; +import { replacer } from "~~/utils/scaffold-move/common"; +import { AbiParameterTuple } from "~~/utils/scaffold-move/contract"; type TupleProps = { abiTupleParameter: AbiParameterTuple; diff --git a/packages/nextjs/app/debug/_components/contract/TupleArray.tsx b/packages/nextjs/app/debug/_components/contract/TupleArray.tsx index 3fa9ac8..e1789d1 100644 --- a/packages/nextjs/app/debug/_components/contract/TupleArray.tsx +++ b/packages/nextjs/app/debug/_components/contract/TupleArray.tsx @@ -1,8 +1,8 @@ import { Dispatch, SetStateAction, useEffect, useState } from "react"; import { ContractInput } from "./ContractInput"; import { getFunctionInputKey, getInitalTupleArrayFormState } from "./utilsContract"; -import { replacer } from "~~/utils/scaffold-eth/common"; -import { AbiParameterTuple } from "~~/utils/scaffold-eth/contract"; +import { replacer } from "~~/utils/scaffold-move/common"; +import { AbiParameterTuple } from "~~/utils/scaffold-move/contract"; type TupleArrayProps = { abiTupleParameter: AbiParameterTuple & { isVirtual?: true }; diff --git a/packages/nextjs/app/debug/_components/contract/TxReceipt.tsx b/packages/nextjs/app/debug/_components/contract/TxReceipt.tsx index 764faeb..bbf84f7 100644 --- a/packages/nextjs/app/debug/_components/contract/TxReceipt.tsx +++ b/packages/nextjs/app/debug/_components/contract/TxReceipt.tsx @@ -3,7 +3,7 @@ import { CopyToClipboard } from "react-copy-to-clipboard"; import { TransactionReceipt } from "viem"; import { CheckCircleIcon, DocumentDuplicateIcon } from "@heroicons/react/24/outline"; import { ObjectFieldDisplay } from "~~/app/debug/_components/contract"; -import { replacer } from "~~/utils/scaffold-eth/common"; +import { replacer } from "~~/utils/scaffold-move/common"; export const TxReceipt = ({ txResult }: { txResult: TransactionReceipt }) => { const [txResultCopied, setTxResultCopied] = useState(false); diff --git a/packages/nextjs/app/debug/_components/contract/utilsContract.tsx b/packages/nextjs/app/debug/_components/contract/utilsContract.tsx index 023efe8..05da2a2 100644 --- a/packages/nextjs/app/debug/_components/contract/utilsContract.tsx +++ b/packages/nextjs/app/debug/_components/contract/utilsContract.tsx @@ -1,5 +1,5 @@ import { AbiFunction, AbiParameter } from "abitype"; -import { AbiParameterTuple } from "~~/utils/scaffold-eth/contract"; +import { AbiParameterTuple } from "~~/utils/scaffold-move/contract"; /** * Generates a key based on function metadata diff --git a/packages/nextjs/app/debug/_components/contract/utilsDisplay.tsx b/packages/nextjs/app/debug/_components/contract/utilsDisplay.tsx index fab99eb..71231ab 100644 --- a/packages/nextjs/app/debug/_components/contract/utilsDisplay.tsx +++ b/packages/nextjs/app/debug/_components/contract/utilsDisplay.tsx @@ -2,7 +2,7 @@ import { ReactElement, useState } from "react"; import { TransactionBase, TransactionReceipt, formatEther, isAddress, isHex } from "viem"; import { ArrowsRightLeftIcon } from "@heroicons/react/24/solid"; import { Address } from "~~/components/scaffold-move"; -import { replacer } from "~~/utils/scaffold-eth/common"; +import { replacer } from "~~/utils/scaffold-move/common"; type DisplayContent = | string diff --git a/packages/nextjs/app/debug/page.tsx b/packages/nextjs/app/debug/page.tsx index 267b3c6..f8a4a85 100644 --- a/packages/nextjs/app/debug/page.tsx +++ b/packages/nextjs/app/debug/page.tsx @@ -1,6 +1,6 @@ import { DebugContracts } from "./_components/DebugContracts"; import type { NextPage } from "next"; -import { getMetadata } from "~~/utils/scaffold-eth/getMetadata"; +import { getMetadata } from "~~/utils/scaffold-move/getMetadata"; export const metadata = getMetadata({ title: "Debug Contracts", diff --git a/packages/nextjs/app/layout.tsx b/packages/nextjs/app/layout.tsx index 9c5daa1..8ac71f3 100644 --- a/packages/nextjs/app/layout.tsx +++ b/packages/nextjs/app/layout.tsx @@ -2,7 +2,7 @@ import "@rainbow-me/rainbowkit/styles.css"; import { ScaffoldEthAppWithProviders } from "~~/components/ScaffoldEthAppWithProviders"; import { ThemeProvider } from "~~/components/ThemeProvider"; import "~~/styles/globals.css"; -import { getMetadata } from "~~/utils/scaffold-eth/getMetadata"; +import { getMetadata } from "~~/utils/scaffold-move/getMetadata"; export const metadata = getMetadata({ title: "Scaffold-Move App", diff --git a/packages/nextjs/components/scaffold-move/Address.tsx b/packages/nextjs/components/scaffold-move/Address.tsx index 7f37b53..09c8336 100644 --- a/packages/nextjs/components/scaffold-move/Address.tsx +++ b/packages/nextjs/components/scaffold-move/Address.tsx @@ -6,7 +6,7 @@ import { CopyToClipboard } from "react-copy-to-clipboard"; import { CheckCircleIcon, DocumentDuplicateIcon } from "@heroicons/react/24/outline"; import { BlockieAvatar } from "~~/components/scaffold-move"; import { useTargetNetwork } from "~~/hooks/scaffold-move/useTargetNetwork"; -import { getBlockExplorerAddressLink } from "~~/utils/scaffold-eth"; +import { getBlockExplorerAddressLink } from "~~/utils/scaffold-move"; type AddressProps = { address?: string; diff --git a/packages/nextjs/components/scaffold-move/CustomConnectButton/AddressInfoDropdown.tsx b/packages/nextjs/components/scaffold-move/CustomConnectButton/AddressInfoDropdown.tsx index eb41d67..551872c 100644 --- a/packages/nextjs/components/scaffold-move/CustomConnectButton/AddressInfoDropdown.tsx +++ b/packages/nextjs/components/scaffold-move/CustomConnectButton/AddressInfoDropdown.tsx @@ -13,7 +13,7 @@ import { } from "@heroicons/react/24/outline"; import { BlockieAvatar, isENS } from "~~/components/scaffold-move"; import { useOutsideClick } from "~~/hooks/scaffold-move"; -import { getTargetNetworks } from "~~/utils/scaffold-eth"; +import { getTargetNetworks } from "~~/utils/scaffold-move"; const allowedNetworks = getTargetNetworks(); diff --git a/packages/nextjs/components/scaffold-move/CustomConnectButton/NetworkOptions.tsx b/packages/nextjs/components/scaffold-move/CustomConnectButton/NetworkOptions.tsx index f73b1d5..348fc23 100644 --- a/packages/nextjs/components/scaffold-move/CustomConnectButton/NetworkOptions.tsx +++ b/packages/nextjs/components/scaffold-move/CustomConnectButton/NetworkOptions.tsx @@ -1,5 +1,5 @@ import { ArrowsRightLeftIcon } from "@heroicons/react/24/solid"; -import { getTargetNetworks } from "~~/utils/scaffold-eth"; +import { getTargetNetworks } from "~~/utils/scaffold-move"; const allowedNetworks = getTargetNetworks(); diff --git a/packages/nextjs/components/scaffold-move/CustomConnectButton/index.tsx b/packages/nextjs/components/scaffold-move/CustomConnectButton/index.tsx index 0a87f50..546ac3c 100644 --- a/packages/nextjs/components/scaffold-move/CustomConnectButton/index.tsx +++ b/packages/nextjs/components/scaffold-move/CustomConnectButton/index.tsx @@ -6,7 +6,7 @@ import { WalletSelector } from "@aptos-labs/wallet-adapter-ant-design"; import { useWallet } from "@aptos-labs/wallet-adapter-react"; // import { WrongNetworkDropdown } from "./WrongNetworkDropdown"; import { useTargetNetwork } from "~~/hooks/scaffold-move/useTargetNetwork"; -import { getBlockExplorerAddressLink } from "~~/utils/scaffold-eth"; +import { getBlockExplorerAddressLink } from "~~/utils/scaffold-move"; export const CustomConnectButton = () => { const { targetNetwork } = useTargetNetwork(); diff --git a/packages/nextjs/contracts/deployedModules.ts b/packages/nextjs/contracts/deployedModules.ts index 7dfc423..59fc3c7 100644 --- a/packages/nextjs/contracts/deployedModules.ts +++ b/packages/nextjs/contracts/deployedModules.ts @@ -17,4 +17,5 @@ const deployedContracts = { } } as const; -export default deployedContracts satisfies GenericContractsDeclaration; \ No newline at end of file +export default deployedContracts; +// satisfies GenericContractsDeclaration; \ No newline at end of file diff --git a/packages/nextjs/contracts/externalModules.ts b/packages/nextjs/contracts/externalModules.ts index 7fd196a..3ef2354 100644 --- a/packages/nextjs/contracts/externalModules.ts +++ b/packages/nextjs/contracts/externalModules.ts @@ -9,4 +9,5 @@ const externalContracts = { } } as const; -export default externalContracts satisfies GenericContractsDeclaration; \ No newline at end of file +export default externalContracts; +// satisfies GenericContractsDeclaration; \ No newline at end of file diff --git a/packages/nextjs/services/web3/wagmiConnectors.tsx b/packages/nextjs/services/web3/wagmiConnectors.tsx deleted file mode 100644 index 3edca69..0000000 --- a/packages/nextjs/services/web3/wagmiConnectors.tsx +++ /dev/null @@ -1,43 +0,0 @@ -import { connectorsForWallets } from "@rainbow-me/rainbowkit"; -import { - coinbaseWallet, - ledgerWallet, - metaMaskWallet, - rainbowWallet, - safeWallet, - walletConnectWallet, -} from "@rainbow-me/rainbowkit/wallets"; -import { rainbowkitBurnerWallet } from "burner-connector"; -import * as chains from "viem/chains"; -import scaffoldConfig from "~~/scaffold.config"; - -const { onlyLocalBurnerWallet, targetNetworks } = scaffoldConfig; - -const wallets = [ - metaMaskWallet, - walletConnectWallet, - ledgerWallet, - coinbaseWallet, - rainbowWallet, - safeWallet, - ...(!targetNetworks.some(network => network.id !== (chains.hardhat as chains.Chain).id) || !onlyLocalBurnerWallet - ? [rainbowkitBurnerWallet] - : []), -]; - -/** - * wagmi connectors for the wagmi context - */ -export const wagmiConnectors = connectorsForWallets( - [ - { - groupName: "Supported Wallets", - wallets, - }, - ], - - { - appName: "scaffold-eth-2", - projectId: "TODO: DELETE", - }, -); diff --git a/packages/nextjs/utils/scaffold-eth/block.ts b/packages/nextjs/utils/scaffold-eth/block.ts deleted file mode 100644 index 19e8c9f..0000000 --- a/packages/nextjs/utils/scaffold-eth/block.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { Block, Transaction, TransactionReceipt } from "viem"; - -export type TransactionWithFunction = Transaction & { - functionName?: string; - functionArgs?: any[]; - functionArgNames?: string[]; - functionArgTypes?: string[]; -}; - -type TransactionReceipts = { - [key: string]: TransactionReceipt; -}; - -export type TransactionsTableProps = { - blocks: Block[]; - transactionReceipts: TransactionReceipts; -}; diff --git a/packages/nextjs/utils/scaffold-eth/contract.ts b/packages/nextjs/utils/scaffold-eth/contract.ts deleted file mode 100644 index b8ea655..0000000 --- a/packages/nextjs/utils/scaffold-eth/contract.ts +++ /dev/null @@ -1,316 +0,0 @@ -import { MutateOptions } from "@tanstack/react-query"; -import { - Abi, - AbiParameter, - AbiParameterToPrimitiveType, - AbiParametersToPrimitiveTypes, - ExtractAbiEvent, - ExtractAbiEventNames, - ExtractAbiFunction, -} from "abitype"; -import type { ExtractAbiFunctionNames } from "abitype"; -import type { Simplify } from "type-fest"; -import type { MergeDeepRecord } from "type-fest/source/merge-deep"; -import { - Address, - Block, - GetEventArgs, - GetTransactionReceiptReturnType, - GetTransactionReturnType, - Log, - TransactionReceipt, - WriteContractErrorType, -} from "viem"; -import { Config, UseReadContractParameters, UseWatchContractEventParameters } from "wagmi"; -import { WriteContractParameters, WriteContractReturnType } from "wagmi/actions"; -import { WriteContractVariables } from "wagmi/query"; -import deployedContractsData from "~~/contracts/deployedModules"; -import externalContractsData from "~~/contracts/externalModules"; -import scaffoldConfig from "~~/scaffold.config"; - -type AddExternalFlag = { - [ChainId in keyof T]: { - [ContractName in keyof T[ChainId]]: T[ChainId][ContractName] & { external?: true }; - }; -}; - -const deepMergeContracts = , E extends Record>( - local: L, - external: E, -) => { - const result: Record = {}; - const allKeys = Array.from(new Set([...Object.keys(external), ...Object.keys(local)])); - for (const key of allKeys) { - if (!external[key]) { - result[key] = local[key]; - continue; - } - const amendedExternal = Object.fromEntries( - Object.entries(external[key] as Record>).map(([contractName, declaration]) => [ - contractName, - { ...declaration, external: true }, - ]), - ); - result[key] = { ...local[key], ...amendedExternal }; - } - return result as MergeDeepRecord, AddExternalFlag, { arrayMergeMode: "replace" }>; -}; - -const contractsData = deepMergeContracts(deployedContractsData, externalContractsData); - -export type InheritedFunctions = { readonly [key: string]: string }; - -export type GenericContract = { - address: Address; - abi: Abi; - inheritedFunctions?: InheritedFunctions; - external?: true; -}; - -export type GenericContractsDeclaration = { - [chainId: number]: { - [contractName: string]: GenericContract; - }; -}; - -export const contracts = contractsData as GenericContractsDeclaration | null; - -type ConfiguredChainId = (typeof scaffoldConfig)["targetNetworks"][0]["id"]; - -type IsContractDeclarationMissing = typeof contractsData extends { [key in ConfiguredChainId]: any } - ? TNo - : TYes; - -type ContractsDeclaration = IsContractDeclarationMissing; - -type Contracts = ContractsDeclaration[ConfiguredChainId]; - -export type ContractName = keyof Contracts; - -export type Contract = Contracts[TContractName]; - -type InferContractAbi = TContract extends { abi: infer TAbi } ? TAbi : never; - -export type ContractAbi = InferContractAbi>; - -export type AbiFunctionInputs = ExtractAbiFunction< - TAbi, - TFunctionName ->["inputs"]; - -export type AbiFunctionArguments = AbiParametersToPrimitiveTypes< - AbiFunctionInputs ->; - -export type AbiFunctionOutputs = ExtractAbiFunction< - TAbi, - TFunctionName ->["outputs"]; - -export type AbiFunctionReturnType = IsContractDeclarationMissing< - any, - AbiParametersToPrimitiveTypes> extends readonly [any] - ? AbiParametersToPrimitiveTypes>[0] - : AbiParametersToPrimitiveTypes> ->; - -export type AbiEventInputs> = ExtractAbiEvent< - TAbi, - TEventName ->["inputs"]; - -export enum ContractCodeStatus { - "LOADING", - "DEPLOYED", - "NOT_FOUND", -} - -type AbiStateMutability = "pure" | "view" | "nonpayable" | "payable"; -export type ReadAbiStateMutability = "view" | "pure"; -export type WriteAbiStateMutability = "nonpayable" | "payable"; - -export type FunctionNamesWithInputs< - TContractName extends ContractName, - TAbiStateMutibility extends AbiStateMutability = AbiStateMutability, -> = Exclude< - Extract< - ContractAbi[number], - { - type: "function"; - stateMutability: TAbiStateMutibility; - } - >, - { - inputs: readonly []; - } ->["name"]; - -type Expand = T extends object ? (T extends infer O ? { [K in keyof O]: O[K] } : never) : T; - -type UnionToIntersection = Expand<(U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never>; - -type OptionalTupple = T extends readonly [infer H, ...infer R] ? readonly [H | undefined, ...OptionalTupple] : T; - -type UseScaffoldArgsParam< - TContractName extends ContractName, - TFunctionName extends ExtractAbiFunctionNames>, -> = - TFunctionName extends FunctionNamesWithInputs - ? { - args: OptionalTupple, TFunctionName>>>; - value?: ExtractAbiFunction, TFunctionName>["stateMutability"] extends "payable" - ? bigint | undefined - : undefined; - } - : { - args?: never; - }; - -export type UseScaffoldReadConfig< - TContractName extends ContractName, - TFunctionName extends ExtractAbiFunctionNames, ReadAbiStateMutability>, -> = { - contractName: TContractName; - watch?: boolean; -} & IsContractDeclarationMissing< - Partial, - { - functionName: TFunctionName; - } & UseScaffoldArgsParam & - Omit ->; - -export type ScaffoldWriteContractVariables< - TContractName extends ContractName, - TFunctionName extends ExtractAbiFunctionNames, WriteAbiStateMutability>, -> = IsContractDeclarationMissing< - Partial, - { - functionName: TFunctionName; - } & UseScaffoldArgsParam & - Omit ->; - -type WriteVariables = WriteContractVariables; - -export type TransactorFuncOptions = { - onBlockConfirmation?: (txnReceipt: TransactionReceipt) => void; - blockConfirmations?: number; -}; - -export type ScaffoldWriteContractOptions = MutateOptions< - WriteContractReturnType, - WriteContractErrorType, - WriteVariables, - unknown -> & - TransactorFuncOptions; - -export type UseScaffoldEventConfig< - TContractName extends ContractName, - TEventName extends ExtractAbiEventNames>, - TEvent extends ExtractAbiEvent, TEventName> = ExtractAbiEvent< - ContractAbi, - TEventName - >, -> = { - contractName: TContractName; - eventName: TEventName; -} & IsContractDeclarationMissing< - Omit & { - onLogs: ( - logs: Simplify< - Omit, "args" | "eventName"> & { - args: Record; - eventName: string; - } - >[], - ) => void; - }, - Omit>, "onLogs" | "address" | "abi" | "eventName"> & { - onLogs: ( - logs: Simplify< - Omit, "args"> & { - args: AbiParametersToPrimitiveTypes & - GetEventArgs< - ContractAbi, - TEventName, - { - IndexedOnly: false; - } - >; - } - >[], - ) => void; - } ->; - -type IndexedEventInputs< - TContractName extends ContractName, - TEventName extends ExtractAbiEventNames>, -> = Extract, TEventName>[number], { indexed: true }>; - -export type EventFilters< - TContractName extends ContractName, - TEventName extends ExtractAbiEventNames>, -> = IsContractDeclarationMissing< - any, - IndexedEventInputs extends never - ? never - : { - [Key in IsContractDeclarationMissing< - any, - IndexedEventInputs["name"] - >]?: AbiParameterToPrimitiveType, { name: Key }>>; - } ->; - -export type UseScaffoldEventHistoryConfig< - TContractName extends ContractName, - TEventName extends ExtractAbiEventNames>, - TBlockData extends boolean = false, - TTransactionData extends boolean = false, - TReceiptData extends boolean = false, -> = { - contractName: TContractName; - eventName: IsContractDeclarationMissing; - fromBlock: bigint; - filters?: EventFilters; - blockData?: TBlockData; - transactionData?: TTransactionData; - receiptData?: TReceiptData; - watch?: boolean; - enabled?: boolean; -}; - -export type UseScaffoldEventHistoryData< - TContractName extends ContractName, - TEventName extends ExtractAbiEventNames>, - TBlockData extends boolean = false, - TTransactionData extends boolean = false, - TReceiptData extends boolean = false, - TEvent extends ExtractAbiEvent, TEventName> = ExtractAbiEvent< - ContractAbi, - TEventName - >, -> = - | IsContractDeclarationMissing< - any[], - { - log: Log; - args: AbiParametersToPrimitiveTypes & - GetEventArgs< - ContractAbi, - TEventName, - { - IndexedOnly: false; - } - >; - block: TBlockData extends true ? Block : null; - receipt: TReceiptData extends true ? GetTransactionReturnType : null; - transaction: TTransactionData extends true ? GetTransactionReceiptReturnType : null; - }[] - > - | undefined; - -export type AbiParameterTuple = Extract; diff --git a/packages/nextjs/utils/scaffold-eth/contractsData.ts b/packages/nextjs/utils/scaffold-eth/contractsData.ts deleted file mode 100644 index 84d4278..0000000 --- a/packages/nextjs/utils/scaffold-eth/contractsData.ts +++ /dev/null @@ -1,7 +0,0 @@ -import scaffoldConfig from "~~/scaffold.config"; -import { contracts } from "~~/utils/scaffold-eth/contract"; - -export function getAllContracts() { - const contractsData = contracts?.[scaffoldConfig.targetNetworks[0].id]; - return contractsData ? contractsData : {}; -} diff --git a/packages/nextjs/utils/scaffold-eth/decodeTxData.ts b/packages/nextjs/utils/scaffold-eth/decodeTxData.ts deleted file mode 100644 index 5b9a3b8..0000000 --- a/packages/nextjs/utils/scaffold-eth/decodeTxData.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { TransactionWithFunction } from "./block"; -import { GenericContractsDeclaration } from "./contract"; -import { Abi, AbiFunction, decodeFunctionData, getAbiItem } from "viem"; -import { hardhat } from "viem/chains"; -import contractData from "~~/contracts/deployedModules"; - -type ContractsInterfaces = Record; -type TransactionType = TransactionWithFunction | null; - -const deployedContracts = contractData as GenericContractsDeclaration | null; -const chainMetaData = deployedContracts?.[hardhat.id]; -const interfaces = chainMetaData - ? Object.entries(chainMetaData).reduce((finalInterfacesObj, [contractName, contract]) => { - finalInterfacesObj[contractName] = contract.abi; - return finalInterfacesObj; - }, {} as ContractsInterfaces) - : {}; - -export const decodeTransactionData = (tx: TransactionWithFunction) => { - if (tx.input.length >= 10 && !tx.input.startsWith("0x60e06040")) { - for (const [, contractAbi] of Object.entries(interfaces)) { - try { - const { functionName, args } = decodeFunctionData({ - abi: contractAbi, - data: tx.input, - }); - tx.functionName = functionName; - tx.functionArgs = args as any[]; - tx.functionArgNames = getAbiItem({ - abi: contractAbi as AbiFunction[], - name: functionName, - })?.inputs?.map((input: any) => input.name); - tx.functionArgTypes = getAbiItem({ - abi: contractAbi as AbiFunction[], - name: functionName, - })?.inputs.map((input: any) => input.type); - - break; - } catch (e) { - console.error(`Parsing failed: ${e}`); - } - } - } - return tx; -}; - -export const getFunctionDetails = (transaction: TransactionType) => { - if ( - transaction && - transaction.functionName && - transaction.functionArgNames && - transaction.functionArgTypes && - transaction.functionArgs - ) { - const details = transaction.functionArgNames.map( - (name, i) => `${transaction.functionArgTypes?.[i] || ""} ${name} = ${transaction.functionArgs?.[i] ?? ""}`, - ); - return `${transaction.functionName}(${details.join(", ")})`; - } - return ""; -}; diff --git a/packages/nextjs/utils/scaffold-eth/common.ts b/packages/nextjs/utils/scaffold-move/common.ts similarity index 100% rename from packages/nextjs/utils/scaffold-eth/common.ts rename to packages/nextjs/utils/scaffold-move/common.ts diff --git a/packages/nextjs/utils/scaffold-move/contract.ts b/packages/nextjs/utils/scaffold-move/contract.ts index 546fbae..174737a 100644 --- a/packages/nextjs/utils/scaffold-move/contract.ts +++ b/packages/nextjs/utils/scaffold-move/contract.ts @@ -3,6 +3,9 @@ import type { MergeDeepRecord } from "type-fest/source/merge-deep"; import deployedContractsData from "~~/contracts/deployedModules"; import externalContractsData from "~~/contracts/externalModules"; import scaffoldConfig from "~~/scaffold.config"; +import { + AbiParameter +} from "abitype"; type AddExternalFlag = { [ChainId in keyof T]: { @@ -34,29 +37,6 @@ const deepMergeContracts = , E extends Record const contractsData = deepMergeContracts(deployedContractsData, externalContractsData); -type MoveFunction = { - name: string; - visibility: string; - is_entry: boolean; - is_view: boolean; - generic_type_params: any[]; - params: string[]; - return: string[]; -}; - -type MoveStructField = { - name: string; - type: string; -}; - -type MoveStruct = { - name: string; - is_native: boolean; - abilities: string[]; - generic_type_params: any[]; - fields: MoveStructField[]; -}; - export type GenericContract = { bytecode: string; abi?: GenericContractAbi; @@ -67,8 +47,8 @@ export type GenericContractAbi = { address: string; // TODO: address type name: string; friends: string[]; //TODO: check which type? - exposed_functions: MoveFunction[]; - structs: MoveStruct[]; + exposed_functions: Types.MoveFunction[]; + structs: Types.MoveStruct[]; }; export type GenericContractsDeclaration = { [chainId: string]: { @@ -86,7 +66,7 @@ type IsContractDeclarationMissing = typeof contractsData extends { [k type ContractsDeclaration = IsContractDeclarationMissing; -type Contracts = ContractsDeclaration[ConfiguredChainId]; +type Contracts = ContractsDeclaration["devnet"]; export type ContractName = keyof Contracts; export type Contract = Contracts[TContractName]; @@ -96,3 +76,5 @@ export enum ContractCodeStatus { "DEPLOYED", "NOT_FOUND", } + +export type AbiParameterTuple = Extract; diff --git a/packages/nextjs/utils/scaffold-eth/getMetadata.ts b/packages/nextjs/utils/scaffold-move/getMetadata.ts similarity index 100% rename from packages/nextjs/utils/scaffold-eth/getMetadata.ts rename to packages/nextjs/utils/scaffold-move/getMetadata.ts diff --git a/packages/nextjs/utils/scaffold-eth/getParsedError.ts b/packages/nextjs/utils/scaffold-move/getParsedError.ts similarity index 100% rename from packages/nextjs/utils/scaffold-eth/getParsedError.ts rename to packages/nextjs/utils/scaffold-move/getParsedError.ts diff --git a/packages/nextjs/utils/scaffold-eth/index.ts b/packages/nextjs/utils/scaffold-move/index.ts similarity index 62% rename from packages/nextjs/utils/scaffold-eth/index.ts rename to packages/nextjs/utils/scaffold-move/index.ts index 0dc6a27..971d7cf 100644 --- a/packages/nextjs/utils/scaffold-eth/index.ts +++ b/packages/nextjs/utils/scaffold-move/index.ts @@ -1,5 +1,3 @@ export * from "./networks"; export * from "./notification"; -export * from "./block"; -export * from "./decodeTxData"; export * from "./getParsedError"; diff --git a/packages/nextjs/utils/scaffold-eth/networks.ts b/packages/nextjs/utils/scaffold-move/networks.ts similarity index 100% rename from packages/nextjs/utils/scaffold-eth/networks.ts rename to packages/nextjs/utils/scaffold-move/networks.ts diff --git a/packages/nextjs/utils/scaffold-eth/notification.tsx b/packages/nextjs/utils/scaffold-move/notification.tsx similarity index 100% rename from packages/nextjs/utils/scaffold-eth/notification.tsx rename to packages/nextjs/utils/scaffold-move/notification.tsx