From 997aa53d45bf7d090067d918fa3588e49b99db11 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 #5143 --- .../address-displayer/form-address-displayer.tsx | 9 ++++----- .../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 + .../address-displayer/address-displayer.tsx | 8 +++----- 8 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/app/components/address-displayer/form-address-displayer.tsx b/src/app/components/address-displayer/form-address-displayer.tsx index e75e82cfa30..17b5e30aef9 100644 --- a/src/app/components/address-displayer/form-address-displayer.tsx +++ b/src/app/components/address-displayer/form-address-displayer.tsx @@ -1,12 +1,12 @@ import { SharedComponentsSelectors } from '@tests/selectors/shared-component.selectors'; -import { Box, BoxProps } from 'leather-styles/jsx'; +import { Box } from 'leather-styles/jsx'; import { AddressDisplayer } from '@app/ui/components/address-displayer/address-displayer'; -interface FormAddressDisplayerProps extends BoxProps { +interface FormAddressDisplayerProps { address: string; } -export function FormAddressDisplayer({ address, ...rest }: FormAddressDisplayerProps) { +export function FormAddressDisplayer({ address }: FormAddressDisplayerProps) { return ( - + {address && } ); } 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..69a32c50256 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('broadcast_ordinal_transaction_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..1298b7e1e9e 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_transaction_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..1a0bde4a3f3 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('btc_transaction_broadcast_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; } diff --git a/src/app/ui/components/address-displayer/address-displayer.tsx b/src/app/ui/components/address-displayer/address-displayer.tsx index 160c66b0b12..cc27d202f96 100644 --- a/src/app/ui/components/address-displayer/address-displayer.tsx +++ b/src/app/ui/components/address-displayer/address-displayer.tsx @@ -1,18 +1,16 @@ -import type { HTMLStyledProps } from 'leather-styles/types'; - import { isEven } from '@app/common/math/helpers'; import { AddressDisplayerLayout } from './address-displayer.layout'; import { groupByFour } from './address-displayer.utils'; -interface AddressDisplayerProps extends HTMLStyledProps<'span'> { +interface AddressDisplayerProps { address: string; } -export function AddressDisplayer({ address, ...props }: AddressDisplayerProps) { +export function AddressDisplayer({ address }: AddressDisplayerProps) { return ( <> {groupByFour(address).map((letterGroup, index) => ( - + {letterGroup} ))}