From c83e16f98ef3cde8f321afc9d55ffb16be58f912 Mon Sep 17 00:00:00 2001 From: Darren Nelsen Date: Fri, 26 Jan 2018 16:22:49 -0500 Subject: [PATCH] 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 --- app/ionic.config.json | 2 +- .../components/transaction/transaction.html | 8 ++-- app/src/providers/currency/currency.ts | 37 +++++++++++++++++-- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/app/ionic.config.json b/app/ionic.config.json index 6f01a59..9ffab3a 100644 --- a/app/ionic.config.json +++ b/app/ionic.config.json @@ -7,6 +7,6 @@ }, "proxies": [{ "path": "/api", - "proxyUrl": "http://localhost:3000/api" + "proxyUrl": "https://bch-insight.bitpay.com/api" }] } diff --git a/app/src/components/transaction/transaction.html b/app/src/components/transaction/transaction.html index 5670b35..cc3528f 100644 --- a/app/src/components/transaction/transaction.html +++ b/app/src/components/transaction/transaction.html @@ -48,7 +48,7 @@
- {{ currency.getConversion(vin.value) }} + {{ currency.getConvertedNumber(vin.value) | number:'1.0-8' }} {{ currency.currencySymbol }}
@@ -76,7 +76,7 @@
- {{ currency.getConversion(vout.value) }} + {{ currency.getConvertedNumber(vout.value) | number:'1.0-8' }} {{ currency.currencySymbol }} (S) (U)
@@ -88,12 +88,12 @@
- Fee {{ currency.getConversion(tx.fees) }} + Fee {{ currency.getConvertedNumber(tx.fees) | number:'1.0-8' }} {{ currency.currencySymbol }}
{{ tx.confirmations }} Confirmations - {{ currency.getConversion(tx.valueOut) }} + {{ currency.getConvertedNumber(tx.valueOut) | number:'1.0-8' }} {{ currency.currencySymbol }}
diff --git a/app/src/providers/currency/currency.ts b/app/src/providers/currency/currency.ts index b3f571b..297392d 100644 --- a/app/src/providers/currency/currency.ts +++ b/app/src/providers/currency/currency.ts @@ -16,6 +16,7 @@ export class CurrencyProvider { public currencySymbol: string; public factor: number = 1; private bitstamp: number; + private kraken: number; private loading: boolean; 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); } + 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 { if (value === 0.00000000) return '0 ' + this.currencySymbol; // fix value to show @@ -34,13 +59,13 @@ export class CurrencyProvider { if (this.currencySymbol === 'USD') { response = this.roundFloat((value * this.factor), 2); - } else if (this.currencySymbol === 'mBTC') { + } 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 { // assumes currencySymbol is BTC + } else { this.factor = 1; response = this.roundFloat((value * this.factor), 8); } @@ -56,7 +81,11 @@ export class CurrencyProvider { this.http.get(this.api.apiPrefix + 'currency').subscribe( (data) => { 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; }, (err) => { @@ -64,7 +93,7 @@ export class CurrencyProvider { this.loading = false; } ); - } else if (currency === 'mBTC') { + } else if (currency === 'm' + this.defaultCurrency) { this.factor = 1000; } else if (currency === 'bits') { this.factor = 1000000;