prepare publish flow in code

This commit is contained in:
Matthias Kretschmann 2021-11-11 11:26:29 +00:00
parent 4e985ba633
commit 8ce573b2a0
Signed by: m
GPG Key ID: 606EEEF3C479A91F
5 changed files with 45 additions and 11 deletions

11
package-lock.json generated
View File

@ -33,6 +33,7 @@
"gray-matter": "^4.0.3",
"is-url-superb": "^6.1.0",
"js-cookie": "^3.0.1",
"js-sha256": "^0.9.0",
"jwt-decode": "^3.1.2",
"lodash.debounce": "^4.0.8",
"lodash.omit": "^4.5.0",
@ -26464,6 +26465,11 @@
"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": {
"version": "0.8.0",
"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",
"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": {
"version": "0.8.0",
"resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz",

View File

@ -43,6 +43,7 @@
"gray-matter": "^4.0.3",
"is-url-superb": "^6.1.0",
"js-cookie": "^3.0.1",
"js-sha256": "^0.9.0",
"jwt-decode": "^3.1.2",
"lodash.debounce": "^4.0.8",
"lodash.omit": "^4.5.0",

View File

@ -31,7 +31,7 @@ export const wizardSteps: StepContent[] = [
}
]
export const initialValues: Partial<FormPublishData> = {
export const initialValues: FormPublishData = {
step: 1,
chainId: 1,
metadata: {

View File

@ -1,3 +1,4 @@
import { sha256 } from 'js-sha256'
import {
dateToStringNoMS,
transformTags,
@ -16,10 +17,15 @@ export function getFieldContent(
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 { type, name, description, tags, author, termsAndConditions } =
data.metadata
values.metadata
const {
access,
files,
@ -29,7 +35,7 @@ export function transformPublishFormToDdo(data: Partial<FormPublishData>): DDO {
entrypoint,
providerUrl,
timeout
} = data.services[0]
} = values.services[0]
const fileUrl = typeof files !== 'string' && files[0].url
@ -51,10 +57,10 @@ export function transformPublishFormToDdo(data: Partial<FormPublishData>): DDO {
language: getUrlFileExtension(fileUrl),
version: '0.1',
container: {
entrypoint: entrypoint,
image: image,
entrypoint,
image,
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 = {
type: access,
files: encryptMe(files),
datatokenAddress: '', // how to get before publish?
datatokenAddress,
serviceEndpoint: providerUrl,
timeout,
...(access === 'compute' && {
@ -84,9 +90,9 @@ export function transformPublishFormToDdo(data: Partial<FormPublishData>): DDO {
const newDdo: DDO = {
'@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',
chainId: data.chainId,
chainId: values.chainId,
metadata,
services: [service]
}

View File

@ -14,6 +14,7 @@ import Actions from './Actions'
import Debug from './Debug'
import Navigation from './Navigation'
import { Steps } from './Steps'
import { FormPublishData } from './_types'
const formName = 'ocean-publish-form'
@ -29,6 +30,21 @@ export default function PublishPage({
const [error, setError] = useState<string>()
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(
// values: Partial<FormPublishData>,
// resetForm: (
@ -90,7 +106,7 @@ export default function PublishPage({
validationSchema={validationSchema}
onSubmit={async (values, { resetForm }) => {
// kick off publishing
// await handleSubmit(values, resetForm)
await handleSubmit(values)
}}
>
{({ values }) => (