fixes & todo

This commit is contained in:
Matthias Kretschmann 2021-11-26 10:35:41 +00:00
parent 11412c2d66
commit 362e404110
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 20 additions and 7 deletions

View File

@ -35,8 +35,6 @@ export async function transformPublishFormToDdo(
): Promise<DDO> {
const { metadata, services, user } = values
const { chainId, accountId } = user
const did = nftAddress ? `0x${sha256(`${nftAddress}${chainId}`)}` : '0x...'
const currentTime = dateToStringNoMS(new Date())
const {
type,
name,
@ -50,6 +48,9 @@ export async function transformPublishFormToDdo(
} = metadata
const { access, files, links, providerUrl, timeout } = services[0]
const did = nftAddress ? `0x${sha256(`${nftAddress}${chainId}`)}` : '0x...'
const currentTime = dateToStringNoMS(new Date())
// Transform from files[0].url to string[] assuming only 1 file
const filesTransformed = files?.length && files[0].valid && [files[0].url]
const linksTransformed = links?.length && links[0].valid && [links[0].url]
@ -68,6 +69,8 @@ export async function transformPublishFormToDdo(
termsAndConditions
},
...(type === 'algorithm' && {
// TODO: This needs some set of predefined values for `container`,
// depending on user selection in the form.
algorithm: {
language: files?.length ? getUrlFileExtension(filesTransformed[0]) : '',
version: '0.1',
@ -81,7 +84,7 @@ export async function transformPublishFormToDdo(
})
}
// Encypt just created string[] of urls
// Encrypt just created string[] of urls
const filesEncrypted =
files?.length &&
files[0].valid &&
@ -99,6 +102,7 @@ export async function transformPublishFormToDdo(
serviceEndpoint: providerUrl.url,
timeout: mapTimeoutStringToSeconds(timeout),
...(access === 'compute' && {
// TODO: get all the default values we want to send here.
compute: {
namespace: 'ocean-compute',
cpu: 1,
@ -121,7 +125,9 @@ export async function transformPublishFormToDdo(
chainId,
metadata: newMetadata,
services: [newService],
// only added for DDO preview, reflecting Asset response
// Only added for DDO preview, reflecting Asset response,
// again, we can assume if `datatokenAddress` is not passed,
// we are on preview.
...(!datatokenAddress && {
dataTokenInfo: {
name: values.services[0].dataTokenOptions.name,

View File

@ -28,6 +28,9 @@ export default function PublishPage({
const { debug } = useUserPreferences()
const { accountId, chainId } = useWeb3()
const { isInPurgatory, purgatoryData } = useAccountPurgatory(accountId)
// TODO: success & error states need to be handled for each step we want to display
// most likely with a nested data structure.
const [success, setSuccess] = useState<string>()
const [error, setError] = useState<string>()
const scrollToRef = useRef()
@ -39,14 +42,19 @@ export default function PublishPage({
// --------------------------------------------------
// const nftOptions = values.metadata.nft
// const nftCreateData = generateNftCreateData(nftOptions)
// TODO: figure out syntax of ercParams we most likely need to pass
// to createNftWithErc() as we need to pass options for the datatoken.
// const ercParams = {}
// const priceOptions = {
// ...values,
// // swapFee is tricky: to get 0.1% you need to send 0.001 as value
// swapFee: `${values.swapFee / 100}`
// swapFee: `${values.pricing.swapFee / 100}`
// }
// const txMint = await createNftWithErc(accountId, nftCreateData)
// TODO: figure out how to get nftAddress & datatokenAddress from tx log.
// const { nftAddress, datatokenAddress } = txMint.logs[0].args
// if (!nftAddress || !datatokenAddress) { throw new Error() }
//
// --------------------------------------------------
// 2. Construct and publish DDO
@ -66,7 +74,6 @@ export default function PublishPage({
// if (checksumBefore !== checksumAfter) {
// throw new Error('DDO integrity check failed!')
// }
setSuccess('Your DDO was published successfully!')
} catch (error) {
setError(error.message)