fix units

This commit is contained in:
JDonadio 2017-11-17 10:42:11 -03:00
parent 6847b00ceb
commit f67306d1fd
No known key found for this signature in database
GPG Key ID: EC1F4E04B2BFA730
3 changed files with 39 additions and 80 deletions

View File

@ -36,16 +36,11 @@
<div class="amount-content">
<div class="expression">{{expression || '0.00'}}
<a class="unit-button" (click)="changeUnit()">{{unit || 'BTC'}}</a>
<a class="unit-button" (click)="updateUnit()">{{unit}}</a>
</div>
<div class="amount" [hidden]="!showExpressionResult">= {{amount | number: '1.2-8'}} {{unit || 'BTC'}}</div>
<div class="result">≈ {{resultAmount | satToFiat: amount * 1e8 }}</div>
<!-- <div [ngClass]="{'amount__results-minimize': smallFont, 'amount__results-standard': !smallFont, 'amount__results-placeholder': amountResult}"
(click)="changeAlternativeUnit()">
<div class="amount__result">{{asd3 | satToFiat: amount * 1e8 }}</div>
<div class="amount__result-equiv" [hidden]="!alternativeAmount">&asymp; {{alternativeAmount || '0.00'}} {{alternativeUnit}}</div>
<div class="amount__result-equiv" [hidden]="alternativeAmount">&nbsp;</div>
</div> -->
<div class="amount" [hidden]="!showExpressionResult">= {{amount | number: '1.2-8'}} {{unit}}</div>
<div class="result" *ngIf="unit == 'BTC' || unit == 'BCH'">≈ {{resultAmount | satToFiat: amount * 1e8: unit }}</div>
<div class="result" *ngIf="unit != 'BTC' && unit != 'BCH'">≈ {{resultAmount | fiatToUnit: amount }}</div>
</div>
</div>
<div class="keypad">

View File

@ -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<any>;
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<any> = [];
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];
}
}

View File

@ -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;
}
}