Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
arjanjohan committed Jul 9, 2024
1 parent 49a49e4 commit 3b66aa5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
27 changes: 25 additions & 2 deletions packages/nextjs/app/debug/_components/contract/FunctionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ 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 [error, setError] = useState<string | null>(null);
const [data, setData] = useState<ContractFormType>({ typeArgs: [], args: [] });

const { account } = useWallet();
Expand Down Expand Up @@ -93,14 +94,22 @@ export const FunctionForm = ({ key, module, fn, write }: FunctionFormProps) => {

try {
await submitTransaction(payload);
console.log("AVH tx response", transactionResponse);

if (transactionResponse?.transactionSubmitted) {
console.log("function_interacted", fn.name, {
txn_status: transactionResponse.success ? "success" : "failed",
});
console.log("AVH tx response", transactionResponse);
if (!transactionResponse.success) {
setError("❌ Transaction failed");
} else {
setError(null); // Clear any previous error
}
}
} catch (e: any) {
console.error("⚡️ ~ file: FunctionForm.tsx:handleWrite ~ error", e);
setError("❌ Transaction failed: " + e.message);
}
};

Expand All @@ -117,20 +126,23 @@ export const FunctionForm = ({ key, module, fn, write }: FunctionFormProps) => {
};
} catch (e: any) {
console.error("Parsing arguments failed: " + e?.message);
setError("Parsing arguments failed: " + e.message);
return;
}
setViewInProcess(true);
try {
const result = await view(viewRequest, state.network_value, data.ledgerVersion);
setResult(result);
console.log("function_interacted", fn.name, { txn_status: "success" });
setError(null); // Clear any previous error
} catch (e: any) {
let error = e.message ?? JSON.stringify(e);
const prefix = "Error:";
if (error.startsWith(prefix)) {
error = error.substring(prefix.length).trim();
}
setResult(undefined);
setError("❌ View request failed: " + error);
console.log("function_interacted", fn.name, { txn_status: "failed" });
}
setViewInProcess(false);
Expand Down Expand Up @@ -168,10 +180,16 @@ export const FunctionForm = ({ key, module, fn, write }: FunctionFormProps) => {
<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"}
{transactionResponse.success ? "✅ transaction successful. txreceipt: " : "❌ transaction failed"}
</pre>
</div>
)}
{error && (
<div className="bg-red-300 rounded-3xl text-sm px-4 py-1.5 break-words overflow-auto">
<p className="font-bold m-0 mb-1">Error:</p>
<pre className="whitespace-pre-wrap break-words">{error}</pre>
</div>
)}
{/* TODO: Add TxReceipt for Move */}
{/* {displayedTxResult ? <TxReceipt txResult={displayedTxResult} /> : null} */}
</div>
Expand All @@ -195,8 +213,13 @@ export const FunctionForm = ({ key, module, fn, write }: FunctionFormProps) => {
<pre className="whitespace-pre-wrap break-words">{displayTxResult(result, "sm")}</pre>
</div>
)}
{error && (
<div className="bg-red-300 rounded-3xl text-sm px-4 py-1.5 break-words overflow-auto">
<p className="font-bold m-0 mb-1">Error:</p>
<pre className="whitespace-pre-wrap break-words">{error}</pre>
</div>
)}
</div>

<button className="btn btn-secondary btn-sm" disabled={viewInProcess} onClick={handleView}>
{viewInProcess && <span className="loading loading-spinner loading-xs"></span>}
Read 📡
Expand Down
5 changes: 2 additions & 3 deletions packages/nextjs/hooks/scaffold-move/useSubmitTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ const useSubmitTransaction = () => {
const [transactionInProcess, setTransactionInProcess] = useState<boolean>(false);
// const [state] = useGlobalState();

const network = useTargetNetwork();
// const network = useTargetNetwork();
const aptos = aptosClient("m1_devnet");
const state = { network_value: "https://aptos.devnet.m1.movementlabs.xyz", aptos_client: aptos };

const { signAndSubmitTransaction } = useWallet();

Expand All @@ -55,7 +54,7 @@ const useSubmitTransaction = () => {
// checkSuccess: true,
// });

await state.aptos_client.waitForTransaction(response["hash"]);
await aptos.waitForTransaction(response["hash"]);

return {
transactionSubmitted: true,
Expand Down

0 comments on commit 3b66aa5

Please sign in to comment.