diff --git a/src/app/common/hooks/use-submit-stx-transaction.ts b/src/app/common/hooks/use-submit-stx-transaction.ts index 56de95a7992..7f64bd24286 100644 --- a/src/app/common/hooks/use-submit-stx-transaction.ts +++ b/src/app/common/hooks/use-submit-stx-transaction.ts @@ -5,6 +5,7 @@ import { bytesToHex } from '@stacks/common'; import { StacksTransaction, broadcastTransaction } from '@stacks/transactions'; import { logger } from '@shared/logger'; +import { isError } from '@shared/utils'; import { getErrorMessage } from '@app/common/get-error-message'; import { useRefreshAllAccountData } from '@app/common/hooks/account/use-refresh-all-account-data'; @@ -59,7 +60,7 @@ export function useSubmitTransactionCallback({ loadingKey }: UseSubmitTransactio } } catch (error) { logger.error('Transaction callback', { error }); - onError(error instanceof Error ? error : { name: '', message: '' }); + onError(isError(error) ? error : { name: '', message: '' }); setIsIdle(); } }, diff --git a/src/app/common/utils/safe-await.ts b/src/app/common/utils/safe-await.ts index 304aff22a0c..e0bcec9c54c 100644 --- a/src/app/common/utils/safe-await.ts +++ b/src/app/common/utils/safe-await.ts @@ -1,4 +1,5 @@ // TypeScript port of https://github.com/DavidWells/safe-await/ +import { isError } from '@shared/utils'; // Native Error types https://mzl.la/2Veh3TR const nativeExceptions = [ @@ -19,7 +20,7 @@ function throwNative(error: Error) { export async function safeAwait(promise: Promise, finallyFn?: () => void) { return promise .then(data => { - if (data instanceof Error) { + if (isError(data)) { throwNative(data); return [data] as readonly [Error]; } diff --git a/src/app/components/bitcoin-transaction-item/bitcoin-transaction-caption.tsx b/src/app/components/bitcoin-transaction-item/bitcoin-transaction-caption.tsx deleted file mode 100644 index a1e6b2a0e72..00000000000 --- a/src/app/components/bitcoin-transaction-item/bitcoin-transaction-caption.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import { styled } from 'leather-styles/jsx'; - -interface BitcoinTransactionCaptionProps { - children: string; -} -export function BitcoinTransactionCaption({ children }: BitcoinTransactionCaptionProps) { - return ( - - {children} - - ); -} diff --git a/src/app/components/bitcoin-transaction-item/bitcoin-transaction-item.tsx b/src/app/components/bitcoin-transaction-item/bitcoin-transaction-item.tsx index 3838cd0a656..38e4069dcb7 100644 --- a/src/app/components/bitcoin-transaction-item/bitcoin-transaction-item.tsx +++ b/src/app/components/bitcoin-transaction-item/bitcoin-transaction-item.tsx @@ -23,13 +23,12 @@ import { useGetInscriptionsByOutputQuery } from '@app/query/bitcoin/ordinals/ins import { useCurrentAccountNativeSegwitAddressIndexZero } from '@app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks'; import { BulletSeparator } from '@app/ui/components/bullet-separator/bullet-separator'; import { BtcIcon } from '@app/ui/components/icons/btc-icon'; +import { Caption } from '@app/ui/components/typography/caption'; import { TransactionItemLayout } from '../transaction-item/transaction-item.layout'; -import { BitcoinTransactionCaption } from './bitcoin-transaction-caption'; import { BitcoinTransactionIcon } from './bitcoin-transaction-icon'; import { InscriptionIcon } from './bitcoin-transaction-inscription-icon'; import { BitcoinTransactionStatus } from './bitcoin-transaction-status'; -import { BitcoinTransactionValue } from './bitcoin-transaction-value'; interface BitcoinTransactionItemProps { transaction: BitcoinTx; @@ -76,13 +75,10 @@ export function BitcoinTransactionItem({ transaction }: BitcoinTransactionItemPr const txCaption = ( - {caption} - {inscriptionData ? ( - {inscriptionData.mime_type} - ) : null} + {caption} + {inscriptionData ? {inscriptionData.mime_type} : null} ); - const txValue = {value}; const title = inscriptionData ? `Ordinal inscription #${inscriptionData.number}` : 'Bitcoin'; const increaseFeeButton = ( @@ -107,7 +103,7 @@ export function BitcoinTransactionItem({ transaction }: BitcoinTransactionItemPr } txStatus={} txTitle={} - txValue={txValue} + txValue={value} /> ); } diff --git a/src/app/components/bitcoin-transaction-item/bitcoin-transaction-status.tsx b/src/app/components/bitcoin-transaction-item/bitcoin-transaction-status.tsx index 7cbc54caa5c..d0c76a41461 100644 --- a/src/app/components/bitcoin-transaction-item/bitcoin-transaction-status.tsx +++ b/src/app/components/bitcoin-transaction-item/bitcoin-transaction-status.tsx @@ -1,6 +1,7 @@ import { BitcoinTx } from '@shared/models/transactions/bitcoin-transaction.model'; -import { PendingLabel } from '@app/components/transaction/pending-label'; +import { BasicTooltip } from '@app/ui/components/tooltip/basic-tooltip'; +import { Caption } from '@app/ui/components/typography/caption'; interface BitcoinTransactionStatusProps { transaction: BitcoinTx; @@ -10,5 +11,9 @@ const pendingWaitingMessage = export function BitcoinTransactionStatus({ transaction }: BitcoinTransactionStatusProps) { const isPending = !transaction.status.confirmed; - return isPending ? : null; + return isPending ? ( + + Pending + + ) : null; } diff --git a/src/app/components/bitcoin-transaction-item/bitcoin-transaction-value.tsx b/src/app/components/bitcoin-transaction-item/bitcoin-transaction-value.tsx deleted file mode 100644 index 71b9e77eb02..00000000000 --- a/src/app/components/bitcoin-transaction-item/bitcoin-transaction-value.tsx +++ /dev/null @@ -1,8 +0,0 @@ -import { Title } from '@app/ui/components/typography/title'; - -interface BitcoinTransactionValueProps { - children: string; -} -export function BitcoinTransactionValue({ children }: BitcoinTransactionValueProps) { - return {children}; -} diff --git a/src/app/components/secret-key/mnemonic-key/mnemonic-word-input.tsx b/src/app/components/secret-key/mnemonic-key/mnemonic-word-input.tsx index 257d8a38bc4..7bb301386cc 100644 --- a/src/app/components/secret-key/mnemonic-key/mnemonic-word-input.tsx +++ b/src/app/components/secret-key/mnemonic-key/mnemonic-word-input.tsx @@ -23,7 +23,7 @@ export function MnemonicWordInput({ const [isFocused, setIsFocused] = useState(false); const isDirty = useIsFieldDirty(name); return ( - + diff --git a/src/app/components/stacks-transaction-item/stacks-transaction-item.tsx b/src/app/components/stacks-transaction-item/stacks-transaction-item.tsx index f43b7440e8c..da082aaaf8b 100644 --- a/src/app/components/stacks-transaction-item/stacks-transaction-item.tsx +++ b/src/app/components/stacks-transaction-item/stacks-transaction-item.tsx @@ -1,7 +1,5 @@ import { createSearchParams, useLocation, useNavigate } from 'react-router-dom'; -import { styled } from 'leather-styles/jsx'; - import { StacksTx, TxTransferDetails } from '@shared/models/transactions/stacks-transaction.model'; import { RouteUrls } from '@shared/route-urls'; @@ -85,22 +83,16 @@ export function StacksTransactionItem({ /> ); const txStatus = transaction && ; - const txCaption = ( - - {caption} - - ); - const txValue = {value}; return ( } - txValue={txValue} + txValue={value} /> ); } diff --git a/src/app/components/stacks-transaction-item/stacks-transaction-status.tsx b/src/app/components/stacks-transaction-item/stacks-transaction-status.tsx index c0cf05f5bb6..8661e0c562d 100644 --- a/src/app/components/stacks-transaction-item/stacks-transaction-status.tsx +++ b/src/app/components/stacks-transaction-item/stacks-transaction-status.tsx @@ -1,11 +1,11 @@ -import { styled } from 'leather-styles/jsx'; - import { StacksTx } from '@shared/models/transactions/stacks-transaction.model'; import { isPendingTx } from '@app/common/transactions/stacks/transaction.utils'; import { BasicTooltip } from '@app/ui/components/tooltip/basic-tooltip'; +import { Caption } from '@app/ui/components/typography/caption'; -import { PendingLabel } from '../transaction/pending-label'; +const pendingWaitingMessage = + 'This transaction is waiting to be confirmed. Depending on network congestion, this may take anywhere from a few minutes, to a couple of hours.'; interface TransactionStatusProps { transaction: StacksTx; @@ -16,12 +16,14 @@ export function StacksTransactionStatus({ transaction }: TransactionStatusProps) return ( <> - {isPending && } + {isPending && ( + + Pending + + )} {isFailed && ( - - Failed - + Failed )} diff --git a/src/app/components/transaction-item/transaction-item.layout.tsx b/src/app/components/transaction-item/transaction-item.layout.tsx index e778cf9591d..921b9f66998 100644 --- a/src/app/components/transaction-item/transaction-item.layout.tsx +++ b/src/app/components/transaction-item/transaction-item.layout.tsx @@ -1,9 +1,10 @@ import { ReactNode } from 'react'; -import { styled } from 'leather-styles/jsx'; +import { HStack, styled } from 'leather-styles/jsx'; import { ItemInteractive } from '@app/ui/components/item/item-interactive'; import { ItemLayout } from '@app/ui/components/item/item.layout'; +import { Caption } from '@app/ui/components/typography/caption'; interface TransactionItemLayoutProps { openTxLink(): void; @@ -25,18 +26,15 @@ export function TransactionItemLayout({ txValue, }: TransactionItemLayoutProps) { return ( - // TODO: Revisit if needed styles position="relative" zIndex={99} - - {txCaption} - + + {txCaption} {txStatus && txStatus} - + } titleRight={ rightElement ? ( diff --git a/src/app/components/transaction/pending-label.tsx b/src/app/components/transaction/pending-label.tsx deleted file mode 100644 index 939a42bc5e5..00000000000 --- a/src/app/components/transaction/pending-label.tsx +++ /dev/null @@ -1,28 +0,0 @@ -import { Box, Flex, styled } from 'leather-styles/jsx'; - -import { InfoIcon } from '@app/ui/components/icons/info-icon'; -import { BasicTooltip } from '@app/ui/components/tooltip/basic-tooltip'; - -const defaultPendingWaitingMessage = - 'This transaction is waiting to be confirmed. Depending on network congestion, this may take anywhere from a few minutes, to a couple of hours.'; - -interface PendingLabelProps { - pendingWaitingMessage?: string; -} - -export function PendingLabel({ - pendingWaitingMessage = defaultPendingWaitingMessage, -}: PendingLabelProps) { - return ( - - - Pending - - - - - - - - ); -} diff --git a/src/app/components/transaction/transaction-title.tsx b/src/app/components/transaction/transaction-title.tsx index 6f9bf4af05c..23397108de8 100644 --- a/src/app/components/transaction/transaction-title.tsx +++ b/src/app/components/transaction/transaction-title.tsx @@ -22,10 +22,11 @@ export function TransactionTitle(props: TransactionTitleProps) { return ( {spamFilter(title)} diff --git a/src/app/features/increase-fee-drawer/hooks/use-btc-increase-fee.ts b/src/app/features/increase-fee-drawer/hooks/use-btc-increase-fee.ts index bbd86d8eef3..212ec4d01f1 100644 --- a/src/app/features/increase-fee-drawer/hooks/use-btc-increase-fee.ts +++ b/src/app/features/increase-fee-drawer/hooks/use-btc-increase-fee.ts @@ -8,6 +8,7 @@ import * as yup from 'yup'; import { createMoney } from '@shared/models/money.model'; import { BitcoinTx } from '@shared/models/transactions/bitcoin-transaction.model'; import { RouteUrls } from '@shared/route-urls'; +import { isError } from '@shared/utils'; import { useAnalytics } from '@app/common/hooks/analytics/use-analytics'; import { useBtcAssetBalance } from '@app/common/hooks/balance/btc/use-btc-balance'; @@ -122,7 +123,7 @@ export function useBtcIncreaseFee(btcTx: BitcoinTx) { } function onError(error: unknown) { - const message = error instanceof Error ? error.message : 'Unknown error'; + const message = isError(error) ? error.message : 'Unknown error'; toast.error(message); navigate(RouteUrls.Home); } diff --git a/src/app/features/ledger/flows/bitcoin-tx-signing/ledger-bitcoin-sign-tx-container.tsx b/src/app/features/ledger/flows/bitcoin-tx-signing/ledger-bitcoin-sign-tx-container.tsx index d6203b39eff..25a6c802f1b 100644 --- a/src/app/features/ledger/flows/bitcoin-tx-signing/ledger-bitcoin-sign-tx-container.tsx +++ b/src/app/features/ledger/flows/bitcoin-tx-signing/ledger-bitcoin-sign-tx-container.tsx @@ -9,6 +9,7 @@ import get from 'lodash.get'; import { BitcoinInputSigningConfig } from '@shared/crypto/bitcoin/signer-config'; import { logger } from '@shared/logger'; import { RouteUrls } from '@shared/route-urls'; +import { isError } from '@shared/utils'; import { useLocationState, useLocationStateWithCache } from '@app/common/hooks/use-location-state'; import { useScrollLock } from '@app/common/hooks/use-scroll-lock'; @@ -115,7 +116,7 @@ function LedgerSignBitcoinTxContainer() { void bitcoinApp.transport.close(); } } catch (e) { - if (e instanceof Error && checkLockedDeviceError(e)) { + if (isError(e) && checkLockedDeviceError(e)) { setLatestDeviceResponse({ deviceLocked: true } as any); return; } diff --git a/src/app/features/ledger/flows/jwt-signing/ledger-sign-jwt-container.tsx b/src/app/features/ledger/flows/jwt-signing/ledger-sign-jwt-container.tsx index d7bcccf80eb..5d7a7a9a3ff 100644 --- a/src/app/features/ledger/flows/jwt-signing/ledger-sign-jwt-container.tsx +++ b/src/app/features/ledger/flows/jwt-signing/ledger-sign-jwt-container.tsx @@ -7,6 +7,7 @@ import get from 'lodash.get'; import { finalizeAuthResponse } from '@shared/actions/finalize-auth-response'; import { logger } from '@shared/logger'; +import { isError } from '@shared/utils'; import { useGetLegacyAuthBitcoinAddresses } from '@app/common/authentication/use-legacy-auth-bitcoin-addresses'; import { useOnboardingState } from '@app/common/hooks/auth/use-onboarding-state'; @@ -92,7 +93,7 @@ export function LedgerSignJwtContainer() { const stacks = await prepareLedgerDeviceStacksAppConnection({ setLoadingState: setAwaitingDeviceConnection, onError(e) { - if (e instanceof Error && checkLockedDeviceError(e)) { + if (isError(e) && checkLockedDeviceError(e)) { setLatestDeviceResponse({ deviceLocked: true } as any); return; } diff --git a/src/app/features/ledger/flows/stacks-message-signing/ledger-stacks-sign-msg-container.tsx b/src/app/features/ledger/flows/stacks-message-signing/ledger-stacks-sign-msg-container.tsx index 855814cc58c..1b969cc860e 100644 --- a/src/app/features/ledger/flows/stacks-message-signing/ledger-stacks-sign-msg-container.tsx +++ b/src/app/features/ledger/flows/stacks-message-signing/ledger-stacks-sign-msg-container.tsx @@ -9,6 +9,7 @@ import get from 'lodash.get'; import { finalizeMessageSignature } from '@shared/actions/finalize-message-signature'; import { logger } from '@shared/logger'; import { UnsignedMessage, whenSignableMessageOfType } from '@shared/signature/signature-types'; +import { isError } from '@shared/utils'; import { useScrollLock } from '@app/common/hooks/use-scroll-lock'; import { delay } from '@app/common/utils'; @@ -67,7 +68,7 @@ function LedgerSignStacksMsg({ account, unsignedMessage }: LedgerSignMsgProps) { const stacksApp = await prepareLedgerDeviceStacksAppConnection({ setLoadingState: setAwaitingDeviceConnection, onError(e) { - if (e instanceof Error && checkLockedDeviceError(e)) { + if (isError(e) && checkLockedDeviceError(e)) { setLatestDeviceResponse({ deviceLocked: true } as any); return; } diff --git a/src/app/features/ledger/flows/stacks-tx-signing/ledger-sign-stacks-tx-container.tsx b/src/app/features/ledger/flows/stacks-tx-signing/ledger-sign-stacks-tx-container.tsx index a4809554c99..9eae8e1df09 100644 --- a/src/app/features/ledger/flows/stacks-tx-signing/ledger-sign-stacks-tx-container.tsx +++ b/src/app/features/ledger/flows/stacks-tx-signing/ledger-sign-stacks-tx-container.tsx @@ -7,6 +7,7 @@ import get from 'lodash.get'; import { logger } from '@shared/logger'; import { RouteUrls } from '@shared/route-urls'; +import { isError } from '@shared/utils'; import { useScrollLock } from '@app/common/hooks/use-scroll-lock'; import { appEvents } from '@app/common/publish-subscribe'; @@ -71,7 +72,7 @@ function LedgerSignStacksTxContainer() { const stacksApp = await prepareLedgerDeviceStacksAppConnection({ setLoadingState: setAwaitingDeviceConnection, onError(e) { - if (e instanceof Error && checkLockedDeviceError(e)) { + if (isError(e) && checkLockedDeviceError(e)) { setLatestDeviceResponse({ deviceLocked: true } as any); return; } @@ -148,7 +149,7 @@ function LedgerSignStacksTxContainer() { signedTx, }); } catch (e) { - ledgerNavigate.toBroadcastErrorStep(e instanceof Error ? e.message : 'Unknown error'); + ledgerNavigate.toBroadcastErrorStep(isError(e) ? e.message : 'Unknown error'); return; } } catch (e) { diff --git a/src/app/features/ledger/generic-flows/request-keys/use-request-ledger-keys.ts b/src/app/features/ledger/generic-flows/request-keys/use-request-ledger-keys.ts index 36a007db0bd..c73de72b4ec 100644 --- a/src/app/features/ledger/generic-flows/request-keys/use-request-ledger-keys.ts +++ b/src/app/features/ledger/generic-flows/request-keys/use-request-ledger-keys.ts @@ -4,6 +4,7 @@ import StacksApp from '@zondax/ledger-stacks'; import AppClient from 'ledger-bitcoin'; import { SupportedBlockchains } from '@shared/constants'; +import { isError } from '@shared/utils'; import { delay } from '@app/common/utils'; @@ -73,7 +74,7 @@ export function useRequestLedgerKeys<App extends AppClient | StacksApp>({ onSuccess?.(); } catch (e) { setAwaitingDeviceConnection(false); - if (e instanceof Error && checkLockedDeviceError(e)) { + if (isError(e) && checkLockedDeviceError(e)) { setLatestDeviceResponse({ deviceLocked: true } as any); return; } diff --git a/src/app/features/psbt-signer/psbt-signer.tsx b/src/app/features/psbt-signer/psbt-signer.tsx index 0b59788e404..85dc31a1fdb 100644 --- a/src/app/features/psbt-signer/psbt-signer.tsx +++ b/src/app/features/psbt-signer/psbt-signer.tsx @@ -3,7 +3,7 @@ import { useNavigate } from 'react-router-dom'; import { getPsbtTxInputs, getPsbtTxOutputs } from '@shared/crypto/bitcoin/bitcoin.utils'; import { RouteUrls } from '@shared/route-urls'; -import { closeWindow } from '@shared/utils'; +import { closeWindow, isError } from '@shared/utils'; import { useRouteHeader } from '@app/common/hooks/use-route-header'; import { SignPsbtArgs } from '@app/common/psbt/requests'; @@ -51,7 +51,7 @@ export function PsbtSigner(props: PsbtSignerProps) { return getRawPsbt(psbtHex); } catch (e) { navigate(RouteUrls.RequestError, { - state: { message: e instanceof Error ? e.message : '', title: 'Failed request' }, + state: { message: isError(e) ? e.message : '', title: 'Failed request' }, }); return; } diff --git a/src/app/features/stacks-transaction-request/hooks/use-stacks-broadcast-transaction.tsx b/src/app/features/stacks-transaction-request/hooks/use-stacks-broadcast-transaction.tsx index b9ebe746dbe..0faef75e0f4 100644 --- a/src/app/features/stacks-transaction-request/hooks/use-stacks-broadcast-transaction.tsx +++ b/src/app/features/stacks-transaction-request/hooks/use-stacks-broadcast-transaction.tsx @@ -8,7 +8,7 @@ import { finalizeTxSignature } from '@shared/actions/finalize-tx-signature'; import { logger } from '@shared/logger'; import { CryptoCurrencies } from '@shared/models/currencies.model'; import { RouteUrls } from '@shared/route-urls'; -import { isString } from '@shared/utils'; +import { isError, isString } from '@shared/utils'; import { useDefaultRequestParams } from '@app/common/hooks/use-default-request-search-params'; import { LoadingKeys } from '@app/common/hooks/use-loading'; @@ -85,7 +85,7 @@ export function useStacksBroadcastTransaction(token: CryptoCurrencies, decimals? } } catch (e) { navigate(RouteUrls.TransactionBroadcastError, { - state: { message: e instanceof Error ? e.message : 'Unknown error' }, + state: { message: isError(e) ? e.message : 'Unknown error' }, }); } finally { setIsBroadcasting(false); diff --git a/src/app/features/switch-account-drawer/switch-account-drawer.tsx b/src/app/features/switch-account-drawer/switch-account-drawer.tsx index 6fa56009a0f..765fdef4070 100644 --- a/src/app/features/switch-account-drawer/switch-account-drawer.tsx +++ b/src/app/features/switch-account-drawer/switch-account-drawer.tsx @@ -39,7 +39,7 @@ export const SwitchAccountDrawer = memo(() => { return isShowing ? ( <ControlledDrawer title="Select account" isShowing={isShowing} onClose={onClose}> - <Box mb={whenWallet({ ledger: 'space.04', software: '' })}> + <Box mb={whenWallet({ ledger: 'space.04', software: '' })} pb="space.09"> <SwitchAccountList currentAccountIndex={currentAccountIndex} handleClose={onClose} diff --git a/src/app/pages/psbt-request/use-psbt-request.tsx b/src/app/pages/psbt-request/use-psbt-request.tsx index 144e46adf37..8eb6e280f1a 100644 --- a/src/app/pages/psbt-request/use-psbt-request.tsx +++ b/src/app/pages/psbt-request/use-psbt-request.tsx @@ -5,6 +5,7 @@ import { bytesToHex, hexToBytes } from '@noble/hashes/utils'; import { finalizePsbt } from '@shared/actions/finalize-psbt'; import { RouteUrls } from '@shared/route-urls'; +import { isError } from '@shared/utils'; import { useAnalytics } from '@app/common/hooks/analytics/use-analytics'; import { usePsbtRequestSearchParams } from '@app/common/psbt/use-psbt-request-params'; @@ -57,7 +58,7 @@ export function usePsbtRequest() { }); } catch (e) { return navigate(RouteUrls.RequestError, { - state: { message: e instanceof Error ? e.message : '', title: 'Failed to sign' }, + state: { message: isError(e) ? e.message : '', title: 'Failed to sign' }, }); } }, diff --git a/src/app/pages/rpc-sign-psbt/use-rpc-sign-psbt.tsx b/src/app/pages/rpc-sign-psbt/use-rpc-sign-psbt.tsx index 4c43efa4b8e..222f4033027 100644 --- a/src/app/pages/rpc-sign-psbt/use-rpc-sign-psbt.tsx +++ b/src/app/pages/rpc-sign-psbt/use-rpc-sign-psbt.tsx @@ -7,7 +7,7 @@ import { bytesToHex } from '@stacks/common'; import { Money } from '@shared/models/money.model'; import { RouteUrls } from '@shared/route-urls'; import { makeRpcErrorResponse, makeRpcSuccessResponse } from '@shared/rpc/rpc-methods'; -import { closeWindow } from '@shared/utils'; +import { closeWindow, isError } from '@shared/utils'; import { useAnalytics } from '@app/common/hooks/analytics/use-analytics'; import { sumMoney } from '@app/common/money/calculate-money'; @@ -78,7 +78,7 @@ export function useRpcSignPsbt() { }, onError(e) { navigate(RouteUrls.RequestError, { - state: { message: e instanceof Error ? e.message : '', title: 'Failed to broadcast' }, + state: { message: isError(e) ? e.message : '', title: 'Failed to broadcast' }, }); }, }); @@ -113,7 +113,7 @@ export function useRpcSignPsbt() { } catch (e) { return navigate(RouteUrls.RequestError, { state: { - message: e instanceof Error ? e.message : '', + message: isError(e) ? e.message : '', title: 'Failed to finalize tx', }, }); @@ -130,7 +130,7 @@ export function useRpcSignPsbt() { closeWindow(); } catch (e) { return navigate(RouteUrls.RequestError, { - state: { message: e instanceof Error ? e.message : '', title: 'Failed to sign' }, + state: { message: isError(e) ? e.message : '', title: 'Failed to sign' }, }); } }, 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 5aa4859b6b8..f60660bf7d2 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 @@ -6,6 +6,7 @@ import * as yup from 'yup'; import { logger } from '@shared/logger'; import { OrdinalSendFormValues } from '@shared/models/form.model'; import { RouteUrls } from '@shared/route-urls'; +import { isError } from '@shared/utils'; import { FormErrorMessages } from '@app/common/error-messages'; import { useAnalytics } from '@app/common/hooks/analytics/use-analytics'; @@ -66,7 +67,7 @@ export function useSendInscriptionForm() { void analytics.track('ordinals_dot_com_unavailable', { error }); let message = 'Unable to establish if utxo has multiple inscriptions'; - if (error instanceof Error) { + if (isError(error)) { message = error.message; } setShowError(message); diff --git a/src/app/pages/swap/hooks/use-stacks-broadcast-swap.tsx b/src/app/pages/swap/hooks/use-stacks-broadcast-swap.tsx index 551eb4598b3..4046cd2ec20 100644 --- a/src/app/pages/swap/hooks/use-stacks-broadcast-swap.tsx +++ b/src/app/pages/swap/hooks/use-stacks-broadcast-swap.tsx @@ -6,7 +6,7 @@ import { StacksTransaction } from '@stacks/transactions'; import { logger } from '@shared/logger'; import { RouteUrls } from '@shared/route-urls'; -import { isString } from '@shared/utils'; +import { isError, isString } from '@shared/utils'; import { LoadingKeys, useLoading } from '@app/common/hooks/use-loading'; import { useSubmitTransactionCallback } from '@app/common/hooks/use-submit-stx-transaction'; @@ -42,7 +42,7 @@ export function useStacksBroadcastSwap() { } catch (e) { setIsIdle(); navigate(RouteUrls.TransactionBroadcastError, { - state: { message: e instanceof Error ? e.message : 'Unknown error' }, + state: { message: isError(e) ? e.message : 'Unknown error' }, }); } finally { setIsIdle(); diff --git a/src/app/query/bitcoin/transaction/use-bitcoin-broadcast-transaction.ts b/src/app/query/bitcoin/transaction/use-bitcoin-broadcast-transaction.ts index 84065d865c5..298a6643721 100644 --- a/src/app/query/bitcoin/transaction/use-bitcoin-broadcast-transaction.ts +++ b/src/app/query/bitcoin/transaction/use-bitcoin-broadcast-transaction.ts @@ -1,5 +1,7 @@ import { useCallback, useState } from 'react'; +import { isError } from '@shared/utils'; + import { useAnalytics } from '@app/common/hooks/analytics/use-analytics'; import { delay } from '@app/common/utils'; import { useBitcoinClient } from '@app/store/common/api-clients.hooks'; @@ -30,7 +32,10 @@ export function useBitcoinBroadcastTransaction() { return txid; } catch (e) { onError?.(e as Error); - void analytics.track('error_broadcasting_transaction', { error: e }); + void analytics.track('error_broadcasting_transaction', { + errorName: isError(e) ? e.name : 'unknown', + errorMsg: isError(e) ? e.message : 'unknown', + }); return; } finally { setIsBroadcasting(false); diff --git a/src/shared/utils.ts b/src/shared/utils.ts index 34e35814db7..9605679b59e 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -29,6 +29,10 @@ export function isObject(value: unknown): value is object { return typeof value === 'object'; } +export function isError(value: unknown): value is Error { + return value instanceof Error; +} + export function isEmpty(value: object) { return Object.keys(value).length === 0; }