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}`, ); } }