mirror of
https://github.com/oceanprotocol/market.git
synced 2024-11-14 17:24:51 +01:00
Fix trade (#253)
* oceanlib verbose Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro> * fix Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro> * round 20 Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro> * round 10 Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro> * round 5 Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro> * round 5 Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro> * round 5 Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro> * round 5 Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro> * debug Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro> * bump lib Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro> * decimal 15 Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro> * fix Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro> * remove verbose Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>
This commit is contained in:
parent
bdd9f92d07
commit
fa7de2eeb4
@ -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",
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user