diff --git a/ui/app/layout.tsx b/ui/app/layout.tsx index 6f4cede..c794242 100644 --- a/ui/app/layout.tsx +++ b/ui/app/layout.tsx @@ -61,17 +61,20 @@ export default function RootLayout({ return (
- - - - + + +- {chainId ? chainId : ☼}:\ - {!user ? ( - ☼ - ) : !isAddress(user) ? ( - user.slice(0, -4) - ) : ( - user - )} - {">"} -
) -} + return ( ++ {chainId ? chainId : ☼}:\ + {!user ? ( + ☼ + ) : !isAddress(user) ? ( + user.slice(0, -4) + ) : ( + user + )} + {">"} +
+ ); +}; export const Shell = () => { const form = useForm{command}
{command}
+{error.message}
); @@ -71,18 +87,18 @@ export const Shell = () => { addCommand({ chainId: chain?.id, user: name ?? address, command }); if (!client) throw new Error("No client available"); if (!address) throw new Error("No wallet connected"); - + const regex = /(\d+(\.\d+)?)\s*eth/i; const match = command.match(regex); let value = 0n; // Default value if no match is found - + if (match && match[1]) { // Convert the matched value to a number value = parseEther(match[1]); } - + console.log({ command, value }); - + const preview = await client.readContract({ address: IE_ADDRESS, abi: IntentsEngineAbi, @@ -90,21 +106,8 @@ export const Shell = () => { args: [command], }); - addLine(- Preview: {JSON.stringify(preview)} -
) - - const confirm = window.confirm( - `Are you sure you want to execute the following command?\n\n${preview}\n\n`, - ); - - console.log({ preview, confirm }); - - if (!confirm) { - addLine(Command cancelled.
); - return; - } - + addLine(Preview: {serialize(preview)}
); + if (!isAddressEqual(preview[2], ETH_ADDRESS)) { // consent to spend tokens const allowance = await client.readContract({ @@ -113,9 +116,9 @@ export const Shell = () => { functionName: "allowance", args: [address, IE_ADDRESS], }); - + console.log({ allowance }); - + if (allowance < preview[1]) { // we do a lil approve dance const approveTxHash = await writeContractAsync({ @@ -124,18 +127,18 @@ export const Shell = () => { functionName: "approve", args: [IE_ADDRESS, maxUint256], }); - + addLine(Approve TX Hash: {approveTxHash}
); - + const allowanceReceipt = await client.waitForTransactionReceipt({ hash: approveTxHash, confirmations: 1, }); - - addLine(Allowance Set. Receipt: {JSON.stringify(allowanceReceipt)}
); + + addLine(Allowance Set. Receipt: {serialize(allowanceReceipt)}
); } } - + const commandTxHash = await writeContractAsync({ address: IE_ADDRESS, abi: IntentsEngineAbi, @@ -143,22 +146,26 @@ export const Shell = () => { value, args: [command], }); - + addLine(Command TX Hash: {commandTxHash}
); - + const commandReceipt = await client.waitForTransactionReceipt({ hash: commandTxHash, confirmations: 1, }); - - addLine(Command Executed. Receipt: {JSON.stringify(commandReceipt)}
); + + addLine( +Command Executed. Receipt: {JSON.stringify(commandReceipt)}
, + ); } catch (error) { console.error(error); - error instanceof Error ? addError(error) : addError(new Error("Unknown error")); + error instanceof Error + ? addError(error) + : addError(new Error("Unknown error")); } } - - const id = createId(chain?.id, name ?? address) + + const id = createId(chain?.id, name ?? address); if (!isConnected || !address || !chain) return null;