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:
parent
0a739cbe93
commit
49cd032274
16
package-lock.json
generated
16
package-lock.json
generated
@ -3627,19 +3627,19 @@
|
|||||||
"integrity": "sha512-p7aFIUT8RVoMzdPP7ML8G08BnQ09syywKjOT16hqJm0GmofunEuVffUXbryG4EkQ+qRbf/zeoxSmesi79kQXlA=="
|
"integrity": "sha512-p7aFIUT8RVoMzdPP7ML8G08BnQ09syywKjOT16hqJm0GmofunEuVffUXbryG4EkQ+qRbf/zeoxSmesi79kQXlA=="
|
||||||
},
|
},
|
||||||
"@oceanprotocol/lib": {
|
"@oceanprotocol/lib": {
|
||||||
"version": "0.14.7",
|
"version": "0.14.8",
|
||||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-0.14.7.tgz",
|
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-0.14.8.tgz",
|
||||||
"integrity": "sha512-xnf2XX3VjmsvcNjLi8nwfWryTNT/t/oK+eOttOu5CrOBEm4Ghi98LKT1zX3ZlE4WObUDypaXDIkLuaxCtBVOOg==",
|
"integrity": "sha512-eqab5iEgowyIM/LcDDs6xhZo/KToOmVw0betjXLG0+g70zS8R6XL2RHzCpFyutSdf/cH0w/ltPUfR8ZBElIyhQ==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@ethereum-navigator/navigator": "^0.5.2",
|
"@ethereum-navigator/navigator": "^0.5.2",
|
||||||
"@oceanprotocol/contracts": "^0.5.16",
|
"@oceanprotocol/contracts": "0.5.16",
|
||||||
"@types/crypto-js": "^4.0.1",
|
"@types/crypto-js": "^4.0.1",
|
||||||
"cross-fetch": "^3.1.2",
|
"cross-fetch": "^3.1.2",
|
||||||
"crypto-js": "^4.0.0",
|
"crypto-js": "^4.0.0",
|
||||||
"decimal.js": "^10.2.1",
|
"decimal.js": "^10.2.1",
|
||||||
"fs": "0.0.1-security",
|
"fs": "0.0.1-security",
|
||||||
"lzma": "^2.3.2",
|
"lzma": "^2.3.2",
|
||||||
"node-abort-controller": "^1.2.0",
|
"node-abort-controller": "^2.0.0",
|
||||||
"save-file": "^2.3.1",
|
"save-file": "^2.3.1",
|
||||||
"uuid": "^8.3.2",
|
"uuid": "^8.3.2",
|
||||||
"web3": "^1.3.5",
|
"web3": "^1.3.5",
|
||||||
@ -28882,9 +28882,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node-abort-controller": {
|
"node-abort-controller": {
|
||||||
"version": "1.2.1",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/node-abort-controller/-/node-abort-controller-1.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/node-abort-controller/-/node-abort-controller-2.0.0.tgz",
|
||||||
"integrity": "sha512-79PYeJuj6S9+yOHirR0JBLFOgjB6sQCir10uN6xRx25iD+ZD4ULqgRn3MwWBRaQGB0vEgReJzWwJo42T1R6YbQ=="
|
"integrity": "sha512-L8RfEgjBTHAISTuagw51PprVAqNZoG6KSB6LQ6H1bskMVkFs5E71IyjauLBv3XbuomJlguWF/VnRHdJ1gqiAqA=="
|
||||||
},
|
},
|
||||||
"node-addon-api": {
|
"node-addon-api": {
|
||||||
"version": "2.0.2",
|
"version": "2.0.2",
|
||||||
|
@ -27,8 +27,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/contracts": "0.5.16",
|
"@oceanprotocol/lib": "^0.14.8",
|
||||||
"@oceanprotocol/lib": "^0.14.7",
|
|
||||||
"@oceanprotocol/typographies": "^0.1.0",
|
"@oceanprotocol/typographies": "^0.1.0",
|
||||||
"@portis/web3": "^3.0.3",
|
"@portis/web3": "^3.0.3",
|
||||||
"@sindresorhus/slugify": "^1.0.0",
|
"@sindresorhus/slugify": "^1.0.0",
|
||||||
|
@ -21,6 +21,7 @@ import UserLiquidity from '../../../atoms/UserLiquidity'
|
|||||||
import InputElement from '../../../atoms/Input/InputElement'
|
import InputElement from '../../../atoms/Input/InputElement'
|
||||||
import { useOcean } from '../../../../providers/Ocean'
|
import { useOcean } from '../../../../providers/Ocean'
|
||||||
import { useWeb3 } from '../../../../providers/Web3'
|
import { useWeb3 } from '../../../../providers/Web3'
|
||||||
|
import Decimal from 'decimal.js'
|
||||||
|
|
||||||
const contentQuery = graphql`
|
const contentQuery = graphql`
|
||||||
query PoolRemoveQuery {
|
query PoolRemoveQuery {
|
||||||
@ -155,14 +156,6 @@ export default function Remove({
|
|||||||
totalPoolTokens
|
totalPoolTokens
|
||||||
])
|
])
|
||||||
|
|
||||||
async function calculateAmountOfOceansRemoved(amountPoolShares: string) {
|
|
||||||
const oceanAmount = await ocean.pool.getOceanRemovedforPoolShares(
|
|
||||||
poolAddress,
|
|
||||||
amountPoolShares
|
|
||||||
)
|
|
||||||
setAmountOcean(oceanAmount)
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const minOceanAmount =
|
const minOceanAmount =
|
||||||
(Number(amountOcean) * (100 - Number(slippage))) / 100
|
(Number(amountOcean) * (100 - Number(slippage))) / 100
|
||||||
@ -177,19 +170,24 @@ export default function Remove({
|
|||||||
setAmountPercent(e.target.value)
|
setAmountPercent(e.target.value)
|
||||||
if (!poolTokens) return
|
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}`)
|
setAmountPoolShares(`${amountPoolShares}`)
|
||||||
calculateAmountOfOceansRemoved(`${amountPoolShares}`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMaxButton(e: ChangeEvent<HTMLInputElement>) {
|
function handleMaxButton(e: ChangeEvent<HTMLInputElement>) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
setAmountPercent(amountMaxPercent)
|
setAmountPercent(amountMaxPercent)
|
||||||
|
|
||||||
const amountPoolShares =
|
const amountPoolShares = new Decimal(amountMaxPercent)
|
||||||
(Number(amountMaxPercent) / 100) * Number(poolTokens)
|
.dividedBy(100)
|
||||||
|
.mul(new Decimal(poolTokens))
|
||||||
|
.toPrecision(18)
|
||||||
|
|
||||||
setAmountPoolShares(`${amountPoolShares}`)
|
setAmountPoolShares(`${amountPoolShares}`)
|
||||||
calculateAmountOfOceansRemoved(`${amountPoolShares}`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleAdvancedButton(e: FormEvent<HTMLButtonElement>) {
|
function handleAdvancedButton(e: FormEvent<HTMLButtonElement>) {
|
||||||
|
Loading…
Reference in New Issue
Block a user