diff --git a/src/pages/send/amount/amount.html b/src/pages/send/amount/amount.html
index 6b0b99a9b..23f25a836 100644
--- a/src/pages/send/amount/amount.html
+++ b/src/pages/send/amount/amount.html
@@ -36,16 +36,11 @@
-
= {{amount | number: '1.2-8'}} {{unit || 'BTC'}}
-
≈ {{resultAmount | satToFiat: amount * 1e8 }}
-
+
= {{amount | number: '1.2-8'}} {{unit}}
+
≈ {{resultAmount | satToFiat: amount * 1e8: unit }}
+
≈ {{resultAmount | fiatToUnit: amount }}
diff --git a/src/pages/send/amount/amount.ts b/src/pages/send/amount/amount.ts
index 2c3eb1227..507f89811 100644
--- a/src/pages/send/amount/amount.ts
+++ b/src/pages/send/amount/amount.ts
@@ -6,6 +6,7 @@ import * as _ from 'lodash';
//providers
import { ProfileProvider } from '../../../providers/profile/profile';
import { PlatformProvider } from '../../../providers/platform/platform';
+import { ConfigProvider } from '../../../providers/config/config';
import { NodeWebkitProvider } from '../../../providers/node-webkit/node-webkit';
//pages
@@ -17,8 +18,13 @@ import { CustomAmountPage } from '../../receive/custom-amount/custom-amount';
templateUrl: 'amount.html',
})
export class AmountPage {
- private LENGTH_EXPRESSION_LIMIT = 19;
- private SMALL_FONT_SIZE_LIMIT = 10;
+ private LENGTH_EXPRESSION_LIMIT: number;
+ private SMALL_FONT_SIZE_LIMIT: number;
+ private availableUnits: Array
;
+ private unit: string;
+ private reNr: RegExp;
+ private reOp: RegExp;
+ private _id: number;
public expression: any;
public amount: any;
@@ -35,13 +41,6 @@ export class AmountPage {
public showSendMax: boolean;
public useSendMax: boolean;
- private availableUnits: Array = [];
- private unitIndex: number = 0;
- private altUnitIndex: number = 0;
- private reNr: RegExp;
- private reOp: RegExp;
- private _id: number;
-
constructor(
private navCtrl: NavController,
private navParams: NavParams,
@@ -49,7 +48,12 @@ export class AmountPage {
private profileProvider: ProfileProvider,
private platformProvider: PlatformProvider,
private nodeWebkitProvider: NodeWebkitProvider,
+ private configProvider: ConfigProvider,
) {
+ this.LENGTH_EXPRESSION_LIMIT = 19;
+ this.SMALL_FONT_SIZE_LIMIT = 10;
+ this.availableUnits = [];
+ this.unit = '';
this.expression = '';
this.amount = 0;
this.showExpressionResult = false;
@@ -59,6 +63,12 @@ export class AmountPage {
}
ionViewDidLoad() {
+
+
+ // TODO
+
+
+
this.toAddress = this.navParams.data.toAddress;
this.fromSend = this.navParams.data.fromSend;
this._id = this.navParams.data.id;
@@ -70,6 +80,7 @@ export class AmountPage {
// this.setAvailableUnits();
// this.updateUnitUI();
this.processAmount();
+ this.setAvailableUnits();
}
@HostListener('document:keydown', ['$event']) handleKeyboardEvent(event: KeyboardEvent) {
@@ -264,68 +275,20 @@ export class AmountPage {
private setAvailableUnits(): void {
let hasBTCWallets = this.profileProvider.getWallets({ coin: 'btc' }).length;
-
- if (hasBTCWallets) {
- this.availableUnits.push({
- name: 'Bitcoin',
- id: 'btc',
- shortName: 'BTC',
- });
- }
-
let hasBCHWallets = this.profileProvider.getWallets({ coin: 'bch' }).length;
+
+ if (hasBTCWallets) this.availableUnits.push('BTC');
+ if (hasBCHWallets) this.availableUnits.push('BCH');
- if (hasBCHWallets) {
- this.availableUnits.push({
- name: 'Bitcoin Cash',
- id: 'bch',
- shortName: 'BCH',
- });
- };
+ const unit = this.configProvider.get().wallet.settings.alternativeIsoCode;
+ this.availableUnits.push(unit);
+ this.availableUnits.push('BCH'); // TEST
+ this.unit = this.availableUnits[0];
+ }
- let unitIndex = 0;
-
- if (this.navParams.data.coin) {
- var coins = this.navParams.data.coin.split(',');
- var newAvailableUnits = [];
-
- _.each(coins, (c) => {
- var coin = _.find(this.availableUnits, {
- id: c
- });
- if (!coin) {
- this.logger.warn('Could not find desired coin:' + this.navParams.data.coin)
- } else {
- newAvailableUnits.push(coin);
- }
- });
-
- if (newAvailableUnits.length > 0) {
- this.availableUnits = newAvailableUnits;
- }
- }
- // currency have preference
- let fiatName;
- // if (this.navParams.data.currency) {
- // this.fiatCode = this.navParams.data.currency;
- // this.altUnitIndex = unitIndex
- // unitIndex = this.availableUnits.length;
- // } else {
- // this.fiatCode = this.config.alternativeIsoCode || 'USD';
- // fiatName = this.config.alternanativeName || this.fiatCode;
- // this.altUnitIndex = this.availableUnits.length;
- // }
-
- // this.availableUnits.push({
- // name: fiatName || this.fiatCode,
- // // TODO
- // id: this.fiatCode,
- // shortName: this.fiatCode,
- // isFiat: true,
- // });
-
- // if (this.navParams.data.fixedUnit) {
- // this.fixedUnit = true;
- // }
+ public updateUnit(): void {
+ this.availableUnits.slice(0, this.availableUnits.length).join(',');
+ this.availableUnits.push(this.availableUnits.shift());
+ this.unit = this.availableUnits[0];
}
}
diff --git a/src/pipes/satToFiat.ts b/src/pipes/satToFiat.ts
index 2fcaf898b..1ca012dc4 100644
--- a/src/pipes/satToFiat.ts
+++ b/src/pipes/satToFiat.ts
@@ -14,8 +14,9 @@ export class SatToFiatPipe implements PipeTransform {
) {
this.walletSettings = this.configProvider.get().wallet.settings;
}
- transform(value: string, amount: number): any {
- let amount_ = this.rateProvider.toFiat(amount / 1e8, this.walletSettings.alternativeIsoCode, this.walletSettings.unitCode);
+ transform(value: string, amount: number, unit?: string): any {
+ unit = unit ? unit.toLocaleLowerCase() : this.walletSettings.unitCode;
+ let amount_ = this.rateProvider.toFiat(amount / 1e8, this.walletSettings.alternativeIsoCode, unit);
return this.decimalPipe.transform(amount_, '1.2-2') + ' ' + this.walletSettings.alternativeIsoCode;
}
}
\ No newline at end of file