Commit 8b87e2a3 authored by Michel Schudel's avatar Michel Schudel
parents d8ff85d1 0a7be4ee
......@@ -4,12 +4,11 @@ import { ReplaySubject } from 'rxjs/ReplaySubject';
import 'rxjs/add/observable/of';
import 'rxjs/add/observable/timer';
import 'rxjs/add/operator/bufferCount';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/switchMap';
import 'rxjs/add/operator/concat';
import 'rxjs/add/operator/startWith';
import 'rxjs/add/operator/takeWhile';
import 'rxjs/add/operator/take';
@Component({
selector: 'app-balance',
......@@ -17,19 +16,18 @@ import 'rxjs/add/operator/takeWhile';
})
export class BalanceComponent implements OnInit, OnChanges {
@Input() balance: number;
currentBalance: number;
currentBalance = 0;
private nextBalance = new ReplaySubject<number>();
ngOnInit(): void {
this.nextBalance
.startWith(0)
.bufferCount(2, 1)
.switchMap(([prev, current]) =>
.switchMap(next =>
Observable.timer(0, 30)
.map(i => prev + i * (current - prev) / 7)
.takeWhile(i => current > prev ? i < current : i > current)
.concat(Observable.of(current))
.take(20)
.map(i => this.currentBalance + i * (next - this.currentBalance) / 20)
.concat(Observable.of(next))
)
.subscribe(b => this.currentBalance = b);
}
......
<h3 class="mb-4">Result</h3>
<div class="wallet" *ngIf="wallet">
<h5>
<h4>
Balance: <app-balance class="text-success"
[class.text-danger]="wallet.balance < 0"
[balance]="wallet.balance"></app-balance>
</h5>
</h4>
<ul class="list-group mt-3">
<li *ngFor="let transaction of wallet.unconfirmedTransactions; trackBy: trackByFn" [@slide]="wallet.unconfirmedTransactions.length"
......
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