diff --git a/package.json b/package.json index 426867c27..e62dd090a 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "@coingecko/cryptoformat": "^0.4.2", "@loadable/component": "^5.14.1", "@oceanprotocol/art": "^3.0.0", - "@oceanprotocol/lib": "^0.9.15", + "@oceanprotocol/lib": "^0.9.16", "@oceanprotocol/list-datapartners": "^1.0.3", "@oceanprotocol/react": "^0.3.19", "@oceanprotocol/typographies": "^0.1.0", diff --git a/src/components/organisms/AssetActions/Trade/FormTrade.tsx b/src/components/organisms/AssetActions/Trade/FormTrade.tsx index dea05197d..d1ef5e4e7 100644 --- a/src/components/organisms/AssetActions/Trade/FormTrade.tsx +++ b/src/components/organisms/AssetActions/Trade/FormTrade.tsx @@ -12,6 +12,7 @@ import TokenBalance from '../../../../@types/TokenBalance' import Alert from '../../../atoms/Alert' import styles from './FormTrade.module.css' import { FormTradeData, initialValues } from '../../../../models/FormTrade' +import Decimal from 'decimal.js' const contentQuery = graphql` query TradeQuery { @@ -70,27 +71,28 @@ export default function FormTrade({ async function handleTrade(values: FormTradeData) { try { + const impact = new Decimal(100 - Number(values.slippage)).div(100) + const precision = 15 const tx = values.type === 'buy' - ? // ? await ocean.pool.buyDT( - // accountId, - // price.address, - // values.datatoken.toString(), - // (values.ocean * 1.01).toString() - // ) - await ocean.pool.buyDTWithExactOcean( + ? await ocean.pool.buyDTWithExactOcean( accountId, price.address, - (values.datatoken * 0.99).toString(), - values.ocean.toString() + new Decimal(values.datatoken) + .mul(impact) + .toFixed(precision) + .toString(), + new Decimal(values.ocean).toFixed(precision).toString() ) : await ocean.pool.sellDT( accountId, price.address, - values.datatoken.toString(), - (values.ocean * 0.99).toString() + new Decimal(values.datatoken).toFixed(precision).toString(), + new Decimal(values.ocean) + .mul(impact) + .toFixed(precision) + .toString() ) - setTxId(tx?.transactionHash) } catch (error) { Logger.error(error.message) diff --git a/src/helpers/NetworkMonitor.tsx b/src/helpers/NetworkMonitor.tsx index c9fb75bd1..6675b003a 100644 --- a/src/helpers/NetworkMonitor.tsx +++ b/src/helpers/NetworkMonitor.tsx @@ -3,6 +3,7 @@ import { useOcean } from '@oceanprotocol/react' import { getOceanConfig } from './wrapRootElement' import { Logger } from '@oceanprotocol/lib' import { ConfigHelperConfig } from '@oceanprotocol/lib/dist/node/utils/ConfigHelper' +import { LogLevel } from '@oceanprotocol/lib/dist/node/utils' export function NetworkMonitor(): ReactElement { const { connect, web3Provider, web3, networkId, config } = useOcean() diff --git a/src/helpers/wrapRootElement.tsx b/src/helpers/wrapRootElement.tsx index b99bbcc49..0dd4c4c72 100644 --- a/src/helpers/wrapRootElement.tsx +++ b/src/helpers/wrapRootElement.tsx @@ -10,6 +10,7 @@ import { } from '@oceanprotocol/lib/dist/node/utils/ConfigHelper' import { UserPreferencesProvider } from '../providers/UserPreferences' import PricesProvider from '../providers/Prices' +import { LogLevel } from '@oceanprotocol/lib/dist/node/utils' export function getOceanConfig( network: ConfigHelperNetworkName | ConfigHelperNetworkId