Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 🧶 #3

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading