Skip to content

Commit

Permalink
[SENTRY] Context and error description cleanup (#361)
Browse files Browse the repository at this point in the history
* sentry updater

* simplify error description

* simpler networl

* remove user address sentry logging
  • Loading branch information
W3stside authored Apr 7, 2022
1 parent 7bbec39 commit 2028ef3
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
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

0 comments on commit 2028ef3

Please sign in to comment.