From 1d542c15e40be4d82613a92a426954b39a172faf Mon Sep 17 00:00:00 2001 From: softsimon Date: Sun, 10 May 2020 01:34:28 +0700 Subject: [PATCH] Arrow navigation fix. Liquid native asset notification fix. --- backend/src/api/websocket-handler.ts | 48 +++++++++++++------ backend/src/interfaces.ts | 3 +- .../blockchain-blocks.component.ts | 11 +++-- .../mempool-blocks.component.ts | 6 +-- 4 files changed, 47 insertions(+), 21 deletions(-) diff --git a/backend/src/api/websocket-handler.ts b/backend/src/api/websocket-handler.ts index 638e68003..cc070528f 100644 --- a/backend/src/api/websocket-handler.ts +++ b/backend/src/api/websocket-handler.ts @@ -11,6 +11,7 @@ import fiatConversion from './fiat-conversion'; class WebsocketHandler { private wss: WebSocket.Server | undefined; private latestGitCommitHash = ''; + private nativeAssetId = '6f0279e9ed041c3d710a9f57d0c02928416460c4b722ae3457a11eec381c526d'; constructor() { this.setLatestGitCommit(); @@ -168,14 +169,23 @@ class WebsocketHandler { const foundTransactions: TransactionExtended[] = []; newTransactions.forEach((tx) => { - const someVin = tx.vin.some((vin) => !!vin.issuance && vin.issuance.asset_id === client['track-asset']); - if (someVin) { - foundTransactions.push(tx); - return; - } - const someVout = tx.vout.some((vout) => !!vout.asset && vout.asset === client['track-asset']); - if (someVout) { - foundTransactions.push(tx); + + if (client['track-asset'] === this.nativeAssetId) { + if (tx.vin.some((vin) => !!vin.is_pegin)) { + foundTransactions.push(tx); + return; + } + if (tx.vout.some((vout) => !!vout.pegout)) { + foundTransactions.push(tx); + } + } else { + if (tx.vin.some((vin) => !!vin.issuance && vin.issuance.asset_id === client['track-asset'])) { + foundTransactions.push(tx); + return; + } + if (tx.vout.some((vout) => !!vout.asset && vout.asset === client['track-asset'])) { + foundTransactions.push(tx); + } } }); @@ -244,12 +254,22 @@ class WebsocketHandler { const foundTransactions: TransactionExtended[] = []; transactions.forEach((tx) => { - if (tx.vin && tx.vin.some((vin) => !!vin.issuance && vin.issuance.asset_id === client['track-asset'])) { - foundTransactions.push(tx); - return; - } - if (tx.vout && tx.vout.some((vout) => !!vout.asset && vout.asset === client['track-asset'])) { - foundTransactions.push(tx); + if (client['track-asset'] === this.nativeAssetId) { + if (tx.vin && tx.vin.some((vin) => !!vin.is_pegin)) { + foundTransactions.push(tx); + return; + } + if (tx.vout && tx.vout.some((vout) => !!vout.pegout)) { + foundTransactions.push(tx); + } + } else { + if (tx.vin && tx.vin.some((vin) => !!vin.issuance && vin.issuance.asset_id === client['track-asset'])) { + foundTransactions.push(tx); + return; + } + if (tx.vout && tx.vout.some((vout) => !!vout.asset && vout.asset === client['track-asset'])) { + foundTransactions.push(tx); + } } }); diff --git a/backend/src/interfaces.ts b/backend/src/interfaces.ts index 85c56afd1..62de6eac8 100644 --- a/backend/src/interfaces.ts +++ b/backend/src/interfaces.ts @@ -56,7 +56,7 @@ export interface Vin { sequence: any; witness?: string[]; inner_witnessscript_asm?: string; - + is_pegin?: boolean; issuance?: Issuance; } @@ -79,6 +79,7 @@ export interface Vout { scriptpubkey_address?: string; value: number; + pegout?: any; asset?: string; } diff --git a/frontend/src/app/components/blockchain-blocks/blockchain-blocks.component.ts b/frontend/src/app/components/blockchain-blocks/blockchain-blocks.component.ts index 1e63e9c53..12b933637 100644 --- a/frontend/src/app/components/blockchain-blocks/blockchain-blocks.component.ts +++ b/frontend/src/app/components/blockchain-blocks/blockchain-blocks.component.ts @@ -10,6 +10,7 @@ import { Router } from '@angular/router'; styleUrls: ['./blockchain-blocks.component.scss'] }) export class BlockchainBlocksComponent implements OnInit, OnDestroy { + network = ''; blocks: Block[] = []; markHeight: number; blocksSubscription: Subscription; @@ -26,6 +27,8 @@ export class BlockchainBlocksComponent implements OnInit, OnDestroy { ) { } ngOnInit() { + this.stateService.networkChanged$.subscribe((network) => this.network = network); + this.blocksSubscription = this.stateService.blocks$ .subscribe((block) => { if (this.blocks.some((b) => b.height === block.height)) { @@ -60,14 +63,16 @@ export class BlockchainBlocksComponent implements OnInit, OnDestroy { if (event.key === 'ArrowRight') { const blockindex = this.blocks.findIndex((b) => b.height === this.markHeight); if (this.blocks[blockindex + 1]) { - this.router.navigate(['/block/', this.blocks[blockindex + 1].id], { state: { data: { block: this.blocks[blockindex + 1] } } }); + this.router.navigate([(this.network ? '/' + this.network : '') + '/block/', + this.blocks[blockindex + 1].id], { state: { data: { block: this.blocks[blockindex + 1] } } }); } } else if (event.key === 'ArrowLeft') { const blockindex = this.blocks.findIndex((b) => b.height === this.markHeight); if (blockindex === 0) { - this.router.navigate(['/mempool-block/', '0']); + this.router.navigate([(this.network ? '/' + this.network : '') + '/mempool-block/', '0']); } else { - this.router.navigate(['/block/', this.blocks[blockindex - 1].id], { state: { data: { block: this.blocks[blockindex - 1] }}}); + this.router.navigate([(this.network ? '/' + this.network : '') + '/block/', + this.blocks[blockindex - 1].id], { state: { data: { block: this.blocks[blockindex - 1] }}}); } } } diff --git a/frontend/src/app/components/mempool-blocks/mempool-blocks.component.ts b/frontend/src/app/components/mempool-blocks/mempool-blocks.component.ts index 38a3c111f..841272042 100644 --- a/frontend/src/app/components/mempool-blocks/mempool-blocks.component.ts +++ b/frontend/src/app/components/mempool-blocks/mempool-blocks.component.ts @@ -74,19 +74,19 @@ export class MempoolBlocksComponent implements OnInit, OnDestroy { } if (event.key === 'ArrowRight') { if (this.mempoolBlocks[this.markIndex - 1]) { - this.router.navigate(['/mempool-block/', this.markIndex - 1]); + this.router.navigate([(this.network ? '/' + this.network : '') + '/mempool-block/', this.markIndex - 1]); } else { this.stateService.blocks$ .pipe(take(8)) .subscribe((block) => { if (this.stateService.latestBlockHeight === block.height) { - this.router.navigate(['/block/', block.id], { state: { data: { block } }}); + this.router.navigate([(this.network ? '/' + this.network : '') + '/block/', block.id], { state: { data: { block } }}); } }); } } else if (event.key === 'ArrowLeft') { if (this.mempoolBlocks[this.markIndex + 1]) { - this.router.navigate(['/mempool-block/', this.markIndex + 1]); + this.router.navigate([(this.network ? '/' + this.network : '') + '/mempool-block/', this.markIndex + 1]); } } });