1
0
mirror of https://github.com/oceanprotocol/react.git synced 2024-11-22 17:50:15 +01:00

Merge pull request #151 from oceanprotocol/feature/new_fetch

Feature/new fetch
This commit is contained in:
Matthias Kretschmann 2020-10-16 12:49:14 +02:00 committed by GitHub
commit 1201bfe8fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 11 deletions

View File

@ -1403,9 +1403,7 @@
"@oceanprotocol/react": {
"version": "file:..",
"requires": {
"@oceanprotocol/lib": "^0.5.6",
"axios": "^0.20.0",
"decimal.js": "^10.2.1",
"web3": "^1.3.0",
"web3modal": "^1.9.0"
},

14
package-lock.json generated
View File

@ -1516,17 +1516,17 @@
}
},
"@oceanprotocol/contracts": {
"version": "0.5.5",
"resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-0.5.5.tgz",
"integrity": "sha512-Omwlh3KxPm2JOuLd6DW4teAQhGaIv0fRTopCvctey0XGsf3DcbJpwS0A0YfgLQnvCyyVMKsiq90YCqpJ3SO/cw=="
"version": "0.5.6",
"resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-0.5.6.tgz",
"integrity": "sha512-LING+GvW37I0L40rZdPCZ1SvcZurDSGGhT0WOVPNO8oyh2C3bXModDBNE4+gCFa8pTbQBOc4ot1/Zoj9PfT/zA=="
},
"@oceanprotocol/lib": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-0.6.0.tgz",
"integrity": "sha512-5Kv6oVV7nneeVoT79fAQh93Ksb4Zg0TjjbVutMIYDt9kB8/Iwc/5NYU88unaz4XHX5zBl5rqnwfWoZMRDaI7hA==",
"version": "0.6.4",
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-0.6.4.tgz",
"integrity": "sha512-yNaeoTXjRmhXrDgRMchxmS49zqWI23e50W49OsOyEt+RqDKpbBBBlqzyeNcI0KU3vwnwhV+CH7nqSDUbOothow==",
"requires": {
"@ethereum-navigator/navigator": "^0.5.0",
"@oceanprotocol/contracts": "^0.5.5",
"@oceanprotocol/contracts": "^0.5.6",
"decimal.js": "^10.2.0",
"fs": "0.0.1-security",
"lzma": "^2.3.2",

View File

@ -25,7 +25,7 @@
"dist/"
],
"dependencies": {
"@oceanprotocol/lib": "^0.6.0",
"@oceanprotocol/lib": "^0.6.4",
"axios": "^0.20.0",
"decimal.js": "^10.2.1",
"web3": "^1.3.0",

View File

@ -86,11 +86,38 @@ export async function getCheapestExchange(
}
}
export async function getFirstPool(
ocean: Ocean,
dataTokenAddress: string
): Promise<Pool | null> {
if (!ocean || !dataTokenAddress) return null
const tokenPools = await ocean.pool.searchPoolforDT(dataTokenAddress)
if (tokenPools === undefined || tokenPools.length === 0) {
return {
address: '',
price: 0
}
}
const firstPoolAddress = tokenPools[0]
const firstPoolPrice = await ocean.pool.getOceanNeeded(firstPoolAddress, '1')
const oceanReserve = await ocean.pool.getOceanReserve(firstPoolAddress)
const dtReserve = await ocean.pool.getDTReserve(firstPoolAddress)
return {
address: firstPoolAddress,
price: Number(firstPoolPrice),
ocean: Number(oceanReserve),
datatoken: Number(dtReserve)
}
}
export async function getBestDataTokenPrice(
ocean: Ocean,
dataTokenAddress: string
): Promise<BestPrice> {
const cheapestPool = await getCheapestPool(ocean, dataTokenAddress)
const cheapestPool = await getFirstPool(ocean, dataTokenAddress)
const cheapestExchange = await getCheapestExchange(ocean, dataTokenAddress)
Decimal.set({ precision: 5 })