fix tx page mempool blocks subscription leak
This commit is contained in:
		
							parent
							
								
									e3f1fced99
								
							
						
					
					
						commit
						9bd968f6c3
					
				@ -49,6 +49,7 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy {
 | 
			
		||||
  blocksSubscription: Subscription;
 | 
			
		||||
  queryParamsSubscription: Subscription;
 | 
			
		||||
  urlFragmentSubscription: Subscription;
 | 
			
		||||
  mempoolBlocksSubscription: Subscription;
 | 
			
		||||
  fragmentParams: URLSearchParams;
 | 
			
		||||
  rbfTransaction: undefined | Transaction;
 | 
			
		||||
  replaced: boolean = false;
 | 
			
		||||
@ -308,7 +309,6 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy {
 | 
			
		||||
          this.isLoadingTx = false;
 | 
			
		||||
          this.error = undefined;
 | 
			
		||||
          this.waitingForTransaction = false;
 | 
			
		||||
          this.setMempoolBlocksSubscription();
 | 
			
		||||
          this.websocketService.startTrackTransaction(tx.txid);
 | 
			
		||||
          this.graphExpanded = false;
 | 
			
		||||
          this.setupGraph();
 | 
			
		||||
@ -391,6 +391,34 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy {
 | 
			
		||||
      this.setFlowEnabled();
 | 
			
		||||
      this.setGraphSize();
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    this.mempoolBlocksSubscription = this.stateService.mempoolBlocks$.subscribe((mempoolBlocks) => {
 | 
			
		||||
      if (!this.tx) {
 | 
			
		||||
        return;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      this.now = Date.now();
 | 
			
		||||
 | 
			
		||||
      const txFeePerVSize =
 | 
			
		||||
        this.tx.effectiveFeePerVsize || this.tx.fee / (this.tx.weight / 4);
 | 
			
		||||
 | 
			
		||||
      let found = false;
 | 
			
		||||
      this.txInBlockIndex = 0;
 | 
			
		||||
      for (const block of mempoolBlocks) {
 | 
			
		||||
        for (let i = 0; i < block.feeRange.length - 1 && !found; i++) {
 | 
			
		||||
          if (
 | 
			
		||||
            txFeePerVSize <= block.feeRange[i + 1] &&
 | 
			
		||||
            txFeePerVSize >= block.feeRange[i]
 | 
			
		||||
          ) {
 | 
			
		||||
            this.txInBlockIndex = mempoolBlocks.indexOf(block);
 | 
			
		||||
            found = true;
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      if (!found && txFeePerVSize < mempoolBlocks[mempoolBlocks.length - 1].feeRange[0]) {
 | 
			
		||||
        this.txInBlockIndex = 7;
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  ngAfterViewInit(): void {
 | 
			
		||||
@ -407,32 +435,6 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy {
 | 
			
		||||
    return of(false);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  setMempoolBlocksSubscription() {
 | 
			
		||||
    this.stateService.mempoolBlocks$.subscribe((mempoolBlocks) => {
 | 
			
		||||
      if (!this.tx) {
 | 
			
		||||
        return;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      this.now = Date.now();
 | 
			
		||||
 | 
			
		||||
      const txFeePerVSize =
 | 
			
		||||
        this.tx.effectiveFeePerVsize || this.tx.fee / (this.tx.weight / 4);
 | 
			
		||||
 | 
			
		||||
      let found = false;
 | 
			
		||||
      for (const block of mempoolBlocks) {
 | 
			
		||||
        for (let i = 0; i < block.feeRange.length - 1 && !found; i++) {
 | 
			
		||||
          if (
 | 
			
		||||
            txFeePerVSize <= block.feeRange[i + 1] &&
 | 
			
		||||
            txFeePerVSize >= block.feeRange[i]
 | 
			
		||||
          ) {
 | 
			
		||||
            this.txInBlockIndex = mempoolBlocks.indexOf(block);
 | 
			
		||||
            found = true;
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  getTransactionTime() {
 | 
			
		||||
    this.apiService
 | 
			
		||||
      .getTransactionTimes$([this.tx.txid])
 | 
			
		||||
@ -540,6 +542,7 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy {
 | 
			
		||||
    this.queryParamsSubscription.unsubscribe();
 | 
			
		||||
    this.flowPrefSubscription.unsubscribe();
 | 
			
		||||
    this.urlFragmentSubscription.unsubscribe();
 | 
			
		||||
    this.mempoolBlocksSubscription.unsubscribe();
 | 
			
		||||
    this.leaveTransaction();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user