Skip to content

Commit 9e9171b

Browse files
authored
Merge pull request #21 from hyperweb-io/feat/upgrade-deps
InterchainJS stack
2 parents 2d8cdea + a18feb3 commit 9e9171b

File tree

98 files changed

+3235
-5830
lines changed

Some content is hidden

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

98 files changed

+3235
-5830
lines changed

templates/chain-admin/components/asset-list/AssetListSection.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import React from 'react';
22
import { Text, Box } from '@interchain-ui/react';
3+
import { useChain } from '@interchain-kit/react';
4+
35
import AssetsOverview from './AssetsOverview';
4-
import { useChain } from '@cosmos-kit/react';
56
import { useAssets } from '@/hooks';
6-
import { ChainName } from 'cosmos-kit';
77

88
interface AssetListSectionProps {
9-
chainName: ChainName;
9+
chainName: string;
1010
children?: React.ReactNode;
1111
}
1212

1313
export const AssetListSection = ({ chainName }: AssetListSectionProps) => {
14-
const { isWalletConnected } = useChain(chainName);
14+
const { address } = useChain(chainName);
1515
const { data, isLoading, refetch } = useAssets(chainName);
1616

17-
if (!isWalletConnected) {
17+
if (!address) {
1818
return (
1919
<Box maxWidth="768px" marginX="auto" marginBottom="60px">
2020
<Text

templates/chain-admin/components/asset-list/AssetsOverview.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React, { useMemo, useState } from 'react';
22
import { flushSync } from 'react-dom';
3-
import { useChain } from '@cosmos-kit/react';
3+
import { useChain } from '@interchain-kit/react';
44
import BigNumber from 'bignumber.js';
5-
import { ChainName } from 'cosmos-kit';
65
import { SingleChain, SingleChainProps } from '@interchain-ui/react';
76

87
import { useDisclosure, useChainUtils, useTotalAssets } from '@/hooks';
@@ -14,14 +13,13 @@ import {
1413

1514
import { DropdownTransferModal } from './DropdownTransferModal';
1615
import { RowTransferModal } from './RowTransferModal';
17-
1816
import { PrettyAsset, Transfer, TransferInfo } from './types';
1917

2018
interface AssetsOverviewProps {
2119
isLoading?: boolean;
2220
assets: PrettyAsset[];
2321
prices: Record<string, number>;
24-
selectedChainName: ChainName;
22+
selectedChainName: string;
2523
refetch?: () => void;
2624
}
2725

@@ -150,13 +148,13 @@ const AssetsOverview = ({
150148
<SingleChain
151149
isLoading={isLoading || isLoadingTotalAssets}
152150
title="Your assets"
153-
listTitle={`On ${chain.pretty_name}`}
151+
listTitle={`On ${chain.prettyName}`}
154152
showDeposit={ibcAssets.length > 0}
155153
showWithdraw={hasBalance}
156154
onDeposit={onDepositAsset}
157155
onWithdraw={onWithdrawAsset}
158156
singleChainHeader={{
159-
label: `Total on ${chain.pretty_name}`,
157+
label: `Total on ${chain.prettyName}`,
160158
value: `${data?.total ?? 0}`,
161159
}}
162160
list={assetsToShow}

templates/chain-admin/components/asset-list/DropdownTransferModal.tsx

Lines changed: 67 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,22 @@ import {
44
OverviewTransfer,
55
OverviewTransferProps,
66
} from '@interchain-ui/react';
7-
import { useChainWallet, useManager } from '@cosmos-kit/react';
7+
import { useChainWallet, useWalletManager } from '@interchain-kit/react';
88
import BigNumber from 'bignumber.js';
9-
import { ibc } from 'osmo-query';
10-
import { StdFee, coins } from '@cosmjs/amino';
11-
import { ChainName } from 'cosmos-kit';
12-
import { keplrWalletName } from '@/config';
13-
import { useDisclosure, useChainUtils, useTx, useBalance } from '@/hooks';
9+
import { useTransfer } from '@interchainjs/react/ibc/applications/transfer/v1/tx.rpc.react';
10+
import { MsgTransfer } from '@interchainjs/react/ibc/applications/transfer/v1/tx';
11+
import { defaultContext } from '@tanstack/react-query';
12+
import { StdFee } from '@interchainjs/react/types';
13+
1414
import { truncDecimals } from '@/utils';
15+
import { keplrWalletName } from '@/config';
16+
import {
17+
useDisclosure,
18+
useChainUtils,
19+
useBalance,
20+
useToastHandlers,
21+
useSigningClient,
22+
} from '@/hooks';
1523

1624
import {
1725
PrettyAsset,
@@ -21,8 +29,6 @@ import {
2129
Unpacked,
2230
} from './types';
2331

24-
const { transfer } = ibc.applications.transfer.v1.MessageComposer.withTypeUrl;
25-
2632
const ZERO_AMOUNT = '0';
2733

2834
interface OverviewTransferWrapperProps {
@@ -36,13 +42,11 @@ interface OverviewTransferWrapperProps {
3642
React.SetStateAction<TransferInfo | undefined>
3743
>;
3844
};
39-
selectedChainName: ChainName;
45+
selectedChainName: string;
4046
}
4147

4248
const OverviewTransferWrapper = (
4349
props: OverviewTransferWrapperProps & {
44-
isLoading: boolean;
45-
setIsLoading: React.Dispatch<React.SetStateAction<boolean>>;
4650
inputValue: string;
4751
setInputValue: React.Dispatch<React.SetStateAction<string>>;
4852
}
@@ -54,8 +58,6 @@ const OverviewTransferWrapper = (
5458
transferInfoState,
5559
updateData,
5660
selectedChainName,
57-
isLoading,
58-
setIsLoading,
5961
inputValue,
6062
setInputValue,
6163
} = props;
@@ -92,8 +94,17 @@ const OverviewTransferWrapper = (
9294
keplrWalletName
9395
);
9496

95-
const { getChainLogo } = useManager();
96-
const { tx } = useTx(sourceChainName);
97+
const { getChainLogoUrl } = useWalletManager();
98+
99+
const toastHandlers = useToastHandlers();
100+
const { data: signingClient } = useSigningClient(sourceChainName);
101+
const { mutate: transfer, isLoading } = useTransfer({
102+
clientResolver: signingClient,
103+
options: {
104+
context: defaultContext,
105+
...toastHandlers,
106+
},
107+
});
97108

98109
const availableAmount = useMemo((): number => {
99110
if (!isDeposit) {
@@ -125,12 +136,10 @@ const OverviewTransferWrapper = (
125136
const closeModal = () => {
126137
modalControl.onClose();
127138
setInputValue('');
128-
setIsLoading(false);
129139
};
130140

131141
const handleTransferSubmit = async () => {
132142
if (!sourceAddress || !destAddress) return;
133-
setIsLoading(true);
134143

135144
const transferAmount = new BigNumber(inputValue)
136145
.shiftedBy(getExponentByDenom(symbolToDenom(transferToken.symbol)))
@@ -142,7 +151,7 @@ const OverviewTransferWrapper = (
142151
);
143152

144153
const fee: StdFee = {
145-
amount: coins('1000', transferToken.denom ?? ''),
154+
amount: [{ denom: transferToken.denom ?? '', amount: '0' }],
146155
gas: '250000',
147156
};
148157

@@ -154,49 +163,55 @@ const OverviewTransferWrapper = (
154163
const stamp = Date.now();
155164
const timeoutInNanos = (stamp + 1.2e6) * 1e6;
156165

157-
const msg = transfer({
166+
const msg = MsgTransfer.fromPartial({
158167
sourcePort,
159168
sourceChannel,
160169
sender: sourceAddress,
161170
receiver: destAddress,
162171
token,
163-
// @ts-ignore
164172
timeoutHeight: undefined,
165173
timeoutTimestamp: BigInt(timeoutInNanos),
166174
});
167175

168-
await tx([msg], {
169-
fee,
170-
onSuccess: () => {
171-
updateData();
172-
closeModal();
176+
transfer(
177+
{
178+
signerAddress: sourceAddress,
179+
message: msg,
180+
fee,
181+
memo: 'Transfer',
173182
},
174-
});
175-
176-
setIsLoading(false);
183+
{
184+
onSuccess: () => {
185+
updateData();
186+
closeModal();
187+
},
188+
}
189+
);
177190
};
178191

179192
const assetOptions: OverviewTransferProps['dropdownList'] = useMemo(() => {
180-
return assets
181-
.filter((asset) => {
182-
if (isDeposit) {
183-
return true;
184-
}
185-
return new BigNumber(asset.amount).gt(0);
186-
})
187-
// .filter((asset) => {
188-
// return asset.symbol !== transferToken.symbol;
189-
// })
190-
.map((asset) => ({
191-
available: new BigNumber(asset.displayAmount).toNumber(),
192-
symbol: asset.symbol,
193-
name: asset.prettyChainName,
194-
denom: asset.denom,
195-
imgSrc: asset.logoUrl ?? '',
196-
priceDisplayAmount: new BigNumber(
197-
truncDecimals(asset.dollarValue, 2)
198-
).toNumber(),
199-
}));
193+
return (
194+
assets
195+
.filter((asset) => {
196+
if (isDeposit) {
197+
return true;
198+
}
199+
return new BigNumber(asset.amount).gt(0);
200+
})
201+
// .filter((asset) => {
202+
// return asset.symbol !== transferToken.symbol;
203+
// })
204+
.map((asset) => ({
205+
available: new BigNumber(asset.displayAmount).toNumber(),
206+
symbol: asset.symbol,
207+
name: asset.prettyChainName,
208+
denom: asset.denom,
209+
imgSrc: asset.logoUrl ?? '',
210+
priceDisplayAmount: new BigNumber(
211+
truncDecimals(asset.dollarValue, 2)
212+
).toNumber(),
213+
}))
214+
);
200215
}, [assets, isDeposit, transferToken]);
201216
console.log('assetOptions', assetOptions);
202217

@@ -240,8 +255,10 @@ const OverviewTransferWrapper = (
240255
new BigNumber(inputValue).isEqualTo(0) ||
241256
isNaN(Number(inputValue))
242257
}
243-
fromChainLogoUrl={getChainLogo(transferInfo?.sourceChainName ?? '') ?? ''}
244-
toChainLogoUrl={getChainLogo(transferInfo?.destChainName ?? '') ?? ''}
258+
fromChainLogoUrl={
259+
getChainLogoUrl(transferInfo?.sourceChainName ?? '') ?? ''
260+
}
261+
toChainLogoUrl={getChainLogoUrl(transferInfo?.destChainName ?? '') ?? ''}
245262
dropdownList={assetOptions}
246263
onTransfer={() => {
247264
handleTransferSubmit();
@@ -259,12 +276,10 @@ export const DropdownTransferModal = (props: OverviewTransferWrapperProps) => {
259276
const { modalControl, transferInfoState } = props;
260277

261278
const [inputValue, setInputValue] = useState('');
262-
const [isLoading, setIsLoading] = useState<boolean>(false);
263279

264280
const closeModal = () => {
265281
modalControl.onClose();
266282
setInputValue('');
267-
setIsLoading(false);
268283
};
269284

270285
return (
@@ -280,8 +295,6 @@ export const DropdownTransferModal = (props: OverviewTransferWrapperProps) => {
280295
...props.modalControl,
281296
onClose: closeModal,
282297
}}
283-
isLoading={isLoading}
284-
setIsLoading={setIsLoading}
285298
inputValue={inputValue}
286299
setInputValue={setInputValue}
287300
/>

0 commit comments

Comments
 (0)