diff --git a/app/src/hooks/useParaspellApi.tsx b/app/src/hooks/useParaspellApi.tsx index 73ac8697..ac820c18 100644 --- a/app/src/hooks/useParaspellApi.tsx +++ b/app/src/hooks/useParaspellApi.tsx @@ -9,6 +9,7 @@ import { isProduction } from '@/utils/env' import { handleObservableEvents } from '@/utils/papi' import { createTx, dryRun, moonbeamTransfer } from '@/utils/paraspell' import { txWasCancelled } from '@/utils/transfer' +import { TDryRunResult } from '@paraspell/sdk' import { captureException } from '@sentry/nextjs' import { switchChain } from '@wagmi/core' import { InvalidTxError, TxEvent } from 'polkadot-api' @@ -81,8 +82,8 @@ const useParaspellApi = () => { setStatus('Validating') const validationResult = await validate(params) - if (validationResult.dryRunSupported && !validationResult.success) - throw new Error(`Transfer dry run failed: ${validationResult.error}`) + if (validationResult.type === 'Supported' && !validationResult.success) + throw new Error(`Transfer dry run failed: ${validationResult.failureReason}`) const tx = await createTx(params, params.sourceChain.rpcConnection) setStatus('Signing') @@ -157,35 +158,27 @@ const useParaspellApi = () => { } } - interface DryRunResult { - dryRunSupported: boolean - success: boolean - error?: string - fee?: bigint - } + type DryRunResult = { type: 'Supported' | 'Unsupported' } & TDryRunResult const validate = async (params: TransferParams): Promise => { try { - const dryRunResult = await dryRun(params, params.sourceChain.rpcConnection) - - const res: DryRunResult = { - dryRunSupported: true, - success: dryRunResult.success, - } + const result = await dryRun(params, params.sourceChain.rpcConnection) - if (dryRunResult.success) res.fee = dryRunResult.fee - else { - res.error = dryRunResult.failureReason - console.error('Dry run failed:', dryRunResult.failureReason) - captureException(new Error(`Dry run failed: ${dryRunResult.failureReason}`)) + const dryRunResult: DryRunResult = { + type: 'Supported', + ...result, } - return res + return dryRunResult } catch (e: unknown) { if (e instanceof Error && e.message.includes('DryRunApi is not available')) - return { dryRunSupported: false, success: false, error: e.message } + return { type: 'Unsupported', success: false, failureReason: e.message } as DryRunResult - return { dryRunSupported: true, success: false, error: (e as Error).message } + return { + type: 'Supported', + success: false, + failureReason: (e as Error).message, + } as DryRunResult } } diff --git a/app/src/utils/paraspell.ts b/app/src/utils/paraspell.ts index fcdc999f..76c5833b 100644 --- a/app/src/utils/paraspell.ts +++ b/app/src/utils/paraspell.ts @@ -62,15 +62,6 @@ export const moonbeamTransfer = async ( throw new Error('Transfer failed: chain id not found.') const currencyId = getCurrencyId(environment, sourceChainFromId, sourceChain.uid, token) - console.log('Moonbeam transfer:', { - sourceChainFromId, - destinationChainFromId, - currencyId, - amount, - recipient, - viemClient, - }) - return EvmBuilder() .from('Moonbeam') .to(destinationChainFromId)