|
1 | 1 | import { Container, Button } from '@chakra-ui/react'; |
2 | 2 | import { useWallet } from '@cosmos-kit/react'; |
3 | | -import { useEffect, useState } from 'react'; |
4 | | -import { StdFee } from '@cosmjs/amino'; |
5 | | -import { assets } from 'chain-registry'; |
6 | | -import { AssetList, Asset } from '@chain-registry/types'; |
| 3 | +import { useState } from 'react'; |
7 | 4 | import { SigningStargateClient } from '@cosmjs/stargate'; |
8 | 5 | import { WalletStatus } from '@cosmos-kit/core'; |
9 | 6 | import BigNumber from 'bignumber.js'; |
10 | 7 |
|
11 | 8 | import { WalletSection } from '../components'; |
12 | 9 | import { cosmos } from '../codegen'; |
13 | | - |
14 | | -const chainName = 'osmosis'; |
15 | | -const chainassets: AssetList = assets.find( |
16 | | - (chain) => chain.chain_name === chainName |
17 | | -) as AssetList; |
18 | | -const baseAsset: Asset = chainassets.assets.find( |
19 | | - (asset) => asset.base === 'uosmo' |
20 | | -) as Asset; |
21 | | - |
22 | | -const sendTokens = ( |
23 | | - getStargateClient: () => Promise<SigningStargateClient>, |
24 | | - setResp: () => any, |
25 | | - address: string |
26 | | -) => { |
27 | | - return async () => { |
28 | | - const stargateClient = await getStargateClient(); |
29 | | - if (!stargateClient || !address) { |
30 | | - console.error('stargateClient undefined or address undefined.'); |
31 | | - return; |
32 | | - } |
33 | | - |
34 | | - const { send } = cosmos.bank.v1beta1.MessageComposer.withTypeUrl; |
35 | | - |
36 | | - const msg = send({ |
37 | | - amount: [ |
38 | | - { |
39 | | - denom: baseAsset.base, |
40 | | - amount: '1000' |
41 | | - } |
42 | | - ], |
43 | | - toAddress: address, |
44 | | - fromAddress: address |
45 | | - }); |
46 | | - |
47 | | - const fee: StdFee = { |
48 | | - amount: [ |
49 | | - { |
50 | | - denom: baseAsset.base, |
51 | | - amount: '0' |
52 | | - } |
53 | | - ], |
54 | | - gas: '86364' |
55 | | - }; |
56 | | - const response = await stargateClient.signAndBroadcast(address, [msg], fee); |
57 | | - setResp(JSON.stringify(response, null, 2)); |
58 | | - }; |
59 | | -}; |
| 10 | +import { baseAsset, chainassets, chainName, sendTokens } from '../config'; |
60 | 11 |
|
61 | 12 | export default function Home() { |
62 | 13 | const { |
63 | 14 | getStargateClient, |
64 | 15 | address, |
65 | | - setCurrentChain, |
66 | 16 | currentWallet, |
67 | 17 | walletStatus |
68 | 18 | } = useWallet(); |
69 | 19 |
|
70 | | - useEffect(() => { |
71 | | - setCurrentChain(chainName); |
72 | | - }, [chainName]); |
73 | | - |
74 | 20 | const [balance, setBalance] = useState(new BigNumber(0)); |
75 | 21 | const [resp, setResp] = useState(''); |
76 | 22 | const getBalance = async () => { |
|
0 commit comments