From 08dd73bee5eb0368bb8c94d3733e251d34f542a3 Mon Sep 17 00:00:00 2001 From: maciek Date: Thu, 11 May 2023 14:53:38 +0200 Subject: [PATCH] chore: suppress sentry logs when eth fails --- libs/deposits/src/lib/use-deposit-balances.ts | 9 +++++++-- libs/deposits/src/lib/use-get-allowance.ts | 9 +++++++-- libs/deposits/src/lib/use-get-deposit-maximum.ts | 9 +++++++-- libs/deposits/src/lib/use-get-deposited-amount.ts | 9 +++++++-- libs/web3/src/lib/use-get-withdraw-delay.ts | 8 +++++++- libs/withdraws/src/lib/use-complete-withdraw.ts | 8 +++++++- libs/withdraws/src/lib/use-verify-withdrawal.ts | 9 +++++++-- libs/withdraws/src/lib/use-withdraw-asset.tsx | 9 +++++++-- 8 files changed, 56 insertions(+), 14 deletions(-) diff --git a/libs/deposits/src/lib/use-deposit-balances.ts b/libs/deposits/src/lib/use-deposit-balances.ts index ade220c4f..c2aae2f7a 100644 --- a/libs/deposits/src/lib/use-deposit-balances.ts +++ b/libs/deposits/src/lib/use-deposit-balances.ts @@ -6,7 +6,7 @@ import { useGetAllowance } from './use-get-allowance'; import { useGetBalanceOfERC20Token } from './use-get-balance-of-erc20-token'; import { useGetDepositMaximum } from './use-get-deposit-maximum'; import { useGetDepositedAmount } from './use-get-deposited-amount'; -import { isAssetTypeERC20 } from '@vegaprotocol/utils'; +import { isAssetTypeERC20, localLoggerFactory } from '@vegaprotocol/utils'; import { useAccountBalance } from '@vegaprotocol/accounts'; import type { Asset } from '@vegaprotocol/assets'; @@ -63,7 +63,12 @@ export const useDepositBalances = ( allowance: allowance ?? initialState.allowance, }); } catch (err) { - Sentry.captureException(err); + const logger = localLoggerFactory({ application: 'deposits' }); + if (err.message.match(/call revert exception/)) { + logger.info('call revert eth exception', err); + } else { + logger.error(err); + } setState(null); } }, [asset, getAllowance, getBalance, getDepositMaximum, getDepositedAmount]); diff --git a/libs/deposits/src/lib/use-get-allowance.ts b/libs/deposits/src/lib/use-get-allowance.ts index 7e6db2f7d..93ab37513 100644 --- a/libs/deposits/src/lib/use-get-allowance.ts +++ b/libs/deposits/src/lib/use-get-allowance.ts @@ -5,7 +5,7 @@ import { useCallback } from 'react'; import { useEthereumConfig } from '@vegaprotocol/web3'; import BigNumber from 'bignumber.js'; import type { Asset } from '@vegaprotocol/assets'; -import { addDecimal } from '@vegaprotocol/utils'; +import { addDecimal, localLoggerFactory } from '@vegaprotocol/utils'; export const useGetAllowance = ( contract: Token | null, @@ -26,7 +26,12 @@ export const useGetAllowance = ( return new BigNumber(addDecimal(res.toString(), asset.decimals)); } catch (err) { - Sentry.captureException(err); + const logger = localLoggerFactory({ application: 'deposits' }); + if (err.message.match(/call revert exception/)) { + logger.info('call revert eth exception', err); + } else { + logger.error(err); + } return; } }, [contract, account, config, asset]); diff --git a/libs/deposits/src/lib/use-get-deposit-maximum.ts b/libs/deposits/src/lib/use-get-deposit-maximum.ts index 2c343c5de..c4cd13c6d 100644 --- a/libs/deposits/src/lib/use-get-deposit-maximum.ts +++ b/libs/deposits/src/lib/use-get-deposit-maximum.ts @@ -2,7 +2,7 @@ import { useCallback } from 'react'; import * as Sentry from '@sentry/react'; import BigNumber from 'bignumber.js'; import type { Asset } from '@vegaprotocol/assets'; -import { addDecimal } from '@vegaprotocol/utils'; +import { addDecimal, localLoggerFactory } from '@vegaprotocol/utils'; import type { CollateralBridge } from '@vegaprotocol/smart-contracts'; export const useGetDepositMaximum = ( @@ -20,7 +20,12 @@ export const useGetDepositMaximum = ( const max = new BigNumber(addDecimal(res.toString(), asset.decimals)); return max.isEqualTo(0) ? new BigNumber(Infinity) : max; } catch (err) { - Sentry.captureException(err); + const logger = localLoggerFactory({ application: 'deposits' }); + if (err.message.match(/call revert exception/)) { + logger.info('call revert eth exception', err); + } else { + logger.error(err); + } return; } }, [contract, asset]); diff --git a/libs/deposits/src/lib/use-get-deposited-amount.ts b/libs/deposits/src/lib/use-get-deposited-amount.ts index 89ed89ba3..2548a08a0 100644 --- a/libs/deposits/src/lib/use-get-deposited-amount.ts +++ b/libs/deposits/src/lib/use-get-deposited-amount.ts @@ -4,7 +4,7 @@ import { ethers } from 'ethers'; import { useEthereumConfig } from '@vegaprotocol/web3'; import BigNumber from 'bignumber.js'; import type { Asset } from '@vegaprotocol/assets'; -import { addDecimal } from '@vegaprotocol/utils'; +import { addDecimal, localLoggerFactory } from '@vegaprotocol/utils'; import { useWeb3React } from '@web3-react/core'; export const useGetDepositedAmount = (asset: Asset | undefined) => { @@ -41,7 +41,12 @@ export const useGetDepositedAmount = (asset: Asset | undefined) => { const value = new BigNumber(res, 16).toString(); return new BigNumber(addDecimal(value, asset.decimals)); } catch (err) { - Sentry.captureException(err); + const logger = localLoggerFactory({ application: 'deposits' }); + if (err.message.match(/call revert exception/)) { + logger.info('call revert eth exception', err); + } else { + logger.error(err); + } return; } }, [provider, asset, config, account]); diff --git a/libs/web3/src/lib/use-get-withdraw-delay.ts b/libs/web3/src/lib/use-get-withdraw-delay.ts index e44d67d17..324d3d7bc 100644 --- a/libs/web3/src/lib/use-get-withdraw-delay.ts +++ b/libs/web3/src/lib/use-get-withdraw-delay.ts @@ -1,6 +1,7 @@ import * as Sentry from '@sentry/react'; import { useBridgeContract } from './use-bridge-contract'; import { useCallback } from 'react'; +import { localLoggerFactory } from '@vegaprotocol/utils'; /** * Gets the delay in seconds thats required if the withdrawal amount is @@ -13,7 +14,12 @@ export const useGetWithdrawDelay = () => { const res = await contract?.default_withdraw_delay(); return res.toNumber(); } catch (err) { - Sentry.captureException(err); + const logger = localLoggerFactory({ application: 'web3' }); + if (err.message.match(/call revert exception/)) { + logger.info('call revert eth exception', err); + } else { + logger.error(err); + } } }, [contract]); diff --git a/libs/withdraws/src/lib/use-complete-withdraw.ts b/libs/withdraws/src/lib/use-complete-withdraw.ts index 5c81d5973..bbd8444c1 100644 --- a/libs/withdraws/src/lib/use-complete-withdraw.ts +++ b/libs/withdraws/src/lib/use-complete-withdraw.ts @@ -7,6 +7,7 @@ import { useEthereumTransaction, } from '@vegaprotocol/web3'; import { useCallback, useEffect, useState } from 'react'; +import { localLoggerFactory } from '@vegaprotocol/utils'; import { Erc20ApprovalDocument } from './__generated__/Erc20Approval'; import type { Erc20ApprovalQuery, @@ -55,7 +56,12 @@ export const useCompleteWithdraw = () => { approval.signatures ); } catch (err) { - captureException(err); + const logger = localLoggerFactory({ application: 'deposits' }); + if (err.message.match(/call revert exception/)) { + logger.info('call revert eth exception', err); + } else { + logger.error(err); + } } }, [contract, query, perform] diff --git a/libs/withdraws/src/lib/use-verify-withdrawal.ts b/libs/withdraws/src/lib/use-verify-withdrawal.ts index 153701159..4ba14880e 100644 --- a/libs/withdraws/src/lib/use-verify-withdrawal.ts +++ b/libs/withdraws/src/lib/use-verify-withdrawal.ts @@ -1,7 +1,7 @@ import { useCallback, useState } from 'react'; import { captureException } from '@sentry/react'; import BigNumber from 'bignumber.js'; -import { addDecimal } from '@vegaprotocol/utils'; +import { addDecimal, localLoggerFactory } from '@vegaprotocol/utils'; import { t } from '@vegaprotocol/i18n'; import { ApprovalStatus, @@ -120,7 +120,12 @@ export const useVerifyWithdrawal = () => { return true; } catch (err) { - captureException(err); + const logger = localLoggerFactory({ application: 'withdraws' }); + if (err.message.match(/call revert exception/)) { + logger.info('call revert eth exception', err); + } else { + logger.error(err); + } setState({ status: ApprovalStatus.Error, }); diff --git a/libs/withdraws/src/lib/use-withdraw-asset.tsx b/libs/withdraws/src/lib/use-withdraw-asset.tsx index 3cb6759bc..7e2cb8ec4 100644 --- a/libs/withdraws/src/lib/use-withdraw-asset.tsx +++ b/libs/withdraws/src/lib/use-withdraw-asset.tsx @@ -1,6 +1,6 @@ import { captureException } from '@sentry/react'; import type { Asset } from '@vegaprotocol/assets'; -import { addDecimal } from '@vegaprotocol/utils'; +import { addDecimal, localLoggerFactory } from '@vegaprotocol/utils'; import * as Schema from '@vegaprotocol/types'; import BigNumber from 'bignumber.js'; import { useCallback, useEffect } from 'react'; @@ -47,7 +47,12 @@ export const useWithdrawAsset = ( threshold = result[0]; delay = result[1]; } catch (err) { - captureException(err); + const logger = localLoggerFactory({ application: 'withdraws' }); + if (err.message.match(/call revert exception/)) { + logger.info('call revert eth exception', err); + } else { + logger.error(err); + } } update({ asset, balance, min, threshold, delay });