Fixed denomination units with ability to change default currency (ie. BTC to BCH); Fixed bug with obtaining exchange rate (for BCH); Added number pipe on transactions component

This commit is contained in:
Darren Nelsen 2018-01-26 16:22:49 -05:00
parent c02dd53fc5
commit c83e16f98e
3 changed files with 38 additions and 9 deletions

View File

@ -7,6 +7,6 @@
}, },
"proxies": [{ "proxies": [{
"path": "/api", "path": "/api",
"proxyUrl": "http://localhost:3000/api" "proxyUrl": "https://bch-insight.bitpay.com/api"
}] }]
} }

View File

@ -48,7 +48,7 @@
</div> </div>
<div item-end> <div item-end>
{{ currency.getConversion(vin.value) }} {{ currency.getConvertedNumber(vin.value) | number:'1.0-8' }} {{ currency.currencySymbol }}
</div> </div>
</ion-item> </ion-item>
</ion-list> </ion-list>
@ -76,7 +76,7 @@
</div> </div>
<div item-end> <div item-end>
{{ currency.getConversion(vout.value) }} {{ currency.getConvertedNumber(vout.value) | number:'1.0-8' }} {{ currency.currencySymbol }}
<span [hidden]="!vout.spentTxId">(S)</span> <span [hidden]="!vout.spentTxId">(S)</span>
<span [hidden]="vout.spentTxId">(U)</span> <span [hidden]="vout.spentTxId">(U)</span>
</div> </div>
@ -88,12 +88,12 @@
<ion-row align-items-center text-uppercase class="small"> <ion-row align-items-center text-uppercase class="small">
<ion-col col-6> <ion-col col-6>
<div [hidden]="tx.isCoinBase"> <div [hidden]="tx.isCoinBase">
Fee <span text-nowrap>{{ currency.getConversion(tx.fees) }}</span> Fee <span text-nowrap>{{ currency.getConvertedNumber(tx.fees) | number:'1.0-8' }} {{ currency.currencySymbol }}</span>
</div> </div>
</ion-col> </ion-col>
<ion-col col-6 text-right> <ion-col col-6 text-right>
<span text-nowrap>{{ tx.confirmations }} Confirmation<span *ngIf="tx.confirmations !== 1">s</span></span> <span text-nowrap>{{ tx.confirmations }} Confirmation<span *ngIf="tx.confirmations !== 1">s</span></span>
<span text-nowrap>{{ currency.getConversion(tx.valueOut) }}</span> <span text-nowrap>{{ currency.getConvertedNumber(tx.valueOut) | number:'1.0-8' }} {{ currency.currencySymbol }}</span>
</ion-col> </ion-col>
</ion-row> </ion-row>
</ion-grid> </ion-grid>

View File

@ -16,6 +16,7 @@ export class CurrencyProvider {
public currencySymbol: string; public currencySymbol: string;
public factor: number = 1; public factor: number = 1;
private bitstamp: number; private bitstamp: number;
private kraken: number;
private loading: boolean; private loading: boolean;
constructor(public http: Http, private api: ApiProvider) { constructor(public http: Http, private api: ApiProvider) {
@ -27,6 +28,30 @@ export class CurrencyProvider {
return Math.round(aFloat * Math.pow(10, decimalPlaces)) / Math.pow(10, decimalPlaces); return Math.round(aFloat * Math.pow(10, decimalPlaces)) / Math.pow(10, decimalPlaces);
} }
public getConvertedNumber(value: number): number {
if (value === 0.00000000) return 0;
let response: number;
if (this.currencySymbol === 'USD') {
response = this.roundFloat((value * this.factor), 2);
} else if (this.currencySymbol === 'm' + this.defaultCurrency) {
this.factor = 1000;
response = this.roundFloat((value * this.factor), 5);
} else if (this.currencySymbol === 'bits') {
this.factor = 1000000;
response = this.roundFloat((value * this.factor), 2);
} else {
this.factor = 1;
response = this.roundFloat((value * this.factor), 8);
}
return response;
}
/**
* @deprecated use getConvertedNumber
*/
public getConversion(value: number): string { public getConversion(value: number): string {
if (value === 0.00000000) return '0 ' + this.currencySymbol; // fix value to show if (value === 0.00000000) return '0 ' + this.currencySymbol; // fix value to show
@ -34,13 +59,13 @@ export class CurrencyProvider {
if (this.currencySymbol === 'USD') { if (this.currencySymbol === 'USD') {
response = this.roundFloat((value * this.factor), 2); response = this.roundFloat((value * this.factor), 2);
} else if (this.currencySymbol === 'mBTC') { } else if (this.currencySymbol === 'm' + this.defaultCurrency) {
this.factor = 1000; this.factor = 1000;
response = this.roundFloat((value * this.factor), 5); response = this.roundFloat((value * this.factor), 5);
} else if (this.currencySymbol === 'bits') { } else if (this.currencySymbol === 'bits') {
this.factor = 1000000; this.factor = 1000000;
response = this.roundFloat((value * this.factor), 2); response = this.roundFloat((value * this.factor), 2);
} else { // assumes currencySymbol is BTC } else {
this.factor = 1; this.factor = 1;
response = this.roundFloat((value * this.factor), 8); response = this.roundFloat((value * this.factor), 8);
} }
@ -56,7 +81,11 @@ export class CurrencyProvider {
this.http.get(this.api.apiPrefix + 'currency').subscribe( this.http.get(this.api.apiPrefix + 'currency').subscribe(
(data) => { (data) => {
let currencyParsed: any = JSON.parse(data['_body']); let currencyParsed: any = JSON.parse(data['_body']);
this.factor = this.bitstamp = currencyParsed.data.bitstamp; if (currencyParsed.data.bitstamp) {
this.factor = this.bitstamp = currencyParsed.data.bitstamp;
} else if (currencyParsed.data.kraken) {
this.factor = this.kraken = currencyParsed.data.kraken;
}
this.loading = false; this.loading = false;
}, },
(err) => { (err) => {
@ -64,7 +93,7 @@ export class CurrencyProvider {
this.loading = false; this.loading = false;
} }
); );
} else if (currency === 'mBTC') { } else if (currency === 'm' + this.defaultCurrency) {
this.factor = 1000; this.factor = 1000;
} else if (currency === 'bits') { } else if (currency === 'bits') {
this.factor = 1000000; this.factor = 1000000;