Skip to content

Commit 9adc03f

Browse files
committed
feat: update contracts
1 parent cd398b8 commit 9adc03f

37 files changed

+428
-471
lines changed

templates/chain-admin/components/common/Wallet/Connected.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
import Image from 'next/image';
22
import { Box, Icon, Text, useColorModeValue } from '@interchain-ui/react';
33
import { FiLogOut } from 'react-icons/fi';
4-
import { ChainWalletBase } from '@cosmos-kit/core';
4+
import { useChainWallet } from '@interchain-kit/react';
55

66
import { darkColors, lightColors } from '@/config';
77
import { useCopyToClipboard } from '@/hooks';
88
import { getWalletLogo, shortenAddress } from '@/utils';
9+
import { useChainStore } from '@/contexts';
910

1011
export const Connected = ({
11-
selectedWallet,
12+
selectedWalletName,
1213
clearSelectedWallet,
1314
}: {
14-
selectedWallet: ChainWalletBase;
15+
selectedWalletName: string;
1516
clearSelectedWallet: () => void;
1617
}) => {
17-
const { walletInfo, disconnect, address } = selectedWallet;
18+
const { selectedChain } = useChainStore();
19+
20+
const { wallet, disconnect, address } = useChainWallet(
21+
selectedChain,
22+
selectedWalletName
23+
);
1824

1925
const { isCopied, copyToClipboard } = useCopyToClipboard();
2026

@@ -39,10 +45,10 @@ export const Connected = ({
3945
boxShadow={`0px 0px 20px 0px ${boxShadowColor}`}
4046
>
4147
<Box display="flex" alignItems="center" gap="4px">
42-
{walletInfo && (
48+
{wallet && (
4349
<Image
44-
src={getWalletLogo(walletInfo)}
45-
alt={walletInfo.prettyName}
50+
src={getWalletLogo(wallet.info)}
51+
alt={wallet.info.prettyName}
4652
width="0"
4753
height="0"
4854
style={{ width: '20px', height: 'auto' }}

templates/chain-admin/components/common/Wallet/Connecting.tsx

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,79 @@
1-
import Link from 'next/link';
21
import Image from 'next/image';
3-
import { useMemo } from 'react';
2+
import { useEffect, useMemo } from 'react';
43
import { Box, Icon, Text, useColorModeValue } from '@interchain-ui/react';
5-
import { ChainWalletBase, WalletStatus } from '@cosmos-kit/core';
4+
import { useChainWallet } from '@interchain-kit/react';
5+
import { Wallet, WalletState } from '@interchain-kit/core';
66

77
import { darkColors, lightColors } from '@/config';
88
import { getWalletLogo } from '@/utils';
99
import { RingLoader } from './RingLoader';
10-
import { Button } from '../Button';
10+
import { useChainStore } from '@/contexts';
1111

1212
export const Connecting = ({
13-
selectedWallet,
13+
selectedWalletName,
1414
clearSelectedWallet,
1515
}: {
16-
selectedWallet: ChainWalletBase;
16+
selectedWalletName: string;
1717
clearSelectedWallet: () => void;
1818
}) => {
19-
const { walletInfo, downloadInfo, message, walletStatus } = selectedWallet;
19+
const { selectedChain } = useChainStore();
20+
21+
const { wallet, connect, status, message } = useChainWallet(
22+
selectedChain,
23+
selectedWalletName
24+
);
25+
26+
useEffect(() => {
27+
connect();
28+
}, []);
2029

2130
const content = useMemo(() => {
22-
if (walletStatus === WalletStatus.NotExist) {
23-
return (
24-
<>
25-
<WalletLogoWithRing wallet={walletInfo} intent="warning" />
26-
<StatusText>{walletInfo.prettyName} Not Installed</StatusText>
27-
{downloadInfo?.link && (
28-
<Link href={downloadInfo.link} target="_blank">
29-
<Button
30-
leftIcon="arrowDownload"
31-
fontSize="14px"
32-
color="$blackAlpha600"
33-
>
34-
Install {walletInfo.prettyName}
35-
</Button>
36-
</Link>
37-
)}
38-
</>
39-
);
40-
}
31+
// if (status === WalletStatus.NotExist) {
32+
// return (
33+
// <>
34+
// <WalletLogoWithRing wallet={walletInfo} intent="warning" />
35+
// <StatusText>{walletInfo.prettyName} Not Installed</StatusText>
36+
// {downloadInfo?.link && (
37+
// <Link href={downloadInfo.link} target="_blank">
38+
// <Button
39+
// leftIcon="arrowDownload"
40+
// fontSize="14px"
41+
// color="$blackAlpha600"
42+
// >
43+
// Install {walletInfo.prettyName}
44+
// </Button>
45+
// </Link>
46+
// )}
47+
// </>
48+
// );
49+
// }
4150

42-
if (walletStatus === WalletStatus.Connecting) {
51+
if (status === WalletState.Connecting) {
4352
return (
4453
<>
45-
<WalletLogoWithRing wallet={walletInfo} intent="connecting" />
54+
<WalletLogoWithRing wallet={wallet.info} intent="connecting" />
4655
<StatusText>Requesting Connection</StatusText>
4756
</>
4857
);
4958
}
5059

51-
if (walletStatus === WalletStatus.Rejected) {
60+
if (status === WalletState.Rejected) {
5261
return (
5362
<>
54-
<WalletLogoWithRing wallet={walletInfo} intent="warning" />
63+
<WalletLogoWithRing wallet={wallet.info} intent="warning" />
5564
<StatusText>Request Rejected</StatusText>
5665
</>
5766
);
5867
}
5968

6069
return (
6170
<>
62-
<WalletLogoWithRing wallet={walletInfo} intent="warning" />
71+
<WalletLogoWithRing wallet={wallet.info} intent="warning" />
6372
<StatusText>Connection Error</StatusText>
6473
{message && <StatusDescription>{message}</StatusDescription>}
6574
</>
6675
);
67-
}, [walletInfo, walletStatus, message]);
76+
}, [wallet.info, status, message]);
6877

6978
const boxShadowColor = useColorModeValue(
7079
lightColors?.blackAlpha200 as string,
@@ -98,7 +107,7 @@ export const Connecting = ({
98107
<Icon name="arrowLeftSLine" color="$blackAlpha500" size="$xl" />
99108
</Box>
100109
<Text color="$blackAlpha600" fontSize="16px" fontWeight="600">
101-
{walletInfo.prettyName}
110+
{wallet.info.prettyName}
102111
</Text>
103112
<Icon
104113
size="$xl"
@@ -137,7 +146,7 @@ const WalletLogoWithRing = ({
137146
wallet,
138147
intent,
139148
}: {
140-
wallet: ChainWalletBase['walletInfo'];
149+
wallet: Wallet;
141150
intent: 'connecting' | 'warning';
142151
}) => {
143152
const isConnecting = intent === 'connecting';

templates/chain-admin/components/common/Wallet/SelectWallet.tsx

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,18 @@
11
import Image from 'next/image';
22
import { Dispatch, SetStateAction } from 'react';
3-
import { MainWalletBase, ChainWalletBase } from '@cosmos-kit/core';
43
import { Box, Text, useColorModeValue } from '@interchain-ui/react';
5-
import { Keplr } from '@keplr-wallet/types';
4+
import { Wallet } from '@interchain-kit/core';
65

76
import { darkColors, lightColors, wallets } from '@/config';
8-
import { getWalletLogo, makeKeplrChainInfo } from '@/utils';
9-
import { useChainStore } from '@/contexts';
7+
import { getWalletLogo } from '@/utils';
108

119
export const SelectWallet = ({
12-
setSelectedWallet,
10+
setSelectedWalletName,
1311
}: {
14-
setSelectedWallet: Dispatch<SetStateAction<ChainWalletBase | null>>;
12+
setSelectedWalletName: Dispatch<SetStateAction<string | null>>;
1513
}) => {
16-
const { selectedChain } = useChainStore();
17-
18-
const handleSelectWallet = (wallet: MainWalletBase) => async () => {
19-
const chainWallet = wallet.getChainWallet(selectedChain)!;
20-
const { chain, assets, connect, client } = chainWallet;
21-
const chainInfo = makeKeplrChainInfo(chain, assets[0]);
22-
23-
try {
24-
if (wallet.walletName.startsWith('keplr')) {
25-
// @ts-ignore
26-
await (client?.client as Keplr).experimentalSuggestChain(chainInfo);
27-
}
28-
connect();
29-
setTimeout(() => {
30-
setSelectedWallet(chainWallet);
31-
}, 100);
32-
} catch (error) {
33-
console.error(error);
34-
}
14+
const handleSelectWallet = (wallet: Wallet) => () => {
15+
setSelectedWalletName(wallet.name);
3516
};
3617

3718
const boxShadowColor = useColorModeValue(
@@ -63,15 +44,15 @@ export const SelectWallet = ({
6344
borderColor="$blackAlpha200"
6445
backgroundColor={{ base: '$background', hover: '$blackAlpha100' }}
6546
cursor="pointer"
66-
attributes={{ onClick: handleSelectWallet(w) }}
67-
key={w.walletName}
47+
attributes={{ onClick: handleSelectWallet(w.info!) }}
48+
key={w.info?.name}
6849
>
6950
<Text color="$blackAlpha600" fontSize="14px" fontWeight="500">
70-
{w.walletPrettyName}
51+
{w.info?.prettyName}
7152
</Text>
7253
<Image
73-
src={getWalletLogo(w.walletInfo)}
74-
alt={w.walletPrettyName}
54+
src={getWalletLogo(w?.info)}
55+
alt={w?.info?.prettyName ?? ''}
7556
width="0"
7657
height="0"
7758
style={{ width: '20px', height: 'auto' }}
Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,36 @@
11
import { useState } from 'react';
2-
import { useChain } from '@cosmos-kit/react';
3-
import { ChainWalletBase } from '@cosmos-kit/core';
2+
import { useChain } from '@interchain-kit/react';
43

54
import { useChainStore } from '@/contexts';
65
import { Connected } from './Connected';
76
import { Connecting } from './Connecting';
87
import { SelectWallet } from './SelectWallet';
9-
import { wallets } from '@/config';
108

119
export const WalletConnect = () => {
1210
const { selectedChain } = useChainStore();
13-
const { wallet } = useChain(selectedChain);
11+
const { wallet, address } = useChain(selectedChain);
1412

15-
const currentWallet = wallets.find((w) => w.walletName === wallet?.name);
16-
const chainWallet = currentWallet?.getChainWallet(selectedChain);
17-
18-
const [selectedWallet, setSelectedWallet] = useState<ChainWalletBase | null>(
19-
chainWallet?.isWalletConnected ? chainWallet : null
13+
const [selectedWalletName, setSelectedWalletName] = useState<string | null>(
14+
wallet && address ? wallet.info.name : null
2015
);
2116

22-
if (selectedWallet && selectedWallet.isWalletConnected) {
17+
if (selectedWalletName && address) {
2318
return (
2419
<Connected
25-
selectedWallet={selectedWallet}
26-
clearSelectedWallet={() => setSelectedWallet(null)}
20+
selectedWalletName={selectedWalletName}
21+
clearSelectedWallet={() => setSelectedWalletName(null)}
2722
/>
2823
);
2924
}
3025

31-
if (selectedWallet) {
26+
if (selectedWalletName) {
3227
return (
3328
<Connecting
34-
selectedWallet={selectedWallet}
35-
clearSelectedWallet={() => setSelectedWallet(null)}
29+
selectedWalletName={selectedWalletName}
30+
clearSelectedWallet={() => setSelectedWalletName(null)}
3631
/>
3732
);
3833
}
3934

40-
return <SelectWallet setSelectedWallet={setSelectedWallet} />;
35+
return <SelectWallet setSelectedWalletName={setSelectedWalletName} />;
4136
};

templates/chain-admin/components/contract/common/AttachFundsRadio.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { useEffect, useMemo, useState } from 'react';
2-
import { Coin } from '@cosmjs/amino';
32
import { Box } from '@interchain-ui/react';
4-
import { Asset } from '@chain-registry/types';
3+
import { Asset } from '@chain-registry/v2-types';
54
import BigNumber from 'bignumber.js';
65
import { TbCurrencyDollarOff } from 'react-icons/tb';
76
import { LuListPlus } from 'react-icons/lu';
87
import { VscJson } from 'react-icons/vsc';
8+
import { Coin } from '@interchainjs/react/types';
99

1010
import { JsonInput } from './JsonInput';
1111
import { SelectAssetContent } from './SelectAssetContent';

templates/chain-admin/components/contract/common/ContractAddressField.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect, useRef, useState } from 'react';
2-
import { useChain } from '@cosmos-kit/react';
2+
import { useChain } from '@interchain-kit/react';
33
import { Text } from '@interchain-ui/react';
44

55
import { useContractInfo, useDetectBreakpoints, useMyContracts } from '@/hooks';
@@ -46,7 +46,7 @@ export const ContractAddressField = ({
4646
onValidAddressChange?.('');
4747

4848
if (input.length) {
49-
const error = validateContractAddress(input, chain.bech32_prefix);
49+
const error = validateContractAddress(input, chain.bech32Prefix ?? '');
5050

5151
if (error) {
5252
return setStatus({ state: 'error', message: error });
@@ -70,7 +70,7 @@ export const ContractAddressField = ({
7070

7171
return () => clearTimeout(timer);
7272
}
73-
}, [input, fetchContractInfo, chain.bech32_prefix]);
73+
}, [input, fetchContractInfo, chain.bech32Prefix]);
7474

7575
const { isMobile } = useDetectBreakpoints();
7676

templates/chain-admin/components/contract/common/SelectAssetItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Dispatch, SetStateAction, useState } from 'react';
22
import { HiOutlineTrash } from 'react-icons/hi';
3-
import { Asset } from '@chain-registry/types';
3+
import { Asset } from '@chain-registry/v2-types';
44
import {
55
Avatar,
66
Box,
@@ -180,7 +180,7 @@ const AssetOption = ({
180180
>
181181
<Avatar
182182
name={asset.symbol}
183-
src={asset.logo_URIs?.svg || asset.logo_URIs?.png || ''}
183+
src={asset.logoURIs?.svg || asset.logoURIs?.png || ''}
184184
size="xs"
185185
/>
186186
<Text

templates/chain-admin/components/contract/deploy/CodeIdField.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect, useState } from 'react';
2-
import { useChain } from '@cosmos-kit/react';
2+
import { useChain } from '@interchain-kit/react';
33
import { Box, Icon, Spinner, TextField } from '@interchain-ui/react';
44

55
import { useChainStore } from '@/contexts';
@@ -44,15 +44,15 @@ export const CodeIdField = ({
4444

4545
const timer = setTimeout(() => {
4646
refetch().then(({ data }) => {
47-
setCodeInfo(data);
48-
4947
if (!data) {
5048
return setStatus({
5149
state: 'error',
5250
message: 'This code ID does not exist',
5351
});
5452
}
5553

54+
setCodeInfo(data);
55+
5656
const hasPermission = resolvePermission(
5757
address || '',
5858
data.permission,

templates/chain-admin/components/contract/deploy/DeployJsContract.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useState } from 'react';
22
import { Box, Text } from '@interchain-ui/react';
3-
import { useChain } from '@cosmos-kit/react';
3+
import { useChain } from '@interchain-kit/react';
44
import { DeliverTxResponse } from 'hyperwebjs';
55

66
import {
@@ -37,7 +37,7 @@ export const DeployJsContract = ({
3737
const [txResult, setTxResult] = useState<DeliverTxResponse>();
3838

3939
const { selectedChain } = useChainStore();
40-
const { address, assets } = useChain(selectedChain);
40+
const { address, assetList } = useChain(selectedChain);
4141
const { instantiateJsdTx } = useInstantiateTx(selectedChain);
4242
const { refetch: updateMyContracts } = useMyContracts();
4343

@@ -89,7 +89,7 @@ export const DeployJsContract = ({
8989
},
9090
{
9191
label: 'Tx Fee',
92-
value: formatTxFee(txFee, assets!),
92+
value: formatTxFee(txFee, assetList),
9393
},
9494
];
9595

0 commit comments

Comments
 (0)