Skip to content

Commit a37e588

Browse files
authored
Merge pull request #23 from cosmology-tech/develop
update
2 parents efd4121 + e9c4dc2 commit a37e588

File tree

34 files changed

+282
-417
lines changed

34 files changed

+282
-417
lines changed

examples/contracts/components/wallet.tsx

Lines changed: 21 additions & 36 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, useMemo } from 'react';
12+
import { MouseEventHandler, useEffect } from 'react';
1313
import { FiAlertTriangle } from 'react-icons/fi';
1414
import {
1515
Astronaut,
@@ -27,9 +27,8 @@ import {
2727
WalletConnectComponent,
2828
ChainCard
2929
} from '../components';
30-
import { getWalletPrettyName } from '@cosmos-kit/config';
31-
import { assets as chainAssets } from 'chain-registry';
32-
import { ChainRecord } from '@cosmos-kit/core';
30+
import { chainName } from '../config';
31+
3332

3433
export const WalletSection = () => {
3534
const walletManager = useWallet();
@@ -41,32 +40,22 @@ export const WalletSection = () => {
4140
address,
4241
message,
4342
currentChainName,
44-
currentWalletName,
45-
chains
43+
currentWallet,
44+
currentChainRecord,
45+
getChainLogo,
46+
setCurrentChain
4647
} = walletManager;
4748

48-
const chainName = currentChainName;
49+
useEffect(() => {
50+
setCurrentChain(chainName);
51+
}, [setCurrentChain]);
4952

50-
const chain = useMemo(
51-
() => {
52-
const getChain = (chainRecord: ChainRecord) => {
53-
const assets = chainAssets.find(
54-
(_chain) => _chain.chain_name === chainRecord.name
55-
)?.assets;
56-
return {
57-
chainName: chainRecord.name,
58-
label: chainRecord.chain.pretty_name,
59-
value: chainRecord.name,
60-
icon: assets
61-
? assets[0]?.logo_URIs?.svg || assets[0]?.logo_URIs?.png
62-
: undefined,
63-
disabled: false
64-
};
65-
}
66-
return getChain(chains[0]);
67-
},
68-
[chains]
69-
);
53+
const chain = {
54+
chainName: currentChainName,
55+
label: currentChainRecord?.chain.pretty_name,
56+
value: currentChainName,
57+
icon: getChainLogo(currentChainName)
58+
}
7059

7160
// Events
7261
const onClickConnect: MouseEventHandler = async (e) => {
@@ -104,17 +93,13 @@ export const WalletSection = () => {
10493
rejected={
10594
<RejectedWarn
10695
icon={<Icon as={FiAlertTriangle} mt={1} />}
107-
wordOfWarning={`${getWalletPrettyName(
108-
currentWalletName
109-
)}: ${message}`}
96+
wordOfWarning={`${currentWallet?.walletInfo.prettyName}: ${message}`}
11097
/>
11198
}
11299
error={
113100
<RejectedWarn
114101
icon={<Icon as={FiAlertTriangle} mt={1} />}
115-
wordOfWarning={`${getWalletPrettyName(
116-
currentWalletName
117-
)}: ${message}`}
102+
wordOfWarning={`${currentWallet?.walletInfo.prettyName}: ${message}`}
118103
/>
119104
}
120105
/>
@@ -123,7 +108,7 @@ export const WalletSection = () => {
123108
const userInfo = (
124109
<ConnectedUserInfo username={username} icon={<Astronaut />} />
125110
);
126-
const addressBtn = chainName && (
111+
const addressBtn = currentChainName && (
127112
<CopyAddressBtn
128113
walletStatus={walletStatus}
129114
connected={<ConnectedShowAddress address={address} isLoading={false} />}
@@ -140,10 +125,10 @@ export const WalletSection = () => {
140125
alignItems="center"
141126
justifyContent="center"
142127
>
143-
{chainName && (
128+
{currentChainName && (
144129
<GridItem marginBottom={'20px'}>
145130
<ChainCard
146-
prettyName={chain?.label || chainName}
131+
prettyName={chain?.label || currentChainName}
147132
icon={chain?.icon}
148133
/>
149134
</GridItem>

examples/contracts/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"@chakra-ui/react": "^2.3.5",
1717
"@cosmjs/cosmwasm-stargate": "0.29.2",
1818
"@cosmjs/stargate": "0.29.2",
19-
"@cosmos-kit/react": "0.18.4",
19+
"@cosmos-kit/react": "0.18.6",
2020
"@cosmos-kit/types": "^0.11.0",
2121
"@emotion/react": "11.10.4",
2222
"@emotion/styled": "11.10.4",
@@ -41,4 +41,4 @@
4141
"eslint-config-next": "12.2.5",
4242
"typescript": "4.7.4"
4343
}
44-
}
44+
}

examples/contracts/pages/_app.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ function CreateCosmosApp({ Component, pageProps }: AppProps) {
3838
return (
3939
<ChakraProvider theme={defaultTheme}>
4040
<WalletProvider
41-
chains={chains.filter(chain => chain.chain_name === chainName)}
42-
assetLists={assets.filter(asset => asset.chain_name === chainName)}
41+
chains={chains}
42+
assetLists={assets}
4343
wallets={wallets}
4444
signerOptions={signerOptions}
4545
>

examples/juno/components/wallet.tsx

Lines changed: 21 additions & 36 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, useMemo } from 'react';
12+
import { MouseEventHandler, useEffect } from 'react';
1313
import { FiAlertTriangle } from 'react-icons/fi';
1414
import {
1515
Astronaut,
@@ -27,9 +27,8 @@ import {
2727
WalletConnectComponent,
2828
ChainCard
2929
} from '../components';
30-
import { getWalletPrettyName } from '@cosmos-kit/config';
31-
import { assets as chainAssets } from 'chain-registry';
32-
import { ChainRecord } from '@cosmos-kit/core';
30+
import { chainName } from '../config';
31+
3332

3433
export const WalletSection = () => {
3534
const walletManager = useWallet();
@@ -41,32 +40,22 @@ export const WalletSection = () => {
4140
address,
4241
message,
4342
currentChainName,
44-
currentWalletName,
45-
chains
43+
currentWallet,
44+
currentChainRecord,
45+
getChainLogo,
46+
setCurrentChain
4647
} = walletManager;
4748

48-
const chainName = currentChainName;
49+
useEffect(() => {
50+
setCurrentChain(chainName);
51+
}, [setCurrentChain]);
4952

50-
const chain = useMemo(
51-
() => {
52-
const getChain = (chainRecord: ChainRecord) => {
53-
const assets = chainAssets.find(
54-
(_chain) => _chain.chain_name === chainRecord.name
55-
)?.assets;
56-
return {
57-
chainName: chainRecord.name,
58-
label: chainRecord.chain.pretty_name,
59-
value: chainRecord.name,
60-
icon: assets
61-
? assets[0]?.logo_URIs?.svg || assets[0]?.logo_URIs?.png
62-
: undefined,
63-
disabled: false
64-
};
65-
}
66-
return getChain(chains[0]);
67-
},
68-
[chains]
69-
);
53+
const chain = {
54+
chainName: currentChainName,
55+
label: currentChainRecord?.chain.pretty_name,
56+
value: currentChainName,
57+
icon: getChainLogo(currentChainName)
58+
}
7059

7160
// Events
7261
const onClickConnect: MouseEventHandler = async (e) => {
@@ -104,17 +93,13 @@ export const WalletSection = () => {
10493
rejected={
10594
<RejectedWarn
10695
icon={<Icon as={FiAlertTriangle} mt={1} />}
107-
wordOfWarning={`${getWalletPrettyName(
108-
currentWalletName
109-
)}: ${message}`}
96+
wordOfWarning={`${currentWallet?.walletInfo.prettyName}: ${message}`}
11097
/>
11198
}
11299
error={
113100
<RejectedWarn
114101
icon={<Icon as={FiAlertTriangle} mt={1} />}
115-
wordOfWarning={`${getWalletPrettyName(
116-
currentWalletName
117-
)}: ${message}`}
102+
wordOfWarning={`${currentWallet?.walletInfo.prettyName}: ${message}`}
118103
/>
119104
}
120105
/>
@@ -123,7 +108,7 @@ export const WalletSection = () => {
123108
const userInfo = (
124109
<ConnectedUserInfo username={username} icon={<Astronaut />} />
125110
);
126-
const addressBtn = chainName && (
111+
const addressBtn = currentChainName && (
127112
<CopyAddressBtn
128113
walletStatus={walletStatus}
129114
connected={<ConnectedShowAddress address={address} isLoading={false} />}
@@ -140,10 +125,10 @@ export const WalletSection = () => {
140125
alignItems="center"
141126
justifyContent="center"
142127
>
143-
{chainName && (
128+
{currentChainName && (
144129
<GridItem marginBottom={'20px'}>
145130
<ChainCard
146-
prettyName={chain?.label || chainName}
131+
prettyName={chain?.label || currentChainName}
147132
icon={chain?.icon}
148133
/>
149134
</GridItem>

examples/juno/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"@cosmjs/stargate": "0.29.2",
1717
"@cosmos-kit/core": "0.19.3",
1818
"@cosmos-kit/keplr": "0.19.3",
19-
"@cosmos-kit/react": "0.18.4",
19+
"@cosmos-kit/react": "0.18.6",
2020
"@emotion/react": "11.10.4",
2121
"@emotion/styled": "11.10.4",
2222
"@juno-network/assets": "0.13.0",
@@ -37,4 +37,4 @@
3737
"eslint-config-next": "12.2.5",
3838
"typescript": "4.7.4"
3939
}
40-
}
40+
}

examples/juno/pages/_app.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ function CreateCosmosApp({ Component, pageProps }: AppProps) {
2929
return (
3030
<ChakraProvider theme={defaultTheme}>
3131
<WalletProvider
32-
chains={chains.filter(chain => chain.chain_name === chainName)}
33-
assetLists={assets.filter(asset => asset.chain_name === chainName)}
32+
chains={chains}
33+
assetLists={assets}
3434
wallets={wallets}
3535
signerOptions={signerOptions}
3636
>

examples/osmosis-cosmwasm/components/wallet.tsx

Lines changed: 21 additions & 36 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, useMemo } from 'react';
12+
import { MouseEventHandler, useEffect } from 'react';
1313
import { FiAlertTriangle } from 'react-icons/fi';
1414
import {
1515
Astronaut,
@@ -27,9 +27,8 @@ import {
2727
WalletConnectComponent,
2828
ChainCard
2929
} from '../components';
30-
import { getWalletPrettyName } from '@cosmos-kit/config';
31-
import { assets as chainAssets } from 'chain-registry';
32-
import { ChainRecord } from '@cosmos-kit/core';
30+
import { chainName } from '../config';
31+
3332

3433
export const WalletSection = () => {
3534
const walletManager = useWallet();
@@ -41,32 +40,22 @@ export const WalletSection = () => {
4140
address,
4241
message,
4342
currentChainName,
44-
currentWalletName,
45-
chains
43+
currentWallet,
44+
currentChainRecord,
45+
getChainLogo,
46+
setCurrentChain
4647
} = walletManager;
4748

48-
const chainName = currentChainName;
49+
useEffect(() => {
50+
setCurrentChain(chainName);
51+
}, [setCurrentChain]);
4952

50-
const chain = useMemo(
51-
() => {
52-
const getChain = (chainRecord: ChainRecord) => {
53-
const assets = chainAssets.find(
54-
(_chain) => _chain.chain_name === chainRecord.name
55-
)?.assets;
56-
return {
57-
chainName: chainRecord.name,
58-
label: chainRecord.chain.pretty_name,
59-
value: chainRecord.name,
60-
icon: assets
61-
? assets[0]?.logo_URIs?.svg || assets[0]?.logo_URIs?.png
62-
: undefined,
63-
disabled: false
64-
};
65-
}
66-
return getChain(chains[0]);
67-
},
68-
[chains]
69-
);
53+
const chain = {
54+
chainName: currentChainName,
55+
label: currentChainRecord?.chain.pretty_name,
56+
value: currentChainName,
57+
icon: getChainLogo(currentChainName)
58+
}
7059

7160
// Events
7261
const onClickConnect: MouseEventHandler = async (e) => {
@@ -104,17 +93,13 @@ export const WalletSection = () => {
10493
rejected={
10594
<RejectedWarn
10695
icon={<Icon as={FiAlertTriangle} mt={1} />}
107-
wordOfWarning={`${getWalletPrettyName(
108-
currentWalletName
109-
)}: ${message}`}
96+
wordOfWarning={`${currentWallet?.walletInfo.prettyName}: ${message}`}
11097
/>
11198
}
11299
error={
113100
<RejectedWarn
114101
icon={<Icon as={FiAlertTriangle} mt={1} />}
115-
wordOfWarning={`${getWalletPrettyName(
116-
currentWalletName
117-
)}: ${message}`}
102+
wordOfWarning={`${currentWallet?.walletInfo.prettyName}: ${message}`}
118103
/>
119104
}
120105
/>
@@ -123,7 +108,7 @@ export const WalletSection = () => {
123108
const userInfo = (
124109
<ConnectedUserInfo username={username} icon={<Astronaut />} />
125110
);
126-
const addressBtn = chainName && (
111+
const addressBtn = currentChainName && (
127112
<CopyAddressBtn
128113
walletStatus={walletStatus}
129114
connected={<ConnectedShowAddress address={address} isLoading={false} />}
@@ -140,10 +125,10 @@ export const WalletSection = () => {
140125
alignItems="center"
141126
justifyContent="center"
142127
>
143-
{chainName && (
128+
{currentChainName && (
144129
<GridItem marginBottom={'20px'}>
145130
<ChainCard
146-
prettyName={chain?.label || chainName}
131+
prettyName={chain?.label || currentChainName}
147132
icon={chain?.icon}
148133
/>
149134
</GridItem>

0 commit comments

Comments
 (0)