1
0
mirror of https://github.com/oceanprotocol/react.git synced 2024-11-23 02:00:27 +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": { "@oceanprotocol/react": {
"version": "file:..", "version": "file:..",
"requires": { "requires": {
"@oceanprotocol/lib": "^0.5.6",
"axios": "^0.20.0", "axios": "^0.20.0",
"decimal.js": "^10.2.1",
"web3": "^1.3.0", "web3": "^1.3.0",
"web3modal": "^1.9.0" "web3modal": "^1.9.0"
}, },

14
package-lock.json generated
View File

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

View File

@ -25,7 +25,7 @@
"dist/" "dist/"
], ],
"dependencies": { "dependencies": {
"@oceanprotocol/lib": "^0.6.0", "@oceanprotocol/lib": "^0.6.4",
"axios": "^0.20.0", "axios": "^0.20.0",
"decimal.js": "^10.2.1", "decimal.js": "^10.2.1",
"web3": "^1.3.0", "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( export async function getBestDataTokenPrice(
ocean: Ocean, ocean: Ocean,
dataTokenAddress: string dataTokenAddress: string
): Promise<BestPrice> { ): Promise<BestPrice> {
const cheapestPool = await getCheapestPool(ocean, dataTokenAddress) const cheapestPool = await getFirstPool(ocean, dataTokenAddress)
const cheapestExchange = await getCheapestExchange(ocean, dataTokenAddress) const cheapestExchange = await getCheapestExchange(ocean, dataTokenAddress)
Decimal.set({ precision: 5 }) Decimal.set({ precision: 5 })