chore(trading): suppress sentry logs when eth fails (#3726)
Co-authored-by: Matthew Russell <mattrussell36@gmail.com>
This commit is contained in:
parent
54161a6dba
commit
59993e3ea6
@ -1,12 +1,11 @@
|
||||
import { useBridgeContract, useTokenContract } from '@vegaprotocol/web3';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as Sentry from '@sentry/react';
|
||||
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';
|
||||
|
||||
@ -43,7 +42,9 @@ export const useDepositBalances = (asset: Asset | undefined) => {
|
||||
|
||||
const getBalances = useCallback(async () => {
|
||||
if (!asset) return;
|
||||
const logger = localLoggerFactory({ application: 'deposits' });
|
||||
try {
|
||||
logger.info('get deposit balances', { asset: asset.id });
|
||||
setState(null);
|
||||
const [max, deposited, balance, allowance] = await Promise.all([
|
||||
getDepositMaximum(),
|
||||
@ -59,7 +60,7 @@ export const useDepositBalances = (asset: Asset | undefined) => {
|
||||
allowance: allowance ?? initialState.allowance,
|
||||
});
|
||||
} catch (err) {
|
||||
Sentry.captureException(err);
|
||||
logger.error('get deposit balances', err);
|
||||
setState(null);
|
||||
}
|
||||
}, [asset, getAllowance, getBalance, getDepositMaximum, getDepositedAmount]);
|
||||
|
@ -1,11 +1,10 @@
|
||||
import type { Token } from '@vegaprotocol/smart-contracts';
|
||||
import * as Sentry from '@sentry/react';
|
||||
import { useWeb3React } from '@web3-react/core';
|
||||
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,
|
||||
@ -18,15 +17,20 @@ export const useGetAllowance = (
|
||||
if (!contract || !account || !config || !asset) {
|
||||
return;
|
||||
}
|
||||
|
||||
const logger = localLoggerFactory({ application: 'deposits' });
|
||||
try {
|
||||
logger.info('get allowance', {
|
||||
account,
|
||||
contractAddress: config.collateral_bridge_contract.address,
|
||||
});
|
||||
const res = await contract.allowance(
|
||||
account,
|
||||
config.collateral_bridge_contract.address
|
||||
);
|
||||
|
||||
return new BigNumber(addDecimal(res.toString(), asset.decimals));
|
||||
} catch (err) {
|
||||
Sentry.captureException(err);
|
||||
logger.error('get allowance', err);
|
||||
return;
|
||||
}
|
||||
}, [contract, account, config, asset]);
|
||||
|
@ -1,8 +1,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 = (
|
||||
@ -13,14 +12,16 @@ export const useGetDepositMaximum = (
|
||||
if (!contract || !asset || asset.source.__typename !== 'ERC20') {
|
||||
return;
|
||||
}
|
||||
const logger = localLoggerFactory({ application: 'deposits' });
|
||||
try {
|
||||
logger.info('get deposit maximum', { asset: asset.id });
|
||||
const res = await contract.get_deposit_maximum(
|
||||
asset.source.contractAddress
|
||||
);
|
||||
const max = new BigNumber(addDecimal(res.toString(), asset.decimals));
|
||||
return max.isEqualTo(0) ? new BigNumber(Infinity) : max;
|
||||
} catch (err) {
|
||||
Sentry.captureException(err);
|
||||
logger.error('get deposit maximum', err);
|
||||
return;
|
||||
}
|
||||
}, [contract, asset]);
|
||||
|
@ -1,10 +1,9 @@
|
||||
import { useCallback } from 'react';
|
||||
import * as Sentry from '@sentry/react';
|
||||
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) => {
|
||||
@ -22,8 +21,9 @@ export const useGetDepositedAmount = (asset: Asset | undefined) => {
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const logger = localLoggerFactory({ application: 'deposits' });
|
||||
try {
|
||||
logger.info('get deposited amount', { asset: asset.id });
|
||||
const abicoder = new ethers.utils.AbiCoder();
|
||||
const innerHash = ethers.utils.keccak256(
|
||||
abicoder.encode(['address', 'uint256'], [account, 4])
|
||||
@ -41,7 +41,7 @@ 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);
|
||||
logger.error('get deposited amount', err);
|
||||
return;
|
||||
}
|
||||
}, [provider, asset, config, account]);
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as Sentry from '@sentry/browser';
|
||||
import * as Sentry from '@sentry/react';
|
||||
import type { Severity } from '@sentry/types/types/severity';
|
||||
import { LocalLogger, localLoggerFactory } from './local-logger';
|
||||
|
||||
|
@ -1,7 +1,12 @@
|
||||
import * as Sentry from '@sentry/browser';
|
||||
import * as Sentry from '@sentry/react';
|
||||
import type { Scope } from '@sentry/browser';
|
||||
import type { Severity, Breadcrumb, Primitive } from '@sentry/types';
|
||||
|
||||
declare global {
|
||||
// eslint-disable-next-line no-var
|
||||
var __LOGGER_SILENT_MODE__: boolean;
|
||||
}
|
||||
|
||||
const LogLevels = [
|
||||
'fatal',
|
||||
'error',
|
||||
@ -13,7 +18,14 @@ const LogLevels = [
|
||||
'silent',
|
||||
];
|
||||
type LogLevelsType = typeof LogLevels[number];
|
||||
type ConsoleArg = string | number | boolean | bigint | symbol | object;
|
||||
type ConsoleArg =
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| bigint
|
||||
| symbol
|
||||
| object
|
||||
| unknown;
|
||||
type ConsoleMethod = {
|
||||
[K in keyof Console]: Console[K] extends (...args: ConsoleArg[]) => unknown
|
||||
? K
|
||||
@ -83,7 +95,10 @@ export class LocalLogger {
|
||||
logMethod: ConsoleMethod,
|
||||
args: ConsoleArg[]
|
||||
) {
|
||||
if (this.numberLogLevel <= LocalLogger.levelLogMap[level]) {
|
||||
if (
|
||||
this.numberLogLevel <= LocalLogger.levelLogMap[level] &&
|
||||
!global.__LOGGER_SILENT_MODE__
|
||||
) {
|
||||
console[logMethod].apply(console, [
|
||||
`${this._application}:${level}: `,
|
||||
...args,
|
||||
@ -110,7 +125,7 @@ export class LocalLogger {
|
||||
if (this.tags.length) {
|
||||
this.tags.forEach((tag) => {
|
||||
const found = args.reduce((aggr, arg) => {
|
||||
if (typeof arg === 'object' && tag in arg) {
|
||||
if (arg && typeof arg === 'object' && tag in arg) {
|
||||
// @ts-ignore change object to record
|
||||
aggr = arg[tag] as unknown as Primitive | object;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
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
|
||||
@ -9,11 +9,13 @@ import { useCallback } from 'react';
|
||||
export const useGetWithdrawDelay = () => {
|
||||
const contract = useBridgeContract();
|
||||
const getDelay = useCallback(async () => {
|
||||
const logger = localLoggerFactory({ application: 'web3' });
|
||||
try {
|
||||
logger.info('get withdraw delay', { contract: contract?.toString() });
|
||||
const res = await contract?.default_withdraw_delay();
|
||||
return res.toNumber();
|
||||
} catch (err) {
|
||||
Sentry.captureException(err);
|
||||
logger.error('get withdraw delay', err);
|
||||
}
|
||||
}, [contract]);
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { useApolloClient } from '@apollo/client';
|
||||
import { captureException } from '@sentry/react';
|
||||
import type { CollateralBridge } from '@vegaprotocol/smart-contracts';
|
||||
import {
|
||||
EthTxStatus,
|
||||
@ -7,6 +6,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,
|
||||
@ -28,10 +28,12 @@ export const useCompleteWithdraw = () => {
|
||||
async (withdrawalId: string) => {
|
||||
setId(withdrawalId);
|
||||
|
||||
const logger = localLoggerFactory({ application: 'deposits' });
|
||||
try {
|
||||
if (!contract) {
|
||||
return;
|
||||
}
|
||||
logger.info('get withdraw approval', { withdrawalId });
|
||||
const res = await query<
|
||||
Erc20ApprovalQuery,
|
||||
Erc20ApprovalQueryVariables
|
||||
@ -45,7 +47,7 @@ export const useCompleteWithdraw = () => {
|
||||
if (!approval) {
|
||||
throw new Error('Could not retrieve withdrawal approval');
|
||||
}
|
||||
|
||||
logger.info('withdraw transaction', { approval });
|
||||
perform(
|
||||
approval.assetSource,
|
||||
approval.amount,
|
||||
@ -55,7 +57,7 @@ export const useCompleteWithdraw = () => {
|
||||
approval.signatures
|
||||
);
|
||||
} catch (err) {
|
||||
captureException(err);
|
||||
logger.error('withdraw transaction', err);
|
||||
}
|
||||
},
|
||||
[contract, query, perform]
|
||||
|
@ -1,7 +1,6 @@
|
||||
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,
|
||||
@ -54,7 +53,9 @@ export const useVerifyWithdrawal = () => {
|
||||
|
||||
const verify = useCallback(
|
||||
async (withdrawal: WithdrawalFieldsFragment) => {
|
||||
const logger = localLoggerFactory({ application: 'withdraws' });
|
||||
try {
|
||||
logger.info('verify withdrawal', withdrawal);
|
||||
setState({ dialogOpen: true });
|
||||
|
||||
if (withdrawal.asset.source.__typename !== 'ERC20') {
|
||||
@ -120,7 +121,7 @@ export const useVerifyWithdrawal = () => {
|
||||
|
||||
return true;
|
||||
} catch (err) {
|
||||
captureException(err);
|
||||
logger.error('use verify withdrawal', err);
|
||||
setState({
|
||||
status: ApprovalStatus.Error,
|
||||
});
|
||||
|
@ -1,6 +1,5 @@
|
||||
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';
|
||||
@ -41,13 +40,14 @@ export const useWithdrawAsset = (
|
||||
// and subsequent delay if withdrawal amount is larger than it
|
||||
let threshold = new BigNumber(0);
|
||||
let delay = 0;
|
||||
|
||||
const logger = localLoggerFactory({ application: 'withdraws' });
|
||||
try {
|
||||
logger.info('get withdraw asset data', { asset: asset?.id });
|
||||
const result = await Promise.all([getThreshold(asset), getDelay()]);
|
||||
threshold = result[0];
|
||||
delay = result[1];
|
||||
} catch (err) {
|
||||
captureException(err);
|
||||
logger.error('get withdraw asset data', err);
|
||||
}
|
||||
|
||||
update({ asset, balance, min, threshold, delay });
|
||||
|
@ -1,4 +1,10 @@
|
||||
import '@testing-library/jest-dom';
|
||||
import ResizeObserver from 'resize-observer-polyfill';
|
||||
|
||||
global.ResizeObserver = ResizeObserver;
|
||||
|
||||
declare global {
|
||||
// eslint-disable-next-line no-var
|
||||
var __LOGGER_SILENT_MODE__: boolean;
|
||||
}
|
||||
|
||||
global.__LOGGER_SILENT_MODE__ = true;
|
||||
|
Loading…
Reference in New Issue
Block a user