Skip to content

Commit 7d2f424

Browse files
committed
kuu village
1 parent 240ddc1 commit 7d2f424

File tree

2 files changed

+74
-11
lines changed

2 files changed

+74
-11
lines changed

pkgs/frontend/app/components/StickyNav.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Link, useParams } from "@remix-run/react";
33
import type { FC } from "react";
44
import { FaCoins } from "react-icons/fa6";
55
import { GoHomeFill } from "react-icons/go";
6-
import { MdCallSplit } from "react-icons/md";
6+
import { MdCallSplit, MdWallet } from "react-icons/md";
77
import { RiTeamFill } from "react-icons/ri";
88

99
export const StickyNav: FC = () => {
@@ -21,7 +21,7 @@ export const StickyNav: FC = () => {
2121
zIndex={100}
2222
>
2323
<Grid
24-
gridTemplateColumns="1fr 1fr 1fr 1fr"
24+
gridTemplateColumns="1fr 1fr 1fr 1fr 1fr"
2525
maxW="430px"
2626
width="100%"
2727
m="0 auto"
@@ -81,6 +81,19 @@ export const StickyNav: FC = () => {
8181
</Box>
8282
</Link>
8383
</GridItem>
84+
85+
<GridItem textAlign="center">
86+
<Link to={"/transaction"}>
87+
<IconButton backgroundColor="transparent" color="blue.500">
88+
<Icon fontSize={30}>
89+
<MdWallet size="30px" />
90+
</Icon>
91+
</IconButton>
92+
<Box fontWeight="bold" fontSize="sm">
93+
Wallet
94+
</Box>
95+
</Link>
96+
</GridItem>
8497
</Grid>
8598
</Box>
8699
</>

pkgs/frontend/app/routes/transaction.tsx

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
import { ERC20_ABI } from "abi/erc20";
1414
import { publicClient } from "hooks/useViem";
1515
import { useActiveWallet } from "hooks/useWallet";
16-
import { type FC, useState } from "react";
16+
import { type FC, useCallback, useEffect, useState } from "react";
1717
import { toast } from "react-toastify";
1818
import { parseEther } from "viem";
1919
import { BasicButton } from "~/components/BasicButton";
@@ -38,16 +38,48 @@ const Transaction: FC = () => {
3838
const { wallet } = useActiveWallet();
3939

4040
const [transactionType, setTransactionType] = useState("ERC20");
41-
const [contractAddress, setContractAddress] = useState("");
41+
const [contractAddress, setContractAddress] = useState(
42+
"0x1856a7e86543F9f38c3bC68921dA0B65DbE018b6",
43+
);
44+
const [balance, setBalance] = useState<string>("0");
4245
const [recipient, setRecipient] = useState("");
4346
const [amount, setAmount] = useState("");
4447
const [isLoading, setIsLoading] = useState(false);
4548

49+
const fetchERC20Balance = useCallback(async () => {
50+
if (!wallet || !contractAddress) return;
51+
// Fetch balance and decimals in parallel
52+
const [erc20Balance, decimals] = await Promise.all([
53+
publicClient.readContract({
54+
address: contractAddress as `0x${string}`,
55+
abi: ERC20_ABI,
56+
functionName: "balanceOf",
57+
args: [wallet.account?.address as `0x${string}`],
58+
}),
59+
publicClient.readContract({
60+
address: contractAddress as `0x${string}`,
61+
abi: ERC20_ABI,
62+
functionName: "decimals",
63+
}),
64+
]);
65+
66+
const decimalsNumber = Number(decimals);
67+
const formattedBalance =
68+
decimalsNumber > 0
69+
? Number(erc20Balance) / 10 ** decimalsNumber
70+
: Number(erc20Balance);
71+
setBalance(Math.floor(formattedBalance).toLocaleString());
72+
}, [wallet, contractAddress]);
73+
74+
useEffect(() => {
75+
fetchERC20Balance();
76+
}, [fetchERC20Balance]);
77+
4678
/**
4779
* handleTransactionExecution function
4880
* トランザクションを実行する
4981
*/
50-
const handleTransactionExecution = async () => {
82+
const handleTransactionExecution = useCallback(async () => {
5183
if (!wallet) {
5284
alert("ウォレットを接続してください。");
5385
return;
@@ -87,8 +119,6 @@ const Transaction: FC = () => {
87119
await publicClient.waitForTransactionReceipt({
88120
hash: transferTxHash,
89121
});
90-
91-
toast.success("トランザクションが正常に実行されました。");
92122
} else {
93123
if (!recipient || !amount) {
94124
alert("全ての項目を入力してください。");
@@ -107,19 +137,29 @@ const Transaction: FC = () => {
107137
});
108138
}
109139
toast.success("トランザクションが正常に実行されました。");
140+
setRecipient("");
141+
setAmount("0");
142+
await fetchERC20Balance();
110143
} catch (error) {
111144
console.error("Transaction execution error:", error);
112145
toast.error("エラーが発生しました。");
113146
}
114147
setIsLoading(false);
115-
};
148+
}, [
149+
fetchERC20Balance,
150+
wallet,
151+
transactionType,
152+
contractAddress,
153+
recipient,
154+
amount,
155+
]);
116156

117157
return (
118158
<Grid gridTemplateRows="1fr auto" h="calc(100vh - 72px)">
119159
<Box w="100%">
120160
<PageHeader title="トランザクション実行" />
121161

122-
<SettingsSubSection headingText="トランザクションタイプ">
162+
{/* <SettingsSubSection headingText="トランザクションタイプ">
123163
<SelectRoot
124164
collection={transactionTypes}
125165
onValueChange={(e) => setTransactionType(e.value[0])}
@@ -152,9 +192,18 @@ const Transaction: FC = () => {
152192
mt={2}
153193
/>
154194
</SettingsSubSection>
155-
)}
195+
)} */}
196+
197+
<SettingsSubSection headingText="残高">
198+
<Text fontSize="2xl">
199+
{balance}{" "}
200+
<Text as="span" fontSize="md">
201+
kuu
202+
</Text>
203+
</Text>
204+
</SettingsSubSection>
156205

157-
<SettingsSubSection headingText="パラメータ">
206+
<SettingsSubSection headingText="">
158207
<Grid templateColumns="repeat(4, 1fr)" gap="6" alignItems="center">
159208
<GridItem colSpan={1}>
160209
<Text>recipient</Text>
@@ -184,6 +233,7 @@ const Transaction: FC = () => {
184233
</GridItem>
185234
<GridItem colSpan={3}>
186235
<CommonInput
236+
type="number"
187237
placeholder="Amount"
188238
value={amount}
189239
onChange={(e) => setAmount(e.target.value)}

0 commit comments

Comments
 (0)