Skip to content

Commit a5cdbce

Browse files
authored
fix: Cleanup Error display and optimize requests (#872)
Cleaned up error display to not show full html optimized requests a bit more to potentially avoid timeouts
1 parent 6effffa commit a5cdbce

2 files changed

Lines changed: 71 additions & 29 deletions

File tree

apps/explorer/src/comps/AddressCsvExportButton.tsx

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,7 @@ export function AddressCsvExportButton(
6060
})
6161

6262
if (!response.ok) {
63-
let message =
64-
kind === 'balances'
65-
? 'Failed to export balances.'
66-
: 'Failed to export transactions.'
67-
68-
const contentType = response.headers.get('Content-Type') ?? ''
69-
if (contentType.includes('application/json')) {
70-
const payload = (await response.json()) as { error?: string }
71-
if (payload.error) message = payload.error
72-
} else {
73-
const text = (await response.text()).trim()
74-
if (text) message = text
75-
}
76-
77-
throw new Error(message)
63+
throw new Error('Error')
7864
}
7965

8066
const blob = await response.blob()
@@ -94,7 +80,7 @@ export function AddressCsvExportButton(
9480
URL.revokeObjectURL(objectUrl)
9581
}
9682
} catch (error) {
97-
setError(error instanceof Error ? error.message : 'CSV export failed.')
83+
setError(error instanceof Error ? error.message : 'Error')
9884
} finally {
9985
setIsExporting(false)
10086
}
@@ -113,7 +99,9 @@ export function AddressCsvExportButton(
11399
}
114100
className={cx(
115101
'flex size-[28px] items-center justify-center rounded-[6px] border text-[12px] transition-colors',
116-
'border-transparent text-tertiary hover:text-secondary hover:bg-base-alt',
102+
error
103+
? 'border-transparent text-red-400 hover:text-red-300 hover:bg-base-alt'
104+
: 'border-transparent text-tertiary hover:text-secondary hover:bg-base-alt',
117105
isExporting && 'cursor-default opacity-60',
118106
!isExporting && 'cursor-pointer',
119107
)}
@@ -125,7 +113,7 @@ export function AddressCsvExportButton(
125113
>
126114
<DownloadIcon className="size-[14px]" />
127115
</button>
128-
{error && <span className="text-[11px] text-red-400">{error}</span>}
116+
{error && <span className="text-[11px] text-red-400">Error</span>}
129117
</div>
130118
)
131119
}

apps/explorer/src/lib/server/address-history.ts

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,11 @@ export async function fetchAddressHistoryData(params: {
214214
chainId: number
215215
searchParams: HistoryRequestParameters
216216
maxLimit?: number | undefined
217+
includeKnownEvents?: boolean | undefined
217218
}): Promise<HistoryResponse> {
218219
const { address, chainId, searchParams } = params
219220
const maxLimit = params.maxLimit ?? MAX_LIMIT
221+
const includeKnownEvents = params.includeKnownEvents ?? true
220222
const config = getWagmiConfig()
221223

222224
const include =
@@ -426,6 +428,65 @@ export async function fetchAddressHistoryData(params: {
426428
}
427429
}
428430

431+
const finalHashValues = finalHashes.map((entry) => entry.hash)
432+
433+
const [receiptRows, txRows] = await Promise.all([
434+
txOnlyPageResult
435+
? Promise.resolve(txOnlyPageResult.receiptRows)
436+
: fetchAddressReceiptRowsByHashes(chainId, finalHashValues),
437+
txOnlyPageResult
438+
? Promise.resolve(txOnlyPageResult.txRows)
439+
: fetchAddressHistoryTxDetailsByHashes(chainId, finalHashValues),
440+
])
441+
442+
const receiptMap = new Map(
443+
receiptRows.map((row) => [row.tx_hash, row] as const),
444+
)
445+
const txMap = new Map(txRows.map((row) => [row.hash, row] as const))
446+
447+
if (!includeKnownEvents) {
448+
const transactions = finalHashes.map((hashEntry) => {
449+
const receipt = receiptMap.get(hashEntry.hash)
450+
const tx = txMap.get(hashEntry.hash)
451+
452+
const fromSource = tx?.from ?? hashEntry.from ?? receipt?.from ?? address
453+
const toSource = tx?.to ?? hashEntry.to ?? receipt?.to ?? null
454+
const valueSource = tx?.value ?? hashEntry.value ?? 0n
455+
const blockNumberSource =
456+
receipt?.block_num ?? tx?.block_num ?? hashEntry.block_num
457+
const timestampSource =
458+
receipt?.block_timestamp ?? tx?.block_timestamp ?? 0
459+
const status = toHistoryStatus(receipt?.status)
460+
461+
return {
462+
hash: hashEntry.hash,
463+
blockNumber: toHexQuantity(blockNumberSource),
464+
timestamp: toFiniteTimestamp(timestampSource),
465+
from: Address.checksum(fromSource as Address.Address),
466+
to: toSource ? Address.checksum(toSource as Address.Address) : null,
467+
value: toHexQuantity(valueSource),
468+
status,
469+
gasUsed: toHexQuantity(receipt?.gas_used),
470+
effectiveGasPrice: toHexQuantity(receipt?.effective_gas_price),
471+
knownEvents: [],
472+
}
473+
})
474+
475+
const finalTransactions = after
476+
? transactions.filter((transaction) => transaction.timestamp >= after)
477+
: transactions
478+
479+
return {
480+
transactions: finalTransactions,
481+
total: after ? finalTransactions.length : totalCount,
482+
offset,
483+
limit,
484+
hasMore: after ? false : hasMore,
485+
countCapped: after ? false : countCapped,
486+
error: null,
487+
}
488+
}
489+
429490
if (isTxOnlySource) {
430491
if (!txOnlyPageResult) {
431492
throw new Error('Missing tx-only history page result')
@@ -434,8 +495,8 @@ export async function fetchAddressHistoryData(params: {
434495
const transactions = await buildTxOnlyTransactions({
435496
address,
436497
hashes: finalHashes,
437-
txRows: txOnlyPageResult.txRows,
438-
receiptRows: txOnlyPageResult.receiptRows,
498+
txRows,
499+
receiptRows,
439500
logRows: txOnlyPageResult.logRows,
440501
})
441502

@@ -450,19 +511,11 @@ export async function fetchAddressHistoryData(params: {
450511
}
451512
}
452513

453-
const finalHashValues = finalHashes.map((entry) => entry.hash)
454-
455-
const [receiptRows, txRows, logRows, transferRows] = await Promise.all([
456-
fetchAddressReceiptRowsByHashes(chainId, finalHashValues),
457-
fetchAddressHistoryTxDetailsByHashes(chainId, finalHashValues),
514+
const [logRows, transferRows] = await Promise.all([
458515
fetchAddressLogRowsByTxHashes(chainId, finalHashValues),
459516
fetchAddressTransferRowsByTxHashes(chainId, finalHashValues),
460517
])
461518

462-
const receiptMap = new Map(
463-
receiptRows.map((row) => [row.tx_hash, row] as const),
464-
)
465-
const txMap = new Map(txRows.map((row) => [row.hash, row] as const))
466519
const logsByHash = new Map<Hex.Hex, Log[]>()
467520

468521
for (const row of logRows) {
@@ -658,6 +711,7 @@ export async function fetchAddressHistoryExportRows(params: {
658711
limit: pageLimit,
659712
},
660713
maxLimit: CSV_EXPORT_PAGE_SIZE,
714+
includeKnownEvents: false,
661715
})
662716

663717
if (page.transactions.length === 0) break

0 commit comments

Comments
 (0)