Skip to content

Commit

Permalink
fix(bridge-ui): add extra info to sentry (#13972)
Browse files Browse the repository at this point in the history
  • Loading branch information
jscriptcoder authored Jun 12, 2023
1 parent cd8ee0a commit 50a1034
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 19 deletions.
4 changes: 3 additions & 1 deletion packages/bridge-ui/src/components/AddressDropdown.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@
'Cannot communicate with the network. Please try again later or contact support.',
);
} else {
Sentry.captureException(error);
Sentry.captureException(error, {
extra: { srcChain: $srcChain?.id },
});
errorToast('There was an error getting your balance.');
}
Expand Down
18 changes: 15 additions & 3 deletions packages/bridge-ui/src/components/BridgeForm/BridgeForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,13 @@
);
} catch (error) {
console.error(error);
Sentry.captureException(error);
Sentry.captureException(error, {
extra: {
token: _token.symbol,
srcChain: $srcChain.id,
},
});
// TODO: we need to improve the toast API so we can simply pass
// title (header), note (footer), icon, etc.
Expand Down Expand Up @@ -422,6 +428,12 @@
} catch (error) {
console.error(error);
// Extra information we're gonna send to Sentry
const extra = {
token: _token.symbol,
srcChain: $srcChain.id,
};
const isBll = _token.symbol.toLocaleLowerCase() === 'bll';
const headerError = '<strong>Failed to bridge funds</strong><br />';
Expand All @@ -432,7 +444,7 @@
if (error.cause?.status === 0) {
// No need to capture this error if BLL is the one failing,
// otherwise we're gonna spam Sentry with expected errors
!isBll && Sentry.captureException(error);
!isBll && Sentry.captureException(error, { extra });
const explorerUrl = `${$srcChain.explorerUrl}/tx/${error.cause.transactionHash}`;
const htmlLink = `<a href="${explorerUrl}" target="_blank"><b><u>here</u></b></a>`;
Expand All @@ -446,7 +458,7 @@
warningToast(`Transaction has been rejected.`);
} else {
// Do not capture if it's BLL. It's expected.
!isBll && Sentry.captureException(error);
!isBll && Sentry.captureException(error, { extra });
errorToast(`${headerError}Try again later.${noteError}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@
})
.catch((error) => {
console.error(error);
Sentry.captureException(error);
Sentry.captureException(error, {
extra: {
token: $token?.symbol,
srcChain: $srcChain?.id,
method,
},
});
amount = '0';
cannotCompute = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
if (error instanceof UserRejectedRequestError) {
warningToast('Switch chain request canceled.');
} else {
Sentry.captureException(error);
Sentry.captureException(error, {
extra: {
chainTo: chain.id,
},
});
errorToast('Error switching chain.');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge-ui/src/components/ChainDropdown.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
if (error instanceof UserRejectedRequestError) {
warningToast('Switch chain request rejected.');
} else {
Sentry.captureException(error);
Sentry.captureException(error, { extra: { chainTo: chain.id } });
errorToast('Error switching chain.');
}
Expand Down
6 changes: 5 additions & 1 deletion packages/bridge-ui/src/components/Faucet/Faucet.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@
if (!wrongChain) {
// We only want to capture and inform the user there is a problem here if
// they are in the right network. Otherwise, the error is expected.
Sentry.captureException(error);
Sentry.captureException(error, {
extra: {
token: _token.symbol,
},
});
errorToast(
`There seems to be a problem with minting ${_token.symbol} tokens.`,
Expand Down
38 changes: 29 additions & 9 deletions packages/bridge-ui/src/components/Transactions/Transaction.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import { chains } from '../../chain/chains';
import { bridgeABI } from '../../constants/abi';
import { BridgeType } from '../../domain/bridge';
import type { Chain } from '../../domain/chain';
import type { Chain, ChainID } from '../../domain/chain';
import { MessageStatus } from '../../domain/message';
import type { NoticeOpenArgs } from '../../domain/modal';
import {
Expand Down Expand Up @@ -82,11 +82,11 @@
// }
async function ensureCorrectChain(
currentChain: Chain,
bridgeTx: BridgeTransaction,
currentChainId: ChainID,
wannaBeChainId: ChainID,
pendingTx: Transaction[],
) {
const isCorrectChain = currentChain.id === bridgeTx.destChainId;
const isCorrectChain = currentChainId === wannaBeChainId;
log(`Are we on the correct chain? ${isCorrectChain}`);
if (!isCorrectChain) {
Expand All @@ -96,7 +96,7 @@
});
}
await switchNetwork(bridgeTx.destChainId);
await switchNetwork(wannaBeChainId);
}
}
Expand All @@ -105,7 +105,11 @@
try {
loading = true;
await ensureCorrectChain($srcChain, bridgeTx, $pendingTransactions);
await ensureCorrectChain(
$srcChain.id,
bridgeTx.destChainId,
$pendingTransactions,
);
// Confirm after switch chain that it worked
const isCorrectChain = await isOnCorrectChain(
Expand Down Expand Up @@ -170,7 +174,13 @@
$token = $token;
} catch (error) {
console.error(error);
Sentry.captureException(error);
Sentry.captureException(error, {
extra: {
srcChain: $srcChain.id,
bridgeTx,
},
});
const headerError = '<strong>Failed to claim funds</strong>';
Expand Down Expand Up @@ -215,7 +225,11 @@
try {
loading = true;
await ensureCorrectChain($srcChain, bridgeTx, $pendingTransactions);
await ensureCorrectChain(
$srcChain.id,
bridgeTx.srcChainId,
$pendingTransactions,
);
// Confirm after switch chain that it worked
const isCorrectChain = await isOnCorrectChain(
Expand Down Expand Up @@ -262,7 +276,13 @@
$token = $token;
} catch (error) {
console.error(error);
Sentry.captureException(error);
Sentry.captureException(error, {
extra: {
srcChain: $srcChain.id,
bridgeTx,
},
});
const headerError = '<strong>Failed to release funds</strong>';
Expand Down
9 changes: 8 additions & 1 deletion packages/bridge-ui/src/signer/subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ export async function subscribeToSigner(newSigner: Signer | null) {
Sentry.captureException(error);
}

const txs = await storageService.getAllByAddress(userAddress);
let txs = [] as BridgeTransaction[];

try {
txs = await storageService.getAllByAddress(userAddress);
} catch (error) {
console.error(error);
Sentry.captureException(error);
}

// Create a map of hashes to API transactions to help us
// filter out transactions from local storage.
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge-ui/src/utils/switchNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function switchNetwork(chainId: number) {

// This will prevent an unlikely infinite loop
const starting = Date.now();
const timeout = 3000; // TODO: config?
const timeout = 5000; // TODO: config?

const waitForNetworkChange = () => {
const srcChainId = get(srcChain)?.id;
Expand Down

0 comments on commit 50a1034

Please sign in to comment.