mirror of
https://github.com/oceanprotocol/react.git
synced 2025-02-14 21:10:38 +01:00
publish
This commit is contained in:
parent
e0172c88cd
commit
6a8566b1db
@ -1,14 +1,15 @@
|
||||
|
||||
import React from 'react';
|
||||
import { useOcean, usePublish } from '@oceanprotocol/react'
|
||||
import { Metadata } from '@oceanprotocol/lib';
|
||||
import { Metadata, DDO } from '@oceanprotocol/lib';
|
||||
import { useState } from 'react';
|
||||
|
||||
|
||||
export function Publish() {
|
||||
|
||||
const { accountId } = useOcean()
|
||||
const { publish } = usePublish()
|
||||
|
||||
const [ddo, setDdo] = useState<DDO|undefined>()
|
||||
|
||||
const asset = {
|
||||
main: {
|
||||
@ -32,14 +33,15 @@ export function Publish() {
|
||||
}
|
||||
|
||||
const publishAsset = async ()=>{
|
||||
const ddo = await publish(asset as Metadata)
|
||||
const ddo = await publish(asset as Metadata,4)
|
||||
console.log(ddo)
|
||||
setDdo(ddo)
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<div>Publish</div>
|
||||
<div><button onClick={publishAsset}>Publish</button></div>
|
||||
|
||||
<div>DID: {ddo && ddo.id} </div>
|
||||
</>
|
||||
)
|
||||
}
|
@ -1,16 +1,12 @@
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import React from 'react';
|
||||
import { useOcean } from '@oceanprotocol/react'
|
||||
import Web3Modal from "web3modal"
|
||||
import Web3 from '@oceanprotocol/lib/node_modules/web3';
|
||||
import { LogLevel } from '@oceanprotocol/lib/dist/node/utils';
|
||||
import { Ocean, Config } from '@oceanprotocol/lib';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
|
||||
export function Wallet() {
|
||||
|
||||
const { ocean, connect, logout, accountId, account } = useOcean()
|
||||
const { ocean, connect, logout, accountId } = useOcean()
|
||||
const conn = async () => {
|
||||
const { default: WalletConnectProvider } = await import('@walletconnect/web3-provider')
|
||||
const { default: Torus } = await import("@toruslabs/torus-embed")
|
||||
|
11789
package-lock.json
generated
11789
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -22,7 +22,6 @@
|
||||
],
|
||||
"dependencies": {
|
||||
"@oceanprotocol/contracts": "^0.2.2",
|
||||
"@oceanprotocol/lib": "../ocean-lib-js",
|
||||
"axios": "^0.19.2",
|
||||
"react": "^16.9.41",
|
||||
"web3": "^1.2.9",
|
||||
|
@ -6,31 +6,34 @@ import { Service } from '@oceanprotocol/lib/dist/node/ddo/interfaces/Service'
|
||||
|
||||
interface UsePublish {
|
||||
|
||||
publish: (asset: Metadata, price?: number) => Promise<DDO>
|
||||
|
||||
publish: (asset: Metadata,tokensToMint: number, price?: number) => Promise<DDO>
|
||||
mint:(did: string, tokenAddress: string, tokensToMint:number)=>void
|
||||
}
|
||||
|
||||
const factory = require('@oceanprotocol/contracts/artifacts/development/Factory.json')
|
||||
const datatokensTemplate = require('@oceanprotocol/contracts/artifacts/development/DataTokenTemplate.json')
|
||||
|
||||
function usePublish(): UsePublish {
|
||||
const { web3, ocean, status, account,accountId, config } = useOcean()
|
||||
|
||||
async function publish(asset: Metadata, price: number = 1): Promise<DDO> {
|
||||
async function publish(asset: Metadata,tokensToMint: number, price: number = 1): Promise<DDO> {
|
||||
if (status !== ProviderStatus.CONNECTED) return
|
||||
|
||||
Logger.log('datatokens params ',factory.abi,datatokensTemplate.abi,ocean.datatokens.factoryAddress)
|
||||
|
||||
const datatoken = new DataTokens(
|
||||
ocean.datatokens.factoryAddress,
|
||||
factory.abi,
|
||||
datatokensTemplate.abi,
|
||||
web3
|
||||
)
|
||||
|
||||
|
||||
Logger.log('datatoken created', datatoken)
|
||||
const data = { t: 1, url: config.metadataStoreUri }
|
||||
const blob = JSON.stringify(data)
|
||||
const tokenAddress = await datatoken.create(blob, accountId)
|
||||
|
||||
Logger.log('tokensto mint',tokensToMint)
|
||||
|
||||
await datatoken.mint(tokenAddress, accountId, tokensToMint)
|
||||
|
||||
Logger.log('tokenAddress created', tokenAddress)
|
||||
const publishedDate = new Date(Date.now()).toISOString().split('.')[0] + 'Z'
|
||||
const timeout = 0
|
||||
@ -58,6 +61,10 @@ function usePublish(): UsePublish {
|
||||
|
||||
return ddo
|
||||
}
|
||||
// WIP
|
||||
async function mint(did: string, tokenAddress: string, tokensToMint: number){
|
||||
//await datatoken.mint(tokenAddress, accountId, tokensToMint)
|
||||
}
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
@ -68,7 +75,8 @@ function usePublish(): UsePublish {
|
||||
}, [])
|
||||
|
||||
return {
|
||||
publish
|
||||
publish,
|
||||
mint
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user