Skip to content

Commit

Permalink
Merge pull request #3 from NaniDAO/ui-nits
Browse files Browse the repository at this point in the history
🐛 🧶
  • Loading branch information
nerderlyne authored Feb 20, 2024
2 parents 837ad51 + 91ada6e commit 62ebd04
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions ui/components/shell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
isAddressEqual,
maxUint256,
parseEther,
zeroAddress,
} from "viem";
import { mainnet } from "viem/chains";
import useShellStore from "@/lib/use-shell-store";
Expand Down Expand Up @@ -88,16 +89,7 @@ export const Shell = () => {
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 });
let value = 0n;

const preview = await client.readContract({
address: IE_ADDRESS,
Expand All @@ -108,17 +100,23 @@ export const Shell = () => {

addLine(<p>Preview: {serialize(preview)}</p>);

if (!isAddressEqual(preview[2], ETH_ADDRESS)) {
if (isAddressEqual(preview[2], zeroAddress)) {
// invalid token
throw new Error("This token is not supported by the Intents Engine. Did you misspell the token symbol?");
}

if (isAddressEqual(preview[2], ETH_ADDRESS)) {
// sending ether directly
value = preview[1];
} else {
// consent to spend tokens
const allowance = await client.readContract({
address: preview[2],
abi: erc20Abi,
functionName: "allowance",
args: [address, IE_ADDRESS],
});

console.log({ allowance });


if (allowance < preview[1]) {
// we do a lil approve dance
const approveTxHash = await writeContractAsync({
Expand Down

0 comments on commit 62ebd04

Please sign in to comment.