Skip to content

Commit 9740978

Browse files
committed
fix: add tx fee value loading indicators to panel
1 parent aa70e4e commit 9740978

File tree

10 files changed

+267
-154
lines changed

10 files changed

+267
-154
lines changed

components/brave_wallet/browser/brave_wallet_constants.h

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ constexpr char kTransakURL[] = "https://global.transak.com/";
4242
constexpr char kTransakApiKey[] = "985d14f0-4cf5-4a4c-8917-78107620d3b7";
4343

4444
constexpr webui::LocalizedString kLocalizedStrings[] = {
45+
{"braveWalletTransactionHasFeeEstimatesError",
46+
IDS_BRAVE_WALLET_TRANSACTION_HAS_FEE_ESTIMATES_ERROR},
4547
{"braveWalletGasFeeLimitLowerThanBaseFeeWarning",
4648
IDS_BRAVE_WALLET_GAS_FEE_LIMIT_LOWER_THAN_BASE_FEE_WARNING},
4749
{"braveWalletTokenMintAddress", IDS_BRAVE_WALLET_TOKEN_MINT_ADDRESS},

components/brave_wallet_ui/common/actions/wallet_actions.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
addFilecoinAccount,
1515
addSitePermission,
1616
addUserAsset,
17-
updateUserAsset,
1817
addUserAssetError,
1918
approveERC20Allowance,
2019
approveTransaction,
@@ -41,8 +40,8 @@
4140
keyringCreated,
4241
keyringReset,
4342
keyringRestored,
44-
lockWallet,
4543
locked,
44+
lockWallet,
4645
nativeAssetBalancesUpdated,
4746
newUnapprovedTxAdded,
4847
portfolioPriceHistoryUpdated,
@@ -52,8 +51,8 @@
5251
refreshAccountInfo,
5352
refreshBalancesAndPriceHistory,
5453
refreshBalancesAndPrices,
55-
refreshNetworksAndTokens,
5654
refreshGasEstimates,
55+
refreshNetworksAndTokens,
5756
rejectAllTransactions,
5857
rejectTransaction,
5958
removeFavoriteApp,
@@ -62,22 +61,23 @@
6261
retryTransaction,
6362
selectAccount,
6463
selectCurrency,
64+
selectedAccountChanged,
6565
selectNetwork,
6666
selectPortfolioTimeline,
67-
selectedAccountChanged,
6867
sendERC20Transfer,
6968
sendERC721TransferFrom,
7069
sendSPLTransfer,
7170
sendTransaction,
7271
setAccountTransactions,
73-
setAllNetworks,
7472
setAllHiddenNetworks,
73+
setAllNetworks,
7574
setAllTokensList,
7675
setAssetAutoDiscoveryCompleted,
7776
setCoinMarkets,
7877
setDefaultAccounts,
7978
setDefaultNetworks,
8079
setGasEstimates,
80+
setHasFeeEstimatesError,
8181
setMetaMaskInstalled,
8282
setNetwork,
8383
setOnRampCurrencies,
@@ -95,10 +95,11 @@
9595
tokenBalancesUpdated,
9696
transactionStatusChanged,
9797
unapprovedTxUpdated,
98-
unlockWallet,
9998
unlocked,
99+
unlockWallet,
100+
updateTokenPinStatus,
100101
updateUnapprovedTransactionGasFields,
101102
updateUnapprovedTransactionNonce,
102103
updateUnapprovedTransactionSpendAllowance,
103-
updateTokenPinStatus
104+
updateUserAsset
104105
} = WalletActions

components/brave_wallet_ui/common/async/handlers.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -520,12 +520,15 @@ handler.on(WalletActions.refreshGasEstimates.type, async (store: Store, txInfo:
520520
const { ethTxManagerProxy, solanaTxManagerProxy } = getAPIProxy()
521521

522522
if (isSolanaTransaction(txInfo)) {
523-
const getSolFee = await solanaTxManagerProxy.getEstimatedTxFee(txInfo.id)
524-
if (!getSolFee.fee) {
525-
console.error('Failed to fetch SOL Fee estimates')
523+
const { fee, errorMessage } = await solanaTxManagerProxy.getEstimatedTxFee(
524+
txInfo.id
525+
)
526+
if (!fee) {
527+
console.error('Failed to fetch SOL Fee estimates: ' + errorMessage)
528+
store.dispatch(WalletActions.setHasFeeEstimatesError(true))
526529
return
527530
}
528-
store.dispatch(WalletActions.setSolFeeEstimates({ fee: getSolFee.fee }))
531+
store.dispatch(WalletActions.setSolFeeEstimates({ fee }))
529532
return
530533
}
531534

@@ -537,13 +540,14 @@ handler.on(WalletActions.refreshGasEstimates.type, async (store: Store, txInfo:
537540
return
538541
}
539542

540-
const basicEstimates = await ethTxManagerProxy.getGasEstimation1559()
541-
if (!basicEstimates.estimation) {
543+
const { estimation } = await ethTxManagerProxy.getGasEstimation1559()
544+
if (!estimation) {
542545
console.error('Failed to fetch gas estimates')
546+
store.dispatch(WalletActions.setHasFeeEstimatesError(true))
543547
return
544548
}
545549

546-
store.dispatch(WalletActions.setGasEstimates(basicEstimates.estimation))
550+
store.dispatch(WalletActions.setGasEstimates(estimation))
547551
})
548552

549553
handler.on(WalletActions.updateUnapprovedTransactionGasFields.type, async (store: Store, payload: UpdateUnapprovedTransactionGasFieldsType) => {

components/brave_wallet_ui/common/hooks/use-pending-transaction.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ import { findAccountName } from '../../utils/account-utils'
1616
import { getLocale } from '../../../common/locale'
1717
import { getNetworkFromTXDataUnion } from '../../utils/network-utils'
1818
import { reduceAddress } from '../../utils/reduce-address'
19+
import { WalletSelectors } from '../selectors'
1920

2021
// Custom Hooks
2122
import { useTransactionParser } from './transaction-parser'
2223
import usePricing from './pricing'
2324
import useTokenInfo from './token'
2425
import { useLib } from './useLib'
26+
import { useSafeWalletSelector } from './use-safe-selector'
2527

2628
// Constants
2729
import { WalletState, BraveWallet } from '../../constants/types'
@@ -46,6 +48,10 @@ export const usePendingTransactions = () => {
4648
pendingTransactions,
4749
defaultNetworks
4850
} = useSelector((state: { wallet: WalletState }) => state.wallet)
51+
const hasFeeEstimatesError = useSafeWalletSelector(
52+
WalletSelectors.hasFeeEstimatesError
53+
)
54+
4955
const transactionGasEstimates = transactionInfo?.txDataUnion.ethTxData1559?.gasEstimation
5056

5157
const transactionsNetwork = React.useMemo(() => {
@@ -174,7 +180,13 @@ export const usePendingTransactions = () => {
174180
: getLocale('braveWalletSend')
175181
, [isSolanaDappTransaction, transactionDetails?.isSwap])
176182

183+
const isLoadingGasFee = transactionDetails?.gasFee === ''
184+
177185
const isConfirmButtonDisabled = React.useMemo(() => {
186+
if (hasFeeEstimatesError || isLoadingGasFee) {
187+
return true
188+
}
189+
178190
if (!transactionDetails) {
179191
return true
180192
}
@@ -189,7 +201,7 @@ export const usePendingTransactions = () => {
189201
!!transactionDetails?.missingGasLimitError ||
190202
!canSelectedPendingTransactionBeApproved
191203
)
192-
}, [transactionDetails])
204+
}, [transactionDetails, hasFeeEstimatesError, isLoadingGasFee])
193205

194206
// effects
195207
React.useEffect(() => {
@@ -279,6 +291,8 @@ export const usePendingTransactions = () => {
279291
updateUnapprovedTransactionGasFields,
280292
updateUnapprovedTransactionNonce,
281293
groupTransactions,
282-
selectedPendingTransactionGroupIndex
294+
selectedPendingTransactionGroupIndex,
295+
hasFeeEstimatesError,
296+
selectedPendingTransaction: transactionInfo
283297
}
284298
}

components/brave_wallet_ui/common/selectors/wallet-selectors.ts

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export const isWalletLocked = ({ wallet }: State) => wallet.isWalletLocked
2626
export const passwordAttempts = ({ wallet }: State) => wallet.passwordAttempts
2727
export const selectedPortfolioTimeline = ({ wallet }: State) => wallet.selectedPortfolioTimeline
2828
export const assetAutoDiscoveryCompleted = ({ wallet }: State) => wallet.assetAutoDiscoveryCompleted
29+
export const hasFeeEstimatesError = ({ wallet }: State) =>
30+
wallet.hasFeeEstimatesError
2931

3032
// unsafe selectors (will cause re-render if not strictly equal "===") (objects and lists)
3133
export const accounts = ({ wallet }: State) => wallet.accounts

components/brave_wallet_ui/common/slices/wallet.slice.ts

+9
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ export const createWalletSlice = (initialState: WalletState = defaultState) => {
442442
},
443443

444444
setGasEstimates (state: WalletState, { payload }: PayloadAction<BraveWallet.GasEstimation1559>) {
445+
state.hasFeeEstimatesError = false
445446
state.gasEstimates = payload
446447
},
447448

@@ -474,9 +475,17 @@ export const createWalletSlice = (initialState: WalletState = defaultState) => {
474475
},
475476

476477
setSolFeeEstimates (state: WalletState, { payload }: PayloadAction<SolFeeEstimates>) {
478+
state.hasFeeEstimatesError = false
477479
state.solFeeEstimates = payload
478480
},
479481

482+
setHasFeeEstimatesError: (
483+
state: WalletState,
484+
{ payload }: PayloadAction<boolean>
485+
) => {
486+
state.hasFeeEstimatesError = payload
487+
},
488+
480489
setTransactionProviderError (state: WalletState, { payload }: PayloadAction<SetTransactionProviderErrorType>) {
481490
state.transactionProviderErrorRegistry[payload.transaction.id] = payload.providerError
482491
},

0 commit comments

Comments
 (0)