Skip to content

Commit a0602e2

Browse files
committed
feat: ui for ibc
1 parent 31f0aa1 commit a0602e2

File tree

8 files changed

+92
-97
lines changed

8 files changed

+92
-97
lines changed

apps/extension/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"@dao-xyz/borsh": "^5.1.5",
3636
"@ledgerhq/hw-transport": "^6.31.4",
3737
"@ledgerhq/hw-transport-webusb": "^6.29.4",
38-
"@namada/sdk": "0.23.0",
38+
"@namada/sdk": "0.24.0-beta.1",
3939
"@zondax/ledger-namada": "^2.0.0",
4040
"bignumber.js": "^9.1.1",
4141
"buffer": "^6.0.3",
@@ -54,7 +54,7 @@
5454
},
5555
"devDependencies": {
5656
"@babel/plugin-transform-modules-commonjs": "^7.20.11",
57-
"@namada/sdk-node": "0.23.0",
57+
"@namada/sdk-node": "0.24.0-beta.1",
5858
"@svgr/webpack": "^6.3.1",
5959
"@types/chrome": "^0.0.237",
6060
"@types/firefox-webext-browser": "^94.0.1",

apps/namadillo/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"@keplr-wallet/types": "^0.12.136",
1313
"@namada/chain-registry": "^1.5.2",
1414
"@namada/indexer-client": "4.0.5",
15-
"@namada/sdk-multicore": "file:.yalc/@namada/sdk-multicore",
15+
"@namada/sdk-multicore": "0.24.0-beta.1",
1616
"@tailwindcss/container-queries": "^0.1.1",
1717
"@tanstack/query-core": "^5.40.0",
1818
"@tanstack/react-query": "^5.40.0",
@@ -79,7 +79,7 @@
7979
},
8080
"devDependencies": {
8181
"@eslint/js": "^9.9.1",
82-
"@namada/sdk-node": "0.23.0",
82+
"@namada/sdk-node": "0.24.0-beta.1",
8383
"@namada/vite-esbuild-plugin": "^1.0.1",
8484
"@playwright/test": "^1.24.1",
8585
"@svgr/webpack": "^6.5.1",

apps/namadillo/src/App/Common/TransferFeeButton.tsx renamed to apps/namadillo/src/App/Common/TransferFee.tsx

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,41 @@ type FrontendFeeInfo = {
1919
displayAmount?: BigNumber;
2020
token?: Address;
2121
};
22-
23-
export const TransferFeeButton = ({
22+
export const TransferFee = ({
2423
feeProps,
2524
inOrOutOfMASP,
2625
isShieldedTransfer = false,
2726
frontendFeeInfo,
27+
showButton = true,
2828
}: {
2929
feeProps: TransactionFeeProps;
3030
inOrOutOfMASP: boolean;
3131
isShieldedTransfer?: boolean;
3232
frontendFeeInfo?: FrontendFeeInfo;
33+
showButton?: boolean;
3334
}): JSX.Element => {
3435
const [modalOpen, setModalOpen] = useState(false);
3536
const [feeDetailsOpen, setFeeDetailsOpen] = useState(false);
3637

3738
const chainAssetsMap = useAtomValue(namadaRegistryChainAssetsMapAtom);
3839

39-
const gasDollarMap =
40-
useAtomValue(
41-
tokenPricesFamily(
42-
feeProps.gasPriceTable?.map((item) => item.token.address) ?? []
43-
)
44-
).data ?? {};
40+
const chainAssetsMapData = chainAssetsMap.data;
4541

4642
const gasDisplayAmount = useMemo(() => {
47-
if (!chainAssetsMap.data) {
43+
if (!chainAssetsMapData) {
4844
return;
4945
}
5046

51-
return getDisplayGasFee(feeProps.gasConfig, chainAssetsMap.data);
52-
}, [feeProps, chainAssetsMap.data]);
47+
return getDisplayGasFee(feeProps.gasConfig, chainAssetsMapData);
48+
}, [feeProps, chainAssetsMapData]);
49+
50+
const gasToken = gasDisplayAmount?.asset.address;
51+
const frontendFeeToken = frontendFeeInfo?.token;
52+
const tokenAddresses =
53+
gasToken && frontendFeeToken ? [gasToken, frontendFeeToken] : [];
54+
55+
const gasDollarMap =
56+
useAtomValue(tokenPricesFamily(tokenAddresses)).data ?? {};
5357

5458
const [frontendFeeAmount, frontendFeeFiatAmount, symbol] = useMemo((): [
5559
BigNumber?,
@@ -67,26 +71,26 @@ export const TransferFeeButton = ({
6771
);
6872
const dollarPrice = gasDollarMap[frontendFeeInfo.token];
6973
const fiatFeeAmount = feeAmount.multipliedBy(dollarPrice);
70-
const symbol = chainAssetsMap?.data?.[frontendFeeInfo.token]?.symbol;
74+
const symbol = chainAssetsMapData?.[frontendFeeInfo.token]?.symbol;
7175

7276
return [feeAmount, fiatFeeAmount, symbol];
7377
}
7478
return [];
7579
}, [gasDollarMap, frontendFeeInfo]);
7680

7781
const fiatAmount = useMemo(() => {
78-
if (!gasDisplayAmount || !gasDollarMap) {
82+
if (!gasDisplayAmount || !gasDollarMap || !gasToken) {
7983
return;
8084
}
81-
const dollarPrice = gasDollarMap[feeProps.gasConfig.gasToken];
85+
const dollarPrice = gasDollarMap[gasToken];
8286
let fiatAmount =
8387
gasDisplayAmount.totalDisplayAmount.multipliedBy(dollarPrice);
8488

85-
if (frontendFeeFiatAmount) {
89+
if (inOrOutOfMASP && frontendFeeFiatAmount) {
8690
fiatAmount = fiatAmount.plus(frontendFeeFiatAmount);
8791
}
8892
return fiatAmount;
89-
}, [gasDisplayAmount, gasDollarMap, frontendFeeAmount]);
93+
}, [gasDisplayAmount, gasDollarMap, inOrOutOfMASP, gasToken]);
9094

9195
return (
9296
<Stack className="w-full text-sm text-neutral-300">
@@ -114,22 +118,25 @@ export const TransferFeeButton = ({
114118
gasDisplayAmount.totalDisplayAmount.toString()
115119
: ""}{" "}
116120
</div>
117-
<div className="flex items-center gap-2">
118-
<button
119-
type="button"
120-
className={twMerge(
121-
"flex items-center gap-1",
122-
"border rounded-sm px-2 py-1 text-xs",
123-
"transition-all cursor-pointer hover:text-yellow"
124-
)}
125-
onClick={() => setModalOpen(true)}
126-
>
127-
<span className="text- font-medium">
128-
{gasDisplayAmount?.asset.symbol || ""}
129-
</span>
130-
<IoIosArrowDown />
131-
</button>
132-
</div>
121+
{!showButton && gasDisplayAmount?.asset.symbol}
122+
{showButton && (
123+
<div className="flex items-center gap-2">
124+
<button
125+
type="button"
126+
className={twMerge(
127+
"flex items-center gap-1",
128+
"border rounded-sm px-2 py-1 text-xs",
129+
"transition-all cursor-pointer hover:text-yellow"
130+
)}
131+
onClick={() => setModalOpen(true)}
132+
>
133+
<span className="text- font-medium">
134+
{gasDisplayAmount?.asset.symbol || ""}
135+
</span>
136+
<IoIosArrowDown />
137+
</button>
138+
</div>
139+
)}
133140
</Stack>
134141
</Stack>
135142
{inOrOutOfMASP && frontendFeeInfo && (

apps/namadillo/src/App/Ibc/IbcTransfer.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const IbcTransfer = ({
7070
const { storeTransaction } = useTransactionActions();
7171
const shielded = isShieldedAddress(destinationAddress ?? "");
7272

73-
const { transferToNamada, gasConfig, frontendFee } = useIbcTransaction({
73+
const { transferToNamada, transactionFeeProps } = useIbcTransaction({
7474
registry,
7575
sourceAddress,
7676
sourceChannel,
@@ -166,8 +166,7 @@ export const IbcTransfer = ({
166166
isShieldedAddress: shielded,
167167
onChangeAddress: setDestinationAddress,
168168
}}
169-
gasConfig={gasConfig.data}
170-
frontendFee={frontendFee}
169+
feeProps={transactionFeeProps}
171170
isSubmitting={
172171
transferToNamada.isPending ||
173172
/* isSuccess means that the transaction has been broadcasted, but doesn't take

apps/namadillo/src/App/Transfer/TransferDestination.tsx

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { AccountType } from "@namada/types";
44
import { shortenAddress } from "@namada/utils";
55
import { ConnectProviderButton } from "App/Common/ConnectProviderButton";
66
import { TokenAmountCard } from "App/Common/TokenAmountCard";
7-
import { TransactionFee } from "App/Common/TransactionFee";
8-
import { TransferFeeButton } from "App/Common/TransferFeeButton";
7+
import { TransferFee } from "App/Common/TransferFee";
98
import { routes } from "App/routes";
109
import {
1110
isIbcAddress,
@@ -40,8 +39,6 @@ type TransferDestinationProps = {
4039
isShieldedTx?: boolean;
4140
isSubmitting?: boolean;
4241
walletAddress?: string;
43-
gasDisplayAmount?: BigNumber;
44-
gasAsset?: Asset;
4542
feeProps?: TransactionFeeProps;
4643
destinationAsset?: Asset;
4744
amount?: BigNumber;
@@ -60,8 +57,6 @@ export const TransferDestination = ({
6057
isShieldedAddress,
6158
isShieldedTx = false,
6259
isSubmitting,
63-
gasDisplayAmount,
64-
gasAsset,
6560
feeProps,
6661
destinationAsset,
6762
amount,
@@ -309,29 +304,21 @@ export const TransferDestination = ({
309304

310305
{!isSubmitting && (
311306
<footer className="flex mt-10">
312-
{changeFeeEnabled ?
313-
feeProps && (
314-
<TransferFeeButton
315-
feeProps={feeProps}
316-
isShieldedTransfer={isShieldedTx}
317-
inOrOutOfMASP={isShielding || isUnshielding}
318-
frontendFeeInfo={
319-
frontendFee && {
320-
fee: frontendFee,
321-
displayAmount: amount,
322-
token: sourceAsset?.address,
323-
}
307+
{feeProps && (
308+
<TransferFee
309+
feeProps={feeProps}
310+
isShieldedTransfer={isShieldedTx}
311+
inOrOutOfMASP={isShielding || isUnshielding}
312+
showButton={changeFeeEnabled}
313+
frontendFeeInfo={
314+
frontendFee && {
315+
fee: frontendFee,
316+
displayAmount: amount,
317+
token: sourceAsset?.address,
324318
}
325-
/>
326-
)
327-
: gasDisplayAmount &&
328-
gasAsset && (
329-
<TransactionFee
330-
displayAmount={gasDisplayAmount}
331-
symbol={gasAsset.symbol}
332-
/>
333-
)
334-
}
319+
}
320+
/>
321+
)}
335322
</footer>
336323
)}
337324
</div>

apps/namadillo/src/App/Transfer/TransferModule.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ export const TransferModule = ({
5151
errorMessage,
5252
currentStatus,
5353
currentStatusExplanation,
54-
gasConfig: gasConfigProp,
55-
frontendFee: frontendFeeProp,
5654
onSubmitTransfer,
5755
completedAt,
5856
onComplete,
@@ -123,9 +121,8 @@ export const TransferModule = ({
123121
});
124122
};
125123

126-
// We have to do this to get correct config for ibc deposits
127-
const gasConfig = gasConfigProp ?? feeProps?.gasConfig;
128-
const frontendFee = frontendFeeProp ?? feeProps?.frontendFee;
124+
const gasConfig = feeProps?.gasConfig;
125+
const frontendFee = feeProps?.frontendFee;
129126

130127
const displayGasFee = useMemo(() => {
131128
return gasConfig ?
@@ -257,8 +254,6 @@ export const TransferModule = ({
257254
memo={destination.memo}
258255
onChangeMemo={destination.onChangeMemo}
259256
feeProps={feeProps}
260-
gasDisplayAmount={displayGasFee?.totalDisplayAmount}
261-
gasAsset={displayGasFee?.asset}
262257
destinationAsset={selectedAsset?.asset}
263258
amount={source.amount}
264259
isSubmitting={isSubmitting}

apps/namadillo/src/hooks/useIbcTransaction.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
useMutation,
44
UseMutationResult,
55
useQuery,
6-
UseQueryResult,
76
} from "@tanstack/react-query";
87
import { TokenCurrency } from "App/Common/TokenCurrency";
98
import { chainParametersAtom } from "atoms/chain";
@@ -34,8 +33,6 @@ import {
3433
Address,
3534
Asset,
3635
ChainRegistryEntry,
37-
FrontendFee,
38-
GasConfig,
3936
IbcTransferStage,
4037
NamadaAsset,
4138
TransferStep,
@@ -49,6 +46,7 @@ import {
4946
} from "utils/frontendFee";
5047
import { getKeplrWallet, sanitizeChannel } from "utils/ibc";
5148
import { useSimulateIbcTransferFee } from "./useSimulateIbcTransferFee";
49+
import { TransactionFeeProps } from "./useTransactionFee";
5250

5351
type useIbcTransactionProps = {
5452
sourceAddress?: string;
@@ -60,8 +58,7 @@ type useIbcTransactionProps = {
6058
};
6159

6260
type useIbcTransactionOutput = {
63-
gasConfig: UseQueryResult<GasConfig>;
64-
frontendFee: FrontendFee;
61+
transactionFeeProps?: TransactionFeeProps;
6562
transferToNamada: UseMutationResult<
6663
TransferTransactionData,
6764
Error,
@@ -301,9 +298,19 @@ export const useIbcTransaction = ({
301298
mutationFn: transferToNamada,
302299
});
303300

301+
const transactionFeeProps: TransactionFeeProps | undefined =
302+
gasConfigQuery.data && {
303+
gasConfig: gasConfigQuery.data,
304+
isLoading: gasConfigQuery.isLoading,
305+
onChangeGasLimit: () => {},
306+
onChangeGasToken: () => {},
307+
frontendFee: frontendFee,
308+
gasEstimate: undefined,
309+
gasPriceTable: undefined,
310+
};
311+
304312
return {
305313
transferToNamada: transferToNamadaQuery,
306-
gasConfig: gasConfigQuery,
307-
frontendFee: frontendFee,
314+
transactionFeeProps,
308315
};
309316
};

0 commit comments

Comments
 (0)