Skip to content

Commit

Permalink
chore: add defensive code and better analytics for broadcast errors, …
Browse files Browse the repository at this point in the history
…ref #5143
  • Loading branch information
pete-watters committed May 15, 2024
1 parent 9f73b24 commit 997aa53
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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 (
<Box
data-testid={SharedComponentsSelectors.AddressDisplayer}
Expand All @@ -15,9 +15,8 @@ export function FormAddressDisplayer({ address, ...rest }: FormAddressDisplayerP
justifyContent="end"
maxWidth="300px"
mr="-8px"
{...rest}
>
<AddressDisplayer address={address} />
{address && <AddressDisplayer address={address} />}
</Box>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ export function Brc20SendFormConfirmation() {
});
},
onError(e) {
void analytics.track('broadcast_brc20_transaction_error', {
error: e,
});

nav.toErrorPage(e);
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ export function BtcSendFormConfirmation() {
);
},
onError(e) {
void analytics.track('btc_transaction_broadcast_error', {
error: e,
});
nav.toErrorPage(e);
},
});
Expand Down
1 change: 1 addition & 0 deletions src/app/query/stacks/bns/bns.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
8 changes: 3 additions & 5 deletions src/app/ui/components/address-displayer/address-displayer.tsx
Original file line number Diff line number Diff line change
@@ -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) => (
<AddressDisplayerLayout key={index} isEven={isEven(index + 1)} {...props}>
<AddressDisplayerLayout key={index} isEven={isEven(index + 1)}>
{letterGroup}
</AddressDisplayerLayout>
))}
Expand Down

0 comments on commit 997aa53

Please sign in to comment.