77} from "@tanstack/react-query" ;
88import { TokenCurrency } from "App/Common/TokenCurrency" ;
99import { chainParametersAtom } from "atoms/chain" ;
10+ import { frontendFeeAtom } from "atoms/fees" ;
1011import {
1112 broadcastIbcTransactionAtom ,
1213 createStargateClient ,
@@ -19,8 +20,9 @@ import {
1920 createNotificationId ,
2021 dispatchToastNotificationAtom ,
2122} from "atoms/notifications" ;
22- import { frontendFeeAtom } from "atoms/settings" ;
2323import BigNumber from "bignumber.js" ;
24+ import { pipe } from "fp-ts/lib/function" ;
25+ import * as O from "fp-ts/Option" ;
2426import invariant from "invariant" ;
2527import { useAtomValue , useSetAtom } from "jotai" ;
2628import {
@@ -35,11 +37,16 @@ import {
3537 FrontendFee ,
3638 GasConfig ,
3739 IbcTransferStage ,
40+ NamadaAsset ,
3841 TransferStep ,
3942 TransferTransactionData ,
4043} from "types" ;
4144import { toBaseAmount } from "utils" ;
4245import { sanitizeAddress } from "utils/address" ;
46+ import {
47+ calculateAmountWithFrontendFee ,
48+ getFrontendFeeEntry ,
49+ } from "utils/frontendFee" ;
4350import { getKeplrWallet , sanitizeChannel } from "utils/ibc" ;
4451import { useSimulateIbcTransferFee } from "./useSimulateIbcTransferFee" ;
4552
@@ -193,6 +200,11 @@ export const useIbcTransaction = ({
193200 gasConfigQuery . error ?. message
194201 ) ;
195202
203+ const frontendFeeEntry = getFrontendFeeEntry (
204+ frontendFee ,
205+ ( selectedAsset as NamadaAsset ) . address
206+ ) ;
207+
196208 const baseAmount = toBaseAmount ( selectedAsset , displayAmount ) ;
197209
198210 const sourceChainAssets =
@@ -227,11 +239,25 @@ export const useIbcTransaction = ({
227239 const chainId = registry . chain . chain_id ;
228240 const denomination = asset . base ;
229241
242+ const amount = pipe (
243+ frontendFeeEntry ,
244+ O . fromNullable ,
245+ O . filter ( ( ) => ! ! shielded ) ,
246+ O . fold (
247+ ( ) => baseAmount ,
248+ ( fee ) =>
249+ toBaseAmount (
250+ selectedAsset ,
251+ calculateAmountWithFrontendFee ( BigNumber ( displayAmount ) , fee )
252+ )
253+ )
254+ ) ;
255+
230256 const transferMsg = createIbcTransferMessage (
231257 sanitizeChannel ( sourceChannel ! ) ,
232258 sanitizeAddress ( sourceAddress ) ,
233259 sanitizeAddress ( maspCompatibleReceiver ) ,
234- baseAmount ,
260+ amount ,
235261 denomination ,
236262 maspCompatibleMemo
237263 ) ;
@@ -256,7 +282,8 @@ export const useIbcTransaction = ({
256282 chainId ,
257283 destinationChainId || "" ,
258284 getIbcTransferStage ( ! ! shielded ) ,
259- ! ! shielded
285+ ! ! shielded ,
286+ baseAmount
260287 ) ;
261288 dispatchPendingTxNotification ( tx ) ;
262289 setTxHash ( tx . hash ) ;
0 commit comments