@@ -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 && (
0 commit comments