From bf36652b856cc8e5d4501207b4aee56c63a642cf Mon Sep 17 00:00:00 2001 From: Pete Watters <2938440+pete-watters@users.noreply.github.com> Date: Tue, 14 May 2024 15:46:05 +0100 Subject: [PATCH] chore: add defensive code and better analytics for broadcast errors, ref #5118 --- package.json | 2 +- pnpm-lock.yaml | 8 ++++---- .../ledger-sign-stacks-tx-container.tsx | 11 ++++++++++- .../ordinal-inscription/send-inscription-review.tsx | 1 + .../form/brc20/brc20-send-form-confirmation.tsx | 4 ++++ .../form/btc/btc-send-form-confirmation.tsx | 3 +++ src/app/query/stacks/bns/bns.utils.ts | 1 + .../blockchain/bitcoin/native-segwit-account.hooks.ts | 1 + 8 files changed, 25 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 95014c656b0..e3fc5941302 100644 --- a/package.json +++ b/package.json @@ -135,7 +135,7 @@ "@dlc-link/dlc-tools": "1.1.1", "@fungible-systems/zone-file": "2.0.0", "@hirosystems/token-metadata-api-client": "1.2.0", - "@leather-wallet/models": "0.4.4", + "@leather-wallet/models": "0.4.5", "@leather-wallet/tokens": "0.0.14", "@ledgerhq/hw-transport-webusb": "6.27.19", "@noble/hashes": "1.3.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0935a38655b..88e4c349e34 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -30,8 +30,8 @@ dependencies: specifier: 1.2.0 version: 1.2.0 '@leather-wallet/models': - specifier: 0.4.4 - version: 0.4.4 + specifier: 0.4.5 + version: 0.4.5 '@leather-wallet/tokens': specifier: 0.0.14 version: 0.0.14 @@ -3702,8 +3702,8 @@ packages: bignumber.js: 9.1.2 dev: true - /@leather-wallet/models@0.4.4: - resolution: {integrity: sha512-dqUTUR0EMM9WFwkeWRahlpixK+Ct2vEpDBhQdvO83tK4GhC/JlopI9hmpaSKyX9+35Ts2LpgycUiCh59kmZbMA==} + /@leather-wallet/models@0.4.5: + resolution: {integrity: sha512-H0NhxYy1C2Byrj1wswL9Zf6bWOejvgVuwgVDT6xh7zqvoPotiAtrfEe3hiBdSeUtUsTh70ha1ZMuGwf/rph67w==} dependencies: bignumber.js: 9.1.2 dev: false 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 f0b1d9cb664..101426eb52b 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 { RouteUrls } from '@shared/route-urls'; import { delay, isError } from '@shared/utils'; +import { analytics } from '@shared/utils/analytics'; import { useScrollLock } from '@app/common/hooks/use-scroll-lock'; import { appEvents } from '@app/common/publish-subscribe'; @@ -129,7 +130,15 @@ function LedgerSignStacksTxContainer() { signedTx, }); } catch (e) { - ledgerNavigate.toBroadcastErrorStep(isError(e) ? e.message : 'Unknown error'); + const error = isError(e) ? e.message : 'Unknown error'; + void analytics.track('ledger_transaction_publish_error', { + error: { + message: error, + error: e, + }, + }); + + ledgerNavigate.toBroadcastErrorStep(error); return; } }, diff --git a/src/app/pages/send/ordinal-inscription/send-inscription-review.tsx b/src/app/pages/send/ordinal-inscription/send-inscription-review.tsx index 2ecddb2c72c..b0530db592e 100644 --- a/src/app/pages/send/ordinal-inscription/send-inscription-review.tsx +++ b/src/app/pages/send/ordinal-inscription/send-inscription-review.tsx @@ -64,6 +64,7 @@ export function SendInscriptionReview() { }); }, onError(e) { + void analytics.track('ordinalbroadcast__error', { error: e }); navigate(`/${RouteUrls.SendOrdinalInscription}/${RouteUrls.SendOrdinalInscriptionError}`, { state: { error: e, diff --git a/src/app/pages/send/send-crypto-asset-form/form/brc20/brc20-send-form-confirmation.tsx b/src/app/pages/send/send-crypto-asset-form/form/brc20/brc20-send-form-confirmation.tsx index d6d176f3e5b..f589aa22c57 100644 --- a/src/app/pages/send/send-crypto-asset-form/form/brc20/brc20-send-form-confirmation.tsx +++ b/src/app/pages/send/send-crypto-asset-form/form/brc20/brc20-send-form-confirmation.tsx @@ -98,6 +98,10 @@ export function Brc20SendFormConfirmation() { }); }, onError(e) { + void analytics.track('broadcast_brc20_error', { + error: e, + }); + nav.toErrorPage(e); }, }); diff --git a/src/app/pages/send/send-crypto-asset-form/form/btc/btc-send-form-confirmation.tsx b/src/app/pages/send/send-crypto-asset-form/form/btc/btc-send-form-confirmation.tsx index 00b9fb55e04..b8fe3651a00 100644 --- a/src/app/pages/send/send-crypto-asset-form/form/btc/btc-send-form-confirmation.tsx +++ b/src/app/pages/send/send-crypto-asset-form/form/btc/btc-send-form-confirmation.tsx @@ -138,6 +138,9 @@ export function BtcSendFormConfirmation() { ); }, onError(e) { + void analytics.track('broadcast_btc_error', { + error: e, + }); nav.toErrorPage(e); }, }); diff --git a/src/app/query/stacks/bns/bns.utils.ts b/src/app/query/stacks/bns/bns.utils.ts index 046818ba1a4..19705a42f8d 100644 --- a/src/app/query/stacks/bns/bns.utils.ts +++ b/src/app/query/stacks/bns/bns.utils.ts @@ -140,6 +140,7 @@ export async function fetchNamesForAddress({ export async function fetchNameOwner(client: StacksClient, name: string, isTestnet: boolean) { const fetchFromApi = async () => { const res = await client.namesApi.getNameInfo({ name }); + if (isUndefined(res.address)) return null; if (!isString(res.address) || res.address.length === 0) return null; return res.address; }; diff --git a/src/app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks.ts b/src/app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks.ts index f0a0aa63e9e..a5c8a799841 100644 --- a/src/app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks.ts +++ b/src/app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks.ts @@ -122,6 +122,7 @@ export function useCurrentAccountNativeSegwitAddressIndexZero() { */ export function useNativeSegwitAccountIndexAddressIndexZero(accountIndex: number) { const signer = useNativeSegwitSigner(accountIndex)?.(0); + // could it be this? return signer?.payment.address as string; }