/
CollectibleDetailsMenu.svelte
78 lines (71 loc) · 2.72 KB
/
CollectibleDetailsMenu.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<script lang="typescript">
import { Modal, MenuItem } from 'shared/components'
import { localize } from '@core/i18n'
import { closePopup, openPopup } from '@auxiliary/popup/actions'
import { checkActiveProfileAuth } from '@core/profile/actions'
import { burnNft } from '@core/wallet'
import { INft, rewriteIpfsUri } from '@core/nfts'
import { CollectiblesRoute, collectiblesRouter } from '@core/router'
import { openUrlInBrowser } from '@core/app'
export let modal: Modal = undefined
export let nft: INft
$: url = composeUrl(nft?.parsedMetadata?.uri)
function openBurnNft(): void {
openPopup({
type: 'confirmation',
props: {
title: localize('actions.confirmNftBurn.title', {
values: {
nftName: nft.name,
},
}),
description: localize('actions.confirmNftBurn.description'),
hint: localize('actions.confirmNftBurn.hint'),
warning: true,
confirmText: localize('actions.burnToken'),
onConfirm: () => {
checkActiveProfileAuth(
async () => {
await burnNft(nft.id)
$collectiblesRouter.goTo(CollectiblesRoute.Gallery)
closePopup()
},
{ stronghold: true }
)
},
},
})
}
function composeUrl(targetUrl: string): string {
if (!targetUrl) {
return undefined
}
const url = new URL(targetUrl)
switch (url.protocol) {
case 'http:':
return targetUrl.replace('http:', 'https:')
case 'https:':
return targetUrl
case 'ipfs:':
return rewriteIpfsUri(targetUrl)
default:
return undefined
}
}
function handleOpenMediaClick(): void {
openUrlInBrowser(url)
}
</script>
<Modal bind:this={modal} position={{ top: '100px', right: '60px' }}>
<div class="flex flex-col">
<MenuItem icon="receive" title={localize('views.collectibles.details.menu.download')} disabled={true} />
<MenuItem icon="profile" title={localize('views.collectibles.details.menu.setAvatar')} disabled={true} />
<MenuItem
icon="export"
title={localize('views.collectibles.details.menu.view')}
onClick={handleOpenMediaClick}
disabled={!url}
/>
<MenuItem icon="delete" title={localize('views.collectibles.details.menu.burn')} onClick={openBurnNft} />
</div>
</Modal>