From a85743bca20393fda3f2b2e5f710e004a9ab801c Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 30 May 2022 15:39:36 +0200 Subject: [PATCH] save published file to FE --- .../publish-to-storage/src/lib/publish-to-storage.tsx | 4 ---- .../publish-to-storage/src/lib/publishOnSwarm.tsx | 9 +++++---- .../publish-to-storage/src/lib/publishToIPFS.tsx | 9 +++++---- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/libs/remix-ui/publish-to-storage/src/lib/publish-to-storage.tsx b/libs/remix-ui/publish-to-storage/src/lib/publish-to-storage.tsx index 78812ab83d..79d81b8537 100644 --- a/libs/remix-ui/publish-to-storage/src/lib/publish-to-storage.tsx +++ b/libs/remix-ui/publish-to-storage/src/lib/publish-to-storage.tsx @@ -29,8 +29,6 @@ export const PublishToStorage = (props: RemixUiPublishToStorageProps) => { const result = await publishToSwarm(contract, api) modal(`Published ${contract.name}'s Metadata`, publishMessage(result.uploaded)) - // triggered each time there's a new verified publish (means hash correspond) - api.writeFile('swarm/' + result.item.hash, result.item.content) } catch (err) { let parseError = err try { @@ -44,8 +42,6 @@ export const PublishToStorage = (props: RemixUiPublishToStorageProps) => { const result = await publishToIPFS(contract, api) modal(`Published ${contract.name}'s Metadata`, publishMessage(result.uploaded)) - // triggered each time there's a new verified publish (means hash correspond) - api.writeFile('ipfs/' + result.item.hash, result.item.content) } catch (err) { modal('IPFS Publish Failed', publishMessageFailed(storage, err)) } diff --git a/libs/remix-ui/publish-to-storage/src/lib/publishOnSwarm.tsx b/libs/remix-ui/publish-to-storage/src/lib/publishOnSwarm.tsx index 3f823c5070..af7e189940 100644 --- a/libs/remix-ui/publish-to-storage/src/lib/publishOnSwarm.tsx +++ b/libs/remix-ui/publish-to-storage/src/lib/publishOnSwarm.tsx @@ -79,7 +79,7 @@ export const publishToSwarm = async (contract, api) => { // publish the list of sources in order, fail if any failed await Promise.all(sources.map(async (item) => { try { - const result = await swarmVerifiedPublish(beeNodes, postageStampId, item.content, item.hash) + const result = await swarmVerifiedPublish(beeNodes, postageStampId, item.content, item.hash, api) try { item.hash = result.url.match('bzz-raw://(.+)')[1] @@ -96,9 +96,9 @@ export const publishToSwarm = async (contract, api) => { } })) - const metadataContent = JSON.stringify(metadata) + const metadataContent = JSON.stringify(metadata, null, '\t') try { - const result = await swarmVerifiedPublish(beeNodes, postageStampId, metadataContent, '') + const result = await swarmVerifiedPublish(beeNodes, postageStampId, metadataContent, '', api) try { contract.metadataHash = result.url.match('bzz-raw://(.+)')[1] @@ -121,7 +121,7 @@ export const publishToSwarm = async (contract, api) => { return { uploaded, item } } -const swarmVerifiedPublish = async (beeNodes: Bee[], postageStampId: string, content, expectedHash): Promise> => { +const swarmVerifiedPublish = async (beeNodes: Bee[], postageStampId: string, content, expectedHash, api): Promise> => { try { const results = await uploadToBeeNodes(beeNodes, postageStampId, content) const hash = hashFromResults(results) @@ -129,6 +129,7 @@ const swarmVerifiedPublish = async (beeNodes: Bee[], postageStampId: string, con if (expectedHash && hash !== expectedHash) { return { message: 'hash mismatch between solidity bytecode and uploaded content.', url: 'bzz-raw://' + hash, hash } } else { + api.writeFile('swarm/' + hash, content) return { message: 'ok', url: 'bzz-raw://' + hash, hash } } } catch (error) { diff --git a/libs/remix-ui/publish-to-storage/src/lib/publishToIPFS.tsx b/libs/remix-ui/publish-to-storage/src/lib/publishToIPFS.tsx index 36f92ab9e8..e5721d5868 100644 --- a/libs/remix-ui/publish-to-storage/src/lib/publishToIPFS.tsx +++ b/libs/remix-ui/publish-to-storage/src/lib/publishToIPFS.tsx @@ -63,7 +63,7 @@ export const publishToIPFS = async (contract, api) => { // publish the list of sources in order, fail if any failed await Promise.all(sources.map(async (item) => { try { - const result = await ipfsVerifiedPublish(item.content, item.hash) + const result = await ipfsVerifiedPublish(item.content, item.hash, api) try { item.hash = result.url.match('dweb:/ipfs/(.+)')[1] @@ -76,10 +76,10 @@ export const publishToIPFS = async (contract, api) => { throw new Error(error) } })) - const metadataContent = JSON.stringify(metadata) + const metadataContent = JSON.stringify(metadata, null, '\t') try { - const result = await ipfsVerifiedPublish(metadataContent, '') + const result = await ipfsVerifiedPublish(metadataContent, '', api) try { contract.metadataHash = result.url.match('dweb:/ipfs/(.+)')[1] @@ -101,13 +101,14 @@ export const publishToIPFS = async (contract, api) => { return { uploaded, item } } -const ipfsVerifiedPublish = async (content, expectedHash) => { +const ipfsVerifiedPublish = async (content, expectedHash, api) => { try { const results = await severalGatewaysPush(content) if (expectedHash && results !== expectedHash) { return { message: 'hash mismatch between solidity bytecode and uploaded content.', url: 'dweb:/ipfs/' + results, hash: results } } else { + api.writeFile('ipfs/' + results, content) return { message: 'ok', url: 'dweb:/ipfs/' + results, hash: results } } } catch (error) {