Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/ddo export #593

Merged
merged 4 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/@utils/downloadJSON.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export function isValidJSON(json: string): boolean {
try {
JSON.parse(json)
return true
} catch (e) {
return false
}
}

// Download JSON file
export function downloadJSON(json: string, filename: string): void {
// check if the json is valid
if (isValidJSON(json)) {
const element = document.createElement('a') // create an <a> tag
const file = new Blob([json], {
type: 'application/json'
}) // create a file
element.href = URL.createObjectURL(file) // create a URL for the file
element.download = `${filename}.json` // Set the file name
document.body.appendChild(element) // Append the tag to the body
element.click() // Click the a element
}
}
20 changes: 20 additions & 0 deletions src/components/@shared/DDODownloadButton/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ReactElement } from 'react'
import Button from '../atoms/Button'
import { downloadJSON } from '@utils/downloadJSON'

export default function DDODownloadButton({
asset
}: {
asset: any
}): ReactElement {
return (
<Button
onClick={() =>
downloadJSON(JSON.stringify(asset), `${asset.metadata.name}_metadata`)
}
size="small"
>
Download DDO
</Button>
)
}
12 changes: 11 additions & 1 deletion src/components/Asset/AssetContent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
import ServiceCredentialVisualizer from '@components/@shared/ServiceCredentialVisualizer'
import Web3Feedback from '@components/@shared/Web3Feedback'
import { useAccount } from 'wagmi'
import DDODownloadButton from '@components/@shared/DDODownloadButton'

export default function AssetContent({
asset
Expand Down Expand Up @@ -108,7 +109,16 @@ export default function AssetContent({
</>
)}
<MetaFull ddo={asset} />
<EditHistory receipts={receipts} setReceipts={setReceipts} />
<div
style={{
display: 'flex',
justifyContent: 'space-between',
flexWrap: 'wrap'
}}
>
<EditHistory receipts={receipts} setReceipts={setReceipts} />
<DDODownloadButton asset={asset} />
</div>
{debug === true && <DebugOutput title="DDO" output={asset} />}
</div>
</div>
Expand Down
Loading