Skip to content

Commit

Permalink
🙂
Browse files Browse the repository at this point in the history
  • Loading branch information
nerderlyne committed Feb 22, 2024
1 parent 18752d7 commit d3ab218
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
3 changes: 2 additions & 1 deletion ui/components/header.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Account } from "./account";
import { Version } from "./version";

export const Header = () => {
return (
<div className="mb-3">
<p>Nani Intents Shell {"[ Version 1.0.0 ]"}</p>
<p>Nani Intents Shell <Version /></p>
<p className="mb-2">(c) 2024 Nani Kotoba DAO LLC. All rights reserved.</p>
<Account />
</div>
Expand Down
5 changes: 3 additions & 2 deletions ui/components/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { WagmiProvider } from "wagmi";
import { mainnet, sepolia } from "wagmi/chains";
import { arbitrum, mainnet, sepolia } from "wagmi/chains";
import { getDefaultConfig, RainbowKitProvider } from "@rainbow-me/rainbowkit";
import { siteConfig } from "@/lib/site";

Expand All @@ -12,7 +12,8 @@ const config = getDefaultConfig({
projectId: process.env.NEXT_PUBLIC_WC_ID!,
chains: [
mainnet,
sepolia
sepolia,
arbitrum
],
ssr: true,
});
Expand Down
16 changes: 11 additions & 5 deletions ui/components/shell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ export const Shell = () => {
chainId: mainnet.id,
});
const { writeContractAsync } = useWriteContract();
const client = usePublicClient();

const client = usePublicClient({
chainId: chain ? chain.id : mainnet.id,
});

const addLine = useShellStore((state) => state.addLine);

Expand Down Expand Up @@ -90,10 +93,12 @@ export const Shell = () => {
if (!address) throw new Error("No wallet connected");
if (!chain) throw new Error("No chain connected");

const ieAddress = IE_ADDRESS[chain.id];

let value = 0n;

const preview = await client.readContract({
address: IE_ADDRESS,
address: ieAddress,
abi: IntentsEngineAbi,
functionName: "previewCommand",
args: [command],
Expand All @@ -115,7 +120,7 @@ export const Shell = () => {
address: preview[2],
abi: erc20Abi,
functionName: "allowance",
args: [address, IE_ADDRESS],
args: [address, ieAddress],
});

if (allowance < preview[1]) {
Expand All @@ -124,7 +129,7 @@ export const Shell = () => {
address: preview[2],
abi: erc20Abi,
functionName: "approve",
args: [IE_ADDRESS, maxUint256],
args: [ieAddress, maxUint256],
});

addLine(
Expand All @@ -150,7 +155,7 @@ export const Shell = () => {
}

const commandTxHash = await writeContractAsync({
address: IE_ADDRESS,
address: ieAddress,
abi: IntentsEngineAbi,
functionName: "command",
value,
Expand All @@ -173,6 +178,7 @@ export const Shell = () => {
const commandReceipt = await client.waitForTransactionReceipt({
hash: commandTxHash,
confirmations: 1,

});

addLine(
Expand Down
18 changes: 18 additions & 0 deletions ui/components/version.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use client'
import { useAccount } from "wagmi"

const versions: {
[key: number]: string
} = {
1: "1.0.0",
42161: "1.0.1 (nightly)",
}

export const Version = () => {
const { chain } = useAccount();

return <span>
{`[ Version ${versions[chain ? chain.id : 1]} ]`}
</span>
}

10 changes: 9 additions & 1 deletion ui/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
export const IE_ADDRESS = "0x1E00000000Cf8ba83e0005c59c1Bf1C4682C8E00";
import { Address } from "viem";

export const IE_ADDRESS: {
[key: number]: Address
} = {
1: "0x1E00000000Cf8ba83e0005c59c1Bf1C4682C8E00",
42161: "0x000000001e202b5b84e56400f409800065cb6d3c"
};

export const ETH_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";

0 comments on commit d3ab218

Please sign in to comment.