1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

using BigNumber instead of Number (#570)

* using BigNumber instead of Number

* remove wrong calculation of ocean ammount

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* remove calculateAmountOfOceansRemoved

* using decimal.js for remove

* bump to ocean.js v0.14.8

Co-authored-by: mihaisc <mihai.scarlat@smartcontrol.ro>
Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
This commit is contained in:
Dimo Dzhurenov 2021-05-04 15:56:47 +03:00 committed by GitHub
parent 0a739cbe93
commit 49cd032274
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 23 deletions

16
package-lock.json generated
View File

@ -3627,19 +3627,19 @@
"integrity": "sha512-p7aFIUT8RVoMzdPP7ML8G08BnQ09syywKjOT16hqJm0GmofunEuVffUXbryG4EkQ+qRbf/zeoxSmesi79kQXlA=="
},
"@oceanprotocol/lib": {
"version": "0.14.7",
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-0.14.7.tgz",
"integrity": "sha512-xnf2XX3VjmsvcNjLi8nwfWryTNT/t/oK+eOttOu5CrOBEm4Ghi98LKT1zX3ZlE4WObUDypaXDIkLuaxCtBVOOg==",
"version": "0.14.8",
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-0.14.8.tgz",
"integrity": "sha512-eqab5iEgowyIM/LcDDs6xhZo/KToOmVw0betjXLG0+g70zS8R6XL2RHzCpFyutSdf/cH0w/ltPUfR8ZBElIyhQ==",
"requires": {
"@ethereum-navigator/navigator": "^0.5.2",
"@oceanprotocol/contracts": "^0.5.16",
"@oceanprotocol/contracts": "0.5.16",
"@types/crypto-js": "^4.0.1",
"cross-fetch": "^3.1.2",
"crypto-js": "^4.0.0",
"decimal.js": "^10.2.1",
"fs": "0.0.1-security",
"lzma": "^2.3.2",
"node-abort-controller": "^1.2.0",
"node-abort-controller": "^2.0.0",
"save-file": "^2.3.1",
"uuid": "^8.3.2",
"web3": "^1.3.5",
@ -28882,9 +28882,9 @@
}
},
"node-abort-controller": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/node-abort-controller/-/node-abort-controller-1.2.1.tgz",
"integrity": "sha512-79PYeJuj6S9+yOHirR0JBLFOgjB6sQCir10uN6xRx25iD+ZD4ULqgRn3MwWBRaQGB0vEgReJzWwJo42T1R6YbQ=="
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/node-abort-controller/-/node-abort-controller-2.0.0.tgz",
"integrity": "sha512-L8RfEgjBTHAISTuagw51PprVAqNZoG6KSB6LQ6H1bskMVkFs5E71IyjauLBv3XbuomJlguWF/VnRHdJ1gqiAqA=="
},
"node-addon-api": {
"version": "2.0.2",

View File

@ -27,8 +27,7 @@
"@coingecko/cryptoformat": "^0.4.2",
"@loadable/component": "^5.14.1",
"@oceanprotocol/art": "^3.0.0",
"@oceanprotocol/contracts": "0.5.16",
"@oceanprotocol/lib": "^0.14.7",
"@oceanprotocol/lib": "^0.14.8",
"@oceanprotocol/typographies": "^0.1.0",
"@portis/web3": "^3.0.3",
"@sindresorhus/slugify": "^1.0.0",

View File

@ -21,6 +21,7 @@ import UserLiquidity from '../../../atoms/UserLiquidity'
import InputElement from '../../../atoms/Input/InputElement'
import { useOcean } from '../../../../providers/Ocean'
import { useWeb3 } from '../../../../providers/Web3'
import Decimal from 'decimal.js'
const contentQuery = graphql`
query PoolRemoveQuery {
@ -155,14 +156,6 @@ export default function Remove({
totalPoolTokens
])
async function calculateAmountOfOceansRemoved(amountPoolShares: string) {
const oceanAmount = await ocean.pool.getOceanRemovedforPoolShares(
poolAddress,
amountPoolShares
)
setAmountOcean(oceanAmount)
}
useEffect(() => {
const minOceanAmount =
(Number(amountOcean) * (100 - Number(slippage))) / 100
@ -177,19 +170,24 @@ export default function Remove({
setAmountPercent(e.target.value)
if (!poolTokens) return
const amountPoolShares = (Number(e.target.value) / 100) * Number(poolTokens)
const amountPoolShares = new Decimal(e.target.value)
.dividedBy(100)
.mul(new Decimal(poolTokens))
.toPrecision(18) // in some cases the returned value contain more than 18 digits which break conversion to wei
setAmountPoolShares(`${amountPoolShares}`)
calculateAmountOfOceansRemoved(`${amountPoolShares}`)
}
function handleMaxButton(e: ChangeEvent<HTMLInputElement>) {
e.preventDefault()
setAmountPercent(amountMaxPercent)
const amountPoolShares =
(Number(amountMaxPercent) / 100) * Number(poolTokens)
const amountPoolShares = new Decimal(amountMaxPercent)
.dividedBy(100)
.mul(new Decimal(poolTokens))
.toPrecision(18)
setAmountPoolShares(`${amountPoolShares}`)
calculateAmountOfOceansRemoved(`${amountPoolShares}`)
}
function handleAdvancedButton(e: FormEvent<HTMLButtonElement>) {