Commit 7ba58952 authored by dev0tion's avatar dev0tion

Add startWith to polling

parent 88671d48
...@@ -5,6 +5,7 @@ import 'rxjs/add/operator/map'; ...@@ -5,6 +5,7 @@ import 'rxjs/add/operator/map';
import 'rxjs/add/operator/switchMap'; import 'rxjs/add/operator/switchMap';
import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/catch';
import "rxjs/add/observable/interval"; import "rxjs/add/observable/interval";
import 'rxjs/add/operator/startWith';
import { WalletCreation } from '../classes/wallet-creation'; import { WalletCreation } from '../classes/wallet-creation';
import { WalletRecovery } from '../classes/wallet-recovery'; import { WalletRecovery } from '../classes/wallet-recovery';
...@@ -24,7 +25,7 @@ export class ApiService { ...@@ -24,7 +25,7 @@ export class ApiService {
private mockApiUrl = 'http://localhost:3000/api'; private mockApiUrl = 'http://localhost:3000/api';
private webApiUrl = 'http://localhost:5000/api'; private webApiUrl = 'http://localhost:5000/api';
private headers = new Headers({'Content-Type': 'application/json'}); private headers = new Headers({'Content-Type': 'application/json'});
private pollingInterval = 2000; private pollingInterval = 3000;
/** /**
* Gets available wallets at the default path * Gets available wallets at the default path
...@@ -80,6 +81,7 @@ export class ApiService { ...@@ -80,6 +81,7 @@ export class ApiService {
return Observable return Observable
.interval(this.pollingInterval) .interval(this.pollingInterval)
.startWith(0)
.switchMap(() => this.http.get(this.webApiUrl + '/wallet/balance', new RequestOptions({headers: this.headers, search: params}))) .switchMap(() => this.http.get(this.webApiUrl + '/wallet/balance', new RequestOptions({headers: this.headers, search: params})))
.map((response: Response) => response); .map((response: Response) => response);
...@@ -97,6 +99,7 @@ export class ApiService { ...@@ -97,6 +99,7 @@ export class ApiService {
return Observable return Observable
.interval(this.pollingInterval) .interval(this.pollingInterval)
.startWith(0)
.switchMap(() => this.http.get(this.webApiUrl + '/wallet/history', new RequestOptions({headers: this.headers, search: params}))) .switchMap(() => this.http.get(this.webApiUrl + '/wallet/history', new RequestOptions({headers: this.headers, search: params})))
.map((response: Response) => response); .map((response: Response) => response);
......
...@@ -48,7 +48,6 @@ export class DashboardComponent { ...@@ -48,7 +48,6 @@ export class DashboardComponent {
private getWalletBalance() { private getWalletBalance() {
let walletInfo = new WalletInfo(this.globalService.getWalletName(), this.globalService.getCoinType()) let walletInfo = new WalletInfo(this.globalService.getWalletName(), this.globalService.getCoinType())
this.walletBalanceSubscription = this.apiService.getWalletBalance(walletInfo) this.walletBalanceSubscription = this.apiService.getWalletBalance(walletInfo)
.first()
.subscribe( .subscribe(
response => { response => {
if (response.status >= 200 && response.status < 400) { if (response.status >= 200 && response.status < 400) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment