1
0
mirror of https://github.com/oceanprotocol/react.git synced 2025-01-05 11:25:18 +01:00

default provider, publish

This commit is contained in:
mihaisc 2020-07-15 12:18:22 +03:00
parent b237412696
commit 563ea4cc46
7 changed files with 1401 additions and 31 deletions

View File

@ -29,8 +29,10 @@ export function Publish() {
}
}
const marketAddress = '0x4D156A2ef69ffdDC55838176C6712C90f60a2285'
const publishAsset = async () => {
const ddo = await publish(asset as Metadata, 4)
const ddo = await publish(asset as Metadata, 4,marketAddress)
console.log(ddo)
setDdo(ddo)
}

View File

@ -11,6 +11,7 @@ export function Wallet() {
const { default: Torus } = await import('@toruslabs/torus-embed')
const providerOptions = {
/* See Provider Options Section */
walletconnect: {
package: WalletConnectProvider, // required
@ -23,7 +24,8 @@ export function Wallet() {
}
}
await connect({ providerOptions })
// await connect({ cacheProvider: true, providerOptions })
await connect()
}
const init = async () => {
if (ocean === undefined) return

1381
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -21,8 +21,8 @@
"dist/"
],
"dependencies": {
"@oceanprotocol/contracts": "^0.2.2",
"@oceanprotocol/lib": "^0.1.2",
"@walletconnect/web3-provider": "^1.0.15",
"axios": "^0.19.2",
"react": "^16.9.41",
"web3": "^1.2.9",

View File

@ -8,7 +8,8 @@ interface UsePublish {
publish: (
asset: Metadata,
tokensToMint: number,
price?: number
marketAddress: string,
cost?: number
) => Promise<DDO>
mint: (tokenAddress: string, tokensToMint: number) => void
}
@ -19,7 +20,8 @@ function usePublish(): UsePublish {
async function publish(
asset: Metadata,
tokensToMint: number,
price = 1
marketAddress: string,
cost = 1
): Promise<DDO> {
if (status !== ProviderStatus.CONNECTED) return
@ -37,8 +39,11 @@ function usePublish(): UsePublish {
Logger.log('tokensto mint', tokensToMint)
await datatoken.mint(tokenAddress, accountId, tokensToMint)
await mint(tokenAddress,tokensToMint,datatoken)
Logger.log('giving allowance to ', marketAddress)
await giveMarketAllowance(tokenAddress,marketAddress, tokensToMint,datatoken)
Logger.log('tokenAddress created', tokenAddress)
const publishedDate = new Date(Date.now()).toISOString().split('.')[0] + 'Z'
const timeout = 0
@ -47,7 +52,7 @@ function usePublish(): UsePublish {
case 'dataset': {
const accessService = await ocean.assets.createAccessServiceAttributes(
account,
price.toString(),
cost.toString(),
publishedDate,
timeout
)
@ -82,7 +87,7 @@ function usePublish(): UsePublish {
(ocean.datatokens.datatokensABI as any).abi,
web3
)
Logger.log('mint function',tokenAddress, accountId)
await datatoken.mint(tokenAddress, accountId, tokensToMint)
}
@ -99,8 +104,8 @@ function usePublish(): UsePublish {
(ocean.datatokens.datatokensABI as any).abi,
web3
)
await datatoken.approve(tokenAddress, marketAddress, tokens, accountId)
const allowance = await datatoken.allowance(
tokenAddress,
accountId,

View File

@ -3,7 +3,7 @@ import Web3 from 'web3'
import ProviderStatus from './ProviderStatus'
import { Ocean, Logger, Account, Config } from '@oceanprotocol/lib'
import Web3Modal, { ICoreOptions } from 'web3modal'
import {getDefaultProviders} from './getDefaultProviders'
interface OceanProviderValue {
web3: Web3 | undefined
web3Provider: any
@ -49,6 +49,9 @@ function OceanProvider({
async function connect(opts?: Partial<ICoreOptions>) {
Logger.log('Connecting ....')
if(opts===undefined) {
opts = await getDefaultProviders()
}
const instance = new Web3Modal(opts)
setWeb3Modal(instance)
Logger.log('Web3Modal instance created', instance)
@ -115,7 +118,7 @@ function OceanProvider({
}
}
// ToDo need to handle this, it's not implemented
// ToDo need to handle this, it's not implemented, need to update chainId and reinitialize ocean lib
const handleNetworkChanged = async (networkId: string | number) => {
console.debug("Handling 'networkChanged' event with payload", networkId)
web3Provider.autoRefreshOnNetworkChange = false

View File

@ -0,0 +1,17 @@
export async function getDefaultProviders(){
const { default: WalletConnectProvider } = await import(
'@walletconnect/web3-provider'
)
const providerOptions = {
walletconnect: {
package: WalletConnectProvider,
options: {
infuraId: 'INFURA_ID' // required
}
}
}
return { cacheProvider: true, providerOptions }
}