fix error when navigating to huge transactions
This commit is contained in:
		
							parent
							
								
									02820b0e68
								
							
						
					
					
						commit
						65bfe8163c
					
				@ -117,8 +117,9 @@ export class TransactionPreviewComponent implements OnInit, OnDestroy {
 | 
				
			|||||||
        }),
 | 
					        }),
 | 
				
			||||||
        switchMap(() => {
 | 
					        switchMap(() => {
 | 
				
			||||||
          let transactionObservable$: Observable<Transaction>;
 | 
					          let transactionObservable$: Observable<Transaction>;
 | 
				
			||||||
          if (history.state.data && history.state.data.fee !== -1) {
 | 
					          const cached = this.stateService.getTxFromCache(this.txId);
 | 
				
			||||||
            transactionObservable$ = of(history.state.data);
 | 
					          if (cached && cached.fee !== -1) {
 | 
				
			||||||
 | 
					            transactionObservable$ = of(cached);
 | 
				
			||||||
          } else {
 | 
					          } else {
 | 
				
			||||||
            transactionObservable$ = this.electrsApiService
 | 
					            transactionObservable$ = this.electrsApiService
 | 
				
			||||||
              .getTransaction$(this.txId)
 | 
					              .getTransaction$(this.txId)
 | 
				
			||||||
 | 
				
			|||||||
@ -3,7 +3,7 @@
 | 
				
			|||||||
  <div class="title-block">
 | 
					  <div class="title-block">
 | 
				
			||||||
    <div *ngIf="rbfTransaction" class="alert alert-mempool" role="alert">
 | 
					    <div *ngIf="rbfTransaction" class="alert alert-mempool" role="alert">
 | 
				
			||||||
      <span i18n="transaction.rbf.replacement|RBF replacement">This transaction has been replaced by:</span>
 | 
					      <span i18n="transaction.rbf.replacement|RBF replacement">This transaction has been replaced by:</span>
 | 
				
			||||||
      <a class="alert-link" [routerLink]="['/tx/' | relativeUrl, rbfTransaction.txid]" [state]="{ data: rbfTransaction.size ? rbfTransaction : null }">
 | 
					      <a class="alert-link" [routerLink]="['/tx/' | relativeUrl, rbfTransaction.txid]">
 | 
				
			||||||
        <span class="d-inline d-lg-none">{{ rbfTransaction.txid | shortenString : 24 }}</span>
 | 
					        <span class="d-inline d-lg-none">{{ rbfTransaction.txid | shortenString : 24 }}</span>
 | 
				
			||||||
        <span class="d-none d-lg-inline">{{ rbfTransaction.txid }}</span>
 | 
					        <span class="d-none d-lg-inline">{{ rbfTransaction.txid }}</span>
 | 
				
			||||||
      </a>
 | 
					      </a>
 | 
				
			||||||
 | 
				
			|||||||
@ -183,8 +183,9 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy {
 | 
				
			|||||||
        }),
 | 
					        }),
 | 
				
			||||||
        switchMap(() => {
 | 
					        switchMap(() => {
 | 
				
			||||||
          let transactionObservable$: Observable<Transaction>;
 | 
					          let transactionObservable$: Observable<Transaction>;
 | 
				
			||||||
          if (history.state.data && history.state.data.fee !== -1) {
 | 
					          const cached = this.stateService.getTxFromCache(this.txId);
 | 
				
			||||||
            transactionObservable$ = of(history.state.data);
 | 
					          if (cached && cached.fee !== -1) {
 | 
				
			||||||
 | 
					            transactionObservable$ = of(cached);
 | 
				
			||||||
          } else {
 | 
					          } else {
 | 
				
			||||||
            transactionObservable$ = this.electrsApiService
 | 
					            transactionObservable$ = this.electrsApiService
 | 
				
			||||||
              .getTransaction$(this.txId)
 | 
					              .getTransaction$(this.txId)
 | 
				
			||||||
@ -279,6 +280,7 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy {
 | 
				
			|||||||
        this.waitingForTransaction = false;
 | 
					        this.waitingForTransaction = false;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      this.rbfTransaction = rbfTransaction;
 | 
					      this.rbfTransaction = rbfTransaction;
 | 
				
			||||||
 | 
					      this.stateService.setTxCache([this.rbfTransaction]);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.queryParamsSubscription = this.route.queryParams.subscribe((params) => {
 | 
					    this.queryParamsSubscription = this.route.queryParams.subscribe((params) => {
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,6 @@
 | 
				
			|||||||
<ng-container *ngFor="let tx of transactions; let i = index; trackBy: trackByFn">
 | 
					<ng-container *ngFor="let tx of transactions; let i = index; trackBy: trackByFn">
 | 
				
			||||||
  <div *ngIf="!transactionPage" class="header-bg box tx-page-container">
 | 
					  <div *ngIf="!transactionPage" class="header-bg box tx-page-container">
 | 
				
			||||||
    <a class="float-left" [routerLink]="['/tx/' | relativeUrl, tx.txid]" [state]="{ data: tx }">
 | 
					    <a class="float-left" [routerLink]="['/tx/' | relativeUrl, tx.txid]">
 | 
				
			||||||
      <span style="float: left;" class="d-block d-md-none">{{ tx.txid | shortenString : 16 }}</span>
 | 
					      <span style="float: left;" class="d-block d-md-none">{{ tx.txid | shortenString : 16 }}</span>
 | 
				
			||||||
      <span style="float: left;" class="d-none d-md-block">{{ tx.txid }}</span>
 | 
					      <span style="float: left;" class="d-none d-md-block">{{ tx.txid }}</span>
 | 
				
			||||||
    </a>
 | 
					    </a>
 | 
				
			||||||
 | 
				
			|||||||
@ -119,7 +119,7 @@ export class TransactionsListComponent implements OnInit, OnChanges {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      this.transactionsLength = this.transactions.length;
 | 
					      this.transactionsLength = this.transactions.length;
 | 
				
			||||||
 | 
					      this.stateService.setTxCache(this.transactions);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      this.transactions.forEach((tx) => {
 | 
					      this.transactions.forEach((tx) => {
 | 
				
			||||||
        tx['@voutLimit'] = true;
 | 
					        tx['@voutLimit'] = true;
 | 
				
			||||||
 | 
				
			|||||||
@ -112,6 +112,8 @@ export class StateService {
 | 
				
			|||||||
  timeLtr: BehaviorSubject<boolean>;
 | 
					  timeLtr: BehaviorSubject<boolean>;
 | 
				
			||||||
  hideFlow: BehaviorSubject<boolean>;
 | 
					  hideFlow: BehaviorSubject<boolean>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  txCache: { [txid: string]: Transaction } = {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  constructor(
 | 
					  constructor(
 | 
				
			||||||
    @Inject(PLATFORM_ID) private platformId: any,
 | 
					    @Inject(PLATFORM_ID) private platformId: any,
 | 
				
			||||||
    @Inject(LOCALE_ID) private locale: string,
 | 
					    @Inject(LOCALE_ID) private locale: string,
 | 
				
			||||||
@ -265,4 +267,19 @@ export class StateService {
 | 
				
			|||||||
  isLiquid() {
 | 
					  isLiquid() {
 | 
				
			||||||
    return this.network === 'liquid' || this.network === 'liquidtestnet';
 | 
					    return this.network === 'liquid' || this.network === 'liquidtestnet';
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  setTxCache(transactions) {
 | 
				
			||||||
 | 
					    this.txCache = {};
 | 
				
			||||||
 | 
					    transactions.forEach(tx => {
 | 
				
			||||||
 | 
					      this.txCache[tx.txid] = tx;
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  getTxFromCache(txid) {
 | 
				
			||||||
 | 
					    if (this.txCache && this.txCache[txid]) {
 | 
				
			||||||
 | 
					      return this.txCache[txid];
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      return null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user