mirror of
https://github.com/oceanprotocol/react.git
synced 2025-02-14 21:10:38 +01:00
allowance
This commit is contained in:
parent
1ec6a8a44d
commit
64a4b5f7f3
@ -6,32 +6,32 @@ import { Service } from '@oceanprotocol/lib/dist/node/ddo/interfaces/Service'
|
|||||||
|
|
||||||
interface UsePublish {
|
interface UsePublish {
|
||||||
|
|
||||||
publish: (asset: Metadata,tokensToMint: number, price?: number) => Promise<DDO>
|
publish: (asset: Metadata, tokensToMint: number, price?: number) => Promise<DDO>
|
||||||
mint:(did: string, tokenAddress: string, tokensToMint:number)=>void
|
mint: (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,tokensToMint: number, 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
|
||||||
|
|
||||||
const datatoken = new DataTokens(
|
const datatoken = new DataTokens(
|
||||||
ocean.datatokens.factoryAddress,
|
ocean.datatokens.factoryAddress,
|
||||||
factory.abi,
|
factory.abi,
|
||||||
datatokensTemplate.abi,
|
datatokensTemplate.abi,
|
||||||
web3
|
web3
|
||||||
)
|
)
|
||||||
|
|
||||||
Logger.log('datatoken created', datatoken)
|
Logger.log('datatoken created', datatoken)
|
||||||
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)
|
Logger.log('tokensto mint', tokensToMint)
|
||||||
|
|
||||||
await datatoken.mint(tokenAddress, accountId, tokensToMint)
|
await datatoken.mint(tokenAddress, accountId, tokensToMint)
|
||||||
|
|
||||||
Logger.log('tokenAddress created', tokenAddress)
|
Logger.log('tokenAddress created', tokenAddress)
|
||||||
@ -61,9 +61,43 @@ function usePublish(): UsePublish {
|
|||||||
|
|
||||||
return ddo
|
return ddo
|
||||||
}
|
}
|
||||||
// WIP
|
|
||||||
async function mint(did: string, tokenAddress: string, tokensToMint: number){
|
async function mint(tokenAddress: string, tokensToMint: number, datatoken?: DataTokens) {
|
||||||
//await datatoken.mint(tokenAddress, accountId, tokensToMint)
|
if (datatoken === undefined)
|
||||||
|
datatoken = new DataTokens(
|
||||||
|
ocean.datatokens.factoryAddress,
|
||||||
|
factory.abi,
|
||||||
|
datatokensTemplate.abi,
|
||||||
|
web3
|
||||||
|
)
|
||||||
|
|
||||||
|
await datatoken.mint(tokenAddress, accountId, tokensToMint)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function giveMarketAllowance(tokenAddress: string, marketAddress: string, tokens: number, datatoken?: DataTokens) {
|
||||||
|
if (datatoken === undefined)
|
||||||
|
datatoken = new DataTokens(
|
||||||
|
ocean.datatokens.factoryAddress,
|
||||||
|
factory.abi,
|
||||||
|
datatokensTemplate.abi,
|
||||||
|
web3
|
||||||
|
)
|
||||||
|
|
||||||
|
await datatoken
|
||||||
|
.approve(
|
||||||
|
tokenAddress,
|
||||||
|
marketAddress,
|
||||||
|
tokens,
|
||||||
|
accountId
|
||||||
|
)
|
||||||
|
const allowance = await datatoken.allowance(
|
||||||
|
tokenAddress,
|
||||||
|
accountId,
|
||||||
|
marketAddress
|
||||||
|
)
|
||||||
|
await datatoken
|
||||||
|
.transferFrom(tokenAddress, accountId, allowance, marketAddress)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,8 +2,7 @@ import React, { useContext, useState, useEffect, createContext } from 'react'
|
|||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
import ProviderStatus from './ProviderStatus'
|
import ProviderStatus from './ProviderStatus'
|
||||||
import { Ocean, Logger, Account, Config } from '@oceanprotocol/lib'
|
import { Ocean, Logger, Account, Config } from '@oceanprotocol/lib'
|
||||||
import Web3Modal, { IProviderOptions, ICoreOptions } from 'web3modal'
|
import Web3Modal, { ICoreOptions } from 'web3modal'
|
||||||
import { LogLevel } from '@oceanprotocol/lib/dist/node/utils/Logger'
|
|
||||||
|
|
||||||
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')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user