mirror of
https://github.com/oceanprotocol/react.git
synced 2025-02-14 21:10:38 +01:00
default provider, publish
This commit is contained in:
parent
b237412696
commit
563ea4cc46
@ -29,8 +29,10 @@ export function Publish() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const marketAddress = '0x4D156A2ef69ffdDC55838176C6712C90f60a2285'
|
||||||
|
|
||||||
const publishAsset = async () => {
|
const publishAsset = async () => {
|
||||||
const ddo = await publish(asset as Metadata, 4)
|
const ddo = await publish(asset as Metadata, 4,marketAddress)
|
||||||
console.log(ddo)
|
console.log(ddo)
|
||||||
setDdo(ddo)
|
setDdo(ddo)
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ export function Wallet() {
|
|||||||
const { default: Torus } = await import('@toruslabs/torus-embed')
|
const { default: Torus } = await import('@toruslabs/torus-embed')
|
||||||
|
|
||||||
const providerOptions = {
|
const providerOptions = {
|
||||||
|
|
||||||
/* See Provider Options Section */
|
/* See Provider Options Section */
|
||||||
walletconnect: {
|
walletconnect: {
|
||||||
package: WalletConnectProvider, // required
|
package: WalletConnectProvider, // required
|
||||||
@ -23,7 +24,8 @@ export function Wallet() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await connect({ providerOptions })
|
// await connect({ cacheProvider: true, providerOptions })
|
||||||
|
await connect()
|
||||||
}
|
}
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
if (ocean === undefined) return
|
if (ocean === undefined) return
|
||||||
|
1381
package-lock.json
generated
1381
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -21,8 +21,8 @@
|
|||||||
"dist/"
|
"dist/"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@oceanprotocol/contracts": "^0.2.2",
|
|
||||||
"@oceanprotocol/lib": "^0.1.2",
|
"@oceanprotocol/lib": "^0.1.2",
|
||||||
|
"@walletconnect/web3-provider": "^1.0.15",
|
||||||
"axios": "^0.19.2",
|
"axios": "^0.19.2",
|
||||||
"react": "^16.9.41",
|
"react": "^16.9.41",
|
||||||
"web3": "^1.2.9",
|
"web3": "^1.2.9",
|
||||||
|
@ -8,7 +8,8 @@ interface UsePublish {
|
|||||||
publish: (
|
publish: (
|
||||||
asset: Metadata,
|
asset: Metadata,
|
||||||
tokensToMint: number,
|
tokensToMint: number,
|
||||||
price?: number
|
marketAddress: string,
|
||||||
|
cost?: number
|
||||||
) => Promise<DDO>
|
) => Promise<DDO>
|
||||||
mint: (tokenAddress: string, tokensToMint: number) => void
|
mint: (tokenAddress: string, tokensToMint: number) => void
|
||||||
}
|
}
|
||||||
@ -19,7 +20,8 @@ function usePublish(): UsePublish {
|
|||||||
async function publish(
|
async function publish(
|
||||||
asset: Metadata,
|
asset: Metadata,
|
||||||
tokensToMint: number,
|
tokensToMint: number,
|
||||||
price = 1
|
marketAddress: string,
|
||||||
|
cost = 1
|
||||||
): Promise<DDO> {
|
): Promise<DDO> {
|
||||||
if (status !== ProviderStatus.CONNECTED) return
|
if (status !== ProviderStatus.CONNECTED) return
|
||||||
|
|
||||||
@ -37,8 +39,11 @@ function usePublish(): UsePublish {
|
|||||||
|
|
||||||
Logger.log('tokensto mint', tokensToMint)
|
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)
|
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
|
||||||
@ -47,7 +52,7 @@ function usePublish(): UsePublish {
|
|||||||
case 'dataset': {
|
case 'dataset': {
|
||||||
const accessService = await ocean.assets.createAccessServiceAttributes(
|
const accessService = await ocean.assets.createAccessServiceAttributes(
|
||||||
account,
|
account,
|
||||||
price.toString(),
|
cost.toString(),
|
||||||
publishedDate,
|
publishedDate,
|
||||||
timeout
|
timeout
|
||||||
)
|
)
|
||||||
@ -82,7 +87,7 @@ function usePublish(): UsePublish {
|
|||||||
(ocean.datatokens.datatokensABI as any).abi,
|
(ocean.datatokens.datatokensABI as any).abi,
|
||||||
web3
|
web3
|
||||||
)
|
)
|
||||||
|
Logger.log('mint function',tokenAddress, accountId)
|
||||||
await datatoken.mint(tokenAddress, accountId, tokensToMint)
|
await datatoken.mint(tokenAddress, accountId, tokensToMint)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,8 +104,8 @@ function usePublish(): UsePublish {
|
|||||||
(ocean.datatokens.datatokensABI as any).abi,
|
(ocean.datatokens.datatokensABI as any).abi,
|
||||||
web3
|
web3
|
||||||
)
|
)
|
||||||
|
|
||||||
await datatoken.approve(tokenAddress, marketAddress, tokens, accountId)
|
await datatoken.approve(tokenAddress, marketAddress, tokens, accountId)
|
||||||
|
|
||||||
const allowance = await datatoken.allowance(
|
const allowance = await datatoken.allowance(
|
||||||
tokenAddress,
|
tokenAddress,
|
||||||
accountId,
|
accountId,
|
||||||
|
@ -3,7 +3,7 @@ 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, { ICoreOptions } from 'web3modal'
|
import Web3Modal, { ICoreOptions } from 'web3modal'
|
||||||
|
import {getDefaultProviders} from './getDefaultProviders'
|
||||||
interface OceanProviderValue {
|
interface OceanProviderValue {
|
||||||
web3: Web3 | undefined
|
web3: Web3 | undefined
|
||||||
web3Provider: any
|
web3Provider: any
|
||||||
@ -49,6 +49,9 @@ function OceanProvider({
|
|||||||
|
|
||||||
async function connect(opts?: Partial<ICoreOptions>) {
|
async function connect(opts?: Partial<ICoreOptions>) {
|
||||||
Logger.log('Connecting ....')
|
Logger.log('Connecting ....')
|
||||||
|
if(opts===undefined) {
|
||||||
|
opts = await getDefaultProviders()
|
||||||
|
}
|
||||||
const instance = new Web3Modal(opts)
|
const instance = new Web3Modal(opts)
|
||||||
setWeb3Modal(instance)
|
setWeb3Modal(instance)
|
||||||
Logger.log('Web3Modal instance created', 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) => {
|
const handleNetworkChanged = async (networkId: string | number) => {
|
||||||
console.debug("Handling 'networkChanged' event with payload", networkId)
|
console.debug("Handling 'networkChanged' event with payload", networkId)
|
||||||
web3Provider.autoRefreshOnNetworkChange = false
|
web3Provider.autoRefreshOnNetworkChange = false
|
||||||
|
17
src/providers/OceanProvider/getDefaultProviders.ts
Normal file
17
src/providers/OceanProvider/getDefaultProviders.ts
Normal 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 }
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user