jeduardogruiz commited on
Commit
9f72b71
1 Parent(s): e71afc0

Create Swap.tsx

Browse files
Files changed (1) hide show
  1. Swap.tsx +63 -0
Swap.tsx ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Avatar, Name } from '@coinbase/onchainkit/identity';
2
+ import {
3
+ Swap,
4
+ SwapAmountInput,
5
+ SwapToggleButton,
6
+ SwapButton,
7
+ SwapMessage,
8
+ } from '@coinbase/onchainkit/swap';
9
+ import { Wallet, ConnectWallet } from '@coinbase/onchainkit/wallet';
10
+ import { useAccount } from 'wagmi';
11
+ import type { Token } from '@coinbase/onchainkit/token';
12
+
13
+ export default function SwapComponents() {
14
+ const { address } = useAccount();
15
+
16
+ const ETHToken: Token = {
17
+ address: "",
18
+ chainId: 8453,
19
+ decimals: 18,
20
+ name: "Ethereum",
21
+ symbol: "ETH",
22
+ image: "https://dynamic-assets.coinbase.com/dbb4b4983bde81309ddab83eb598358eb44375b930b94687ebe38bc22e52c3b2125258ffb8477a5ef22e33d6bd72e32a506c391caa13af64c00e46613c3e5806/asset_icons/4113b082d21cc5fab17fc8f2d19fb996165bcce635e6900f7fc2d57c4ef33ae9.png",
23
+ };
24
+
25
+ const USDCToken: Token = {
26
+ address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
27
+ chainId: 8453,
28
+ decimals: 6,
29
+ name: "USDC",
30
+ symbol: "USDC",
31
+ image: "https://dynamic-assets.coinbase.com/3c15df5e2ac7d4abbe9499ed9335041f00c620f28e8de2f93474a9f432058742cdf4674bd43f309e69778a26969372310135be97eb183d91c492154176d455b8/asset_icons/9d67b728b6c8f457717154b3a35f9ddc702eae7e76c4684ee39302c4d7fd0bb8.png",
32
+ };
33
+
34
+ // add other tokens here to display them as options in the swap
35
+ const swappableTokens: Token[] = [ETHToken, USDCToken];
36
+
37
+ return address ? (
38
+ <Swap>
39
+ <SwapAmountInput
40
+ label="Sell"
41
+ swappableTokens={swappableTokens}
42
+ token={ETHToken}
43
+ type="from"
44
+ />
45
+ <SwapToggleButton />
46
+ <SwapAmountInput
47
+ label="Buy"
48
+ swappableTokens={swappableTokens}
49
+ token={USDCToken}
50
+ type="to"
51
+ />
52
+ <SwapButton />
53
+ <SwapMessage />
54
+ </Swap>
55
+ ) : (
56
+ <Wallet>
57
+ <ConnectWallet>
58
+ <Avatar className="h-6 w-6" />
59
+ <Name />
60
+ </ConnectWallet>
61
+ </Wallet>
62
+ );
63
+ }