diff --git a/package.json b/package.json index 3616e2e85..b7cf4734f 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/common/services/ErrorLogs.ts b/src/common/services/ErrorLogs.ts index e1a859fca..fc63e52b5 100644 --- a/src/common/services/ErrorLogs.ts +++ b/src/common/services/ErrorLogs.ts @@ -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 => { diff --git a/src/components/ConfirmationModal/ConfirmationModal.tsx b/src/components/ConfirmationModal/ConfirmationModal.tsx index fc59ea27f..0930a7108 100644 --- a/src/components/ConfirmationModal/ConfirmationModal.tsx +++ b/src/components/ConfirmationModal/ConfirmationModal.tsx @@ -3,7 +3,6 @@ import { Button, CloseCircleOutlined, Flex, - message, Modal, ModalRef, Typography, @@ -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'; @@ -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, @@ -135,8 +132,6 @@ const ErrorModalContent = ( payload: ModalChainingPayload, withErrorIcon?: boolean, ) => { - const { errorEvent } = useErrorEvent(); - return ( {withErrorIcon && ( @@ -161,27 +156,11 @@ const ErrorModalContent = ( Transaction rejected - + Try again later - {errorEvent?.id && ( - - message.success(t`Copied to clipboard!`)} - > - - Error id:
{errorEvent.id} -
-
-
- )} diff --git a/src/network/cardano/api/operations/common/ammTxFeeMapping.ts b/src/network/cardano/api/operations/common/ammTxFeeMapping.ts index f22888bc8..4ccf0bbcc 100644 --- a/src/network/cardano/api/operations/common/ammTxFeeMapping.ts +++ b/src/network/cardano/api/operations/common/ammTxFeeMapping.ts @@ -7,4 +7,5 @@ export const ammTxFeeMapping: AmmTxFeeMapping = { swapExecution: 500000n, depositExecution: 500000n, redeemExecution: 500000n, + poolCreation: 2000000n, }; diff --git a/src/network/cardano/api/operations/common/inputSelector.ts b/src/network/cardano/api/operations/common/inputSelector.ts index ab5f6cab3..78274308c 100644 --- a/src/network/cardano/api/operations/common/inputSelector.ts +++ b/src/network/cardano/api/operations/common/inputSelector.ts @@ -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'; @@ -33,6 +34,30 @@ export class DefaultInputSelector implements InputSelector { ) .toPromise() as Promise; } + + selectById(txHash: TxHash, index: number): Promise { + 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; + } } export class DefaultCollateralSelector implements CollateralSelector { diff --git a/src/network/cardano/api/operations/deposit.tsx b/src/network/cardano/api/operations/deposit.tsx index cd292fd32..6cff618d5 100644 --- a/src/network/cardano/api/operations/deposit.tsx +++ b/src/network/cardano/api/operations/deposit.tsx @@ -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, @@ -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(), ); }; @@ -87,6 +105,7 @@ export const walletDeposit = ( ), switchMap((tx) => submitTx(tx)), tap({ error: addErrorLog({ op: 'deposit' }) }), + catchError((err) => throwError(toSentryOperationError(err))), ); export const deposit = ( @@ -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(), ); diff --git a/src/network/cardano/api/operations/redeem.tsx b/src/network/cardano/api/operations/redeem.tsx index 78d445880..6c8e1b140 100644 --- a/src/network/cardano/api/operations/redeem.tsx +++ b/src/network/cardano/api/operations/redeem.tsx @@ -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, @@ -50,8 +63,12 @@ const toRedeemTxCandidate = ({ }), ), map( - ([transaction]: [Transaction | null, TxCandidate, RedeemTxInfo]) => - transaction!, + ([transaction]: [ + Transaction | null, + TxCandidate, + RedeemTxInfo, + Error | null, + ]) => transaction!, ), first(), ); @@ -73,6 +90,7 @@ export const walletRedeem = ( ), switchMap((tx) => submitTx(tx)), tap({ error: addErrorLog({ op: 'redeem' }) }), + catchError((err) => throwError(toSentryOperationError(err))), ); export const redeem = ( diff --git a/src/network/cardano/api/operations/refund.ts b/src/network/cardano/api/operations/refund.ts index 54de3d73e..19b88c1fb 100644 --- a/src/network/cardano/api/operations/refund.ts +++ b/src/network/cardano/api/operations/refund.ts @@ -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, @@ -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, @@ -121,7 +126,6 @@ const walletRefund = (txId: TxId): Observable => ), ), ), - tap(console.log, console.log), map(([, tx, error]: [TxCandidate, Transaction | null, Error | null]) => { if (!tx) { throw error || new Error(''); @@ -130,6 +134,7 @@ const walletRefund = (txId: TxId): Observable => }), switchMap((tx) => submitTx(tx, true)), tap({ error: addErrorLog({ txId, op: 'refund' }) }), + catchError((err) => throwError(toSentryOperationError(err))), ); export const refund = ( diff --git a/src/network/cardano/api/operations/swap.tsx b/src/network/cardano/api/operations/swap.tsx index 6a93c8bdf..457258231 100644 --- a/src/network/cardano/api/operations/swap.tsx +++ b/src/network/cardano/api/operations/swap.tsx @@ -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, @@ -66,8 +80,12 @@ const toSwapTxCandidate = ({ }), ), map( - ([transaction]: [Transaction | null, TxCandidate, SwapTxInfo]) => - transaction!, + ([transaction]: [ + Transaction | null, + TxCandidate, + SwapTxInfo, + Error | null, + ]) => transaction!, ), first(), ); @@ -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): Observable => { @@ -168,10 +187,18 @@ export const useSwapValidators = (): OperationValidator[] => { 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(), ); diff --git a/src/network/cardano/api/wallet/common/BoxSelector.ts b/src/network/cardano/api/wallet/common/BoxSelector.ts index 9a7ac4bff..f7c800484 100644 --- a/src/network/cardano/api/wallet/common/BoxSelector.ts +++ b/src/network/cardano/api/wallet/common/BoxSelector.ts @@ -127,9 +127,6 @@ export const selectUtxos = ( ); const sortedUtxosByAda = getSortedUtxosByAsset(utxos, adaCoin); - console.log(sortedUtxosByNonAdaCoins, sortedUtxosByAda); - console.log('____'); - let selectedUtxos: SelectedUtxos = sortedUtxosByNonAdaCoins.reduce(selectUtxosByAsset, { available: {}, diff --git a/yarn.lock b/yarn.lock index e3d3c6ae0..9eaf8349c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3337,10 +3337,10 @@ dependencies: "@amplitude/analytics-browser" "^1.9.0" -"@spectrumlabs/cardano-dex-sdk@^0.1.170": - version "0.1.170" - resolved "https://registry.yarnpkg.com/@spectrumlabs/cardano-dex-sdk/-/cardano-dex-sdk-0.1.170.tgz#7d70e512777715726b73afc642eb4f1784ca7c4a" - integrity sha512-Ftvn/ryAFj06pTyHmBC2VbaupzR1C/pjGg48xOTqjLoIUY5knS7+j+wLFMgOus1Hp74DIuohiwN4tQUvEzxLog== +"@spectrumlabs/cardano-dex-sdk@^0.1.172": + version "0.1.172" + resolved "https://registry.yarnpkg.com/@spectrumlabs/cardano-dex-sdk/-/cardano-dex-sdk-0.1.172.tgz#8731ed5c46a6e4c814e159f2df6a7245c75e9b10" + integrity sha512-IIc/1lhSn+zntiYRdNlKfaKHYikaag86Pw+ZrbTlk05yqp54yWWLYvaSNsJTvJcnX2qTCPsbV2fC+m+FxVzDAw== dependencies: "@emurgo/cardano-serialization-lib-browser" "^11.4.0" axios "^0.21.1"