1
0
mirror of https://github.com/oceanprotocol/react.git synced 2025-02-14 21:10:38 +01:00

publish update

This commit is contained in:
mihaisc 2020-07-28 13:54:28 +03:00
parent e410504c1f
commit 519a762762
2 changed files with 18 additions and 43 deletions

View File

@ -13,15 +13,10 @@ interface UsePublish {
publish: ( publish: (
asset: Metadata, asset: Metadata,
tokensToMint: string, tokensToMint: string,
marketAddress: string, serviceConfigs: ServiceConfig[],
serviceConfigs: ServiceConfig[] dtAddress?: string
) => Promise<DDO> ) => Promise<DDO>
mint: (tokenAddress: string, tokensToMint: string) => void mint: (tokenAddress: string, tokensToMint: string) => void
giveMarketAllowance: (
tokenAddress: string,
marketAddress: string,
tokens: string
) => void
publishStep?: number publishStep?: number
publishStepText?: string publishStepText?: string
publishError?: string publishError?: string
@ -44,33 +39,33 @@ function usePublish(): UsePublish {
* Publish an asset.It also creates the datatoken, mints tokens and gives the market allowance * Publish an asset.It also creates the datatoken, mints tokens and gives the market allowance
* @param {Metadata} asset The metadata of the asset. * @param {Metadata} asset The metadata of the asset.
* @param {string} tokensToMint Numer of tokens to mint and give allowance to market * @param {string} tokensToMint Numer of tokens to mint and give allowance to market
* @param {string} marketAddress The address of the market
* @param {ServiceConfig[]} serviceConfigs Desired services of the asset, ex: [{serviceType: 'access', cost:'1'}] * @param {ServiceConfig[]} serviceConfigs Desired services of the asset, ex: [{serviceType: 'access', cost:'1'}]
* @param {string} dtAddress The address of the market
* @return {Promise<DDO>} Returns the newly published ddo * @return {Promise<DDO>} Returns the newly published ddo
*/ */
async function publish( async function publish(
asset: Metadata, asset: Metadata,
tokensToMint: string, tokensToMint: string,
marketAddress: string, serviceConfigs: ServiceConfig[],
serviceConfigs: ServiceConfig[] dtAddress?: string
): Promise<DDO> { ): Promise<DDO> {
if (status !== ProviderStatus.CONNECTED || !ocean || !account) return if (status !== ProviderStatus.CONNECTED || !ocean || !account) return
setIsLoading(true) setIsLoading(true)
setPublishError(undefined) setPublishError(undefined)
try { try {
setStep(0) if (dtAddress) {
const data = { t: 1, url: config.metadataStoreUri } setStep(0)
const blob = JSON.stringify(data) const data = { t: 1, url: config.metadataStoreUri }
const tokenAddress = await ocean.datatokens.create(blob, accountId) const blob = JSON.stringify(data)
Logger.log('datatoken created', tokenAddress) dtAddress = await ocean.datatokens.create(blob, accountId)
Logger.log('datatoken created', dtAddress)
}
setStep(1) setStep(1)
await mint(tokenAddress, tokensToMint) await mint(dtAddress, tokensToMint)
Logger.log(`minted ${tokensToMint} tokens`) Logger.log(`minted ${tokensToMint} tokens`)
setStep(2) setStep(2)
// await giveMarketAllowance(tokenAddress, marketAddress, tokensToMint)
// Logger.log('allowance to market', marketAddress)
const publishedDate = const publishedDate =
new Date(Date.now()).toISOString().split('.')[0] + 'Z' new Date(Date.now()).toISOString().split('.')[0] + 'Z'
const timeout = 0 const timeout = 0
@ -140,12 +135,7 @@ function usePublish(): UsePublish {
}) })
Logger.log('services created', services) Logger.log('services created', services)
setStep(3) setStep(3)
const ddo = await ocean.assets.create( const ddo = await ocean.assets.create(asset, account, services, dtAddress)
asset,
account,
services,
tokenAddress
)
Logger.log('ddo created', ddo) Logger.log('ddo created', ddo)
setStep(4) setStep(4)
@ -164,23 +154,9 @@ function usePublish(): UsePublish {
await ocean.datatokens.mint(tokenAddress, accountId, tokensToMint) await ocean.datatokens.mint(tokenAddress, accountId, tokensToMint)
} }
async function giveMarketAllowance(
tokenAddress: string,
marketAddress: string,
tokens: string
) {
await ocean.datatokens.approve(
tokenAddress,
marketAddress,
tokens,
accountId
)
}
return { return {
publish, publish,
mint, mint,
giveMarketAllowance,
publishStep, publishStep,
publishStepText, publishStepText,
isLoading, isLoading,

View File

@ -20,9 +20,8 @@ export const feedback: { [key in number]: string } = {
} }
export const publishFeedback: { [key in number]: string } = { export const publishFeedback: { [key in number]: string } = {
0: '1/5 Creating datatoken ...', 0: '1/4 Creating datatoken ...',
1: '2/5 Minting tokens ...', 1: '2/4 Minting tokens ...',
2: '3/5 Giving allowance to market to sell your tokens ...', 3: '3/4 Publishing asset ...',
3: '4/5 Publishing asset ...', 4: '4/4 Asset published succesfully'
4: '5/5 Asset published succesfully'
} }