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 React from 'react';
|
||||||
import { useOcean, usePublish } from '@oceanprotocol/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() {
|
export function Publish() {
|
||||||
|
|
||||||
const { accountId } = useOcean()
|
const { accountId } = useOcean()
|
||||||
const { publish } = usePublish()
|
const { publish } = usePublish()
|
||||||
|
const [ddo, setDdo] = useState<DDO|undefined>()
|
||||||
|
|
||||||
const asset = {
|
const asset = {
|
||||||
main: {
|
main: {
|
||||||
@ -32,14 +33,15 @@ export function Publish() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const publishAsset = async ()=>{
|
const publishAsset = async ()=>{
|
||||||
const ddo = await publish(asset as Metadata)
|
const ddo = await publish(asset as Metadata,4)
|
||||||
console.log(ddo)
|
console.log(ddo)
|
||||||
|
setDdo(ddo)
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div>Publish</div>
|
<div>Publish</div>
|
||||||
<div><button onClick={publishAsset}>Publish</button></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 { 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';
|
import { useEffect } from 'react';
|
||||||
|
|
||||||
|
|
||||||
export function Wallet() {
|
export function Wallet() {
|
||||||
|
|
||||||
const { ocean, connect, logout, accountId, account } = useOcean()
|
const { ocean, connect, logout, accountId } = useOcean()
|
||||||
const conn = async () => {
|
const conn = async () => {
|
||||||
const { default: WalletConnectProvider } = await import('@walletconnect/web3-provider')
|
const { default: WalletConnectProvider } = await import('@walletconnect/web3-provider')
|
||||||
const { default: Torus } = await import("@toruslabs/torus-embed")
|
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": {
|
"dependencies": {
|
||||||
"@oceanprotocol/contracts": "^0.2.2",
|
"@oceanprotocol/contracts": "^0.2.2",
|
||||||
"@oceanprotocol/lib": "../ocean-lib-js",
|
|
||||||
"axios": "^0.19.2",
|
"axios": "^0.19.2",
|
||||||
"react": "^16.9.41",
|
"react": "^16.9.41",
|
||||||
"web3": "^1.2.9",
|
"web3": "^1.2.9",
|
||||||
|
@ -6,20 +6,18 @@ import { Service } from '@oceanprotocol/lib/dist/node/ddo/interfaces/Service'
|
|||||||
|
|
||||||
interface UsePublish {
|
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 factory = require('@oceanprotocol/contracts/artifacts/development/Factory.json')
|
||||||
const datatokensTemplate = require('@oceanprotocol/contracts/artifacts/development/DataTokenTemplate.json')
|
const datatokensTemplate = require('@oceanprotocol/contracts/artifacts/development/DataTokenTemplate.json')
|
||||||
|
|
||||||
function usePublish(): UsePublish {
|
function usePublish(): UsePublish {
|
||||||
const { web3, ocean, status, account,accountId, config } = useOcean()
|
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
|
if (status !== ProviderStatus.CONNECTED) return
|
||||||
|
|
||||||
Logger.log('datatokens params ',factory.abi,datatokensTemplate.abi,ocean.datatokens.factoryAddress)
|
|
||||||
const datatoken = new DataTokens(
|
const datatoken = new DataTokens(
|
||||||
ocean.datatokens.factoryAddress,
|
ocean.datatokens.factoryAddress,
|
||||||
factory.abi,
|
factory.abi,
|
||||||
@ -31,6 +29,11 @@ function usePublish(): UsePublish {
|
|||||||
const data = { t: 1, url: config.metadataStoreUri }
|
const data = { t: 1, url: config.metadataStoreUri }
|
||||||
const blob = JSON.stringify(data)
|
const blob = JSON.stringify(data)
|
||||||
const tokenAddress = await datatoken.create(blob, accountId)
|
const tokenAddress = await datatoken.create(blob, accountId)
|
||||||
|
|
||||||
|
Logger.log('tokensto mint',tokensToMint)
|
||||||
|
|
||||||
|
await datatoken.mint(tokenAddress, accountId, tokensToMint)
|
||||||
|
|
||||||
Logger.log('tokenAddress created', tokenAddress)
|
Logger.log('tokenAddress created', tokenAddress)
|
||||||
const publishedDate = new Date(Date.now()).toISOString().split('.')[0] + 'Z'
|
const publishedDate = new Date(Date.now()).toISOString().split('.')[0] + 'Z'
|
||||||
const timeout = 0
|
const timeout = 0
|
||||||
@ -58,6 +61,10 @@ function usePublish(): UsePublish {
|
|||||||
|
|
||||||
return ddo
|
return ddo
|
||||||
}
|
}
|
||||||
|
// WIP
|
||||||
|
async function mint(did: string, tokenAddress: string, tokensToMint: number){
|
||||||
|
//await datatoken.mint(tokenAddress, accountId, tokensToMint)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -68,7 +75,8 @@ function usePublish(): UsePublish {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
publish
|
publish,
|
||||||
|
mint
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user