Skip to content

Commit 96ac130

Browse files
committed
feat(explorer): add unconfirmed events to the address page
1 parent 6547d89 commit 96ac130

File tree

3 files changed

+59
-30
lines changed

3 files changed

+59
-30
lines changed

.changeset/modern-pandas-punch.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'explorer': minor
3+
---
4+
5+
Added unconfirmed transactions to the address page.

apps/explorer/app/address/[id]/page.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ export default async function Page({ params }) {
2727
const [
2828
[balance, balanceError, balanceResponse],
2929
{ data: events },
30+
{ data: unconfirmedEvents },
3031
{ data: unspentOutputs },
3132
] = await Promise.all([
3233
to(getExplored().addressBalance({ params: { address } })),
3334
getExplored().addressEvents({ params: { address, limit: 500 } }),
35+
getExplored().addressUnconfirmedEvents({ params: { address } }),
3436
getExplored().addressSiacoinUTXOs({ params: { address } }),
3537
])
3638

@@ -45,6 +47,7 @@ export default async function Page({ params }) {
4547
addressInfo={{
4648
balance,
4749
events,
50+
unconfirmedEvents,
4851
unspentOutputs,
4952
}}
5053
/>

apps/explorer/components/Address/index.tsx

+51-30
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type Props = {
3535
addressInfo: {
3636
balance: AddressBalance
3737
events: ExplorerEvent[]
38+
unconfirmedEvents: ExplorerEvent[]
3839
unspentOutputs: ExplorerSiacoinOutput[]
3940
}
4041
}
@@ -44,6 +45,7 @@ export function Address({
4445
addressInfo: {
4546
balance: { unspentSiacoins, unspentSiafunds },
4647
events,
48+
unconfirmedEvents,
4749
unspentOutputs,
4850
},
4951
}: Props) {
@@ -66,36 +68,17 @@ export function Address({
6668
}, [unspentSiacoins, unspentSiafunds])
6769

6870
const eventEntities = useMemo(() => {
69-
const list: EntityListItemProps[] = []
70-
71-
if (events.length) {
72-
events.forEach((event) => {
73-
switch (event.type) {
74-
case 'v1Transaction':
75-
list.push(formatV1TransactionEntity(id, event))
76-
break
77-
case 'v2Transaction':
78-
list.push(formatV2TransactionEntity(id, event))
79-
break
80-
case 'v1ContractResolution':
81-
list.push(formatV1ContractResolutionEntity(event))
82-
break
83-
case 'v2ContractResolution':
84-
list.push(formatV2ContractResolutionEntity(event))
85-
break
86-
case 'payout':
87-
list.push(formatPayoutEntity(event))
88-
break
89-
}
90-
})
91-
}
71+
const list: EntityListItemProps[] = [
72+
...unconfirmedEvents.map((uEvent) => formatEvent(id, uEvent, true)),
73+
...events.map((event) => formatEvent(id, event)),
74+
]
9275

9376
return list.sort(
9477
(a, b) =>
9578
new Date(b.timestamp || 0).getTime() -
9679
new Date(a.timestamp || 0).getTime()
9780
)
98-
}, [id, events])
81+
}, [id, events, unconfirmedEvents])
9982

10083
const utxos = useMemo(() => {
10184
const list: EntityListItemProps[] = []
@@ -176,7 +159,10 @@ function getTotal({
176159
)
177160
}
178161

179-
function formatV1TransactionEntity(id: string, v1Transaction: ExplorerEvent) {
162+
function formatV1TransactionEntity(
163+
id: string,
164+
v1Transaction: ExplorerEvent
165+
): EntityListItemProps {
180166
const { transaction } = v1Transaction.data as EventV1Transaction
181167
return {
182168
hash: v1Transaction.id,
@@ -198,7 +184,10 @@ function formatV1TransactionEntity(id: string, v1Transaction: ExplorerEvent) {
198184
}
199185
}
200186

201-
function formatV2TransactionEntity(id: string, v2Transaction: ExplorerEvent) {
187+
function formatV2TransactionEntity(
188+
id: string,
189+
v2Transaction: ExplorerEvent
190+
): EntityListItemProps {
202191
const transaction = v2Transaction.data as ExplorerV2Transaction
203192
return {
204193
hash: v2Transaction.id,
@@ -223,7 +212,9 @@ function formatV2TransactionEntity(id: string, v2Transaction: ExplorerEvent) {
223212
}
224213
}
225214

226-
function formatV1ContractResolutionEntity(v1ContractResolution: ExplorerEvent) {
215+
function formatV1ContractResolutionEntity(
216+
v1ContractResolution: ExplorerEvent
217+
): EntityListItemProps {
227218
const { parent, siacoinElement } =
228219
v1ContractResolution.data as EventV1ContractResolution
229220
return {
@@ -236,7 +227,9 @@ function formatV1ContractResolutionEntity(v1ContractResolution: ExplorerEvent) {
236227
}
237228
}
238229

239-
function formatV2ContractResolutionEntity(v1ContractResolution: ExplorerEvent) {
230+
function formatV2ContractResolutionEntity(
231+
v1ContractResolution: ExplorerEvent
232+
): EntityListItemProps {
240233
const { resolution, siacoinElement } =
241234
v1ContractResolution.data as EventV2ContractResolution
242235
return {
@@ -249,7 +242,7 @@ function formatV2ContractResolutionEntity(v1ContractResolution: ExplorerEvent) {
249242
}
250243
}
251244

252-
function formatPayoutEntity(payout: ExplorerEvent) {
245+
function formatPayoutEntity(payout: ExplorerEvent): EntityListItemProps {
253246
const { siacoinElement } = payout.data as EventPayout
254247
return {
255248
hash: payout.id,
@@ -264,7 +257,7 @@ function formatPayoutEntity(payout: ExplorerEvent) {
264257

265258
function formatUnspentSiacoinOutputEntity(
266259
siacoinOutput: ExplorerSiacoinOutput
267-
) {
260+
): EntityListItemProps {
268261
return {
269262
hash: siacoinOutput.id,
270263
sc: new BigNumber(siacoinOutput.siacoinOutput.value),
@@ -273,3 +266,31 @@ function formatUnspentSiacoinOutputEntity(
273266
scVariant: 'value' as const,
274267
}
275268
}
269+
270+
const formatEvent = (
271+
id: string,
272+
event: ExplorerEvent,
273+
isUnconfirmed = false
274+
): EntityListItemProps => {
275+
let baseEntity: EntityListItemProps
276+
277+
switch (event.type) {
278+
case 'v1Transaction':
279+
baseEntity = formatV1TransactionEntity(id, event)
280+
break
281+
case 'v2Transaction':
282+
baseEntity = formatV2TransactionEntity(id, event)
283+
break
284+
case 'v1ContractResolution':
285+
baseEntity = formatV1ContractResolutionEntity(event)
286+
break
287+
case 'v2ContractResolution':
288+
baseEntity = formatV2ContractResolutionEntity(event)
289+
break
290+
case 'payout':
291+
baseEntity = formatPayoutEntity(event)
292+
break
293+
}
294+
295+
return isUnconfirmed ? { ...baseEntity, unconfirmed: true } : baseEntity
296+
}

0 commit comments

Comments
 (0)