@@ -21,6 +21,7 @@ export type TransactionFeeProps = {
2121 gasEstimate : GasEstimate | undefined ;
2222 gasPriceTable : GasPriceTable | undefined ;
2323 gasSource : "shielded" | "transparent" ;
24+ gasSourceSwitch : boolean ;
2425 onChangeGasLimit : ( value : BigNumber ) => void ;
2526 onChangeGasToken : ( value : string ) => void ;
2627 onChangeGasSource : ( value : "shielded" | "transparent" ) => void ;
@@ -35,9 +36,10 @@ export const useTransactionFee = (
3536 const userTransparentBalances = useAtomValue ( transparentBalanceAtom ) ;
3637 const userShieldedBalances = useAtomValue ( shieldedBalanceAtom ) ;
3738 const [ gasSource , setGasSource ] = useState < "shielded" | "transparent" > (
38- "shielded"
39+ isShielded ? "shielded" : "transparent "
3940 ) ;
4041 const isPublicKeyRevealed = useAtomValue ( isPublicKeyRevealedAtom ) ;
42+ const isShieldedSource = gasSource === "shielded" ;
4143
4244 const { data : nativeToken , isLoading : isLoadingNativeToken } = useAtomValue (
4345 nativeTokenAddressAtom
@@ -80,17 +82,17 @@ export const useTransactionFee = (
8082 const availableGasTokenAddress = useMemo ( ( ) => {
8183 if ( ! gasPriceTable ) return nativeToken ;
8284
83- if ( isShielded && ! userShieldedBalances . data ) {
85+ if ( isShieldedSource && ! userShieldedBalances . data ) {
8486 return nativeToken ;
8587 }
8688
87- if ( ! isShielded && ! userTransparentBalances . data ) {
89+ if ( ! isShieldedSource && ! userTransparentBalances . data ) {
8890 return nativeToken ;
8991 }
9092
9193 // Separate shielded amount from transparent
9294 const balances =
93- ( isShielded ?
95+ ( isShieldedSource ?
9496 // TODO: we need to refactor userShieldedBalances to return Balance[] type instead
9597 userShieldedBalances . data ?. map ( ( balance ) => ( {
9698 minDenomAmount : balance . minDenomAmount ,
@@ -128,7 +130,7 @@ export const useTransactionFee = (
128130 userShieldedBalances . data ,
129131 gasPriceTable ,
130132 gasDollarMap ,
131- isShielded ,
133+ isShieldedSource ,
132134 ] ) ;
133135
134136 const averageGasLimit = gasEstimate && BigNumber ( gasEstimate . avg ) ;
@@ -149,12 +151,17 @@ export const useTransactionFee = (
149151 isLoadingGasEstimate ||
150152 isLoadingGasPriceTable ;
151153
154+ const gasSourceSwitch =
155+ txKinds . includes ( "ShieldedTransfer" ) ||
156+ txKinds . includes ( "UnshieldingTransfer" ) ;
157+
152158 return {
153159 gasConfig,
154160 isLoading,
155161 gasEstimate,
156162 gasPriceTable,
157163 gasSource,
164+ gasSourceSwitch,
158165 onChangeGasLimit : setGasLimitValue ,
159166 onChangeGasToken : setGasTokenValue ,
160167 onChangeGasSource : setGasSource ,
0 commit comments