mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
prepare publish flow in code
This commit is contained in:
parent
4e985ba633
commit
8ce573b2a0
11
package-lock.json
generated
11
package-lock.json
generated
@ -33,6 +33,7 @@
|
|||||||
"gray-matter": "^4.0.3",
|
"gray-matter": "^4.0.3",
|
||||||
"is-url-superb": "^6.1.0",
|
"is-url-superb": "^6.1.0",
|
||||||
"js-cookie": "^3.0.1",
|
"js-cookie": "^3.0.1",
|
||||||
|
"js-sha256": "^0.9.0",
|
||||||
"jwt-decode": "^3.1.2",
|
"jwt-decode": "^3.1.2",
|
||||||
"lodash.debounce": "^4.0.8",
|
"lodash.debounce": "^4.0.8",
|
||||||
"lodash.omit": "^4.5.0",
|
"lodash.omit": "^4.5.0",
|
||||||
@ -26464,6 +26465,11 @@
|
|||||||
"node": ">=12"
|
"node": ">=12"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/js-sha256": {
|
||||||
|
"version": "0.9.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/js-sha256/-/js-sha256-0.9.0.tgz",
|
||||||
|
"integrity": "sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA=="
|
||||||
|
},
|
||||||
"node_modules/js-sha3": {
|
"node_modules/js-sha3": {
|
||||||
"version": "0.8.0",
|
"version": "0.8.0",
|
||||||
"resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz",
|
"resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz",
|
||||||
@ -64207,6 +64213,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-3.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-3.0.1.tgz",
|
||||||
"integrity": "sha512-+0rgsUXZu4ncpPxRL+lNEptWMOWl9etvPHc/koSRp6MPwpRYAhmk0dUG00J4bxVV3r9uUzfo24wW0knS07SKSw=="
|
"integrity": "sha512-+0rgsUXZu4ncpPxRL+lNEptWMOWl9etvPHc/koSRp6MPwpRYAhmk0dUG00J4bxVV3r9uUzfo24wW0knS07SKSw=="
|
||||||
},
|
},
|
||||||
|
"js-sha256": {
|
||||||
|
"version": "0.9.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/js-sha256/-/js-sha256-0.9.0.tgz",
|
||||||
|
"integrity": "sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA=="
|
||||||
|
},
|
||||||
"js-sha3": {
|
"js-sha3": {
|
||||||
"version": "0.8.0",
|
"version": "0.8.0",
|
||||||
"resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz",
|
"resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz",
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
"gray-matter": "^4.0.3",
|
"gray-matter": "^4.0.3",
|
||||||
"is-url-superb": "^6.1.0",
|
"is-url-superb": "^6.1.0",
|
||||||
"js-cookie": "^3.0.1",
|
"js-cookie": "^3.0.1",
|
||||||
|
"js-sha256": "^0.9.0",
|
||||||
"jwt-decode": "^3.1.2",
|
"jwt-decode": "^3.1.2",
|
||||||
"lodash.debounce": "^4.0.8",
|
"lodash.debounce": "^4.0.8",
|
||||||
"lodash.omit": "^4.5.0",
|
"lodash.omit": "^4.5.0",
|
||||||
|
@ -31,7 +31,7 @@ export const wizardSteps: StepContent[] = [
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
export const initialValues: Partial<FormPublishData> = {
|
export const initialValues: FormPublishData = {
|
||||||
step: 1,
|
step: 1,
|
||||||
chainId: 1,
|
chainId: 1,
|
||||||
metadata: {
|
metadata: {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { sha256 } from 'js-sha256'
|
||||||
import {
|
import {
|
||||||
dateToStringNoMS,
|
dateToStringNoMS,
|
||||||
transformTags,
|
transformTags,
|
||||||
@ -16,10 +17,15 @@ export function getFieldContent(
|
|||||||
return fields.filter((field: FormFieldContent) => field.name === fieldName)[0]
|
return fields.filter((field: FormFieldContent) => field.name === fieldName)[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
export function transformPublishFormToDdo(data: Partial<FormPublishData>): DDO {
|
export function transformPublishFormToDdo(
|
||||||
|
values: FormPublishData,
|
||||||
|
datatokenAddress: string,
|
||||||
|
nftAddress: string
|
||||||
|
): DDO {
|
||||||
|
const did = sha256(`${nftAddress}${values.chainId}`)
|
||||||
const currentTime = dateToStringNoMS(new Date())
|
const currentTime = dateToStringNoMS(new Date())
|
||||||
const { type, name, description, tags, author, termsAndConditions } =
|
const { type, name, description, tags, author, termsAndConditions } =
|
||||||
data.metadata
|
values.metadata
|
||||||
const {
|
const {
|
||||||
access,
|
access,
|
||||||
files,
|
files,
|
||||||
@ -29,7 +35,7 @@ export function transformPublishFormToDdo(data: Partial<FormPublishData>): DDO {
|
|||||||
entrypoint,
|
entrypoint,
|
||||||
providerUrl,
|
providerUrl,
|
||||||
timeout
|
timeout
|
||||||
} = data.services[0]
|
} = values.services[0]
|
||||||
|
|
||||||
const fileUrl = typeof files !== 'string' && files[0].url
|
const fileUrl = typeof files !== 'string' && files[0].url
|
||||||
|
|
||||||
@ -51,10 +57,10 @@ export function transformPublishFormToDdo(data: Partial<FormPublishData>): DDO {
|
|||||||
language: getUrlFileExtension(fileUrl),
|
language: getUrlFileExtension(fileUrl),
|
||||||
version: '0.1',
|
version: '0.1',
|
||||||
container: {
|
container: {
|
||||||
entrypoint: entrypoint,
|
entrypoint,
|
||||||
image: image,
|
image,
|
||||||
tag: containerTag,
|
tag: containerTag,
|
||||||
checksum: ''
|
checksum: '' // how to get? Is it user input?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -63,7 +69,7 @@ export function transformPublishFormToDdo(data: Partial<FormPublishData>): DDO {
|
|||||||
const service: Service = {
|
const service: Service = {
|
||||||
type: access,
|
type: access,
|
||||||
files: encryptMe(files),
|
files: encryptMe(files),
|
||||||
datatokenAddress: '', // how to get before publish?
|
datatokenAddress,
|
||||||
serviceEndpoint: providerUrl,
|
serviceEndpoint: providerUrl,
|
||||||
timeout,
|
timeout,
|
||||||
...(access === 'compute' && {
|
...(access === 'compute' && {
|
||||||
@ -84,9 +90,9 @@ export function transformPublishFormToDdo(data: Partial<FormPublishData>): DDO {
|
|||||||
|
|
||||||
const newDdo: DDO = {
|
const newDdo: DDO = {
|
||||||
'@context': ['https://w3id.org/did/v1'],
|
'@context': ['https://w3id.org/did/v1'],
|
||||||
id: '', // how to get before publish? sha256(address of ERC721 contract + data.chainId)
|
id: did,
|
||||||
version: '4.0.0',
|
version: '4.0.0',
|
||||||
chainId: data.chainId,
|
chainId: values.chainId,
|
||||||
metadata,
|
metadata,
|
||||||
services: [service]
|
services: [service]
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import Actions from './Actions'
|
|||||||
import Debug from './Debug'
|
import Debug from './Debug'
|
||||||
import Navigation from './Navigation'
|
import Navigation from './Navigation'
|
||||||
import { Steps } from './Steps'
|
import { Steps } from './Steps'
|
||||||
|
import { FormPublishData } from './_types'
|
||||||
|
|
||||||
const formName = 'ocean-publish-form'
|
const formName = 'ocean-publish-form'
|
||||||
|
|
||||||
@ -29,6 +30,21 @@ export default function PublishPage({
|
|||||||
const [error, setError] = useState<string>()
|
const [error, setError] = useState<string>()
|
||||||
const scrollToRef = useRef()
|
const scrollToRef = useRef()
|
||||||
|
|
||||||
|
async function handleSubmit(values: FormPublishData) {
|
||||||
|
try {
|
||||||
|
// 1. Mint NFT & datatokens & put in pool
|
||||||
|
// const txMint = await createNftWithErc()
|
||||||
|
// const { nftAddress, datatokenAddress } = txMint.logs[0].args
|
||||||
|
// 2. Construct and publish DDO
|
||||||
|
// const did = sha256(`${nftAddress}${chainId}`)
|
||||||
|
// const ddo = transformPublishFormToDdo(values, datatokenAddress, nftAddress)
|
||||||
|
// const txPublish = await publish(ddo)
|
||||||
|
setSuccess('Your DDO was published successfully!')
|
||||||
|
} catch (error) {
|
||||||
|
setError(error.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// async function handleSubmit(
|
// async function handleSubmit(
|
||||||
// values: Partial<FormPublishData>,
|
// values: Partial<FormPublishData>,
|
||||||
// resetForm: (
|
// resetForm: (
|
||||||
@ -90,7 +106,7 @@ export default function PublishPage({
|
|||||||
validationSchema={validationSchema}
|
validationSchema={validationSchema}
|
||||||
onSubmit={async (values, { resetForm }) => {
|
onSubmit={async (values, { resetForm }) => {
|
||||||
// kick off publishing
|
// kick off publishing
|
||||||
// await handleSubmit(values, resetForm)
|
await handleSubmit(values)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{({ values }) => (
|
{({ values }) => (
|
||||||
|
Loading…
Reference in New Issue
Block a user