@@ -21,6 +21,7 @@ export type TransactionFeeProps = {
21
21
gasEstimate : GasEstimate | undefined ;
22
22
gasPriceTable : GasPriceTable | undefined ;
23
23
gasSource : "shielded" | "transparent" ;
24
+ gasSourceSwitch : boolean ;
24
25
onChangeGasLimit : ( value : BigNumber ) => void ;
25
26
onChangeGasToken : ( value : string ) => void ;
26
27
onChangeGasSource : ( value : "shielded" | "transparent" ) => void ;
@@ -35,9 +36,10 @@ export const useTransactionFee = (
35
36
const userTransparentBalances = useAtomValue ( transparentBalanceAtom ) ;
36
37
const userShieldedBalances = useAtomValue ( shieldedBalanceAtom ) ;
37
38
const [ gasSource , setGasSource ] = useState < "shielded" | "transparent" > (
38
- "shielded"
39
+ isShielded ? "shielded" : "transparent "
39
40
) ;
40
41
const isPublicKeyRevealed = useAtomValue ( isPublicKeyRevealedAtom ) ;
42
+ const isShieldedSource = gasSource === "shielded" ;
41
43
42
44
const { data : nativeToken , isLoading : isLoadingNativeToken } = useAtomValue (
43
45
nativeTokenAddressAtom
@@ -80,17 +82,17 @@ export const useTransactionFee = (
80
82
const availableGasTokenAddress = useMemo ( ( ) => {
81
83
if ( ! gasPriceTable ) return nativeToken ;
82
84
83
- if ( isShielded && ! userShieldedBalances . data ) {
85
+ if ( isShieldedSource && ! userShieldedBalances . data ) {
84
86
return nativeToken ;
85
87
}
86
88
87
- if ( ! isShielded && ! userTransparentBalances . data ) {
89
+ if ( ! isShieldedSource && ! userTransparentBalances . data ) {
88
90
return nativeToken ;
89
91
}
90
92
91
93
// Separate shielded amount from transparent
92
94
const balances =
93
- ( isShielded ?
95
+ ( isShieldedSource ?
94
96
// TODO: we need to refactor userShieldedBalances to return Balance[] type instead
95
97
userShieldedBalances . data ?. map ( ( balance ) => ( {
96
98
minDenomAmount : balance . minDenomAmount ,
@@ -128,7 +130,7 @@ export const useTransactionFee = (
128
130
userShieldedBalances . data ,
129
131
gasPriceTable ,
130
132
gasDollarMap ,
131
- isShielded ,
133
+ isShieldedSource ,
132
134
] ) ;
133
135
134
136
const averageGasLimit = gasEstimate && BigNumber ( gasEstimate . avg ) ;
@@ -149,12 +151,17 @@ export const useTransactionFee = (
149
151
isLoadingGasEstimate ||
150
152
isLoadingGasPriceTable ;
151
153
154
+ const gasSourceSwitch =
155
+ txKinds . includes ( "ShieldedTransfer" ) ||
156
+ txKinds . includes ( "UnshieldingTransfer" ) ;
157
+
152
158
return {
153
159
gasConfig,
154
160
isLoading,
155
161
gasEstimate,
156
162
gasPriceTable,
157
163
gasSource,
164
+ gasSourceSwitch,
158
165
onChangeGasLimit : setGasLimitValue ,
159
166
onChangeGasToken : setGasTokenValue ,
160
167
onChangeGasSource : setGasSource ,
0 commit comments