Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SENTRY] Context and error description cleanup #361

Merged
merged 4 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/custom/state/sentry/updater/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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', // TODO: validate with legal
wallet: walletName,
network: chainId ? SupportedChainId[chainId] : chainId,
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
}
4 changes: 1 addition & 3 deletions src/custom/utils/price.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
})

Expand Down
3 changes: 3 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -62,6 +64,7 @@ function Updaters() {
<GpOrdersUpdater />
<GasUpdater />
<LogsUpdater />
<SentryUpdater />
</>
)
}
Expand Down