Skip to content

Commit 0c35103

Browse files
authored
Merge pull request #19 from cosmology-tech/develop
Develop
2 parents 27497cf + ca00345 commit 0c35103

File tree

65 files changed

+751
-797
lines changed

Some content is hidden

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

65 files changed

+751
-797
lines changed

examples/contracts/components/wallet.tsx

Lines changed: 13 additions & 18 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,23 +62,16 @@ 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();
76-
openView();
77-
if (currentWalletName) {
78-
await connect();
79-
}
74+
await connect();
8075
};
8176

8277
const onClickOpenView: MouseEventHandler = (e) => {
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.1",
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/contracts/tsconfig.json

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
22
"compilerOptions": {
3-
"target": "es5",
4-
"lib": ["dom", "dom.iterable", "esnext"],
3+
"target": "ES2020",
4+
"lib": [
5+
"dom",
6+
"dom.iterable",
7+
"esnext"
8+
],
59
"allowJs": true,
610
"skipLibCheck": true,
711
"strict": true,
@@ -15,6 +19,12 @@
1519
"jsx": "preserve",
1620
"incremental": true
1721
},
18-
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
19-
"exclude": ["node_modules"]
20-
}
22+
"include": [
23+
"next-env.d.ts",
24+
"**/*.ts",
25+
"**/*.tsx"
26+
],
27+
"exclude": [
28+
"node_modules"
29+
]
30+
}

examples/juno/components/wallet.tsx

Lines changed: 13 additions & 18 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,23 +62,16 @@ 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();
76-
openView();
77-
if (currentWalletName) {
78-
await connect();
79-
}
74+
await connect();
8075
};
8176

8277
const onClickOpenView: MouseEventHandler = (e) => {

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';

0 commit comments

Comments
 (0)