Skip to content
Merged
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
32 changes: 21 additions & 11 deletions src/pages/Explorer/block.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { fromHex } from "polkadot-api/utils"
import {
catchError,
combineLatest,
combineLatestWith,
concat,
defer,
EMPTY,
Expand All @@ -27,7 +28,9 @@ import {
Observable,
of,
repeat,
retry,
scan,
share,
skip,
startWith,
Subject,
Expand All @@ -36,7 +39,6 @@ import {
takeUntil,
takeWhile,
tap,
timer,
toArray,
withLatestFrom,
} from "rxjs"
Expand Down Expand Up @@ -77,8 +79,13 @@ const finalizedBlocks$ = state(
}),
),
)
finalizedBlocks$.pipe(liftSuspense()).subscribe()
finalizedBlocks$.pipe(liftSuspense(), retry()).subscribe()

const MAX_HEIGHT = 600
const sharedBlocks$ = client$.pipe(
switchMap((client) => client.blocks$),
share(),
)
export const [blockInfo$, recordedBlocks$] = partitionByKey(
client$.pipe(switchMap((client) => client.blocks$)),
(v) => v.hash,
Expand Down Expand Up @@ -122,16 +129,19 @@ export const [blockInfo$, recordedBlocks$] = partitionByKey(
diff: getBlockDiff$(parent, hash),
}),
NEVER,
).pipe(
takeUntil(
merge(
// Reset when client is changed
client$.pipe(skip(1)),
// Or after 1 hour
sharedBlocks$.pipe(
filter((b) => b.number >= number + MAX_HEIGHT),
),
),
),
),
),
takeUntil(
merge(
// Reset when client is changed
client$.pipe(skip(1)),
// Or after 1 hour
timer(60 * 60 * 1000),
),
),
),
)

Expand Down Expand Up @@ -384,7 +394,7 @@ const getBlockStatus$ = (
parent: string,
): Observable<BlockState> =>
client.bestBlocks$.pipe(
withLatestFrom(finalizedBlocks$),
combineLatestWith(finalizedBlocks$),
map(([best, finBlocks]) => {
const status = getBlockStatus(best, finBlocks, number, hash)
if (status === BlockState.Finalized && !finBlocks.has(parent))
Expand Down