Skip to content

Commit

Permalink
add setnry environment #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Ridel1e committed Aug 24, 2023
1 parent f6952dd commit 1a65ee3
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 120 deletions.
54 changes: 27 additions & 27 deletions src/common/services/ErrorLogs.ts
Original file line number Diff line number Diff line change
@@ -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',
);
};
7 changes: 1 addition & 6 deletions src/components/ConfirmationModal/ConfirmationModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { TxId } from '@ergolabs/ergo-sdk';
import {
Button,
CloseCircleOutlined,
Flex,
Modal,
Expand All @@ -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';

Expand Down Expand Up @@ -156,14 +154,11 @@ const ErrorModalContent = (
<Trans>Transaction rejected</Trans>
</Typography.Body>
</Flex.Item>
<Flex.Item marginBottom={2}>
<Flex.Item>
<Typography.Body align="center" secondary>
<Trans>Try again later</Trans>
</Typography.Body>
</Flex.Item>
<Button size="large" type="dashed" onClick={downloadErrorLog}>
<Trans>Download Error log</Trans>
</Button>
</Flex>
);
};
Expand Down
9 changes: 0 additions & 9 deletions src/components/common/Layout/Header/BurgerMenu/BurgerMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
Button,
DownloadOutlined,
Dropdown,
FileTextOutlined,
GithubOutlined,
Expand All @@ -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';
Expand Down Expand Up @@ -102,13 +100,6 @@ const BurgerMenu = (): JSX.Element => {
setIsMainMenu(false);
},
},
{
title: t`Download Error Log`,
icon: <DownloadOutlined />,
onClick: () => {
downloadErrorLog();
},
},
];

const changeLanguage = (locale: string) => {
Expand Down
35 changes: 12 additions & 23 deletions src/network/cardano/api/operations/deposit.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 = (
Expand Down Expand Up @@ -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]
Expand Down
22 changes: 5 additions & 17 deletions src/network/cardano/api/operations/redeem.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 = (
Expand Down
13 changes: 5 additions & 8 deletions src/network/cardano/api/operations/refund.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -133,8 +128,10 @@ const walletRefund = (txId: TxId): Observable<TxId> =>
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 = (
Expand Down
32 changes: 10 additions & 22 deletions src/network/cardano/api/operations/swap.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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<SwapFormModel>): Observable<TxId> => {
Expand Down Expand Up @@ -192,10 +177,13 @@ export const useSwapValidators = (): OperationValidator<SwapFormModel>[] => {
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
Expand Down
7 changes: 5 additions & 2 deletions src/network/ergo/operations/swap/nativeFee/ergopaySwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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'),
}),
);
7 changes: 5 additions & 2 deletions src/network/ergo/operations/swap/nativeFee/walletSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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'),
}),
);
7 changes: 5 additions & 2 deletions src/network/ergo/operations/swap/spfFee/ergopaySwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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'),
}),
);
6 changes: 4 additions & 2 deletions src/network/ergo/operations/swap/spfFee/walletSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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'),
}),
);

0 comments on commit 1a65ee3

Please sign in to comment.