Skip to content

Commit

Permalink
add manually sentry logs to validators
Browse files Browse the repository at this point in the history
  • Loading branch information
Ridel1e committed Aug 22, 2023
1 parent b34fdf7 commit 5cac7c5
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 52 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@sentry/react": "^6.16.1",
"@sentry/tracing": "^6.16.1",
"@spectrumlabs/analytics": "^1.1.8",
"@spectrumlabs/cardano-dex-sdk": "^0.1.170",
"@spectrumlabs/cardano-dex-sdk": "^0.1.172",
"@types/file-saver": "^2.0.5",
"@types/lodash": "^4.14.172",
"@types/numeral": "^2.0.2",
Expand Down
13 changes: 13 additions & 0 deletions src/common/services/ErrorLogs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import { Severity } from '@sentry/react';
import { saveAs } from 'file-saver';

const errorLogs: { meta: any; error: any }[] = [];

interface OperationError {
readonly level: Severity;
readonly error: Error;
}

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 => {
Expand Down
23 changes: 1 addition & 22 deletions src/components/ConfirmationModal/ConfirmationModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
Button,
CloseCircleOutlined,
Flex,
message,
Modal,
ModalRef,
Typography,
Expand All @@ -14,7 +13,6 @@ import { RequestProps } from '@ergolabs/ui-kit/dist/components/Modal/presets/Req
import { t, Trans } from '@lingui/macro';
import { DateTime } from 'luxon';
import { ReactNode } from 'react';
import CopyToClipboard from 'react-copy-to-clipboard';
import { TimeoutError } from 'rxjs';

import { applicationConfig } from '../../applicationConfig';
Expand All @@ -25,7 +23,6 @@ import { Currency } from '../../common/models/Currency';
import { downloadErrorLog } from '../../common/services/ErrorLogs';
import { exploreTx } from '../../gateway/utils/exploreAddress';
import { getLockingPeriodString } from '../../pages/Liquidity/utils';
import { useErrorEvent } from '../ErrorBoundary/ErrorEventProvider';

export enum Operation {
SWAP,
Expand Down Expand Up @@ -135,8 +132,6 @@ const ErrorModalContent = (
payload: ModalChainingPayload,
withErrorIcon?: boolean,
) => {
const { errorEvent } = useErrorEvent();

return (
<Flex col align="center">
{withErrorIcon && (
Expand All @@ -161,27 +156,11 @@ const ErrorModalContent = (
<Trans>Transaction rejected</Trans>
</Typography.Body>
</Flex.Item>
<Flex.Item marginBottom={errorEvent?.id ? 3 : 1}>
<Flex.Item marginBottom={2}>
<Typography.Body align="center" secondary>
<Trans>Try again later</Trans>
</Typography.Body>
</Flex.Item>
{errorEvent?.id && (
<Flex.Item marginBottom={2}>
<CopyToClipboard
text={errorEvent.id}
onCopy={() => message.success(t`Copied to clipboard!`)}
>
<Typography.Body
align="center"
secondary
style={{ cursor: 'pointer' }}
>
<Trans>Error id:</Trans> <br /> {errorEvent.id}
</Typography.Body>
</CopyToClipboard>
</Flex.Item>
)}
<Button size="large" type="dashed" onClick={downloadErrorLog}>
<Trans>Download Error log</Trans>
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export const ammTxFeeMapping: AmmTxFeeMapping = {
swapExecution: 500000n,
depositExecution: 500000n,
redeemExecution: 500000n,
poolCreation: 2000000n,
};
27 changes: 26 additions & 1 deletion src/network/cardano/api/operations/common/inputSelector.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FullTxIn, InputSelector } from '@spectrumlabs/cardano-dex-sdk';
import { FullTxIn, InputSelector, TxHash } from '@spectrumlabs/cardano-dex-sdk';
import { TxOut } from '@spectrumlabs/cardano-dex-sdk/build/main/cardano/entities/txOut';
import { Value } from '@spectrumlabs/cardano-dex-sdk/build/main/cardano/entities/value';
import { CollateralSelector } from '@spectrumlabs/cardano-dex-sdk/build/main/cardano/wallet/collateralSelector';
import { catchError, filter, first, map, of, switchMap } from 'rxjs';
Expand Down Expand Up @@ -33,6 +34,30 @@ export class DefaultInputSelector implements InputSelector {
)
.toPromise() as Promise<FullTxIn[] | Error>;
}

selectById(txHash: TxHash, index: number): Promise<FullTxIn[] | Error> {
return selectedWallet$
.pipe(
first(),
switchMap((wallet) => {
if (wallet) {
return wallet.getUtxos();
}
throw new Error('insufficient funds');
}),
map((utxos) => {
const txOut: TxOut | undefined = utxos.find(
(utxo) => utxo.index === index && utxo.txHash === txHash,
);

if (!txOut) {
throw new Error('insufficient funds');
}
return [{ txOut }];
}),
)
.toPromise() as Promise<FullTxIn[] | Error>;
}
}

export class DefaultCollateralSelector implements CollateralSelector {
Expand Down
49 changes: 42 additions & 7 deletions src/network/cardano/api/operations/deposit.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
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 { first, map, Observable, Subject, switchMap, tap, zip } from 'rxjs';
import {
catchError,
first,
map,
Observable,
Subject,
switchMap,
tap,
throwError,
zip,
} from 'rxjs';

import { Balance } from '../../../../common/models/Balance';
import { Currency } from '../../../../common/models/Currency';
import { addErrorLog } from '../../../../common/services/ErrorLogs';
import {
addErrorLog,
toSentryOperationError,
} from '../../../../common/services/ErrorLogs';
import { TxId } from '../../../../common/types';
import {
openConfirmationModal,
Expand Down Expand Up @@ -64,7 +79,10 @@ const toDepositTxCandidate = ({
pk: settings.ph!,
}),
),
map((data: [Transaction | null, TxCandidate, DepositTxInfo]) => data[0]!),
map(
(data: [Transaction | null, TxCandidate, DepositTxInfo, Error | null]) =>
data[0]!,
),
first(),
);
};
Expand All @@ -87,6 +105,7 @@ export const walletDeposit = (
),
switchMap((tx) => submitTx(tx)),
tap({ error: addErrorLog({ op: 'deposit' }) }),
catchError((err) => throwError(toSentryOperationError(err))),
);

export const deposit = (
Expand Down Expand Up @@ -142,10 +161,26 @@ export const useDepositValidators =
pk: settings.ph!,
}),
),
map((data: [Transaction | null, TxCandidate, DepositTxInfo]) =>
data[0]
? undefined
: t`Insufficient ${networkAsset.ticker} balance for fees`,
map(
(
data: [
Transaction | null,
TxCandidate,
DepositTxInfo,
Error | null,
],
) => {
const error = data[3];
if (error && !data[0]) {
Sentry.captureMessage(error?.message || (error as any), {
level: Severity.Critical,
});
}

return data[0]
? undefined
: t`Insufficient ${networkAsset.ticker} balance for fees`;
},
),
first(),
);
Expand Down
26 changes: 22 additions & 4 deletions src/network/cardano/api/operations/redeem.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
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 { first, map, Observable, Subject, switchMap, tap, zip } from 'rxjs';
import {
catchError,
first,
map,
Observable,
Subject,
switchMap,
tap,
throwError,
zip,
} from 'rxjs';

import { Currency } from '../../../../common/models/Currency';
import { addErrorLog } from '../../../../common/services/ErrorLogs';
import {
addErrorLog,
toSentryOperationError,
} from '../../../../common/services/ErrorLogs';
import { TxId } from '../../../../common/types';
import {
openConfirmationModal,
Expand Down Expand Up @@ -50,8 +63,12 @@ const toRedeemTxCandidate = ({
}),
),
map(
([transaction]: [Transaction | null, TxCandidate, RedeemTxInfo]) =>
transaction!,
([transaction]: [
Transaction | null,
TxCandidate,
RedeemTxInfo,
Error | null,
]) => transaction!,
),
first(),
);
Expand All @@ -73,6 +90,7 @@ export const walletRedeem = (
),
switchMap((tx) => submitTx(tx)),
tap({ error: addErrorLog({ op: 'redeem' }) }),
catchError((err) => throwError(toSentryOperationError(err))),
);

export const redeem = (
Expand Down
9 changes: 7 additions & 2 deletions src/network/cardano/api/operations/refund.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ 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 @@ -30,11 +31,15 @@ import {
Subject,
switchMap,
tap,
throwError,
zip,
} from 'rxjs';

import { Currency } from '../../../../common/models/Currency';
import { addErrorLog } from '../../../../common/services/ErrorLogs';
import {
addErrorLog,
toSentryOperationError,
} from '../../../../common/services/ErrorLogs';
import { TxId } from '../../../../common/types';
import {
openConfirmationModal,
Expand Down Expand Up @@ -121,7 +126,6 @@ const walletRefund = (txId: TxId): Observable<TxId> =>
),
),
),
tap(console.log, console.log),
map(([, tx, error]: [TxCandidate, Transaction | null, Error | null]) => {
if (!tx) {
throw error || new Error('');
Expand All @@ -130,6 +134,7 @@ const walletRefund = (txId: TxId): Observable<TxId> =>
}),
switchMap((tx) => submitTx(tx, true)),
tap({ error: addErrorLog({ txId, op: 'refund' }) }),
catchError((err) => throwError(toSentryOperationError(err))),
);

export const refund = (
Expand Down
43 changes: 35 additions & 8 deletions src/network/cardano/api/operations/swap.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
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 { first, map, Observable, Subject, switchMap, tap } from 'rxjs';
import {
catchError,
first,
map,
Observable,
Subject,
switchMap,
tap,
throwError,
} from 'rxjs';

import { Currency } from '../../../../common/models/Currency';
import { addErrorLog } from '../../../../common/services/ErrorLogs';
import {
addErrorLog,
toSentryOperationError,
} from '../../../../common/services/ErrorLogs';
import { Nitro, Percent, TxId } from '../../../../common/types';
import {
openConfirmationModal,
Expand Down Expand Up @@ -66,8 +80,12 @@ const toSwapTxCandidate = ({
}),
),
map(
([transaction]: [Transaction | null, TxCandidate, SwapTxInfo]) =>
transaction!,
([transaction]: [
Transaction | null,
TxCandidate,
SwapTxInfo,
Error | null,
]) => transaction!,
),
first(),
);
Expand All @@ -92,6 +110,7 @@ export const walletSwap = (
),
switchMap((tx) => submitTx(tx)),
tap({ error: addErrorLog({ op: 'swap' }) }),
catchError((err) => throwError(toSentryOperationError(err))),
);

export const swap = (data: Required<SwapFormModel>): Observable<TxId> => {
Expand Down Expand Up @@ -168,10 +187,18 @@ export const useSwapValidators = (): OperationValidator<SwapFormModel>[] => {
pool: pool.pool as any,
}),
),
map((data: [Transaction | null, TxCandidate, SwapTxInfo]) =>
data[0]
? undefined
: t`Insufficient ${networkAsset.ticker} balance for fees`,
map(
(data: [Transaction | null, TxCandidate, SwapTxInfo, Error | null]) => {
const error = data[3];
if (error && !data[0]) {
Sentry.captureMessage(error?.message || (error as any), {
level: Severity.Critical,
});
}
return data[0]
? undefined
: t`Insufficient ${networkAsset.ticker} balance for fees`;
},
),
first(),
);
Expand Down
3 changes: 0 additions & 3 deletions src/network/cardano/api/wallet/common/BoxSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,6 @@ export const selectUtxos = (
);
const sortedUtxosByAda = getSortedUtxosByAsset(utxos, adaCoin);

console.log(sortedUtxosByNonAdaCoins, sortedUtxosByAda);
console.log('____');

let selectedUtxos: SelectedUtxos =
sortedUtxosByNonAdaCoins.reduce<SelectedUtxos>(selectUtxosByAsset, {
available: {},
Expand Down
Loading

0 comments on commit 5cac7c5

Please sign in to comment.