-
Notifications
You must be signed in to change notification settings - Fork 103
/
TransactionDetails.svelte
190 lines (179 loc) · 6.82 KB
/
TransactionDetails.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<script lang="typescript">
import {
TransactionActivityStatusPill,
ActivityAsyncStatusPill,
KeyValueBox,
Pill,
AmountBox,
SubjectBox,
} from 'shared/components'
import { formatDate, localize } from '@core/i18n'
import { activeProfile } from '@core/profile'
import {
formatTokenAmountDefault,
formatTokenAmountPrecise,
ActivityAsyncStatus,
ActivityType,
Subject,
InclusionState,
ActivityDirection,
IPersistedAsset,
} from '@core/wallet'
import { BASE_TOKEN } from '@core/network'
import { getOfficialExplorerUrl } from '@core/network/utils'
import { Platform, time } from '@core/app'
import { truncateString } from '@core/utils'
import { setClipboard } from '@core/utils'
export let asset: IPersistedAsset
export let asyncStatus: ActivityAsyncStatus = null
export let claimedDate: Date = null
export let claimingTransactionId: string = null
export let direction: ActivityDirection
export let expirationDate: Date = null
export let timelockDate: Date = null
export let formattedFiatValue: string = null
export let inclusionState: InclusionState = InclusionState.Pending
export let metadata: string = null
export let rawAmount: string = null
export let unit: string
export let storageDeposit = 0
export let giftedStorageDeposit = 0
export let surplus: string = null
export let subject: Subject = null
export let tag: string = null
export let transactionTime: Date = null
export let isInternal: boolean = false
export let isClaiming: boolean = false
export let type: ActivityType
const explorerUrl = getOfficialExplorerUrl($activeProfile?.networkProtocol, $activeProfile?.networkType)
$: amount = formatTokenAmountDefault(Number(rawAmount), asset?.metadata, unit)
$: formattedTransactionTime = getDateFormat(transactionTime)
$: formattedTimelockDate = getDateFormat(timelockDate)
$: expirationTime = getDateFormat(expirationDate)
$: claimedTime = getDateFormat(claimedDate)
$: isTimelocked = timelockDate > $time
$: hasStorageDeposit = storageDeposit || (storageDeposit === 0 && giftedStorageDeposit === 0)
$: formattedStorageDeposit = formatTokenAmountPrecise(
storageDeposit ?? 0,
BASE_TOKEN[$activeProfile?.networkProtocol]
)
$: formattedGiftedStorageDeposit = formatTokenAmountPrecise(
giftedStorageDeposit ?? 0,
BASE_TOKEN[$activeProfile?.networkProtocol]
)
$: formattedSurplus = formatTokenAmountPrecise(Number(surplus) ?? 0, BASE_TOKEN[$activeProfile?.networkProtocol])
$: localePrefix = `tooltips.transactionDetails.${direction}.`
let detailsList: { [key in string]: { data: string; tooltipText?: string } }
$: detailsList = {
...(transactionTime && {
transactionTime: { data: formattedTransactionTime },
}),
...(metadata && {
metadata: {
data: metadata,
tooltipText: localize(localePrefix + 'metadata'),
},
}),
...(tag && {
tag: {
data: tag,
tooltipText: localize(localePrefix + 'tag'),
},
}),
...(hasStorageDeposit && {
storageDeposit: {
data: formattedStorageDeposit,
tooltipText: localize(localePrefix + 'storageDeposit'),
},
}),
...(giftedStorageDeposit && {
giftedStorageDeposit: {
data: formattedGiftedStorageDeposit,
tooltipText: localize(localePrefix + 'giftedStorageDeposit'),
},
}),
...(surplus && {
surplus: {
data: formattedSurplus,
tooltipText: localize(localePrefix + 'surplus'),
},
}),
...(expirationTime && {
expirationTime: {
data: expirationTime,
tooltipText: localize(localePrefix + 'expirationTime'),
},
}),
...(timelockDate && {
timelockDate: {
data: formattedTimelockDate,
tooltipText: localize(localePrefix + 'timelockDate'),
},
}),
...(claimedTime && { claimedTime: { data: claimedTime } }),
}
function handleTransactionIdClick(): void {
explorerUrl
? Platform.openUrl(`${explorerUrl}/transaction/${claimingTransactionId}`)
: setClipboard(claimingTransactionId)
}
function getDateFormat(date: Date): string {
try {
if (date) {
return formatDate(date, {
dateStyle: 'long',
timeStyle: 'medium',
})
} else {
return undefined
}
} catch (error) {
return undefined
}
}
</script>
<transaction-details class="w-full h-full space-y-6 flex flex-auto flex-col flex-shrink-0">
<main-content class="flex flex-auto w-full flex-col items-center justify-center space-y-3">
{#if amount}
<AmountBox {amount} fiatAmount={formattedFiatValue} {unit} {asset} />
{/if}
<transaction-status class="flex flex-row w-full space-x-2 justify-center">
{#if inclusionState && direction}
<TransactionActivityStatusPill {type} {direction} {isInternal} {inclusionState} />
{/if}
{#if asyncStatus}
<ActivityAsyncStatusPill {asyncStatus} />
{/if}
{#if isTimelocked}
<Pill backgroundColor="gray-200" darkBackgroundColor="gray-200">
{localize('pills.locked')}
</Pill>
{/if}
</transaction-status>
{#if subject}
<SubjectBox {subject} />
{/if}
</main-content>
{#if Object.entries(detailsList).length > 0}
<details-list class="flex flex-col space-y-2">
{#each Object.entries(detailsList) as [key, value]}
<KeyValueBox
keyText={localize(`general.${key}`)}
valueText={value.data}
tooltipText={value.tooltipText}
/>
{/each}
{#if claimingTransactionId}
<KeyValueBox keyText={localize(isClaiming ? 'general.claimingIn' : 'general.claimedIn')}>
<button
slot="value"
class="action w-fit flex justify-start text-center font-medium text-14 text-blue-500"
on:click={handleTransactionIdClick}
>
{truncateString(claimingTransactionId, 12, 12)}
</button>
</KeyValueBox>
{/if}
</details-list>
{/if}
</transaction-details>