Fix blockchain scroll jumping
This commit is contained in:
parent
b645ad3fd8
commit
1a6a0c12ec
@ -166,7 +166,6 @@ export class BlockComponent implements OnInit, OnDestroy {
|
|||||||
this.page = 1;
|
this.page = 1;
|
||||||
this.error = undefined;
|
this.error = undefined;
|
||||||
this.fees = undefined;
|
this.fees = undefined;
|
||||||
this.stateService.markBlock$.next({});
|
|
||||||
|
|
||||||
if (history.state.data && history.state.data.blockHeight) {
|
if (history.state.data && history.state.data.blockHeight) {
|
||||||
this.blockHeight = history.state.data.blockHeight;
|
this.blockHeight = history.state.data.blockHeight;
|
||||||
@ -176,6 +175,7 @@ export class BlockComponent implements OnInit, OnDestroy {
|
|||||||
let isBlockHeight = false;
|
let isBlockHeight = false;
|
||||||
if (/^[0-9]+$/.test(blockHash)) {
|
if (/^[0-9]+$/.test(blockHash)) {
|
||||||
isBlockHeight = true;
|
isBlockHeight = true;
|
||||||
|
this.stateService.markBlock$.next({ blockHeight: parseInt(blockHash, 10)});
|
||||||
} else {
|
} else {
|
||||||
this.blockHash = blockHash;
|
this.blockHash = blockHash;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<div class="text-center" class="blockchain-wrapper" [class.time-ltr]="timeLtr" [class.ltr-transition]="ltrTransitionEnabled" #container>
|
<div class="text-center" class="blockchain-wrapper" [class.time-ltr]="timeLtr" [class.ltr-transition]="ltrTransitionEnabled" #container>
|
||||||
<div class="position-container" [ngClass]="network ? network : ''" [style.--divider-offset]="dividerOffset + 'px'" [style.--mempool-offset]="mempoolOffset + 'px'">
|
<div #positionContainer class="position-container" [ngClass]="network ? network : ''" [style]="positionStyle">
|
||||||
<span>
|
<span>
|
||||||
<div class="blocks-wrapper">
|
<div class="blocks-wrapper">
|
||||||
<div class="scroll-spacer" *ngIf="minScrollWidth" [style.left]="minScrollWidth + 'px'"></div>
|
<div class="scroll-spacer" *ngIf="minScrollWidth" [style.left]="minScrollWidth + 'px'"></div>
|
||||||
|
@ -26,15 +26,7 @@
|
|||||||
position: absolute;
|
position: absolute;
|
||||||
left: 0;
|
left: 0;
|
||||||
top: 75px;
|
top: 75px;
|
||||||
--divider-offset: 50vw;
|
transform: translateX(1280px);
|
||||||
--mempool-offset: 0px;
|
|
||||||
transform: translateX(calc(var(--divider-offset) + var(--mempool-offset)));
|
|
||||||
}
|
|
||||||
|
|
||||||
.blockchain-wrapper.time-ltr {
|
|
||||||
.position-container {
|
|
||||||
transform: translateX(calc(100vw - var(--divider-offset) - var(--mempool-offset)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.black-background {
|
.black-background {
|
||||||
|
@ -27,8 +27,11 @@ export class BlockchainComponent implements OnInit, OnDestroy, OnChanges {
|
|||||||
loadingTip: boolean = true;
|
loadingTip: boolean = true;
|
||||||
connected: boolean = true;
|
connected: boolean = true;
|
||||||
|
|
||||||
dividerOffset: number = 0;
|
dividerOffset: number | null = null;
|
||||||
mempoolOffset: number = 0;
|
mempoolOffset: number | null = null;
|
||||||
|
positionStyle = {
|
||||||
|
transform: "translateX(1280px)",
|
||||||
|
};
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public stateService: StateService,
|
public stateService: StateService,
|
||||||
@ -40,6 +43,7 @@ export class BlockchainComponent implements OnInit, OnDestroy, OnChanges {
|
|||||||
this.network = this.stateService.network;
|
this.network = this.stateService.network;
|
||||||
this.timeLtrSubscription = this.stateService.timeLtr.subscribe((ltr) => {
|
this.timeLtrSubscription = this.stateService.timeLtr.subscribe((ltr) => {
|
||||||
this.timeLtr = !!ltr;
|
this.timeLtr = !!ltr;
|
||||||
|
this.updateStyle();
|
||||||
});
|
});
|
||||||
this.connectionStateSubscription = this.stateService.connectionState$.subscribe(state => {
|
this.connectionStateSubscription = this.stateService.connectionState$.subscribe(state => {
|
||||||
this.connected = (state === 2);
|
this.connected = (state === 2);
|
||||||
@ -63,29 +67,47 @@ export class BlockchainComponent implements OnInit, OnDestroy, OnChanges {
|
|||||||
const prevOffset = this.mempoolOffset;
|
const prevOffset = this.mempoolOffset;
|
||||||
this.mempoolOffset = 0;
|
this.mempoolOffset = 0;
|
||||||
this.mempoolOffsetChange.emit(0);
|
this.mempoolOffsetChange.emit(0);
|
||||||
|
this.updateStyle();
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.ltrTransitionEnabled = true;
|
this.ltrTransitionEnabled = true;
|
||||||
this.flipping = true;
|
this.flipping = true;
|
||||||
this.stateService.timeLtr.next(!this.timeLtr);
|
this.stateService.timeLtr.next(!this.timeLtr);
|
||||||
|
this.cd.markForCheck();
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.ltrTransitionEnabled = false;
|
this.ltrTransitionEnabled = false;
|
||||||
this.flipping = false;
|
this.flipping = false;
|
||||||
this.mempoolOffset = prevOffset;
|
this.mempoolOffset = prevOffset;
|
||||||
this.mempoolOffsetChange.emit(this.mempoolOffset);
|
this.mempoolOffsetChange.emit((this.mempoolOffset || 0));
|
||||||
|
this.updateStyle();
|
||||||
|
this.cd.markForCheck();
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}, 0);
|
}, 0);
|
||||||
this.cd.markForCheck();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onMempoolWidthChange(width): void {
|
onMempoolWidthChange(width): void {
|
||||||
if (this.flipping) {
|
if (this.flipping) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.mempoolOffset = Math.max(0, width - this.dividerOffset);
|
this.mempoolOffset = Math.max(0, width - (this.dividerOffset || 0));
|
||||||
this.cd.markForCheck();
|
this.updateStyle();
|
||||||
this.mempoolOffsetChange.emit(this.mempoolOffset);
|
this.mempoolOffsetChange.emit(this.mempoolOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateStyle(): void {
|
||||||
|
if (this.dividerOffset == null || this.mempoolOffset == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const oldTransform = this.positionStyle.transform;
|
||||||
|
this.positionStyle = this.timeLtr ? {
|
||||||
|
transform: `translateX(calc(100vw - ${this.dividerOffset + this.mempoolOffset}px)`,
|
||||||
|
} : {
|
||||||
|
transform: `translateX(${this.dividerOffset + this.mempoolOffset}px)`,
|
||||||
|
};
|
||||||
|
if (oldTransform !== this.positionStyle.transform) {
|
||||||
|
this.cd.detectChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ngOnChanges(changes: SimpleChanges): void {
|
ngOnChanges(changes: SimpleChanges): void {
|
||||||
if (changes.containerWidth) {
|
if (changes.containerWidth) {
|
||||||
this.onResize();
|
this.onResize();
|
||||||
@ -107,6 +129,6 @@ export class BlockchainComponent implements OnInit, OnDestroy, OnChanges {
|
|||||||
this.dividerOffset = width * 0.95;
|
this.dividerOffset = width * 0.95;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.cd.markForCheck();
|
this.updateStyle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,6 +97,10 @@ export class MempoolBlocksComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.chainTip = this.stateService.latestBlockHeight;
|
this.chainTip = this.stateService.latestBlockHeight;
|
||||||
|
|
||||||
|
const width = this.containerOffset + (this.stateService.env.MEMPOOL_BLOCKS_AMOUNT) * this.blockOffset;
|
||||||
|
this.mempoolWidth = width;
|
||||||
|
this.widthChange.emit(this.mempoolWidth);
|
||||||
|
|
||||||
if (['', 'testnet', 'signet'].includes(this.stateService.network)) {
|
if (['', 'testnet', 'signet'].includes(this.stateService.network)) {
|
||||||
this.enabledMiningInfoIfNeeded(this.location.path());
|
this.enabledMiningInfoIfNeeded(this.location.path());
|
||||||
this.location.onUrlChange((url) => this.enabledMiningInfoIfNeeded(url));
|
this.location.onUrlChange((url) => this.enabledMiningInfoIfNeeded(url));
|
||||||
@ -161,11 +165,11 @@ export class MempoolBlocksComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
return this.mempoolBlocks;
|
return this.mempoolBlocks;
|
||||||
}),
|
}),
|
||||||
tap(() => {
|
tap(() => {
|
||||||
this.cd.markForCheck();
|
|
||||||
const width = this.containerOffset + this.mempoolBlocks.length * this.blockOffset;
|
const width = this.containerOffset + this.mempoolBlocks.length * this.blockOffset;
|
||||||
if (this.mempoolWidth !== width) {
|
if (this.mempoolWidth !== width) {
|
||||||
this.mempoolWidth = width;
|
this.mempoolWidth = width;
|
||||||
this.widthChange.emit(this.mempoolWidth);
|
this.widthChange.emit(this.mempoolWidth);
|
||||||
|
this.cd.markForCheck();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@ -215,11 +219,13 @@ export class MempoolBlocksComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
if (isNewBlock && (block?.extras?.similarity == null || block?.extras?.similarity > 0.5) && !this.tabHidden) {
|
if (isNewBlock && (block?.extras?.similarity == null || block?.extras?.similarity > 0.5) && !this.tabHidden) {
|
||||||
this.blockIndex++;
|
this.blockIndex++;
|
||||||
}
|
}
|
||||||
|
this.cd.markForCheck();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.chainTipSubscription = this.stateService.chainTip$.subscribe((height) => {
|
this.chainTipSubscription = this.stateService.chainTip$.subscribe((height) => {
|
||||||
if (this.chainTip === -1) {
|
if (this.chainTip === -1) {
|
||||||
this.chainTip = height;
|
this.chainTip = height;
|
||||||
|
this.cd.markForCheck();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -257,6 +263,7 @@ export class MempoolBlocksComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
this.blockPadding = 0.24 * this.blockWidth;
|
this.blockPadding = 0.24 * this.blockWidth;
|
||||||
this.containerOffset = 0.32 * this.blockWidth;
|
this.containerOffset = 0.32 * this.blockWidth;
|
||||||
this.blockOffset = this.blockWidth + this.blockPadding;
|
this.blockOffset = this.blockWidth + this.blockPadding;
|
||||||
|
this.cd.markForCheck();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,6 +282,7 @@ export class MempoolBlocksComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
onResize(): void {
|
onResize(): void {
|
||||||
this.animateEntry = false;
|
this.animateEntry = false;
|
||||||
this.reduceEmptyBlocksToFitScreen(this.mempoolEmptyBlocks);
|
this.reduceEmptyBlocksToFitScreen(this.mempoolEmptyBlocks);
|
||||||
|
this.cd.markForCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
trackByFn(index: number, block: MempoolBlock) {
|
trackByFn(index: number, block: MempoolBlock) {
|
||||||
|
@ -24,7 +24,7 @@ export class StartComponent implements OnInit, AfterViewChecked, OnDestroy {
|
|||||||
timeLtrSubscription: Subscription;
|
timeLtrSubscription: Subscription;
|
||||||
timeLtr: boolean = this.stateService.timeLtr.value;
|
timeLtr: boolean = this.stateService.timeLtr.value;
|
||||||
chainTipSubscription: Subscription;
|
chainTipSubscription: Subscription;
|
||||||
chainTip: number = -1;
|
chainTip: number = 100;
|
||||||
tipIsSet: boolean = false;
|
tipIsSet: boolean = false;
|
||||||
lastMark: MarkBlockState;
|
lastMark: MarkBlockState;
|
||||||
markBlockSubscription: Subscription;
|
markBlockSubscription: Subscription;
|
||||||
@ -42,7 +42,7 @@ export class StartComponent implements OnInit, AfterViewChecked, OnDestroy {
|
|||||||
blocksPerPage: number = 1;
|
blocksPerPage: number = 1;
|
||||||
pageWidth: number;
|
pageWidth: number;
|
||||||
firstPageWidth: number;
|
firstPageWidth: number;
|
||||||
minScrollWidth: number;
|
minScrollWidth: number = 40 + (155 * (8 + (2 * Math.ceil(window.innerWidth / 155))));
|
||||||
currentScrollWidth: number = null;
|
currentScrollWidth: number = null;
|
||||||
pageIndex: number = 0;
|
pageIndex: number = 0;
|
||||||
pages: any[] = [];
|
pages: any[] = [];
|
||||||
@ -51,7 +51,7 @@ export class StartComponent implements OnInit, AfterViewChecked, OnDestroy {
|
|||||||
lastUpdate: number = 0;
|
lastUpdate: number = 0;
|
||||||
lastMouseX: number;
|
lastMouseX: number;
|
||||||
velocity: number = 0;
|
velocity: number = 0;
|
||||||
mempoolOffset: number | null = null;
|
mempoolOffset: number = null;
|
||||||
mempoolWidth: number = 0;
|
mempoolWidth: number = 0;
|
||||||
scrollLeft: number = null;
|
scrollLeft: number = null;
|
||||||
|
|
||||||
@ -67,12 +67,13 @@ export class StartComponent implements OnInit, AfterViewChecked, OnDestroy {
|
|||||||
this.isiOS = ['iPhone','iPod','iPad'].includes((navigator as any)?.userAgentData?.platform || navigator.platform);
|
this.isiOS = ['iPhone','iPod','iPad'].includes((navigator as any)?.userAgentData?.platform || navigator.platform);
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit() {
|
||||||
this.firstPageWidth = 40 + (this.blockWidth * this.dynamicBlocksAmount);
|
this.firstPageWidth = 40 + (this.blockWidth * this.dynamicBlocksAmount);
|
||||||
this.blockCounterSubscription = this.stateService.blocks$.subscribe((blocks) => {
|
this.blockCounterSubscription = this.stateService.blocks$.subscribe((blocks) => {
|
||||||
this.blockCount = blocks.length;
|
this.blockCount = blocks.length;
|
||||||
this.dynamicBlocksAmount = Math.min(this.blockCount, this.stateService.env.KEEP_BLOCKS_AMOUNT, 8);
|
this.dynamicBlocksAmount = Math.min(this.blockCount, this.stateService.env.KEEP_BLOCKS_AMOUNT, 8);
|
||||||
this.firstPageWidth = 40 + (this.blockWidth * this.dynamicBlocksAmount);
|
this.firstPageWidth = 40 + (this.blockWidth * this.dynamicBlocksAmount);
|
||||||
|
this.minScrollWidth = 40 + (8 * this.blockWidth) + (this.pageWidth * 2);
|
||||||
if (this.blockCount <= Math.min(8, this.stateService.env.KEEP_BLOCKS_AMOUNT)) {
|
if (this.blockCount <= Math.min(8, this.stateService.env.KEEP_BLOCKS_AMOUNT)) {
|
||||||
this.onResize();
|
this.onResize();
|
||||||
}
|
}
|
||||||
@ -181,7 +182,9 @@ export class StartComponent implements OnInit, AfterViewChecked, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onMempoolOffsetChange(offset): void {
|
onMempoolOffsetChange(offset): void {
|
||||||
this.pendingOffset = offset;
|
if (offset !== this.mempoolOffset) {
|
||||||
|
this.pendingOffset = offset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
applyScrollLeft(): void {
|
applyScrollLeft(): void {
|
||||||
@ -198,11 +201,11 @@ export class StartComponent implements OnInit, AfterViewChecked, OnDestroy {
|
|||||||
}
|
}
|
||||||
this.blockchainContainer.nativeElement.scrollLeft = this.scrollLeft;
|
this.blockchainContainer.nativeElement.scrollLeft = this.scrollLeft;
|
||||||
}
|
}
|
||||||
this.cd.markForCheck();
|
this.cd.detectChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
applyPendingMarkArrow(): void {
|
applyPendingMarkArrow(): void {
|
||||||
if (this.pendingMark != null) {
|
if (this.pendingMark != null && this.pendingMark <= this.chainTip) {
|
||||||
if (this.pendingMark < 0) {
|
if (this.pendingMark < 0) {
|
||||||
this.scrollToBlock(this.chainTip - this.pendingMark);
|
this.scrollToBlock(this.chainTip - this.pendingMark);
|
||||||
} else {
|
} else {
|
||||||
@ -239,13 +242,14 @@ export class StartComponent implements OnInit, AfterViewChecked, OnDestroy {
|
|||||||
|
|
||||||
this.blocksPerPage = Math.ceil(this.chainWidth / this.blockWidth);
|
this.blocksPerPage = Math.ceil(this.chainWidth / this.blockWidth);
|
||||||
this.pageWidth = this.blocksPerPage * this.blockWidth;
|
this.pageWidth = this.blocksPerPage * this.blockWidth;
|
||||||
this.minScrollWidth = this.firstPageWidth + (this.pageWidth * 2);
|
this.minScrollWidth = 40 + (8 * this.blockWidth) + (this.pageWidth * 2);
|
||||||
|
|
||||||
if (firstVisibleBlock != null) {
|
if (firstVisibleBlock != null) {
|
||||||
this.scrollToBlock(firstVisibleBlock, offset);
|
this.scrollToBlock(firstVisibleBlock, offset);
|
||||||
} else {
|
} else {
|
||||||
this.updatePages();
|
this.updatePages();
|
||||||
}
|
}
|
||||||
|
this.cd.markForCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
onMouseDown(event: MouseEvent) {
|
onMouseDown(event: MouseEvent) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user