mirror of https://github.com/BTCPrivate/copay.git
add key event listener
This commit is contained in:
parent
7a051dc663
commit
ba6b533b00
|
@ -1,4 +1,4 @@
|
||||||
import { Component } from '@angular/core';
|
import { Component, HostListener } from '@angular/core';
|
||||||
import { NavController, NavParams } from 'ionic-angular';
|
import { NavController, NavParams } from 'ionic-angular';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
import { ConfirmPage } from '../confirm/confirm';
|
import { ConfirmPage } from '../confirm/confirm';
|
||||||
|
@ -21,19 +21,36 @@ export class AmountPage {
|
||||||
private SMALL_FONT_SIZE_LIMIT = 10;
|
private SMALL_FONT_SIZE_LIMIT = 10;
|
||||||
private availableUnits: Array<any> = [];
|
private availableUnits: Array<any> = [];
|
||||||
private unitIndex: number = 0;
|
private unitIndex: number = 0;
|
||||||
|
private reNr: RegExp = /^[1234567890\.]$/;
|
||||||
|
private reOp: RegExp = /^[\*\+\-\/]$/;
|
||||||
|
|
||||||
constructor(public navCtrl: NavController, public navParams: NavParams) {
|
constructor(public navCtrl: NavController, public navParams: NavParams) {
|
||||||
this.amount = "";
|
this.amount = '';
|
||||||
this.allowSend = false;
|
this.allowSend = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ionViewDidLoad() {
|
ionViewDidLoad() {
|
||||||
console.log('ionViewDidLoad AmountPage');
|
console.log('Params', this.navParams.data);
|
||||||
console.log("this.navParams.data", this.navParams.data);
|
|
||||||
this.address = this.navParams.data.address;
|
this.address = this.navParams.data.address;
|
||||||
this.sending = this.navParams.data.sending;
|
this.sending = this.navParams.data.sending;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@HostListener('document:keydown', ['$event']) handleKeyboardEvent(event: KeyboardEvent) {
|
||||||
|
if (!event.key) return;
|
||||||
|
if (event.which === 8) {
|
||||||
|
event.preventDefault();
|
||||||
|
this.removeDigit();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.key.match(this.reNr)) {
|
||||||
|
this.pushDigit(event.key);
|
||||||
|
} else if (event.key.match(this.reOp)) {
|
||||||
|
this.pushOperator(event.key);
|
||||||
|
} else if (event.keyCode === 86) {
|
||||||
|
// if (event.ctrlKey || event.metaKey) processClipboard();
|
||||||
|
} else if (event.keyCode === 13) this.finish();
|
||||||
|
}
|
||||||
|
|
||||||
pushDigit(digit: string) {
|
pushDigit(digit: string) {
|
||||||
if (this.amount && this.amount.length >= this.LENGTH_EXPRESSION_LIMIT) return;
|
if (this.amount && this.amount.length >= this.LENGTH_EXPRESSION_LIMIT) return;
|
||||||
if (this.amount.indexOf('.') > -1 && digit == '.') return;
|
if (this.amount.indexOf('.') > -1 && digit == '.') return;
|
||||||
|
@ -41,7 +58,6 @@ export class AmountPage {
|
||||||
//if (this.availableUnits[this.unitIndex].isFiat && this.amount.indexOf('.') > -1 && this.amount[this.amount.indexOf('.') + 2]) return;
|
//if (this.availableUnits[this.unitIndex].isFiat && this.amount.indexOf('.') > -1 && this.amount[this.amount.indexOf('.') + 2]) return;
|
||||||
|
|
||||||
this.amount = (this.amount + digit).replace('..', '.');
|
this.amount = (this.amount + digit).replace('..', '.');
|
||||||
console.log("this.amount", this.amount);
|
|
||||||
this.checkFontSize();
|
this.checkFontSize();
|
||||||
this.processAmount();
|
this.processAmount();
|
||||||
};
|
};
|
||||||
|
@ -57,7 +73,7 @@ export class AmountPage {
|
||||||
this.amount = this._pushOperator(this.amount, operator);
|
this.amount = this._pushOperator(this.amount, operator);
|
||||||
};
|
};
|
||||||
|
|
||||||
_pushOperator(val: string, operator: string) {
|
private _pushOperator(val: string, operator: string) {
|
||||||
if (!this.isOperator(_.last(val))) {
|
if (!this.isOperator(_.last(val))) {
|
||||||
return val + operator;
|
return val + operator;
|
||||||
} else {
|
} else {
|
||||||
|
@ -66,12 +82,12 @@ export class AmountPage {
|
||||||
};
|
};
|
||||||
|
|
||||||
isOperator(val: string) {
|
isOperator(val: string) {
|
||||||
var regex = /[\/\-\+\x\*]/;
|
const regex = /[\/\-\+\x\*]/;
|
||||||
return regex.test(val);
|
return regex.test(val);
|
||||||
};
|
};
|
||||||
|
|
||||||
isExpression(val: string) {
|
isExpression(val: string) {
|
||||||
var regex = /^\.?\d+(\.?\d+)?([\/\-\+\*x]\d?\.?\d+)+$/;
|
const regex = /^\.?\d+(\.?\d+)?([\/\-\+\*x]\d?\.?\d+)+$/;
|
||||||
return regex.test(val);
|
return regex.test(val);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -122,7 +138,6 @@ export class AmountPage {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (!_.isFinite(result)) return 0;
|
if (!_.isFinite(result)) return 0;
|
||||||
console.log("evaluate result: ", result);
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -152,5 +167,4 @@ export class AmountPage {
|
||||||
this.navCtrl.push(CustomAmountPage, {address: this.address, amount: this.globalResult});
|
this.navCtrl.push(CustomAmountPage, {address: this.address, amount: this.globalResult});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { NavController, NavParams } from 'ionic-angular';
|
import { NavController } from 'ionic-angular';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
import { AmountPage } from './amount/amount';
|
import { AmountPage } from './amount/amount';
|
||||||
|
|
||||||
|
@ -8,11 +8,13 @@ import { AmountPage } from './amount/amount';
|
||||||
templateUrl: 'send.html',
|
templateUrl: 'send.html',
|
||||||
})
|
})
|
||||||
export class SendPage {
|
export class SendPage {
|
||||||
|
public search: string;
|
||||||
|
|
||||||
constructor(public navCtrl: NavController, public navParams: NavParams) {
|
constructor(public navCtrl: NavController) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ionViewDidLoad() {
|
ionViewDidLoad() {
|
||||||
|
this.search = '';
|
||||||
console.log('ionViewDidLoad SendPage');
|
console.log('ionViewDidLoad SendPage');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +25,7 @@ export class SendPage {
|
||||||
findContact(search: string) {
|
findContact(search: string) {
|
||||||
// TODO: Improve this function
|
// TODO: Improve this function
|
||||||
console.log("Send search string", search);
|
console.log("Send search string", search);
|
||||||
if (search.length === 34 && _.startsWith(search, '1')) {
|
if (search.length === 34) {
|
||||||
this.navCtrl.push(AmountPage, {address: search, sending: true});
|
this.navCtrl.push(AmountPage, {address: search, sending: true});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue