Skip to content

Commit ca00345

Browse files
committed
update
1 parent b80996a commit ca00345

File tree

60 files changed

+672
-733
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+672
-733
lines changed

examples/contracts/components/wallet.tsx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
useColorModeValue,
1010
Text
1111
} from '@chakra-ui/react';
12-
import { MouseEventHandler, useEffect, useMemo } from 'react';
12+
import { MouseEventHandler, useMemo } from 'react';
1313
import { FiAlertTriangle } from 'react-icons/fi';
1414
import {
1515
Astronaut,
@@ -28,26 +28,28 @@ import {
2828
ChainCard
2929
} from '../components';
3030
import { getWalletPrettyName } from '@cosmos-kit/config';
31-
import { ChainName } from '@cosmos-kit/core';
3231
import { assets as chainAssets } from 'chain-registry';
32+
import { ChainRecord } from '@cosmos-kit/core';
3333

34-
export const WalletSection = ({ chainName }: { chainName?: ChainName }) => {
34+
export const WalletSection = () => {
3535
const walletManager = useWallet();
3636
const {
3737
connect,
3838
openView,
39-
setCurrentChain,
4039
walletStatus,
4140
username,
4241
address,
4342
message,
43+
currentChainName,
4444
currentWalletName,
4545
chains
4646
} = walletManager;
4747

48-
const chainOptions = useMemo(
49-
() =>
50-
chains.map((chainRecord) => {
48+
const chainName = currentChainName;
49+
50+
const chain = useMemo(
51+
() => {
52+
const getChain = (chainRecord: ChainRecord) => {
5153
const assets = chainAssets.find(
5254
(_chain) => _chain.chain_name === chainRecord.name
5355
)?.assets;
@@ -60,16 +62,12 @@ export const WalletSection = ({ chainName }: { chainName?: ChainName }) => {
6062
: undefined,
6163
disabled: false
6264
};
63-
}),
65+
}
66+
return getChain(chains[0]);
67+
},
6468
[chains]
6569
);
6670

67-
const chain = chainOptions.find((c) => c.chainName === chainName);
68-
69-
useEffect(() => {
70-
setCurrentChain(chainName);
71-
}, [chainName, setCurrentChain]);
72-
7371
// Events
7472
const onClickConnect: MouseEventHandler = async (e) => {
7573
e.preventDefault();
@@ -80,6 +78,7 @@ export const WalletSection = ({ chainName }: { chainName?: ChainName }) => {
8078
e.preventDefault();
8179
openView();
8280
};
81+
8382
// Components
8483
const connectWalletButton = (
8584
<WalletConnectComponent
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { StdFee } from '@cosmjs/amino';
2+
import { assets } from 'chain-registry';
3+
import { AssetList, Asset } from '@chain-registry/types';
4+
5+
export const chainName = 'osmosis';
6+
7+
export const chainassets: AssetList = assets.find(
8+
(chain) => chain.chain_name === chainName
9+
) as AssetList;
10+
11+
export const baseAsset: Asset = chainassets.assets.find(
12+
(asset) => asset.base === 'uosmo'
13+
) as Asset;
14+
15+
export const sendTokens = (
16+
getStargateClient: () => Promise<SigningStargateClient>,
17+
setResp: () => any,
18+
address: string
19+
) => {
20+
return async () => {
21+
const stargateClient = await getStargateClient();
22+
if (!stargateClient || !address) {
23+
console.error('stargateClient undefined or address undefined.');
24+
return;
25+
}
26+
27+
const { send } = cosmos.bank.v1beta1.MessageComposer.withTypeUrl;
28+
29+
const msg = send({
30+
amount: [
31+
{
32+
denom: baseAsset.base,
33+
amount: '1000'
34+
}
35+
],
36+
toAddress: address,
37+
fromAddress: address
38+
});
39+
40+
const fee: StdFee = {
41+
amount: [
42+
{
43+
denom: baseAsset.base,
44+
amount: '0'
45+
}
46+
],
47+
gas: '86364'
48+
};
49+
const response = await stargateClient.signAndBroadcast(address, [msg], fee);
50+
setResp(JSON.stringify(response, null, 2));
51+
};
52+
};

examples/contracts/config/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './theme';
22
export * from './features';
3+
export * from './defaults';

examples/contracts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"@chakra-ui/react": "^2.3.4",
1717
"@cosmjs/cosmwasm-stargate": "0.29.0",
1818
"@cosmjs/stargate": "0.29.0",
19-
"@cosmos-kit/react": "^0.18.2",
19+
"@cosmos-kit/react": "0.18.4",
2020
"@cosmos-kit/types": "^0.11.0",
2121
"@emotion/react": "11.10.4",
2222
"@emotion/styled": "11.10.4",

examples/contracts/pages/_app.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import '../styles/globals.css';
22
import type { AppProps } from 'next/app';
33
import { WalletProvider } from '@cosmos-kit/react';
44
import { ChakraProvider } from '@chakra-ui/react';
5-
import { defaultTheme } from '../config';
5+
import { chainName, defaultTheme } from '../config';
66
import { wallets } from '@cosmos-kit/keplr';
77
import { chains, assets } from 'chain-registry';
88
import { getSigningCosmosClientOptions } from '../codegen';
@@ -38,8 +38,8 @@ function CreateCosmosApp({ Component, pageProps }: AppProps) {
3838
return (
3939
<ChakraProvider theme={defaultTheme}>
4040
<WalletProvider
41-
chains={chains}
42-
assetLists={assets}
41+
chains={chains.filter(chain => chain.chain_name === chainName)}
42+
assetLists={assets.filter(asset => asset.chain_name === chainName)}
4343
wallets={wallets}
4444
signerOptions={signerOptions}
4545
>

examples/contracts/pages/index.tsx

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,22 @@
11
import { Container, Button } from '@chakra-ui/react';
22
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';
74
import { SigningStargateClient } from '@cosmjs/stargate';
85
import { WalletStatus } from '@cosmos-kit/core';
96
import BigNumber from 'bignumber.js';
107

118
import { WalletSection } from '../components';
129
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';
6011

6112
export default function Home() {
6213
const {
6314
getStargateClient,
6415
address,
65-
setCurrentChain,
6616
currentWallet,
6717
walletStatus
6818
} = useWallet();
6919

70-
useEffect(() => {
71-
setCurrentChain(chainName);
72-
}, [chainName]);
73-
7420
const [balance, setBalance] = useState(new BigNumber(0));
7521
const [resp, setResp] = useState('');
7622
const getBalance = async () => {

examples/juno/components/wallet.tsx

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
useColorModeValue,
1010
Text
1111
} from '@chakra-ui/react';
12-
import { MouseEventHandler, useEffect, useMemo } from 'react';
12+
import { MouseEventHandler, useMemo } from 'react';
1313
import { FiAlertTriangle } from 'react-icons/fi';
1414
import {
1515
Astronaut,
@@ -28,28 +28,28 @@ import {
2828
ChainCard
2929
} from '../components';
3030
import { getWalletPrettyName } from '@cosmos-kit/config';
31-
import { ChainName } from '@cosmos-kit/core';
3231
import { assets as chainAssets } from 'chain-registry';
32+
import { ChainRecord } from '@cosmos-kit/core';
3333

34-
export const WalletSection = ({ chainName }: { chainName?: ChainName }) => {
34+
export const WalletSection = () => {
3535
const walletManager = useWallet();
3636
const {
3737
connect,
3838
openView,
39-
setCurrentChain,
40-
chains,
4139
walletStatus,
4240
username,
4341
address,
4442
message,
45-
currentChainName: chainName,
43+
currentChainName,
4644
currentWalletName,
47-
currentWallet
45+
chains
4846
} = walletManager;
4947

50-
const chainOptions = useMemo(
51-
() =>
52-
chains.map((chainRecord) => {
48+
const chainName = currentChainName;
49+
50+
const chain = useMemo(
51+
() => {
52+
const getChain = (chainRecord: ChainRecord) => {
5353
const assets = chainAssets.find(
5454
(_chain) => _chain.chain_name === chainRecord.name
5555
)?.assets;
@@ -62,16 +62,12 @@ export const WalletSection = ({ chainName }: { chainName?: ChainName }) => {
6262
: undefined,
6363
disabled: false
6464
};
65-
}),
65+
}
66+
return getChain(chains[0]);
67+
},
6668
[chains]
6769
);
6870

69-
const chain = chainOptions.find((c) => c.chainName === chainName);
70-
71-
useEffect(() => {
72-
setCurrentChain(chainName);
73-
}, [chainName, setCurrentChain]);
74-
7571
// Events
7672
const onClickConnect: MouseEventHandler = async (e) => {
7773
e.preventDefault();
@@ -82,6 +78,7 @@ export const WalletSection = ({ chainName }: { chainName?: ChainName }) => {
8278
e.preventDefault();
8379
openView();
8480
};
81+
8582
// Components
8683
const connectWalletButton = (
8784
<WalletConnectComponent

examples/juno/config/defaults.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { assets } from 'chain-registry';
2+
import { AssetList, Asset } from '@chain-registry/types';
3+
4+
export const chainName = 'juno';
5+
6+
export const chainassets: AssetList = assets.find(
7+
(chain) => chain.chain_name === chainName
8+
) as AssetList;
9+
10+
export const coin: Asset = chainassets.assets.find(
11+
(asset) => asset.base === 'ujuno'
12+
) as Asset;

examples/juno/config/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './theme';
22
export * from './features';
3+
export * from './defaults';

examples/juno/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
"@chakra-ui/react": "2.3.4",
1515
"@cosmjs/cosmwasm-stargate": "0.29.0",
1616
"@cosmjs/stargate": "0.29.0",
17-
"@cosmos-kit/core": "0.19.1",
18-
"@cosmos-kit/keplr": "0.19.1",
19-
"@cosmos-kit/react": "0.18.2",
17+
"@cosmos-kit/core": "0.19.3",
18+
"@cosmos-kit/keplr": "0.19.3",
19+
"@cosmos-kit/react": "0.18.4",
2020
"@emotion/react": "11.10.4",
2121
"@emotion/styled": "11.10.4",
2222
"@juno-network/assets": "0.11.1",

0 commit comments

Comments
 (0)