diff --git a/packages/swap/src/adapters/api/dexhunter/transformers.ts b/packages/swap/src/adapters/api/dexhunter/transformers.ts index 82ad3ca12f..aaa74a0dff 100644 --- a/packages/swap/src/adapters/api/dexhunter/transformers.ts +++ b/packages/swap/src/adapters/api/dexhunter/transformers.ts @@ -297,6 +297,7 @@ export const transformersMaker = ({ total_input = 0, total_output = 0, }: LimitBuildResponse): Swap.CreateResponse => ({ + aggregator: Swap.Aggregator.Dexhunter, cbor, splits: splits?.map(transformSplit) ?? [], batcherFee: batcher_fee, @@ -336,6 +337,7 @@ export const transformersMaker = ({ total_output = 0, total_output_without_slippage = 0, }: BuildResponse): Swap.CreateResponse => ({ + aggregator: Swap.Aggregator.Dexhunter, cbor, splits: splits?.map(transformSplit) ?? [], batcherFee: batcher_fee, diff --git a/packages/swap/src/adapters/api/muesliswap/transformers.ts b/packages/swap/src/adapters/api/muesliswap/transformers.ts index 3af67a2a04..9bdfcf7cce 100644 --- a/packages/swap/src/adapters/api/muesliswap/transformers.ts +++ b/packages/swap/src/adapters/api/muesliswap/transformers.ts @@ -247,22 +247,14 @@ export const transformersMaker = ({ response: ( res: ConstructSwapDatumResponse, estimate: Swap.EstimateResponse, - ): Swap.CreateResponse => { - const cbor: string = swapCreateCbor(res) - - return { - cbor, - ...estimate, - totalInput: estimate.totalInput ?? estimate.splits[0]?.amountIn ?? 0, - } - }, + ): Swap.CreateResponse => ({ + aggregator: Swap.Aggregator.Muesliswap, + contractAddress: res.address, + datumData: res.datum, + datumHash: res.hash, + ...estimate, + totalInput: estimate.totalInput ?? estimate.splits[0]?.amountIn ?? 0, + }), }, } as const } - -// TODO: Transform contractAddress, datum, hash into cbor, code in StartSwapOrderScreen.tsx -const swapCreateCbor = ({ - address: contractAddress, - datum, - hash, -}: ConstructSwapDatumResponse) => `${contractAddress}${datum}${hash}` diff --git a/packages/swap/src/fixtures/ErrorBoundary.tsx b/packages/swap/src/fixtures/ErrorBoundary.tsx deleted file mode 100644 index 2cc55d1de9..0000000000 --- a/packages/swap/src/fixtures/ErrorBoundary.tsx +++ /dev/null @@ -1,34 +0,0 @@ -import React, {Component, ReactNode} from 'react' -import {View, Text} from 'react-native' - -interface Props { - children: ReactNode -} - -interface State { - hasError: boolean - error?: Error -} - -export class ErrorBoundary extends Component { - state: State = { - hasError: false, - } - - static getDerivedStateFromError(error: Error): State { - return {hasError: true, error} - } - - render() { - if (this.state.hasError) { - return ( - - hasError - {JSON.stringify(this.state.error)} - - ) - } - - return this.props.children - } -} diff --git a/packages/swap/src/fixtures/SuspenseBoundary.tsx b/packages/swap/src/fixtures/SuspenseBoundary.tsx deleted file mode 100644 index f9b3ee6fc6..0000000000 --- a/packages/swap/src/fixtures/SuspenseBoundary.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import * as React from 'react' -import {Text, View} from 'react-native' - -export const SuspenseBoundary = ({children}: {children: React.ReactNode}) => { - return ( - - suspending - - } - > - {children} - - ) -} diff --git a/packages/swap/src/fixtures/manager-wrapper.tsx b/packages/swap/src/fixtures/manager-wrapper.tsx deleted file mode 100644 index 8a2361f5e9..0000000000 --- a/packages/swap/src/fixtures/manager-wrapper.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import * as React from 'react' -import {QueryClient, QueryClientProvider} from 'react-query' -import {Swap} from '@yoroi/types' - -import {SuspenseBoundary} from './SuspenseBoundary' -import {ErrorBoundary} from './ErrorBoundary' -import {SwapProvider} from '../translators/reactjs/provider/SwapProvider' - -type Props = { - queryClient: QueryClient - swapManager: Swap.Manager -} - -export const wrapperManagerFixture = - ({queryClient, swapManager}: Props) => - ({children}: {children: React.ReactNode}) => - ( - - - - {children} - - - - ) diff --git a/packages/swap/src/fixtures/query-client.ts b/packages/swap/src/fixtures/query-client.ts deleted file mode 100644 index d3cb0695fb..0000000000 --- a/packages/swap/src/fixtures/query-client.ts +++ /dev/null @@ -1,14 +0,0 @@ -import {QueryClient} from 'react-query' - -export const queryClientFixture = () => - new QueryClient({ - defaultOptions: { - queries: { - retry: false, - cacheTime: 0, - }, - mutations: { - retry: false, - }, - }, - }) diff --git a/packages/swap/src/helpers/getLiquidityProviderFee.ts b/packages/swap/src/helpers/getLiquidityProviderFee.ts deleted file mode 100644 index 27abc89bd2..0000000000 --- a/packages/swap/src/helpers/getLiquidityProviderFee.ts +++ /dev/null @@ -1,16 +0,0 @@ -import {Portfolio} from '@yoroi/types' - -export const getLiquidityProviderFee = ( - poolFee: string, - sell: Portfolio.Token.Amount, -): Portfolio.Token.Amount => { - const providerFee = - sell.quantity === 0n - ? 0n - : ceilDivision( - BigInt(Math.floor(Number(poolFee) * 1000)) * BigInt(sell.quantity), - 100n * 1000n, - ) - - return {info: sell.info, quantity: providerFee} -} diff --git a/packages/types/src/swap/api.ts b/packages/types/src/swap/api.ts index e0756d1840..0af03ee973 100644 --- a/packages/types/src/swap/api.ts +++ b/packages/types/src/swap/api.ts @@ -95,8 +95,8 @@ export type SwapCreateRequest = { } ) +// Leaks aggregator because of current challenge creating a cbor inside package export type SwapCreateResponse = { - cbor: string splits: SwapSplit[] batcherFee: number deposits: number @@ -107,7 +107,22 @@ export type SwapCreateResponse = { totalInput: number totalOutput: number totalOutputWithoutSlippage?: number -} +} & ( + | { + aggregator: typeof SwapAggregator.Muesliswap + datumData: string + datumHash: string + contractAddress: string + cbor?: undefined + } + | { + aggregator: typeof SwapAggregator.Dexhunter + datumData?: undefined + datumHash?: undefined + contractAddress?: undefined + cbor: string + } +) export type SwapCancelRequest = { order: SwapOrder