Skip to content

Commit

Permalink
yarn format
Browse files Browse the repository at this point in the history
  • Loading branch information
arjanjohan committed Jul 9, 2024
1 parent a4a0439 commit a1218da
Show file tree
Hide file tree
Showing 35 changed files with 225 additions and 388 deletions.
39 changes: 15 additions & 24 deletions packages/nextjs/app/bio/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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,
Expand Down Expand Up @@ -133,25 +130,19 @@ const OnchainBio: NextPage = () => {
Fetch Bio
</button>


{accountHasBio && !transactionInProcess && (
<div className="space-y-4 w-full max-w-lg">
<div className="flex items-center">
<span className="text-xs font-medium mr-2 leading-none">Name:</span>
</div>
<div className="w-full flex flex-col space-y-2">
{currentName}
</div>
<div className="flex items-center">
<span className="text-xs font-medium mr-2 leading-none">Bio:</span>
</div>
<div className="w-full flex flex-col space-y-2">
{currentBio}
</div>
</div>
)}
{accountHasBio && !transactionInProcess && (
<div className="space-y-4 w-full max-w-lg">
<div className="flex items-center">
<span className="text-xs font-medium mr-2 leading-none">Name:</span>
</div>
<div className="w-full flex flex-col space-y-2">{currentName}</div>
<div className="flex items-center">
<span className="text-xs font-medium mr-2 leading-none">Bio:</span>
</div>
<div className="w-full flex flex-col space-y-2">{currentBio}</div>
</div>
)}
</div>

</div>
</>
);
Expand Down
1 change: 0 additions & 1 deletion packages/nextjs/app/debug/_components/DebugContracts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContractName>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,23 @@
import { FunctionForm } from "~~/app/debug/_components/contract";
import { Contract, ContractName } from "~~/utils/scaffold-move/contract";

export const ContractReadMethods = ({
deployedContractData
}: {
deployedContractData: Contract<ContractName>
}) => {
export const ContractReadMethods = ({ deployedContractData }: { deployedContractData: Contract<ContractName> }) => {
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</>;
}

return (
<>

{functionsToDisplay.map((fn, index) => (
<div key={index}>
<FunctionForm
key={index}
module={deployedContractData.abi!}
fn={fn}
write={false}
/></div>
<FunctionForm key={index} module={deployedContractData.abi!} fn={fn} write={false} />
</div>
))}
</>
);
Expand Down
21 changes: 7 additions & 14 deletions packages/nextjs/app/debug/_components/contract/ContractUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,18 +47,16 @@ export const ContractUI = ({ contractName, className = "" }: ContractUIProps) =>
<Address address={deployedContractData.abi.address} />
<div className="flex gap-1 items-center">
<span className="font-bold text-sm">Balance:</span>
<Balance address={deployedContractData.abi.address}/>
<Balance address={deployedContractData.abi.address} />
</div>
</div>
</div>
{targetNetwork && (
<p className="my-0 text-sm">
<span className="font-bold">Network</span>:{" "}
<span >{String(targetNetwork.name)}</span>
<span className="font-bold">Network</span>: <span>{String(targetNetwork.name)}</span>
</p>
)}
</div>

</div>
<div className="col-span-1 lg:col-span-2 flex flex-col gap-6">
<div className="z-10">
Expand All @@ -82,9 +79,7 @@ export const ContractUI = ({ contractName, className = "" }: ContractUIProps) =>
</div>
</div>
<div className="p-5 divide-y divide-base-300">
<ContractWriteMethods
deployedContractData={deployedContractData}
/>
<ContractWriteMethods deployedContractData={deployedContractData} />
</div>
</div>
</div>
Expand All @@ -96,9 +91,7 @@ export const ContractUI = ({ contractName, className = "" }: ContractUIProps) =>
</div>
</div>
<div className="p-5 divide-y divide-base-300">
<ModuleResources
deployedContractData={deployedContractData}
/>
<ModuleResources deployedContractData={deployedContractData} />
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ContractName>;
}) => {
export const ContractWriteMethods = ({ deployedContractData }: { deployedContractData: Contract<ContractName> }) => {
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</>;
Expand All @@ -22,12 +16,8 @@ export const ContractWriteMethods = ({
<>
{functionsToDisplay.map((fn, index) => (
<div key={index}>
<FunctionForm
key={index}
module={deployedContractData.abi!}
fn={fn}
write={true}
/></div>
<FunctionForm key={index} module={deployedContractData.abi!} fn={fn} write={true} />
</div>
))}
</>
);
Expand Down
49 changes: 19 additions & 30 deletions packages/nextjs/app/debug/_components/contract/FunctionForm.tsx
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<Types.MoveValue[]>();
const [data, setData] = useState<ContractFormType>({ 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);

Expand All @@ -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();
});
}
Expand Down Expand Up @@ -149,9 +139,7 @@ export const FunctionForm = ({
return (
<div key={key} className="py-5 space-y-3 first:pt-0 last:pb-1">
<div className={`flex gap-3 ${zeroInputs ? "flex-row justify-between items-center" : "flex-col"}`}>
<p className="font-medium my-0 break-words">
{fn.name}
</p>
<p className="font-medium my-0 break-words">{fn.name}</p>
{fnParams.map((param, i) => {
return (
<div key={`arg-${i}`} className="flex flex-col gap-1.5 w-full">
Expand All @@ -162,7 +150,7 @@ export const FunctionForm = ({
<input
placeholder={param}
className="input input-ghost focus-within:border-transparent focus:outline-none focus:bg-transparent focus:text-gray-400 h-[2.2rem] min-h-[2.2rem] px-4 border w-full font-medium placeholder:text-accent/50 text-gray-400"
onChange={(e) => {
onChange={e => {
const newArgs = [...data.args];
newArgs[i] = e.target.value;
setData({ ...data, args: newArgs });
Expand All @@ -176,23 +164,27 @@ export const FunctionForm = ({
{write && (
<div className="flex flex-col md:flex-row justify-between gap-2 flex-wrap">
<div className="flex-grow basis-0">

{transactionResponse !== null && transactionResponse?.transactionSubmitted && (
<div className="bg-base-300 rounded-3xl text-sm px-4 py-1.5 break-words overflow-auto">
<p className="font-bold m-0 mb-1">Result:</p>
<pre className="whitespace-pre-wrap break-words">{transactionResponse.success ? "✅ transaction successful" : "❌ transaction failed"}</pre>
<pre className="whitespace-pre-wrap break-words">
{transactionResponse.success ? "✅ transaction successful" : "❌ transaction failed"}
</pre>
</div>
)}
{/* TODO: Add TxReceipt for Move */}
{/* {displayedTxResult ? <TxReceipt txResult={displayedTxResult} /> : null} */}
</div>

<button className="btn btn-secondary btn-sm" disabled={transactionInProcess || !account} onClick={handleWrite}>
<button
className="btn btn-secondary btn-sm"
disabled={transactionInProcess || !account}
onClick={handleWrite}
>
{transactionInProcess && <span className="loading loading-spinner loading-xs"></span>}
Send 💸
</button>
</div>

)}
{!write && (
<div className="flex flex-col md:flex-row justify-between gap-2 flex-wrap">
Expand All @@ -210,11 +202,8 @@ export const FunctionForm = ({
Read 📡
</button>
</div>

)}

</div>

</div>
);
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

import {Types} from "aptos";
import { Types } from "aptos";
import ReactJson from "react-json-view";

type ModuleResourceProps = {
Expand All @@ -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 (
<>
<div>{resource.type}</div>
Expand Down
Loading

0 comments on commit a1218da

Please sign in to comment.