From e4304f0cd396286af31b1b2dbc4443bb1350de82 Mon Sep 17 00:00:00 2001 From: w3stside Date: Wed, 30 Mar 2022 15:34:47 +0100 Subject: [PATCH 1/4] sentry updater --- src/custom/state/sentry/updater/index.ts | 53 ++++++++++++++++++++++++ src/index.tsx | 3 ++ 2 files changed, 56 insertions(+) create mode 100644 src/custom/state/sentry/updater/index.ts diff --git a/src/custom/state/sentry/updater/index.ts b/src/custom/state/sentry/updater/index.ts new file mode 100644 index 0000000000..738abe1d0f --- /dev/null +++ b/src/custom/state/sentry/updater/index.ts @@ -0,0 +1,53 @@ +import { useEffect } from 'react' +import * as Sentry from '@sentry/browser' + +import useIsWindowVisible from 'hooks/useIsWindowVisible' +import { useSwapState } from 'state/swap/hooks' +import { SupportedChainId } from 'constants/chains' +import { useCurrency } from 'hooks/Tokens' +import { useWalletInfo } from 'hooks/useWalletInfo' + +export default function Updater(): null { + const { account, chainId, walletName, isSupportedWallet } = useWalletInfo() + const windowVisible = useIsWindowVisible() + + const { + INPUT: { currencyId: sellTokenAddress }, + OUTPUT: { currencyId: buyTokenAddress }, + } = useSwapState() + + const sellCurrency = useCurrency(sellTokenAddress) + const buyCurrency = useCurrency(buyTokenAddress) + + // create sentry context based on "main" parameters + useEffect(() => { + if (windowVisible) { + Sentry.setContext('user', { + userAddress: account || 'DISCONNECTED', + wallet: walletName, + isWalletSupported: isSupportedWallet, + network: + account && chainId + ? SupportedChainId[chainId] + : `${chainId ? SupportedChainId[chainId] : 'MAINNET'} - DISCONNECTED`, + sellToken: `${sellTokenAddress} <${sellCurrency?.symbol}>`, + buyToken: `${buyTokenAddress} <${buyCurrency?.symbol}>`, + }) + } + }, [ + // user + account, + chainId, + walletName, + isSupportedWallet, + // tokens + sellTokenAddress, + buyTokenAddress, + buyCurrency?.symbol, + sellCurrency?.symbol, + // window visibility check + windowVisible, + ]) + + return null +} diff --git a/src/index.tsx b/src/index.tsx index 5e6091dac3..1338e67706 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -22,6 +22,8 @@ import EnhancedTransactionUpdater from 'state/enhancedTransactions/updater' import UserUpdater from 'state/user/updater' import FeesUpdater from 'state/price/updater' import GasUpdater from 'state/gas/updater' +import SentryUpdater from 'state/sentry/updater' + import { GpOrdersUpdater, CancelledOrdersUpdater, @@ -62,6 +64,7 @@ function Updaters() { + ) } From 0b20d9f2a6a4bffc0663ff466874f8e6fc208ef3 Mon Sep 17 00:00:00 2001 From: w3stside Date: Fri, 1 Apr 2022 12:36:45 +0100 Subject: [PATCH 2/4] simplify error description --- src/custom/utils/price.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/custom/utils/price.ts b/src/custom/utils/price.ts index d2a8c53925..8998c0d4fb 100644 --- a/src/custom/utils/price.ts +++ b/src/custom/utils/price.ts @@ -236,11 +236,9 @@ export async function getBestPrice(params: PriceQuoteParams, options?: GetBestPr matcha0xPriceResult, ]) - const { baseToken, quoteToken } = params - const sentryError = new Error() Object.assign(sentryError, priceQuoteError, { - message: `Error querying best price from APIs - baseToken: ${baseToken}, quoteToken: ${quoteToken}`, + message: `Error querying best price from APIs`, name: 'PriceErrorObject', }) From ed8dde22e944d8835fd2446d9a40c7765fb1d18d Mon Sep 17 00:00:00 2001 From: w3stside Date: Thu, 7 Apr 2022 12:51:08 +0100 Subject: [PATCH 3/4] simpler networl --- src/custom/state/sentry/updater/index.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/custom/state/sentry/updater/index.ts b/src/custom/state/sentry/updater/index.ts index 738abe1d0f..066e1bc0c2 100644 --- a/src/custom/state/sentry/updater/index.ts +++ b/src/custom/state/sentry/updater/index.ts @@ -25,11 +25,7 @@ export default function Updater(): null { Sentry.setContext('user', { userAddress: account || 'DISCONNECTED', wallet: walletName, - isWalletSupported: isSupportedWallet, - network: - account && chainId - ? SupportedChainId[chainId] - : `${chainId ? SupportedChainId[chainId] : 'MAINNET'} - DISCONNECTED`, + network: chainId ? SupportedChainId[chainId] : chainId, sellToken: `${sellTokenAddress} <${sellCurrency?.symbol}>`, buyToken: `${buyTokenAddress} <${buyCurrency?.symbol}>`, }) From a92606c416dc79ce4583651f4bdb09ce5a09ff49 Mon Sep 17 00:00:00 2001 From: w3stside Date: Thu, 7 Apr 2022 14:12:11 +0100 Subject: [PATCH 4/4] remove user address sentry logging --- src/custom/state/sentry/updater/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/custom/state/sentry/updater/index.ts b/src/custom/state/sentry/updater/index.ts index 066e1bc0c2..9ee024e993 100644 --- a/src/custom/state/sentry/updater/index.ts +++ b/src/custom/state/sentry/updater/index.ts @@ -23,7 +23,7 @@ export default function Updater(): null { useEffect(() => { if (windowVisible) { Sentry.setContext('user', { - userAddress: account || 'DISCONNECTED', + // userAddress: account || 'DISCONNECTED', // TODO: validate with legal wallet: walletName, network: chainId ? SupportedChainId[chainId] : chainId, sellToken: `${sellTokenAddress} <${sellCurrency?.symbol}>`,