From f73f3a44979aa3147537806217a2954a38acedc9 Mon Sep 17 00:00:00 2001 From: alter-eggo Date: Fri, 29 Sep 2023 12:25:14 +0400 Subject: [PATCH] fix: send inscription error processing, closes #4286 --- .../hooks/use-send-inscription-form.tsx | 37 +++++++++++-------- .../address/transactions-by-address.query.ts | 4 +- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/app/pages/send/ordinal-inscription/hooks/use-send-inscription-form.tsx b/src/app/pages/send/ordinal-inscription/hooks/use-send-inscription-form.tsx index ad004a21fcd..59c505c5705 100644 --- a/src/app/pages/send/ordinal-inscription/hooks/use-send-inscription-form.tsx +++ b/src/app/pages/send/ordinal-inscription/hooks/use-send-inscription-form.tsx @@ -39,23 +39,24 @@ export function useSendInscriptionForm() { isCheckingFees, async chooseTransactionFee(values: OrdinalSendFormValues) { setIsCheckingFees(true); - // Check tx with lowest fee for errors before routing and - // generating the final transaction with the chosen fee to send - const resp = coverFeeFromAdditionalUtxos(values); - if (!resp) { - setShowError( - 'Insufficient funds to cover fee. Deposit some BTC to your Native Segwit address.' - ); - return; - } + try { + // Check tx with lowest fee for errors before routing and + // generating the final transaction with the chosen fee to send + const resp = coverFeeFromAdditionalUtxos(values); - if (Number(inscription.offset) !== 0) { - setShowError('Sending inscriptions at non-zero offsets is unsupported'); - return; - } + if (!resp) { + setShowError( + 'Insufficient funds to cover fee. Deposit some BTC to your Native Segwit address.' + ); + return; + } + + if (Number(inscription.offset) !== 0) { + setShowError('Sending inscriptions at non-zero offsets is unsupported'); + return; + } - try { const numInscriptionsOnUtxo = await getNumberOfInscriptionOnUtxo(utxo.txid, utxo.vout); if (numInscriptionsOnUtxo > 1) { setShowError('Sending inscription from utxo with multiple inscriptions is unsupported'); @@ -63,8 +64,12 @@ export function useSendInscriptionForm() { } } catch (error) { void analytics.track('ordinals_dot_com_unavailable', { error }); - setShowError('Unable to establish if utxo has multiple inscriptions'); - return; + + let message = 'Unable to establish if utxo has multiple inscriptions'; + if (error instanceof Error) { + message = error.message; + } + setShowError(message); } finally { setIsCheckingFees(false); } diff --git a/src/app/query/bitcoin/address/transactions-by-address.query.ts b/src/app/query/bitcoin/address/transactions-by-address.query.ts index eae6f270f65..7a44f6fc55e 100644 --- a/src/app/query/bitcoin/address/transactions-by-address.query.ts +++ b/src/app/query/bitcoin/address/transactions-by-address.query.ts @@ -5,7 +5,7 @@ import { BitcoinTx } from '@shared/models/transactions/bitcoin-transaction.model import { AppUseQueryConfig } from '@app/query/query-config'; import { useBitcoinClient } from '@app/store/common/api-clients.hooks'; -const staleTime = 5 * 1000; +const staleTime = 10 * 1000; const queryOptions = { staleTime, refetchInterval: staleTime }; @@ -34,7 +34,7 @@ export function useGetBitcoinTransactionsByAddressesQuery { return { enabled: !!address, - queryKey: ['btc-txs-by-addresses', address], + queryKey: ['btc-txs-by-address', address], queryFn: () => client.addressApi.getTransactionsByAddress(address), ...queryOptions, ...options,