diff --git a/StratisCore.UI/src/app/wallet/tokens/components/issue-token-progress/issue-token-progress.component.ts b/StratisCore.UI/src/app/wallet/tokens/components/issue-token-progress/issue-token-progress.component.ts index 28b659f6..ab296bcf 100644 --- a/StratisCore.UI/src/app/wallet/tokens/components/issue-token-progress/issue-token-progress.component.ts +++ b/StratisCore.UI/src/app/wallet/tokens/components/issue-token-progress/issue-token-progress.component.ts @@ -1,8 +1,8 @@ import { Component, Input, OnDestroy, OnInit } from '@angular/core'; import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; import { ModalService } from '@shared/services/modal.service'; -import { BehaviorSubject, interval, of, ReplaySubject, timer, race, throwError } from 'rxjs'; -import { catchError, switchMap, takeUntil, takeWhile, skipUntil, skipWhile, switchMapTo, mergeMap, first, map } from 'rxjs/operators'; +import { interval, of, race, ReplaySubject, throwError, timer } from 'rxjs'; +import { catchError, first, mergeMap, switchMapTo } from 'rxjs/operators'; import { SmartContractsServiceBase } from 'src/app/wallet/smart-contracts/smart-contracts.service'; import { Disposable } from '../../models/disposable'; @@ -38,23 +38,23 @@ export class IssueTokenProgressComponent implements OnInit, OnDestroy, Disposabl ngOnInit() { this.loading = true; - let timeOut = timer(this.maxTimeout) + const timeOut = timer(this.maxTimeout) .pipe( switchMapTo(throwError(`It seems to be taking longer to issue a token. Please go to "Smart Contracts" tab to monitor transactions and check the progress of the token issuance. Once successful, add token manually.`)) ); // Polls for a receipt on an interval and only emits when a receipt is found - let pollReceipt = interval(this.pollingInterval) + const pollReceipt = interval(this.pollingInterval) .pipe( mergeMap(_ => this.smartContractsService.GetReceiptSilent(this.transactionHash) .pipe( catchError(error => { - // Receipt API returns a 400 if the receipt is not found. + // Receipt API returns a 400 if the receipt is not found. Log.log(`Receipt not found yet`); return of(undefined); }) - ) + ) ), // Don't care about errors here, they will be handled in the subscribe first(r => { // Ignore the response until it has a value @@ -63,29 +63,28 @@ export class IssueTokenProgressComponent implements OnInit, OnDestroy, Disposabl ); race(timeOut, pollReceipt) - .pipe( - takeUntil(this.disposed$) - ) - .subscribe(receipt => { - this.loading = false; + .subscribe( + receipt => { + this.loading = false; + + if (!!receipt['error']) { + this.showError(receipt['error']); + this.activeModal.close('ok'); + return; + } - if (!!receipt['error']) { - this.showError(receipt['error']); + const newTokenAddress = receipt['newContractAddress']; + const token = new SavedToken(this.symbol, newTokenAddress, 0); + this.tokenService.AddToken(token); + this.activeModal.close('ok'); + }, + error => { + this.loading = false; + this.showError(error); + Log.error(error); this.activeModal.close('ok'); - return; } - - const newTokenAddress = receipt['newContractAddress']; - const token = new SavedToken(this.symbol, newTokenAddress, 0); - this.tokenService.AddToken(token); - this.activeModal.close('ok'); - }, - error => { - this.loading = false; - this.showError(error); - Log.error(error); - this.activeModal.close('ok'); - }); + ); } ngOnDestroy() {