Skip to content
This repository has been archived by the owner on May 24, 2021. It is now read-only.

Commit

Permalink
Remove pipe from race
Browse files Browse the repository at this point in the history
  • Loading branch information
fenix2222 committed Jul 12, 2019
1 parent e320aa4 commit d6eaf9c
Showing 1 changed file with 25 additions and 26 deletions.
@@ -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';
Expand Down Expand Up @@ -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
Expand All @@ -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() {
Expand Down

0 comments on commit d6eaf9c

Please sign in to comment.