mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +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",
|
"@coingecko/cryptoformat": "^0.4.2",
|
||||||
"@loadable/component": "^5.14.1",
|
"@loadable/component": "^5.14.1",
|
||||||
"@oceanprotocol/art": "^3.0.0",
|
"@oceanprotocol/art": "^3.0.0",
|
||||||
"@oceanprotocol/lib": "^0.9.15",
|
"@oceanprotocol/lib": "^0.9.16",
|
||||||
"@oceanprotocol/list-datapartners": "^1.0.3",
|
"@oceanprotocol/list-datapartners": "^1.0.3",
|
||||||
"@oceanprotocol/react": "^0.3.19",
|
"@oceanprotocol/react": "^0.3.19",
|
||||||
"@oceanprotocol/typographies": "^0.1.0",
|
"@oceanprotocol/typographies": "^0.1.0",
|
||||||
|
@ -12,6 +12,7 @@ import TokenBalance from '../../../../@types/TokenBalance'
|
|||||||
import Alert from '../../../atoms/Alert'
|
import Alert from '../../../atoms/Alert'
|
||||||
import styles from './FormTrade.module.css'
|
import styles from './FormTrade.module.css'
|
||||||
import { FormTradeData, initialValues } from '../../../../models/FormTrade'
|
import { FormTradeData, initialValues } from '../../../../models/FormTrade'
|
||||||
|
import Decimal from 'decimal.js'
|
||||||
|
|
||||||
const contentQuery = graphql`
|
const contentQuery = graphql`
|
||||||
query TradeQuery {
|
query TradeQuery {
|
||||||
@ -70,27 +71,28 @@ export default function FormTrade({
|
|||||||
|
|
||||||
async function handleTrade(values: FormTradeData) {
|
async function handleTrade(values: FormTradeData) {
|
||||||
try {
|
try {
|
||||||
|
const impact = new Decimal(100 - Number(values.slippage)).div(100)
|
||||||
|
const precision = 15
|
||||||
const tx =
|
const tx =
|
||||||
values.type === 'buy'
|
values.type === 'buy'
|
||||||
? // ? await ocean.pool.buyDT(
|
? await ocean.pool.buyDTWithExactOcean(
|
||||||
// accountId,
|
|
||||||
// price.address,
|
|
||||||
// values.datatoken.toString(),
|
|
||||||
// (values.ocean * 1.01).toString()
|
|
||||||
// )
|
|
||||||
await ocean.pool.buyDTWithExactOcean(
|
|
||||||
accountId,
|
accountId,
|
||||||
price.address,
|
price.address,
|
||||||
(values.datatoken * 0.99).toString(),
|
new Decimal(values.datatoken)
|
||||||
values.ocean.toString()
|
.mul(impact)
|
||||||
|
.toFixed(precision)
|
||||||
|
.toString(),
|
||||||
|
new Decimal(values.ocean).toFixed(precision).toString()
|
||||||
)
|
)
|
||||||
: await ocean.pool.sellDT(
|
: await ocean.pool.sellDT(
|
||||||
accountId,
|
accountId,
|
||||||
price.address,
|
price.address,
|
||||||
values.datatoken.toString(),
|
new Decimal(values.datatoken).toFixed(precision).toString(),
|
||||||
(values.ocean * 0.99).toString()
|
new Decimal(values.ocean)
|
||||||
|
.mul(impact)
|
||||||
|
.toFixed(precision)
|
||||||
|
.toString()
|
||||||
)
|
)
|
||||||
|
|
||||||
setTxId(tx?.transactionHash)
|
setTxId(tx?.transactionHash)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Logger.error(error.message)
|
Logger.error(error.message)
|
||||||
|
@ -3,6 +3,7 @@ import { useOcean } from '@oceanprotocol/react'
|
|||||||
import { getOceanConfig } from './wrapRootElement'
|
import { getOceanConfig } from './wrapRootElement'
|
||||||
import { Logger } from '@oceanprotocol/lib'
|
import { Logger } from '@oceanprotocol/lib'
|
||||||
import { ConfigHelperConfig } from '@oceanprotocol/lib/dist/node/utils/ConfigHelper'
|
import { ConfigHelperConfig } from '@oceanprotocol/lib/dist/node/utils/ConfigHelper'
|
||||||
|
import { LogLevel } from '@oceanprotocol/lib/dist/node/utils'
|
||||||
|
|
||||||
export function NetworkMonitor(): ReactElement {
|
export function NetworkMonitor(): ReactElement {
|
||||||
const { connect, web3Provider, web3, networkId, config } = useOcean()
|
const { connect, web3Provider, web3, networkId, config } = useOcean()
|
||||||
|
@ -10,6 +10,7 @@ import {
|
|||||||
} from '@oceanprotocol/lib/dist/node/utils/ConfigHelper'
|
} from '@oceanprotocol/lib/dist/node/utils/ConfigHelper'
|
||||||
import { UserPreferencesProvider } from '../providers/UserPreferences'
|
import { UserPreferencesProvider } from '../providers/UserPreferences'
|
||||||
import PricesProvider from '../providers/Prices'
|
import PricesProvider from '../providers/Prices'
|
||||||
|
import { LogLevel } from '@oceanprotocol/lib/dist/node/utils'
|
||||||
|
|
||||||
export function getOceanConfig(
|
export function getOceanConfig(
|
||||||
network: ConfigHelperNetworkName | ConfigHelperNetworkId
|
network: ConfigHelperNetworkName | ConfigHelperNetworkId
|
||||||
|
Loading…
x
Reference in New Issue
Block a user