mirror of
https://github.com/oceanprotocol/react.git
synced 2025-01-03 18:35:18 +01:00
format +new oceanlib
This commit is contained in:
parent
58adcaacd8
commit
a36d72d6d7
12
.github/dependabot.yml
vendored
12
.github/dependabot.yml
vendored
@ -1,8 +1,8 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: npm
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: weekly
|
||||
time: '03:00'
|
||||
timezone: Europe/Berlin
|
||||
- package-ecosystem: npm
|
||||
directory: '/'
|
||||
schedule:
|
||||
interval: weekly
|
||||
time: '03:00'
|
||||
timezone: Europe/Berlin
|
||||
|
@ -1,18 +1,16 @@
|
||||
.app {
|
||||
width: 100%;
|
||||
|
||||
.app {
|
||||
width: 100%;
|
||||
}
|
||||
.container{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
max-width: 860px;
|
||||
|
||||
.container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
max-width: 860px;
|
||||
}
|
||||
|
||||
.container div{
|
||||
display: flex;
|
||||
padding: 10px;
|
||||
margin-top: 40px;
|
||||
}
|
||||
.container div {
|
||||
display: flex;
|
||||
padding: 10px;
|
||||
margin-top: 40px;
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
import React from 'react';
|
||||
import { render } from '@testing-library/react';
|
||||
import App from './App';
|
||||
import React from 'react'
|
||||
import { render } from '@testing-library/react'
|
||||
import App from './App'
|
||||
|
||||
test('renders learn react link', () => {
|
||||
const { getByText } = render(<App />);
|
||||
const linkElement = getByText(/learn react/i);
|
||||
expect(linkElement).toBeInTheDocument();
|
||||
});
|
||||
const { getByText } = render(<App />)
|
||||
const linkElement = getByText(/learn react/i)
|
||||
expect(linkElement).toBeInTheDocument()
|
||||
})
|
||||
|
@ -1,13 +1,12 @@
|
||||
import React, { useEffect } from 'react';
|
||||
import './App.css';
|
||||
import React, { useEffect } from 'react'
|
||||
import './App.css'
|
||||
import { OceanProvider } from '@oceanprotocol/react'
|
||||
import { LogLevel } from '@oceanprotocol/lib/dist/node/utils/Logger';
|
||||
import { Wallet } from './Wallet';
|
||||
import { Publish } from './Publish';
|
||||
import { Config } from '@oceanprotocol/lib';
|
||||
import { LogLevel } from '@oceanprotocol/lib/dist/node/utils/Logger'
|
||||
import { Wallet } from './Wallet'
|
||||
import { Publish } from './Publish'
|
||||
import { Config } from '@oceanprotocol/lib'
|
||||
|
||||
function App() {
|
||||
|
||||
// factory Address needs to be updated each time you deploy the contract on local network
|
||||
const config = {
|
||||
metadataStoreUri: 'http://aquarius:5000',
|
||||
@ -15,28 +14,26 @@ function App() {
|
||||
nodeUri: `http://localhost:8545`,
|
||||
factoryAddress: '0x2fC1fd21cb222Dc180Ef817dE4c426fd9230b5A5'
|
||||
} as Config
|
||||
const init = async () => {
|
||||
|
||||
|
||||
}
|
||||
const init = async () => {}
|
||||
useEffect(() => {
|
||||
init()
|
||||
}, [])
|
||||
|
||||
|
||||
return (
|
||||
<div className="app">
|
||||
<OceanProvider config={config}>
|
||||
<div className="container">
|
||||
<div><Wallet /></div>
|
||||
|
||||
<div><Publish /></div>
|
||||
<div>
|
||||
<Wallet />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Publish />
|
||||
</div>
|
||||
</div>
|
||||
</OceanProvider>
|
||||
|
||||
</div>
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
export default App;
|
||||
export default App
|
||||
|
@ -1,47 +1,46 @@
|
||||
|
||||
import React from 'react';
|
||||
import React from 'react'
|
||||
import { useOcean, usePublish } from '@oceanprotocol/react'
|
||||
import { Metadata, DDO } from '@oceanprotocol/lib';
|
||||
import { useState } from 'react';
|
||||
|
||||
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 { accountId } = useOcean()
|
||||
const { publish } = usePublish()
|
||||
const [ddo, setDdo] = useState<DDO|undefined>()
|
||||
|
||||
const asset = {
|
||||
main: {
|
||||
type: 'dataset',
|
||||
name: 'test-dataset',
|
||||
dateCreated: new Date(Date.now()).toISOString().split('.')[0] + 'Z', // remove milliseconds
|
||||
author: 'oceanprotocol-team',
|
||||
license: 'MIT',
|
||||
files: [
|
||||
{
|
||||
url:
|
||||
'https://raw.githubusercontent.com/tbertinmahieux/MSongsDB/master/Tasks_Demos/CoverSongs/shs_dataset_test.txt',
|
||||
checksum: 'efb2c764274b745f5fc37f97c6b0e761',
|
||||
contentLength: '4535431',
|
||||
contentType: 'text/csv',
|
||||
encoding: 'UTF-8',
|
||||
compression: 'zip'
|
||||
}
|
||||
]
|
||||
const asset = {
|
||||
main: {
|
||||
type: 'dataset',
|
||||
name: 'test-dataset',
|
||||
dateCreated: new Date(Date.now()).toISOString().split('.')[0] + 'Z', // remove milliseconds
|
||||
author: 'oceanprotocol-team',
|
||||
license: 'MIT',
|
||||
files: [
|
||||
{
|
||||
url:
|
||||
'https://raw.githubusercontent.com/tbertinmahieux/MSongsDB/master/Tasks_Demos/CoverSongs/shs_dataset_test.txt',
|
||||
checksum: 'efb2c764274b745f5fc37f97c6b0e761',
|
||||
contentLength: '4535431',
|
||||
contentType: 'text/csv',
|
||||
encoding: 'UTF-8',
|
||||
compression: 'zip'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
const publishAsset = async ()=>{
|
||||
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>
|
||||
</>
|
||||
)
|
||||
}
|
||||
const publishAsset = async () => {
|
||||
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,34 +1,32 @@
|
||||
|
||||
import React from 'react';
|
||||
import React from 'react'
|
||||
import { useOcean } from '@oceanprotocol/react'
|
||||
import { useEffect } from 'react';
|
||||
|
||||
import { useEffect } from 'react'
|
||||
|
||||
export function Wallet() {
|
||||
|
||||
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")
|
||||
const { default: WalletConnectProvider } = await import(
|
||||
'@walletconnect/web3-provider'
|
||||
)
|
||||
const { default: Torus } = await import('@toruslabs/torus-embed')
|
||||
|
||||
const providerOptions = {
|
||||
/* See Provider Options Section */
|
||||
walletconnect: {
|
||||
package: WalletConnectProvider, // required
|
||||
options: {
|
||||
infuraId: "INFURA_ID" // required
|
||||
infuraId: 'INFURA_ID' // required
|
||||
}
|
||||
},
|
||||
torus: {
|
||||
package: Torus, // required
|
||||
package: Torus // required
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
await connect({ providerOptions })
|
||||
|
||||
}
|
||||
const init = async () => {
|
||||
if(ocean === undefined) return
|
||||
if (ocean === undefined) return
|
||||
console.log(ocean.datatokens.factoryAddress)
|
||||
|
||||
const accs = await ocean.accounts.list()
|
||||
@ -36,7 +34,6 @@ export function Wallet() {
|
||||
}
|
||||
useEffect(() => {
|
||||
init()
|
||||
|
||||
}, [ocean])
|
||||
|
||||
const disc = async () => {
|
||||
@ -46,12 +43,15 @@ export function Wallet() {
|
||||
return (
|
||||
<>
|
||||
<div>wallet</div>
|
||||
<div><button onClick={conn}>Connect</button></div>
|
||||
<div>
|
||||
<button onClick={conn}>Connect</button>
|
||||
</div>
|
||||
|
||||
<div><button onClick={disc}>Disconnect</button></div>
|
||||
<div>
|
||||
<button onClick={disc}>Disconnect</button>
|
||||
</div>
|
||||
|
||||
<div>{accountId}</div>
|
||||
|
||||
</>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,17 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import './index.css';
|
||||
import App from './App';
|
||||
import * as serviceWorker from './serviceWorker';
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom'
|
||||
import './index.css'
|
||||
import App from './App'
|
||||
import * as serviceWorker from './serviceWorker'
|
||||
|
||||
ReactDOM.render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>,
|
||||
document.getElementById('root')
|
||||
);
|
||||
)
|
||||
|
||||
// If you want your app to work offline and load faster, you can change
|
||||
// unregister() to register() below. Note this comes with some pitfalls.
|
||||
// Learn more about service workers: https://bit.ly/CRA-PWA
|
||||
serviceWorker.unregister();
|
||||
serviceWorker.unregister()
|
||||
|
@ -18,33 +18,30 @@ const isLocalhost = Boolean(
|
||||
window.location.hostname.match(
|
||||
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
|
||||
)
|
||||
);
|
||||
)
|
||||
|
||||
type Config = {
|
||||
onSuccess?: (registration: ServiceWorkerRegistration) => void;
|
||||
onUpdate?: (registration: ServiceWorkerRegistration) => void;
|
||||
};
|
||||
onSuccess?: (registration: ServiceWorkerRegistration) => void
|
||||
onUpdate?: (registration: ServiceWorkerRegistration) => void
|
||||
}
|
||||
|
||||
export function register(config?: Config) {
|
||||
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
|
||||
// The URL constructor is available in all browsers that support SW.
|
||||
const publicUrl = new URL(
|
||||
process.env.PUBLIC_URL,
|
||||
window.location.href
|
||||
);
|
||||
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href)
|
||||
if (publicUrl.origin !== window.location.origin) {
|
||||
// Our service worker won't work if PUBLIC_URL is on a different origin
|
||||
// from what our page is served on. This might happen if a CDN is used to
|
||||
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
|
||||
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`
|
||||
|
||||
if (isLocalhost) {
|
||||
// This is running on localhost. Let's check if a service worker still exists or not.
|
||||
checkValidServiceWorker(swUrl, config);
|
||||
checkValidServiceWorker(swUrl, config)
|
||||
|
||||
// Add some additional logging to localhost, pointing developers to the
|
||||
// service worker/PWA documentation.
|
||||
@ -52,24 +49,24 @@ export function register(config?: Config) {
|
||||
console.log(
|
||||
'This web app is being served cache-first by a service ' +
|
||||
'worker. To learn more, visit https://bit.ly/CRA-PWA'
|
||||
);
|
||||
});
|
||||
)
|
||||
})
|
||||
} else {
|
||||
// Is not localhost. Just register service worker
|
||||
registerValidSW(swUrl, config);
|
||||
registerValidSW(swUrl, config)
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function registerValidSW(swUrl: string, config?: Config) {
|
||||
navigator.serviceWorker
|
||||
.register(swUrl)
|
||||
.then(registration => {
|
||||
.then((registration) => {
|
||||
registration.onupdatefound = () => {
|
||||
const installingWorker = registration.installing;
|
||||
const installingWorker = registration.installing
|
||||
if (installingWorker == null) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
installingWorker.onstatechange = () => {
|
||||
if (installingWorker.state === 'installed') {
|
||||
@ -80,30 +77,30 @@ function registerValidSW(swUrl: string, config?: Config) {
|
||||
console.log(
|
||||
'New content is available and will be used when all ' +
|
||||
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
|
||||
);
|
||||
)
|
||||
|
||||
// Execute callback
|
||||
if (config && config.onUpdate) {
|
||||
config.onUpdate(registration);
|
||||
config.onUpdate(registration)
|
||||
}
|
||||
} else {
|
||||
// At this point, everything has been precached.
|
||||
// It's the perfect time to display a
|
||||
// "Content is cached for offline use." message.
|
||||
console.log('Content is cached for offline use.');
|
||||
console.log('Content is cached for offline use.')
|
||||
|
||||
// Execute callback
|
||||
if (config && config.onSuccess) {
|
||||
config.onSuccess(registration);
|
||||
config.onSuccess(registration)
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error during service worker registration:', error)
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error during service worker registration:', error);
|
||||
});
|
||||
}
|
||||
|
||||
function checkValidServiceWorker(swUrl: string, config?: Config) {
|
||||
@ -111,39 +108,39 @@ function checkValidServiceWorker(swUrl: string, config?: Config) {
|
||||
fetch(swUrl, {
|
||||
headers: { 'Service-Worker': 'script' }
|
||||
})
|
||||
.then(response => {
|
||||
.then((response) => {
|
||||
// Ensure service worker exists, and that we really are getting a JS file.
|
||||
const contentType = response.headers.get('content-type');
|
||||
const contentType = response.headers.get('content-type')
|
||||
if (
|
||||
response.status === 404 ||
|
||||
(contentType != null && contentType.indexOf('javascript') === -1)
|
||||
) {
|
||||
// No service worker found. Probably a different app. Reload the page.
|
||||
navigator.serviceWorker.ready.then(registration => {
|
||||
navigator.serviceWorker.ready.then((registration) => {
|
||||
registration.unregister().then(() => {
|
||||
window.location.reload();
|
||||
});
|
||||
});
|
||||
window.location.reload()
|
||||
})
|
||||
})
|
||||
} else {
|
||||
// Service worker found. Proceed as normal.
|
||||
registerValidSW(swUrl, config);
|
||||
registerValidSW(swUrl, config)
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
console.log(
|
||||
'No internet connection found. App is running in offline mode.'
|
||||
);
|
||||
});
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
export function unregister() {
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.ready
|
||||
.then(registration => {
|
||||
registration.unregister();
|
||||
.then((registration) => {
|
||||
registration.unregister()
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error.message)
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error.message);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -2,4 +2,4 @@
|
||||
// allows you to do things like:
|
||||
// expect(element).toHaveTextContent(/react/i)
|
||||
// learn more: https://github.com/testing-library/jest-dom
|
||||
import '@testing-library/jest-dom/extend-expect';
|
||||
import '@testing-library/jest-dom/extend-expect'
|
||||
|
@ -1,11 +1,7 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"lib": [
|
||||
"dom",
|
||||
"dom.iterable",
|
||||
"esnext"
|
||||
],
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true,
|
||||
@ -19,7 +15,5 @@
|
||||
"jsx": "react",
|
||||
"strict": true
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
]
|
||||
"include": ["src"]
|
||||
}
|
||||
|
222
package-lock.json
generated
222
package-lock.json
generated
@ -45,15 +45,6 @@
|
||||
"js-tokens": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"@babel/runtime": {
|
||||
"version": "7.9.2",
|
||||
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.9.2.tgz",
|
||||
"integrity": "sha512-NE2DtOdufG7R5vnfQUTehdTfNycfUANEtCa9PssN9O/xmTzP4E08UI797ixaei6hBEVL9BI/PsdJS5x7mWoB9Q==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"regenerator-runtime": "^0.13.4"
|
||||
}
|
||||
},
|
||||
"@babel/types": {
|
||||
"version": "7.9.6",
|
||||
"resolved": "https://registry.npmjs.org/@babel/types/-/types-7.9.6.tgz",
|
||||
@ -82,6 +73,20 @@
|
||||
"resolved": "https://registry.npmjs.org/@emotion/unitless/-/unitless-0.7.5.tgz",
|
||||
"integrity": "sha512-OWORNpfjMsSSUBVrRBVGECkhWcULOAJz9ZW8uK9qgxD+87M7jHRcvh/A96XXNhXTLmKcoYSQtBEX7lHMO7YRwg=="
|
||||
},
|
||||
"@ethereum-navigator/atlas": {
|
||||
"version": "0.7.1",
|
||||
"resolved": "https://registry.npmjs.org/@ethereum-navigator/atlas/-/atlas-0.7.1.tgz",
|
||||
"integrity": "sha512-YV7tMVwpRcJbc+Kj/Rr0RzNV/2hHBEEM1/tMWDVLB15dGJfoQuRfPJpFt6uq+Ji6s3EkldIt9kZylEeG5ALKAA=="
|
||||
},
|
||||
"@ethereum-navigator/navigator": {
|
||||
"version": "0.5.2",
|
||||
"resolved": "https://registry.npmjs.org/@ethereum-navigator/navigator/-/navigator-0.5.2.tgz",
|
||||
"integrity": "sha512-agSE2xzLxOKKid8QiS4v8jPhnFXW5uSXsICZ4JmS437aCZ8L3SUAy3cDQKikHb2PPZ3AazJO05k8m8i6u77peQ==",
|
||||
"requires": {
|
||||
"@ethereum-navigator/atlas": "^0.7.1",
|
||||
"web3": "^1.2.7"
|
||||
}
|
||||
},
|
||||
"@ethersproject/abi": {
|
||||
"version": "5.0.0-beta.153",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/abi/-/abi-5.0.0-beta.153.tgz",
|
||||
@ -261,6 +266,30 @@
|
||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-0.2.2.tgz",
|
||||
"integrity": "sha512-wu5Ub5F50vCAON0GKyv4anPPLm+oWfHViksiAewVS/xvbbnSCt4gHws2Uc1ct25tiO/2AHAyJkqEiC0ep8SHeQ=="
|
||||
},
|
||||
"@oceanprotocol/lib": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-0.1.2.tgz",
|
||||
"integrity": "sha512-v4Y0u7WnhhA33uIMuGKlWqGdlZLen7xRcwCBMvTlLp13Z3K+lOcg7UTByVxnKy2Tg2//wMYUWfuhSsk4nDA/DA==",
|
||||
"requires": {
|
||||
"@ethereum-navigator/navigator": "^0.5.0",
|
||||
"bignumber.js": "^9.0.0",
|
||||
"deprecated-decorator": "^0.1.6",
|
||||
"fs": "0.0.1-security",
|
||||
"node-fetch": "^2.6.0",
|
||||
"save-file": "^2.3.1",
|
||||
"uuid": "^8.2.0",
|
||||
"web3": "^1.2.9",
|
||||
"web3-eth-contract": "^1.2.9",
|
||||
"whatwg-url": "^8.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"uuid": {
|
||||
"version": "8.2.0",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.2.0.tgz",
|
||||
"integrity": "sha512-CYpGiFTUrmI6OBMkAdjSDM0k5h8SkkiTP4WAjQgDgNB1S3Ou9VBEvr6q0Kv2H1mMk7IWfxYGpMH5sd5AvcIV2Q=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"@octokit/auth-token": {
|
||||
"version": "2.4.2",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-2.4.2.tgz",
|
||||
@ -606,6 +635,15 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"@typescript-eslint/visitor-keys": {
|
||||
"version": "3.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-3.6.0.tgz",
|
||||
"integrity": "sha512-p1izllL2Ubwunite0ITjubuMQRBGgjdVYwyG7lXPX8GbrA6qF0uwSRz9MnXZaHMxID4948gX0Ez8v9tUDi/KfQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"eslint-visitor-keys": "^1.1.0"
|
||||
}
|
||||
},
|
||||
"accepts": {
|
||||
"version": "1.3.7",
|
||||
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz",
|
||||
@ -751,6 +789,17 @@
|
||||
"es-abstract": "^1.17.0-next.1"
|
||||
}
|
||||
},
|
||||
"array.prototype.flatmap": {
|
||||
"version": "1.2.3",
|
||||
"resolved": "https://registry.npmjs.org/array.prototype.flatmap/-/array.prototype.flatmap-1.2.3.tgz",
|
||||
"integrity": "sha512-OOEk+lkePcg+ODXIpvuU9PAryCikCJyo7GlDG1upleEpQRx6mzL9puEBkozQ5iAx20KV0l3DbyQwqciJtqe5Pg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"define-properties": "^1.1.3",
|
||||
"es-abstract": "^1.17.0-next.1",
|
||||
"function-bind": "^1.1.1"
|
||||
}
|
||||
},
|
||||
"asn1": {
|
||||
"version": "0.2.4",
|
||||
"resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz",
|
||||
@ -799,6 +848,11 @@
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
|
||||
},
|
||||
"atob-lite": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/atob-lite/-/atob-lite-2.0.0.tgz",
|
||||
"integrity": "sha1-D+9a1G8b16hQLGVyfwNn1e5D1pY="
|
||||
},
|
||||
"auto-changelog": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/auto-changelog/-/auto-changelog-2.2.0.tgz",
|
||||
@ -1638,6 +1692,11 @@
|
||||
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
|
||||
"integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak="
|
||||
},
|
||||
"deprecated-decorator": {
|
||||
"version": "0.1.6",
|
||||
"resolved": "https://registry.npmjs.org/deprecated-decorator/-/deprecated-decorator-0.1.6.tgz",
|
||||
"integrity": "sha1-AJZjF7ehL+kvPMgx91g68ym4bDc="
|
||||
},
|
||||
"deprecated-obj": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/deprecated-obj/-/deprecated-obj-1.0.1.tgz",
|
||||
@ -1751,6 +1810,11 @@
|
||||
"create-hmac": "^1.1.4"
|
||||
}
|
||||
},
|
||||
"dtype": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/dtype/-/dtype-2.0.0.tgz",
|
||||
"integrity": "sha1-zQUjI84GFETs0uj1dI9popvihDQ="
|
||||
},
|
||||
"duplexer3": {
|
||||
"version": "0.1.4",
|
||||
"resolved": "https://registry.npmjs.org/duplexer3/-/duplexer3-0.1.4.tgz",
|
||||
@ -1803,6 +1867,15 @@
|
||||
"once": "^1.4.0"
|
||||
}
|
||||
},
|
||||
"enquirer": {
|
||||
"version": "2.3.6",
|
||||
"resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.3.6.tgz",
|
||||
"integrity": "sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"ansi-colors": "^4.1.1"
|
||||
}
|
||||
},
|
||||
"error-ex": {
|
||||
"version": "1.3.2",
|
||||
"resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz",
|
||||
@ -2840,6 +2913,11 @@
|
||||
"flat-cache": "^2.0.1"
|
||||
}
|
||||
},
|
||||
"file-saver": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/file-saver/-/file-saver-2.0.2.tgz",
|
||||
"integrity": "sha512-Wz3c3XQ5xroCxd1G8b7yL0Ehkf0TC9oYC6buPFkNnU9EnaPlifeAFCyCh+iewXTyFRcg0a6j3J7FmJsIhlhBdw=="
|
||||
},
|
||||
"file-uri-to-path": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
|
||||
@ -2918,6 +2996,14 @@
|
||||
"integrity": "sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA==",
|
||||
"dev": true
|
||||
},
|
||||
"flatten-vertex-data": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/flatten-vertex-data/-/flatten-vertex-data-1.0.2.tgz",
|
||||
"integrity": "sha512-BvCBFK2NZqerFTdMDgqfHBwxYWnxeCkwONsw6PvBMcUXqo8U/KDWwmXhqx1x2kLIg7DqIsJfOaJFOmlua3Lxuw==",
|
||||
"requires": {
|
||||
"dtype": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"follow-redirects": {
|
||||
"version": "1.5.10",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
|
||||
@ -2966,6 +3052,11 @@
|
||||
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
|
||||
"integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac="
|
||||
},
|
||||
"fs": {
|
||||
"version": "0.0.1-security",
|
||||
"resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
|
||||
"integrity": "sha1-invTcYa23d84E/I4WLV+yq9eQdQ="
|
||||
},
|
||||
"fs-extra": {
|
||||
"version": "4.0.3",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-4.0.3.tgz",
|
||||
@ -3531,11 +3622,20 @@
|
||||
"integrity": "sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=",
|
||||
"dev": true
|
||||
},
|
||||
"is-base64": {
|
||||
"version": "0.1.0",
|
||||
"resolved": "https://registry.npmjs.org/is-base64/-/is-base64-0.1.0.tgz",
|
||||
"integrity": "sha512-WRRyllsGXJM7ZN7gPTCCQ/6wNPTRDwiWdPK66l5sJzcU/oOzcIcRRf0Rux8bkpox/1yjt0F6VJRsQOIG2qz5sg=="
|
||||
},
|
||||
"is-blob": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-blob/-/is-blob-1.0.0.tgz",
|
||||
"integrity": "sha1-o9fZb+HD/wZex84nwsIea6ksGDI="
|
||||
},
|
||||
"is-buffer": {
|
||||
"version": "2.0.4",
|
||||
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.4.tgz",
|
||||
"integrity": "sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A==",
|
||||
"dev": true
|
||||
"integrity": "sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A=="
|
||||
},
|
||||
"is-callable": {
|
||||
"version": "1.1.5",
|
||||
@ -3951,6 +4051,11 @@
|
||||
"integrity": "sha1-2HV7HagH3eJIFrDWqEvqGnYjCyM=",
|
||||
"dev": true
|
||||
},
|
||||
"lodash.sortby": {
|
||||
"version": "4.7.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz",
|
||||
"integrity": "sha1-7dFMgk4sycHgsKG0K7UhBRakJDg="
|
||||
},
|
||||
"lodash.uniqby": {
|
||||
"version": "4.7.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.uniqby/-/lodash.uniqby-4.7.0.tgz",
|
||||
@ -3985,6 +4090,15 @@
|
||||
"integrity": "sha512-ko6deozZYiAkqa/0gmcsz+p4jSy3gY7/ZsCEokPaYd8k+6/aXGkiTgr61+Owup7Sf+xjqW8u2ElhoM9SEcEfuA==",
|
||||
"dev": true
|
||||
},
|
||||
"make-dir": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz",
|
||||
"integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"semver": "^6.0.0"
|
||||
}
|
||||
},
|
||||
"md5.js": {
|
||||
"version": "1.3.5",
|
||||
"resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz",
|
||||
@ -4236,8 +4350,7 @@
|
||||
"node-fetch": {
|
||||
"version": "2.6.0",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz",
|
||||
"integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==",
|
||||
"dev": true
|
||||
"integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA=="
|
||||
},
|
||||
"normalize-package-data": {
|
||||
"version": "2.5.0",
|
||||
@ -4982,12 +5095,6 @@
|
||||
"resolve": "^1.1.6"
|
||||
}
|
||||
},
|
||||
"regenerator-runtime": {
|
||||
"version": "0.13.5",
|
||||
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.5.tgz",
|
||||
"integrity": "sha512-ZS5w8CpKFinUzOwW3c83oPeVXoNsrLsaCoLtJvAClH135j/R77RuymhiSErhm2lKcwSCIpmvIWSbDkIfAqKQlA==",
|
||||
"dev": true
|
||||
},
|
||||
"regexp.prototype.flags": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.3.0.tgz",
|
||||
@ -5523,6 +5630,19 @@
|
||||
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
||||
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
|
||||
},
|
||||
"save-file": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/save-file/-/save-file-2.3.1.tgz",
|
||||
"integrity": "sha512-VOD2Ojb1/kuj0XbvSXzZ5xr4rRSZD8f+HzKWGztXNp93gBQDj3njFt9HMhmLtnwd7q0BjJkzLXqd8M2+PFS1qg==",
|
||||
"requires": {
|
||||
"file-saver": "^2.0.0-rc.4",
|
||||
"is-blob": "^1.0.0",
|
||||
"is-buffer": "^2.0.0",
|
||||
"simple-mime": "^0.1.0",
|
||||
"to-array-buffer": "^3.2.0",
|
||||
"write": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"scheduler": {
|
||||
"version": "0.19.1",
|
||||
"resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.19.1.tgz",
|
||||
@ -5708,6 +5828,11 @@
|
||||
"simple-concat": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"simple-mime": {
|
||||
"version": "0.1.0",
|
||||
"resolved": "https://registry.npmjs.org/simple-mime/-/simple-mime-0.1.0.tgz",
|
||||
"integrity": "sha1-lfUXxPRm18/1YacfydqyWW6p7y4="
|
||||
},
|
||||
"slash": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz",
|
||||
@ -5803,6 +5928,15 @@
|
||||
"resolved": "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz",
|
||||
"integrity": "sha1-J5siXfHVgrH1TmWt3UNS4Y+qBxM="
|
||||
},
|
||||
"string-to-arraybuffer": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/string-to-arraybuffer/-/string-to-arraybuffer-1.0.2.tgz",
|
||||
"integrity": "sha512-DaGZidzi93dwjQen5I2osxR9ERS/R7B1PFyufNMnzhj+fmlDQAc1DSDIJVJhgI8Oq221efIMbABUBdPHDRt43Q==",
|
||||
"requires": {
|
||||
"atob-lite": "^2.0.0",
|
||||
"is-base64": "^0.1.0"
|
||||
}
|
||||
},
|
||||
"string-width": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz",
|
||||
@ -6128,6 +6262,23 @@
|
||||
"os-tmpdir": "~1.0.2"
|
||||
}
|
||||
},
|
||||
"to-array-buffer": {
|
||||
"version": "3.2.0",
|
||||
"resolved": "https://registry.npmjs.org/to-array-buffer/-/to-array-buffer-3.2.0.tgz",
|
||||
"integrity": "sha512-zN33mwi0gpL+7xW1ITLfJ48CEj6ZQW0ZAP0MU+2W3kEY0PAIncyuxmD4OqkUVhPAbTP7amq9j/iwvZKYS+lzSQ==",
|
||||
"requires": {
|
||||
"flatten-vertex-data": "^1.0.2",
|
||||
"is-blob": "^2.0.1",
|
||||
"string-to-arraybuffer": "^1.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"is-blob": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/is-blob/-/is-blob-2.1.0.tgz",
|
||||
"integrity": "sha512-SZ/fTft5eUhQM6oF/ZaASFDEdbFVe89Imltn9uZr03wdKMcWNVYSMjQPFtg05QuNkt5l5c135ElvXEQG0rk4tw=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"to-fast-properties": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz",
|
||||
@ -6161,6 +6312,14 @@
|
||||
"punycode": "^2.1.1"
|
||||
}
|
||||
},
|
||||
"tr46": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/tr46/-/tr46-2.0.2.tgz",
|
||||
"integrity": "sha512-3n1qG+/5kg+jrbTzwAykB5yRYtQCTqOGKq5U5PE3b0a1/mzo6snDhjGS0zJVJunO0NrT3Dg1MLy5TjWP/UJppg==",
|
||||
"requires": {
|
||||
"punycode": "^2.1.1"
|
||||
}
|
||||
},
|
||||
"tslib": {
|
||||
"version": "1.11.1",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.11.1.tgz",
|
||||
@ -6774,6 +6933,11 @@
|
||||
"tslib": "^1.10.0"
|
||||
}
|
||||
},
|
||||
"webidl-conversions": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-5.0.0.tgz",
|
||||
"integrity": "sha512-VlZwKPCkYKxQgeSbH5EyngOmRp7Ww7I9rQLERETtf5ofd9pGeswWiOtogpEO850jziPRarreGxn5QIiTqpb2wA=="
|
||||
},
|
||||
"websocket": {
|
||||
"version": "1.0.31",
|
||||
"resolved": "https://registry.npmjs.org/websocket/-/websocket-1.0.31.tgz",
|
||||
@ -6801,6 +6965,16 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"whatwg-url": {
|
||||
"version": "8.1.0",
|
||||
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-8.1.0.tgz",
|
||||
"integrity": "sha512-vEIkwNi9Hqt4TV9RdnaBPNt+E2Sgmo3gePebCRgZ1R7g6d23+53zCTnuB0amKI4AXq6VM8jj2DUAa0S1vjJxkw==",
|
||||
"requires": {
|
||||
"lodash.sortby": "^4.7.0",
|
||||
"tr46": "^2.0.2",
|
||||
"webidl-conversions": "^5.0.0"
|
||||
}
|
||||
},
|
||||
"which": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz",
|
||||
@ -6902,7 +7076,6 @@
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/write/-/write-1.0.3.tgz",
|
||||
"integrity": "sha512-/lg70HAjtkUgWPVZhZcm+T4hkL8Zbtp1nFNOn3lRrxnlv50SRBv7cR7RqR+GMsd3hUXy9hWBo4CHTbFTcOYwig==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"mkdirp": "^0.5.1"
|
||||
}
|
||||
@ -6976,15 +7149,6 @@
|
||||
"cookiejar": "^2.1.1"
|
||||
}
|
||||
},
|
||||
"xregexp": {
|
||||
"version": "4.3.0",
|
||||
"resolved": "https://registry.npmjs.org/xregexp/-/xregexp-4.3.0.tgz",
|
||||
"integrity": "sha512-7jXDIFXh5yJ/orPn4SXjuVrWWoi4Cr8jfV1eHv9CixKSbU+jY4mxfrBwAuDvupPNKpMUY+FeIqsVw/JLT9+B8g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/runtime-corejs3": "^7.8.3"
|
||||
}
|
||||
},
|
||||
"xtend": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
|
||||
|
@ -22,6 +22,7 @@
|
||||
],
|
||||
"dependencies": {
|
||||
"@oceanprotocol/contracts": "^0.2.2",
|
||||
"@oceanprotocol/lib": "^0.1.2",
|
||||
"axios": "^0.19.2",
|
||||
"react": "^16.9.41",
|
||||
"web3": "^1.2.9",
|
||||
|
@ -1,3 +1,3 @@
|
||||
export * from './useConsume'
|
||||
export * from './useMetadata'
|
||||
export * from './usePublish'
|
||||
export * from './usePublish'
|
||||
|
@ -33,15 +33,13 @@ function useConsume(): UseConsume {
|
||||
setConsumeError(undefined)
|
||||
|
||||
try {
|
||||
|
||||
setConsumeStep(0)
|
||||
setConsumeStepText(consumeFeedback[0])
|
||||
const ddo = await ocean.metadatastore.retrieveDDO(did)
|
||||
|
||||
setConsumeStep(1)
|
||||
setConsumeStepText(consumeFeedback[1])
|
||||
const order = await ocean.assets
|
||||
.order(did, serviceType, accountId)
|
||||
const order = await ocean.assets.order(did, serviceType, accountId)
|
||||
setConsumeStep(2)
|
||||
setConsumeStepText(consumeFeedback[2])
|
||||
const res = JSON.parse(order)
|
||||
@ -63,7 +61,6 @@ function useConsume(): UseConsume {
|
||||
|
||||
setConsumeStep(4)
|
||||
setConsumeStepText(consumeFeedback[4])
|
||||
|
||||
} catch (error) {
|
||||
setConsumeError(error.message)
|
||||
} finally {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import axios from 'axios'
|
||||
import { DID, DDO, Metadata } from '@oceanprotocol/lib'
|
||||
import { useOcean, } from '../../providers'
|
||||
import { useOcean } from '../../providers'
|
||||
import ProviderStatus from '../../providers/OceanProvider/ProviderStatus'
|
||||
|
||||
interface UseMetadata {
|
||||
@ -33,7 +33,6 @@ function useMetadata(did?: DID | string): UseMetadata {
|
||||
return metadata.attributes
|
||||
}
|
||||
|
||||
|
||||
async function getTitle(did: DID | string): Promise<string> {
|
||||
const metadata = await getMetadata(did)
|
||||
return metadata.main.name
|
||||
@ -58,7 +57,7 @@ function useMetadata(did?: DID | string): UseMetadata {
|
||||
title,
|
||||
getDDO,
|
||||
getMetadata,
|
||||
getTitle,
|
||||
getTitle
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,117 +1,131 @@
|
||||
import { useEffect } from 'react'
|
||||
import { DDO, Metadata, DataTokens, Logger } from '@oceanprotocol/lib'
|
||||
import { useOcean, } from '../../providers'
|
||||
import { useOcean } from '../../providers'
|
||||
import ProviderStatus from '../../providers/OceanProvider/ProviderStatus'
|
||||
import { Service } from '@oceanprotocol/lib/dist/node/ddo/interfaces/Service'
|
||||
|
||||
interface UsePublish {
|
||||
|
||||
publish: (asset: Metadata, tokensToMint: number, price?: number) => Promise<DDO>
|
||||
mint: (tokenAddress: string, tokensToMint: number) => void
|
||||
publish: (
|
||||
asset: Metadata,
|
||||
tokensToMint: number,
|
||||
price?: number
|
||||
) => Promise<DDO>
|
||||
mint: (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()
|
||||
const { web3, ocean, status, account, accountId, config } = useOcean()
|
||||
|
||||
async function publish(asset: Metadata, tokensToMint: number, price: number = 1): Promise<DDO> {
|
||||
if (status !== ProviderStatus.CONNECTED) return
|
||||
async function publish(
|
||||
asset: Metadata,
|
||||
tokensToMint: number,
|
||||
price: number = 1
|
||||
): Promise<DDO> {
|
||||
if (status !== ProviderStatus.CONNECTED) return
|
||||
|
||||
const datatoken = new DataTokens(
|
||||
ocean.datatokens.factoryAddress,
|
||||
factory.abi,
|
||||
datatokensTemplate.abi,
|
||||
web3
|
||||
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
|
||||
let services: Service[] = []
|
||||
switch (asset.main.type) {
|
||||
case 'dataset': {
|
||||
const accessService = await ocean.assets.createAccessServiceAttributes(
|
||||
account,
|
||||
price.toString(),
|
||||
publishedDate,
|
||||
timeout
|
||||
)
|
||||
|
||||
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
|
||||
let services: Service[] = []
|
||||
switch (asset.main.type) {
|
||||
case 'dataset': {
|
||||
const accessService = await ocean.assets.createAccessServiceAttributes(
|
||||
account,
|
||||
price,
|
||||
publishedDate,
|
||||
timeout
|
||||
)
|
||||
Logger.log('access service created', accessService)
|
||||
services = [accessService]
|
||||
break;
|
||||
}
|
||||
case 'algorithm': {
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const ddo = await ocean.assets.create(asset, account, services, tokenAddress)
|
||||
|
||||
return ddo
|
||||
Logger.log('access service created', accessService)
|
||||
services = [accessService]
|
||||
break
|
||||
}
|
||||
case 'algorithm': {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
async function mint(tokenAddress: string, tokensToMint: number, datatoken?: DataTokens) {
|
||||
if (datatoken === undefined)
|
||||
datatoken = new DataTokens(
|
||||
ocean.datatokens.factoryAddress,
|
||||
factory.abi,
|
||||
datatokensTemplate.abi,
|
||||
web3
|
||||
)
|
||||
const ddo = await ocean.assets.create(
|
||||
asset,
|
||||
account,
|
||||
services,
|
||||
tokenAddress
|
||||
)
|
||||
|
||||
await datatoken.mint(tokenAddress, accountId, tokensToMint)
|
||||
}
|
||||
return ddo
|
||||
}
|
||||
|
||||
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
|
||||
)
|
||||
async function mint(
|
||||
tokenAddress: string,
|
||||
tokensToMint: 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)
|
||||
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
|
||||
)
|
||||
// allowance should be string not number, so this is a temp hack
|
||||
await datatoken.transferFrom(
|
||||
tokenAddress,
|
||||
accountId,
|
||||
(allowance as unknown) as number,
|
||||
marketAddress
|
||||
)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
async function init(): Promise<void> {
|
||||
useEffect(() => {
|
||||
async function init(): Promise<void> {}
|
||||
init()
|
||||
}, [])
|
||||
|
||||
}
|
||||
init()
|
||||
}, [])
|
||||
|
||||
return {
|
||||
publish,
|
||||
mint
|
||||
}
|
||||
return {
|
||||
publish,
|
||||
mint
|
||||
}
|
||||
}
|
||||
|
||||
export { usePublish, UsePublish }
|
||||
|
@ -22,7 +22,6 @@ interface OceanProviderValue {
|
||||
logout: () => void
|
||||
}
|
||||
|
||||
|
||||
const OceanContext = createContext(null)
|
||||
|
||||
function OceanProvider({
|
||||
@ -40,33 +39,32 @@ function OceanProvider({
|
||||
const [account, setAccount] = useState<Account | undefined>()
|
||||
const [accountId, setAccountId] = useState<string | undefined>()
|
||||
const [balance, setBalance] = useState<string | undefined>()
|
||||
const [status, setStatus] = useState(
|
||||
ProviderStatus.NOT_AVAILABLE
|
||||
)
|
||||
|
||||
const [status, setStatus] = useState(ProviderStatus.NOT_AVAILABLE)
|
||||
|
||||
function init() {
|
||||
Logger.log("Ocean Provider init")
|
||||
Logger.log('Ocean Provider init')
|
||||
}
|
||||
|
||||
// On mount setup Web3Modal instance
|
||||
// On mount setup Web3Modal instance
|
||||
useEffect(() => {
|
||||
init()
|
||||
}, [])
|
||||
|
||||
async function connect(opts?: Partial<ICoreOptions>) {
|
||||
Logger.log("Connecting ....")
|
||||
const instance = new Web3Modal(opts);
|
||||
Logger.log('Connecting ....')
|
||||
const instance = new Web3Modal(opts)
|
||||
setWeb3Modal(instance)
|
||||
Logger.log("Web3Modal instance created", instance)
|
||||
Logger.log('Web3Modal instance created', instance)
|
||||
const provider = await instance.connect()
|
||||
setWeb3Provider(provider)
|
||||
|
||||
const web3 = new Web3(provider)
|
||||
setWeb3(web3)
|
||||
|
||||
config.factoryABI = config.factoryABI? config.factoryABI : factory.abi
|
||||
config.datatokensABI= config.datatokensABI? config.datatokensABI: datatokensTemplate.abi
|
||||
config.factoryABI = config.factoryABI ? config.factoryABI : factory.abi
|
||||
config.datatokensABI = config.datatokensABI
|
||||
? config.datatokensABI
|
||||
: datatokensTemplate.abi
|
||||
config.web3Provider = web3
|
||||
const ocean = await Ocean.getInstance(config)
|
||||
|
||||
@ -90,10 +88,8 @@ function OceanProvider({
|
||||
}
|
||||
|
||||
async function logout() {
|
||||
|
||||
// ToDo check how is the proper way to logout
|
||||
web3Modal.clearCachedProvider()
|
||||
|
||||
}
|
||||
|
||||
async function getAccount(web3: Web3) {
|
||||
@ -112,8 +108,6 @@ function OceanProvider({
|
||||
//
|
||||
const handleConnect = async (provider: any) => {
|
||||
Logger.debug("Handling 'connect' event with payload", provider)
|
||||
|
||||
|
||||
}
|
||||
|
||||
const handleAccountsChanged = async (accounts: string[]) => {
|
||||
@ -136,12 +130,10 @@ function OceanProvider({
|
||||
// handleConnect(ethProvider)
|
||||
}
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
web3Modal && web3Modal.on('connect', handleConnect)
|
||||
|
||||
if (web3Provider !== undefined && web3Provider !== null) {
|
||||
|
||||
web3Provider.on('accountsChanged', handleAccountsChanged)
|
||||
web3Provider.on('networkChanged', handleNetworkChanged)
|
||||
|
||||
@ -152,8 +144,6 @@ function OceanProvider({
|
||||
}
|
||||
}, [web3, web3Modal, web3Provider])
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<OceanContext.Provider
|
||||
value={
|
||||
@ -169,7 +159,7 @@ function OceanProvider({
|
||||
status,
|
||||
config,
|
||||
connect,
|
||||
logout,
|
||||
logout
|
||||
} as OceanProviderValue
|
||||
}
|
||||
>
|
||||
@ -181,9 +171,5 @@ function OceanProvider({
|
||||
// Helper hook to access the provider values
|
||||
const useOcean = (): OceanProviderValue => useContext(OceanContext)
|
||||
|
||||
export {
|
||||
OceanProvider,
|
||||
useOcean,
|
||||
OceanProviderValue
|
||||
}
|
||||
export { OceanProvider, useOcean, OceanProviderValue }
|
||||
export default OceanProvider
|
||||
|
@ -1,7 +1,7 @@
|
||||
enum ProviderStatus {
|
||||
NOT_AVAILABLE = -1,
|
||||
NOT_CONNECTED = 0,
|
||||
CONNECTED = 1
|
||||
NOT_AVAILABLE = -1,
|
||||
NOT_CONNECTED = 0,
|
||||
CONNECTED = 1
|
||||
}
|
||||
|
||||
export default ProviderStatus
|
||||
export default ProviderStatus
|
||||
|
@ -1,2 +1,2 @@
|
||||
export * from './OceanProvider'
|
||||
export * from './ProviderStatus'
|
||||
export * from './ProviderStatus'
|
||||
|
Loading…
Reference in New Issue
Block a user