|
1 | 1 | "use client";
|
2 | 2 | import { useSwapActions, useSwapState } from "@/state/swapStore";
|
3 |
| -import React from "react"; |
| 3 | +import React, { useEffect } from "react"; |
4 | 4 | import { Button } from "../ui/Button";
|
| 5 | +import AmountInput from "./AmountInput"; |
| 6 | +import { useTokenInitializer } from "@/hooks/useTokenInitializer"; |
5 | 7 |
|
6 | 8 | type Props = {};
|
7 | 9 |
|
8 | 10 | export const SwapWidget = (props: Props) => {
|
9 |
| - const { sellToken, buyToken, sellAmount, buyAmount } = useSwapState(); |
10 |
| - const { setBuyToken, setSellToken, setSellAmount, setBuyAmount } = |
11 |
| - useSwapActions(); |
| 11 | + const { |
| 12 | + sellToken, |
| 13 | + buyToken, |
| 14 | + tokens, |
| 15 | + sellAmount, |
| 16 | + currentBuyAsset, |
| 17 | + buyAmount, |
| 18 | + currentSellAsset, |
| 19 | + } = useSwapState(); |
| 20 | + const { |
| 21 | + setBuyToken, |
| 22 | + setSellToken, |
| 23 | + setSellAmount, |
| 24 | + setBuyAmount, |
| 25 | + setCurrentSellAsset, |
| 26 | + setCurrentBuyAsset, |
| 27 | + } = useSwapActions(); |
| 28 | + console.log({ currentBuyAsset }); |
12 | 29 |
|
13 | 30 | return (
|
14 |
| - <div className="bg-primary/20 border-secondary border-[2px] rounded-xl"> |
15 |
| - <h2 className="text-xl font-bold text-white mb-4">Swap</h2> |
16 |
| - <div className="mb-4"> |
17 |
| - <label className="text-sm text-gray-400">you are buying</label> |
18 |
| - <select |
19 |
| - className="w-full mt-2 p-3 bg-gray-700 rounded text-white" |
20 |
| - value={buyToken} |
21 |
| - onChange={(e) => setBuyToken(e.target.value)} |
22 |
| - > |
23 |
| - <option value="DAI">DAI</option> |
24 |
| - <option value="USDC">USDC</option> |
25 |
| - </select> |
26 |
| - <input |
27 |
| - type="number" |
28 |
| - placeholder="Enter amount" |
29 |
| - className="w-full mt-2 p-3 bg-gray-700 rounded text-white" |
30 |
| - value={buyAmount} |
31 |
| - onChange={(e) => setBuyAmount(e.target.value)} |
| 31 | + <div className="bg-[#030D0A] p-4 col-span-2 max-w-[448px] w-full border-secondary border-[1px] rounded-xl"> |
| 32 | + <h2 className="text-lg font-bold text-white bg-primary w-fit px-2 py-1 rounded-3xl mb-4"> |
| 33 | + Swap |
| 34 | + </h2> |
| 35 | + <div className="flex flex-col gap-3"> |
| 36 | + <AmountInput |
| 37 | + title="You're Buying" |
| 38 | + token={buyToken} |
| 39 | + Amount={buyAmount} |
| 40 | + currentTokenAsset={currentBuyAsset} |
| 41 | + setCurrentTokenDetal={setCurrentBuyAsset} |
| 42 | + setAmount={setBuyAmount} |
| 43 | + setToken={setBuyToken} |
| 44 | + walletBalanceAsset={500} // Replace with actual balance |
32 | 45 | />
|
33 |
| - </div> |
34 |
| - <div className="mb-4"> |
35 |
| - <label className="text-sm text-gray-400">you are Selling</label> |
36 |
| - <select |
37 |
| - className="w-full mt-2 p-3 bg-gray-700 rounded text-white" |
38 |
| - value={sellToken} |
39 |
| - onChange={(e) => setSellToken(e.target.value)} |
40 |
| - > |
41 |
| - <option value="DAI">DAI</option> |
42 |
| - <option value="USDC">USDC</option> |
43 |
| - </select> |
44 |
| - <input |
45 |
| - type="number" |
46 |
| - placeholder="Enter amount" |
47 |
| - className="w-full mt-2 p-3 bg-gray-700 rounded text-white" |
48 |
| - value={sellAmount} |
49 |
| - onChange={(e) => setSellAmount(e.target.value)} |
| 46 | + <AmountInput |
| 47 | + title="You're Selling" |
| 48 | + setCurrentTokenDetal={setCurrentSellAsset} |
| 49 | + token={sellToken} |
| 50 | + currentTokenAsset={currentSellAsset} |
| 51 | + Amount={sellAmount} |
| 52 | + setAmount={setSellAmount} |
| 53 | + setToken={setSellToken} |
| 54 | + walletBalanceAsset={1000} // Replace with actual balance |
50 | 55 | />
|
51 | 56 | </div>
|
| 57 | + |
52 | 58 | <Button
|
53 | 59 | variant={"primary"}
|
54 | 60 | className="w-full mt-4 py-3 text-white font-bold rounded"
|
|
0 commit comments