-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from arjanjohan/block-explorer
Debug tab
- Loading branch information
Showing
48 changed files
with
2,510 additions
and
410 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
yarn lint-staged --verbose | ||
# yarn lint-staged --verbose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,14 @@ | |
"private": true, | ||
"workspaces": { | ||
"packages": [ | ||
"packages/hardhat", | ||
"packages/move", | ||
"packages/nextjs" | ||
] | ||
}, | ||
"scripts": { | ||
"account": "", | ||
"chain": "", | ||
"deploy": "", | ||
"deploy": "cd packages/move && movement aptos move publish && node scripts/loadContracts.js", | ||
"compile": "", | ||
"test": "", | ||
"format": "yarn next:format && yarn hardhat:format", | ||
|
@@ -28,10 +28,15 @@ | |
}, | ||
"packageManager": "[email protected]", | ||
"devDependencies": { | ||
"@types/js-yaml": "^4", | ||
"husky": "^8.0.1", | ||
"lint-staged": "^13.0.3" | ||
}, | ||
"engines": { | ||
"node": ">=18.17.0" | ||
}, | ||
"dependencies": { | ||
"aptos": "^1.21.0", | ||
"js-yaml": "^4.1.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
"use client"; | ||
|
||
import { useState } from "react"; | ||
import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk"; | ||
import { InputTransactionData, useWallet } from "@aptos-labs/wallet-adapter-react"; | ||
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"; | ||
|
||
// 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 ONCHAIN_BIO = deployedModules.devnet.onchain_bio.abi; | ||
|
||
const OnchainBio: NextPage = () => { | ||
const { account } = useWallet(); | ||
|
||
const [inputName, setInputName] = useState<string>(""); | ||
const [inputBio, setInputBio] = useState<string>(""); | ||
|
||
const [accountHasBio, setAccountHasBio] = useState(false); | ||
const [currentName, setCurrentName] = useState(null); | ||
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} = | ||
useSubmitTransaction(); | ||
|
||
const fetchBio = async () => { | ||
if (!account) { | ||
console.log("No account"); | ||
return []; | ||
} | ||
try { | ||
|
||
const resourceName = "Bio"; | ||
const bioResource = await aptos.getAccountResource({ | ||
accountAddress: account?.address, | ||
resourceType: `${ONCHAIN_BIO.address}::${ONCHAIN_BIO.name}::${resourceName}`, | ||
}); | ||
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); | ||
} | ||
}; | ||
|
||
async function registerBio() { | ||
if (inputName === null || inputBio === null) { | ||
// error msg popup | ||
} else { | ||
const onchainName = inputName; | ||
const onchainBio = inputBio; | ||
const functionName = "register"; | ||
const transaction: InputTransactionData = { | ||
data: { | ||
function: `${ONCHAIN_BIO.address}::${ONCHAIN_BIO.name}::${functionName}`, | ||
functionArguments: [onchainName, onchainBio], | ||
}, | ||
}; | ||
await submitTransaction(transaction); | ||
|
||
fetchBio(); | ||
|
||
// TODO: no transactionResponse? | ||
if (transactionResponse?.transactionSubmitted) { | ||
console.log("function_interacted", { | ||
txn_status: transactionResponse.success ? "success" : "failed", | ||
}); | ||
} | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
<div className="flex items-center flex-col flex-grow "> | ||
<div className="flex flex-col items-center bg-base-100 shadow-lg shadow-secondary border-8 border-secondary rounded-xl p-6 mt-8 w-full max-w-lg"> | ||
<div className="text-xl">Your Onchain Bio</div> | ||
</div> | ||
|
||
{/* Create bio */} | ||
{/* <div className="flex flex-col gap-1.5 w-full"> */} | ||
|
||
<div className="flex flex-col space-y-4 bg-base-100 shadow-lg shadow-secondary border-8 border-secondary rounded-xl p-6 mt-8 w-full max-w-lg"> | ||
<div className="flex items-center ml-2"> | ||
<span className="text-xs font-medium mr-2 leading-none">Your name</span> | ||
</div> | ||
<div className="w-full flex flex-col space-y-2"> | ||
<InputBase placeholder="Name" value={inputName} onChange={value => setInputName(value)} /> | ||
</div> | ||
<div className="flex items-center ml-2"> | ||
<span className="text-xs font-medium mr-2 leading-none">Your bio</span> | ||
</div>{" "} | ||
<div className="w-full flex flex-col space-y-2"> | ||
<InputBase placeholder="Bio" value={inputBio} onChange={value => setInputBio(value)} /> | ||
</div> | ||
<button | ||
className="btn btn-secondary mt-2" | ||
onClick={async () => { | ||
try { | ||
await registerBio(); | ||
} catch (err) { | ||
console.error("Error calling registerBio function"); | ||
} | ||
}} | ||
> | ||
Register Bio | ||
</button> | ||
</div> | ||
|
||
{/* Fetch bio */} | ||
<div className="flex flex-col items-center space-y-4 bg-base-100 shadow-lg shadow-secondary border-8 border-secondary rounded-xl p-6 mt-8 w-full max-w-lg"> | ||
<button | ||
className="btn btn-secondary mt-2" | ||
onClick={async () => { | ||
try { | ||
await fetchBio(); | ||
} catch (err) { | ||
console.error("Error calling fetchBio function"); | ||
} | ||
}} | ||
> | ||
Fetch Bio | ||
</button> | ||
</div> | ||
|
||
{accountHasBio && !transactionInProcess && ( | ||
<div> | ||
<div>{currentName}</div> | ||
<div>{currentBio}</div> | ||
</div> | ||
)} | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default OnchainBio; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 21 additions & 28 deletions
49
packages/nextjs/app/debug/_components/contract/ContractReadMethods.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,36 @@ | ||
import { Abi, AbiFunction } from "abitype"; | ||
import { ReadOnlyFunctionForm } from "~~/app/debug/_components/contract"; | ||
import { Contract, ContractName, GenericContract, InheritedFunctions } from "~~/utils/scaffold-eth/contract"; | ||
import { FunctionForm } from "~~/app/debug/_components/contract"; | ||
import { Contract, ContractName } from "~~/utils/scaffold-move/contract"; | ||
|
||
export const ContractReadMethods = ({ deployedContractData }: { deployedContractData: Contract<ContractName> }) => { | ||
if (!deployedContractData) { | ||
export const ContractReadMethods = ({ | ||
deployedContractData | ||
}: { | ||
deployedContractData: Contract<ContractName> | ||
}) => { | ||
if (!deployedContractData || deployedContractData.abi === undefined) { | ||
return null; | ||
} | ||
|
||
const functionsToDisplay = ( | ||
((deployedContractData.abi || []) as Abi).filter(part => part.type === "function") as AbiFunction[] | ||
) | ||
.filter(fn => { | ||
const isQueryableWithParams = | ||
(fn.stateMutability === "view" || fn.stateMutability === "pure") && fn.inputs.length > 0; | ||
return isQueryableWithParams; | ||
}) | ||
.map(fn => { | ||
return { | ||
fn, | ||
inheritedFrom: ((deployedContractData as GenericContract)?.inheritedFunctions as InheritedFunctions)?.[fn.name], | ||
}; | ||
}) | ||
.sort((a, b) => (b.inheritedFrom ? b.inheritedFrom.localeCompare(a.inheritedFrom) : 1)); | ||
const functionsToDisplay = deployedContractData.abi.exposed_functions.filter((fn) => | ||
fn.is_view, | ||
); | ||
|
||
if (!functionsToDisplay.length) { | ||
return <>No read methods</>; | ||
} | ||
|
||
return ( | ||
<> | ||
{functionsToDisplay.map(({ fn, inheritedFrom }) => ( | ||
<ReadOnlyFunctionForm | ||
abi={deployedContractData.abi as Abi} | ||
contractAddress={deployedContractData.address} | ||
abiFunction={fn} | ||
key={fn.name} | ||
inheritedFrom={inheritedFrom} | ||
{/* {functionsToDisplay.map(({ fn }) => ( | ||
<WriteOnlyFunctionForm | ||
module={deployedContractData} | ||
fn={fn} | ||
/> | ||
))} */} | ||
<FunctionForm | ||
module={deployedContractData.abi} | ||
fn={functionsToDisplay[0]} | ||
write={false} | ||
/> | ||
))} | ||
</> | ||
); | ||
}; |
Oops, something went wrong.