From 1a65ee3b233323059e0a473e96157fc4ef91fbba Mon Sep 17 00:00:00 2001 From: ridel1e Date: Thu, 24 Aug 2023 09:27:07 +0300 Subject: [PATCH] add setnry environment #2 --- src/common/services/ErrorLogs.ts | 54 +++++++++---------- .../ConfirmationModal/ConfirmationModal.tsx | 7 +-- .../Layout/Header/BurgerMenu/BurgerMenu.tsx | 9 ---- .../cardano/api/operations/deposit.tsx | 35 +++++------- src/network/cardano/api/operations/redeem.tsx | 22 ++------ src/network/cardano/api/operations/refund.ts | 13 ++--- src/network/cardano/api/operations/swap.tsx | 32 ++++------- .../operations/swap/nativeFee/ergopaySwap.ts | 7 ++- .../operations/swap/nativeFee/walletSwap.ts | 7 ++- .../operations/swap/spfFee/ergopaySwap.ts | 7 ++- .../ergo/operations/swap/spfFee/walletSwap.ts | 6 ++- 11 files changed, 79 insertions(+), 120 deletions(-) diff --git a/src/common/services/ErrorLogs.ts b/src/common/services/ErrorLogs.ts index 591ae735a..f25825167 100644 --- a/src/common/services/ErrorLogs.ts +++ b/src/common/services/ErrorLogs.ts @@ -1,40 +1,40 @@ import { Severity } from '@sentry/react'; -import { saveAs } from 'file-saver'; - -const errorLogs: { meta: any; error: any }[] = []; +import * as Sentry from '@sentry/react'; +import { TxCandidate } from '@spectrumlabs/cardano-dex-sdk'; interface OperationError { readonly level: Severity; readonly error: Error; } +const jsonReplacer = (_, value) => + typeof value === 'bigint' ? value.toString() : value; + +export const captureOperationError = ( + error: Error | string, + network: 'cardano' | 'ergo', + operation: string, + candidate?: TxCandidate, + context?: object, +): void => { + const message = typeof error === 'string' ? error : error.message; + + Sentry.captureMessage(message, { + level: Severity.Critical, + extra: { + candidate: candidate + ? JSON.stringify(candidate, jsonReplacer, 2) + : undefined, + context: context ? JSON.stringify(context, jsonReplacer, 2) : undefined, + network, + operation, + }, + }); +}; + export const toSentryOperationError = ( error: Error | string, ): OperationError => ({ level: Severity.Critical, error: typeof error === 'string' ? new Error(error as string) : error, }); - -export const addErrorLog = - (meta: any) => - (error: Error): void => { - errorLogs.push({ meta, error: error?.message || error }); - }; - -export const downloadErrorLog = () => { - saveAs( - new Blob( - [ - JSON.stringify( - errorLogs, - (_, value) => (typeof value === 'bigint' ? value.toString() : value), - 2, - ), - ], - { - type: 'text/plain;charset=utf-8', - }, - ), - 'logs.txt', - ); -}; diff --git a/src/components/ConfirmationModal/ConfirmationModal.tsx b/src/components/ConfirmationModal/ConfirmationModal.tsx index 0930a7108..3bafb4347 100644 --- a/src/components/ConfirmationModal/ConfirmationModal.tsx +++ b/src/components/ConfirmationModal/ConfirmationModal.tsx @@ -1,6 +1,5 @@ import { TxId } from '@ergolabs/ergo-sdk'; import { - Button, CloseCircleOutlined, Flex, Modal, @@ -20,7 +19,6 @@ import { ReactComponent as DiscordIcon } from '../../assets/icons/social/Discord import { ReactComponent as TelegramIcon } from '../../assets/icons/social/Telegram.svg'; import { AssetLock } from '../../common/models/AssetLock'; import { Currency } from '../../common/models/Currency'; -import { downloadErrorLog } from '../../common/services/ErrorLogs'; import { exploreTx } from '../../gateway/utils/exploreAddress'; import { getLockingPeriodString } from '../../pages/Liquidity/utils'; @@ -156,14 +154,11 @@ const ErrorModalContent = ( Transaction rejected - + Try again later - ); }; diff --git a/src/components/common/Layout/Header/BurgerMenu/BurgerMenu.tsx b/src/components/common/Layout/Header/BurgerMenu/BurgerMenu.tsx index b6945d0e8..6a0b1b751 100644 --- a/src/components/common/Layout/Header/BurgerMenu/BurgerMenu.tsx +++ b/src/components/common/Layout/Header/BurgerMenu/BurgerMenu.tsx @@ -1,6 +1,5 @@ import { Button, - DownloadOutlined, Dropdown, FileTextOutlined, GithubOutlined, @@ -24,7 +23,6 @@ import { LOCALE_LABEL, SUPPORTED_LOCALES, } from '../../../../../common/constants/locales'; -import { downloadErrorLog } from '../../../../../common/services/ErrorLogs'; import { useApplicationSettings } from '../../../../../context'; import { useQuery } from '../../../../../hooks/useQuery'; import { ThemeSwitch } from '../../../../ThemeSwitch/ThemeSwitch'; @@ -102,13 +100,6 @@ const BurgerMenu = (): JSX.Element => { setIsMainMenu(false); }, }, - { - title: t`Download Error Log`, - icon: , - onClick: () => { - downloadErrorLog(); - }, - }, ]; const changeLanguage = (locale: string) => { diff --git a/src/network/cardano/api/operations/deposit.tsx b/src/network/cardano/api/operations/deposit.tsx index 36324e241..cd7be0c9a 100644 --- a/src/network/cardano/api/operations/deposit.tsx +++ b/src/network/cardano/api/operations/deposit.tsx @@ -1,28 +1,13 @@ import { Transaction } from '@emurgo/cardano-serialization-lib-nodejs'; import { t } from '@lingui/macro'; -import * as Sentry from '@sentry/react'; -import { Severity } from '@sentry/react'; import { TxCandidate } from '@spectrumlabs/cardano-dex-sdk'; import { DepositTxInfo } from '@spectrumlabs/cardano-dex-sdk/build/main/amm/interpreters/ammTxBuilder/depositAmmTxBuilder'; import { NetworkParams } from '@spectrumlabs/cardano-dex-sdk/build/main/cardano/entities/env'; -import { - catchError, - first, - map, - Observable, - Subject, - switchMap, - tap, - throwError, - zip, -} from 'rxjs'; +import { first, map, Observable, Subject, switchMap, tap, zip } from 'rxjs'; import { Balance } from '../../../../common/models/Balance'; import { Currency } from '../../../../common/models/Currency'; -import { - addErrorLog, - toSentryOperationError, -} from '../../../../common/services/ErrorLogs'; +import { captureOperationError } from '../../../../common/services/ErrorLogs'; import { TxId } from '../../../../common/types'; import { openConfirmationModal, @@ -104,8 +89,9 @@ export const walletDeposit = ( }), ), switchMap((tx) => submitTx(tx)), - tap({ error: addErrorLog({ op: 'deposit' }) }), - catchError((err) => throwError(toSentryOperationError(err))), + tap({ + error: (error) => captureOperationError(error, 'cardano', 'deposit'), + }), ); export const deposit = ( @@ -172,10 +158,13 @@ export const useDepositValidators = ) => { const error = data[3]; if (error && !data[0]) { - Sentry.captureMessage(error?.message || (error as any), { - level: Severity.Critical, - }); - addErrorLog({ op: 'depositValidation', ctx: data[2] })(error); + captureOperationError( + error, + 'cardano', + 'depositValidation', + data[1], + data[2], + ); } return data[0] diff --git a/src/network/cardano/api/operations/redeem.tsx b/src/network/cardano/api/operations/redeem.tsx index 6c8e1b140..b6eba6338 100644 --- a/src/network/cardano/api/operations/redeem.tsx +++ b/src/network/cardano/api/operations/redeem.tsx @@ -1,23 +1,10 @@ import { Transaction } from '@emurgo/cardano-serialization-lib-nodejs'; import { RedeemTxInfo, TxCandidate } from '@spectrumlabs/cardano-dex-sdk'; import { NetworkParams } from '@spectrumlabs/cardano-dex-sdk/build/main/cardano/entities/env'; -import { - catchError, - first, - map, - Observable, - Subject, - switchMap, - tap, - throwError, - zip, -} from 'rxjs'; +import { first, map, Observable, Subject, switchMap, tap, zip } from 'rxjs'; import { Currency } from '../../../../common/models/Currency'; -import { - addErrorLog, - toSentryOperationError, -} from '../../../../common/services/ErrorLogs'; +import { captureOperationError } from '../../../../common/services/ErrorLogs'; import { TxId } from '../../../../common/types'; import { openConfirmationModal, @@ -89,8 +76,9 @@ export const walletRedeem = ( }), ), switchMap((tx) => submitTx(tx)), - tap({ error: addErrorLog({ op: 'redeem' }) }), - catchError((err) => throwError(toSentryOperationError(err))), + tap({ + error: (error) => captureOperationError(error, 'cardano', 'redeem'), + }), ); export const redeem = ( diff --git a/src/network/cardano/api/operations/refund.ts b/src/network/cardano/api/operations/refund.ts index 19b88c1fb..68eac14a6 100644 --- a/src/network/cardano/api/operations/refund.ts +++ b/src/network/cardano/api/operations/refund.ts @@ -21,7 +21,6 @@ import { import { NetworkParams } from '@spectrumlabs/cardano-dex-sdk/build/main/cardano/entities/env'; import { CardanoWasm } from '@spectrumlabs/cardano-dex-sdk/build/main/utils/rustLoader'; import { - catchError, combineLatest, first, map, @@ -31,15 +30,11 @@ import { Subject, switchMap, tap, - throwError, zip, } from 'rxjs'; import { Currency } from '../../../../common/models/Currency'; -import { - addErrorLog, - toSentryOperationError, -} from '../../../../common/services/ErrorLogs'; +import { captureOperationError } from '../../../../common/services/ErrorLogs'; import { TxId } from '../../../../common/types'; import { openConfirmationModal, @@ -133,8 +128,10 @@ const walletRefund = (txId: TxId): Observable => return tx; }), switchMap((tx) => submitTx(tx, true)), - tap({ error: addErrorLog({ txId, op: 'refund' }) }), - catchError((err) => throwError(toSentryOperationError(err))), + tap({ + error: (error) => + captureOperationError(error, 'cardano', 'refund', undefined, { txId }), + }), ); export const refund = ( diff --git a/src/network/cardano/api/operations/swap.tsx b/src/network/cardano/api/operations/swap.tsx index 04a49c449..3187523b8 100644 --- a/src/network/cardano/api/operations/swap.tsx +++ b/src/network/cardano/api/operations/swap.tsx @@ -1,24 +1,10 @@ import { Transaction } from '@emurgo/cardano-serialization-lib-nodejs'; import { t } from '@lingui/macro'; -import * as Sentry from '@sentry/react'; -import { Severity } from '@sentry/react'; import { SwapTxInfo, TxCandidate } from '@spectrumlabs/cardano-dex-sdk'; -import { - catchError, - first, - map, - Observable, - Subject, - switchMap, - tap, - throwError, -} from 'rxjs'; +import { first, map, Observable, Subject, switchMap, tap } from 'rxjs'; import { Currency } from '../../../../common/models/Currency'; -import { - addErrorLog, - toSentryOperationError, -} from '../../../../common/services/ErrorLogs'; +import { captureOperationError } from '../../../../common/services/ErrorLogs'; import { Nitro, Percent, TxId } from '../../../../common/types'; import { openConfirmationModal, @@ -109,8 +95,7 @@ export const walletSwap = ( }), ), switchMap((tx) => submitTx(tx)), - tap({ error: addErrorLog({ op: 'swap' }) }), - catchError((err) => throwError(toSentryOperationError(err))), + tap({ error: (error) => captureOperationError(error, 'cardano', 'swap') }), ); export const swap = (data: Required): Observable => { @@ -192,10 +177,13 @@ export const useSwapValidators = (): OperationValidator[] => { const error = data[3]; if (error && !data[0]) { - Sentry.captureMessage(error?.message || (error as any), { - level: Severity.Critical, - }); - addErrorLog({ op: 'swapValidation', ctx: data[2] })(error); + captureOperationError( + error, + 'cardano', + 'swapValidation', + data[1], + data[2], + ); } return data[0] ? undefined diff --git a/src/network/ergo/operations/swap/nativeFee/ergopaySwap.ts b/src/network/ergo/operations/swap/nativeFee/ergopaySwap.ts index 432afaef4..2cb69ff70 100644 --- a/src/network/ergo/operations/swap/nativeFee/ergopaySwap.ts +++ b/src/network/ergo/operations/swap/nativeFee/ergopaySwap.ts @@ -10,7 +10,7 @@ import { import { applicationConfig } from '../../../../../applicationConfig'; // import { panalytics } from '../../../../../common/analytics'; import { Currency } from '../../../../../common/models/Currency'; -import { addErrorLog } from '../../../../../common/services/ErrorLogs'; +import { captureOperationError } from '../../../../../common/services/ErrorLogs'; import { TxId } from '../../../../../common/types'; import { ErgoAmmPool } from '../../../api/ammPools/ErgoAmmPool'; import { ergoPayMessageManager } from '../../common/ergopayMessageManager'; @@ -48,5 +48,8 @@ export const ergoPaySwap = ( }), ), timeout(applicationConfig.operationTimeoutTime), - tap({ error: addErrorLog({ op: 'Native ergopay swap' }) }), + tap({ + error: (error) => + captureOperationError(error, 'ergo', 'Native ergopay swap'), + }), ); diff --git a/src/network/ergo/operations/swap/nativeFee/walletSwap.ts b/src/network/ergo/operations/swap/nativeFee/walletSwap.ts index 452282c0b..bd5584cc7 100644 --- a/src/network/ergo/operations/swap/nativeFee/walletSwap.ts +++ b/src/network/ergo/operations/swap/nativeFee/walletSwap.ts @@ -2,7 +2,7 @@ import { from as fromPromise, Observable, switchMap, tap, timeout } from 'rxjs'; import { applicationConfig } from '../../../../../applicationConfig'; import { Currency } from '../../../../../common/models/Currency'; -import { addErrorLog } from '../../../../../common/services/ErrorLogs'; +import { captureOperationError } from '../../../../../common/services/ErrorLogs'; import { TxId } from '../../../../../common/types'; import { ErgoAmmPool } from '../../../api/ammPools/ErgoAmmPool'; import { nativeFeePoolActions } from '../../common/nativeFeePoolActions'; @@ -29,5 +29,8 @@ export const walletSwap = ( }), ), timeout(applicationConfig.operationTimeoutTime), - tap({ error: addErrorLog({ op: 'Native wallet swap' }) }), + tap({ + error: (error) => + captureOperationError(error, 'ergo', 'Native wallet swap'), + }), ); diff --git a/src/network/ergo/operations/swap/spfFee/ergopaySwap.ts b/src/network/ergo/operations/swap/spfFee/ergopaySwap.ts index 61a11919d..156813385 100644 --- a/src/network/ergo/operations/swap/spfFee/ergopaySwap.ts +++ b/src/network/ergo/operations/swap/spfFee/ergopaySwap.ts @@ -10,7 +10,7 @@ import { import { applicationConfig } from '../../../../../applicationConfig'; // import { panalytics } from '../../../../../common/analytics'; import { Currency } from '../../../../../common/models/Currency'; -import { addErrorLog } from '../../../../../common/services/ErrorLogs'; +import { captureOperationError } from '../../../../../common/services/ErrorLogs'; import { TxId } from '../../../../../common/types'; import { ErgoAmmPool } from '../../../api/ammPools/ErgoAmmPool'; import { ergoPayMessageManager } from '../../common/ergopayMessageManager'; @@ -48,5 +48,8 @@ export const ergoPaySwap = ( }), ), timeout(applicationConfig.operationTimeoutTime), - tap({ error: addErrorLog({ op: 'Spf ergopay swap' }) }), + tap({ + error: (error) => + captureOperationError(error, 'ergo', 'Spf ergopay swap'), + }), ); diff --git a/src/network/ergo/operations/swap/spfFee/walletSwap.ts b/src/network/ergo/operations/swap/spfFee/walletSwap.ts index 94a0fbb24..5098e3e42 100644 --- a/src/network/ergo/operations/swap/spfFee/walletSwap.ts +++ b/src/network/ergo/operations/swap/spfFee/walletSwap.ts @@ -2,7 +2,7 @@ import { from as fromPromise, Observable, switchMap, tap, timeout } from 'rxjs'; import { applicationConfig } from '../../../../../applicationConfig'; import { Currency } from '../../../../../common/models/Currency'; -import { addErrorLog } from '../../../../../common/services/ErrorLogs'; +import { captureOperationError } from '../../../../../common/services/ErrorLogs'; import { TxId } from '../../../../../common/types'; import { ErgoAmmPool } from '../../../api/ammPools/ErgoAmmPool'; import { spfFeePoolActions } from '../../common/nativeFeePoolActions'; @@ -29,5 +29,7 @@ export const walletSwap = ( }), ), timeout(applicationConfig.operationTimeoutTime), - tap({ error: addErrorLog({ op: 'Spf wallet swap' }) }), + tap({ + error: (error) => captureOperationError(error, 'ergo', 'Spf wallet swap'), + }), );