1
0
mirror of https://github.com/oceanprotocol/react.git synced 2025-02-14 21:10:38 +01:00

Merge pull request #131 from oceanprotocol/ocean-lib-update

update ocean-lib
This commit is contained in:
mihaisc 2020-10-01 15:22:11 +03:00 committed by GitHub
commit 1b7f9e3f92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 26 deletions

View File

@ -9,14 +9,20 @@ import { MetadataExample } from './MetadataExample'
export function AllDdos() { export function AllDdos() {
const { chainId, account, accountId, ocean } = useOcean() const { chainId, account, accountId, ocean } = useOcean()
const [ddos, setDdos] = useState<DDO[] | undefined>() const [ddos, setDdos] = useState<DDO[]>()
useEffect(() => { useEffect(() => {
async function init() { async function init() {
if (!ocean || !account || !accountId) return if (!ocean || !accountId || !accountId) return
const assets = await ocean.assets.ownerAssets(accountId) const assets = await ocean.assets.ownerAssets(accountId)
// const assets = await ocean.assets.query({
// page: 1,
// offset: 10,
// query: {},
// sort: { created: -1 }
// })
console.log('assets', assets.results)
setDdos(assets.results.slice(0, 4)) setDdos(assets.results.slice(0, 4))
} }
init() init()

14
package-lock.json generated
View File

@ -1516,17 +1516,17 @@
} }
}, },
"@oceanprotocol/contracts": { "@oceanprotocol/contracts": {
"version": "0.4.4", "version": "0.5.1",
"resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-0.4.4.tgz", "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-0.5.1.tgz",
"integrity": "sha512-0+Tp6UdoDTBJZp4yX3kkSrV+CcOS/hJ3SJ4HuWiL5FE5Nlj3JCeV86iuWPkFuXzIdgri00DaGvQhP58knzJ2Uw==" "integrity": "sha512-bt5uwh79D759H6O4bAv+ycGdZQISFAxi65cqIygzA9hwsu29+GuOLwu1mxrzl2lVNLs6Emxo7TaDv0jAoyqnCg=="
}, },
"@oceanprotocol/lib": { "@oceanprotocol/lib": {
"version": "0.3.2", "version": "0.5.1",
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-0.3.2.tgz", "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-0.5.1.tgz",
"integrity": "sha512-pdgY+PqDlLt64C/ZzxzZtUwN+f+pBTyBzSgXeS0j1D79BChnCtyZAeAR4JyMB/bJSarsWNv1oVUxxVPx9SJ5hw==", "integrity": "sha512-OaQTpIqi0KXfptVhrHf1adchE99olSayDjiUrP2/LXuBaAxuOlA3MbCIQ7ecsNLlY9He06h9dtypSx/x2FcdGQ==",
"requires": { "requires": {
"@ethereum-navigator/navigator": "^0.5.0", "@ethereum-navigator/navigator": "^0.5.0",
"@oceanprotocol/contracts": "^0.4.4", "@oceanprotocol/contracts": "^0.5.1",
"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.3.2", "@oceanprotocol/lib": "^0.5.1",
"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

@ -16,7 +16,8 @@ interface UsePublish {
asset: Metadata, asset: Metadata,
priceOptions: PriceOptions, priceOptions: PriceOptions,
serviceConfigs: ServiceType, serviceConfigs: ServiceType,
dataTokenOptions?: DataTokenOptions dataTokenOptions?: DataTokenOptions,
providerUri?: string
) => Promise<DDO | undefined | null> ) => Promise<DDO | undefined | null>
mint: (tokenAddress: string, tokensToMint: string) => void mint: (tokenAddress: string, tokensToMint: string) => void
publishStep?: number publishStep?: number
@ -92,7 +93,8 @@ function usePublish(): UsePublish {
asset: Metadata, asset: Metadata,
priceOptions: PriceOptions, priceOptions: PriceOptions,
serviceType: ServiceType, serviceType: ServiceType,
dataTokenOptions?: DataTokenOptions dataTokenOptions?: DataTokenOptions,
providerUri?: string
): Promise<DDO | undefined | null> { ): Promise<DDO | undefined | null> {
if (status !== ProviderStatus.CONNECTED || !ocean || !account) return null if (status !== ProviderStatus.CONNECTED || !ocean || !account) return null
@ -178,7 +180,8 @@ function usePublish(): UsePublish {
undefined, undefined,
dataTokenOptions?.cap, dataTokenOptions?.cap,
dataTokenOptions?.name, dataTokenOptions?.name,
dataTokenOptions?.symbol dataTokenOptions?.symbol,
providerUri
) )
.next(setStep) .next(setStep)
Logger.log('ddo created', ddo) Logger.log('ddo created', ddo)

View File

@ -6,15 +6,11 @@ import Web3 from 'web3'
export async function getCheapestPool( export async function getCheapestPool(
ocean: Ocean, ocean: Ocean,
accountId: string,
dataTokenAddress: string dataTokenAddress: string
): Promise<Pool | null> { ): Promise<Pool | null> {
if (!ocean || !accountId || !dataTokenAddress) return null if (!ocean || !dataTokenAddress) return null
const tokenPools = await ocean.pool.searchPoolforDT( const tokenPools = await ocean.pool.searchPoolforDT(dataTokenAddress)
accountId,
dataTokenAddress
)
if (tokenPools === undefined || tokenPools.length === 0) { if (tokenPools === undefined || tokenPools.length === 0) {
return { return {
@ -27,11 +23,7 @@ export async function getCheapestPool(
if (tokenPools) { if (tokenPools) {
for (let i = 0; i < tokenPools.length; i++) { for (let i = 0; i < tokenPools.length; i++) {
const poolPrice = await ocean.pool.getOceanNeeded( const poolPrice = await ocean.pool.getOceanNeeded(tokenPools[i], '1')
accountId,
tokenPools[i],
'1'
)
const decimalPoolPrice = new Decimal(poolPrice) const decimalPoolPrice = new Decimal(poolPrice)
if (decimalPoolPrice < cheapestPoolPrice) { if (decimalPoolPrice < cheapestPoolPrice) {
@ -94,7 +86,7 @@ export async function getBestDataTokenPrice(
dataTokenAddress: string, dataTokenAddress: string,
accountId: string accountId: string
): Promise<BestPrice> { ): Promise<BestPrice> {
const cheapestPool = await getCheapestPool(ocean, accountId, dataTokenAddress) const cheapestPool = await getCheapestPool(ocean, dataTokenAddress)
const cheapestExchange = await getCheapestExchange(ocean, dataTokenAddress) const cheapestExchange = await getCheapestExchange(ocean, dataTokenAddress)
Decimal.set({ precision: 5 }) Decimal.set({ precision: 5 })