Skip to content

Commit

Permalink
0.0.37 no confirm page
Browse files Browse the repository at this point in the history
  • Loading branch information
simplycash committed Oct 17, 2018
1 parent 89c44f3 commit 1be3815
Show file tree
Hide file tree
Showing 13 changed files with 345 additions and 176 deletions.
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<widget id="cash.simply.wallet" version="0.0.36" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<widget id="cash.simply.wallet" version="0.0.37" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>simply cash</name>
<description>simply a bitcoin cash wallet</description>
<author email="[email protected]" href="https://simply.cash/">Simply Cash Limited</author>
Expand Down
7 changes: 3 additions & 4 deletions ionic.config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"name": "wallet",
"app_id": "",
"type": "ionic-angular",
"integrations": {
"cordova": {}
}
}
},
"type": "ionic-angular"
}
2 changes: 2 additions & 0 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"Q_SEND_NOW": "send now?",
"Q_SEND_MAX_AMOUNT": "send max amount?",
"NEXT": "next",
"CLEAR": "clear",
"COPIED_ADDRESS": "copied address",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/ja.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"Q_SEND_NOW": "今すぐ送信しますか?",
"Q_SEND_MAX_AMOUNT": "最大額を送信しますか?",
"NEXT": "次へ",
"CLEAR": "消去",
"COPIED_ADDRESS": "コピーされたアドレス",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/zh-cmn-Hans.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"Q_SEND_NOW": "现在发送?",
"Q_SEND_MAX_AMOUNT": "发送最大金额?",
"NEXT": "下一步",
"CLEAR": "清除",
"COPIED_ADDRESS": "已复制的地址",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/zh-cmn-Hant.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"Q_SEND_NOW": "現在發送?",
"Q_SEND_MAX_AMOUNT": "發送最大金額?",
"NEXT": "下一步",
"CLEAR": "清除",
"COPIED_ADDRESS": "已複製的地址",
Expand Down
11 changes: 9 additions & 2 deletions src/components/my-amount/my-amount.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@
#amount
type="number"
[placeholder]="placeholder || ''"
[readonly]="fixedAmount ? '' : null"
(input)="amountInput($event)"
(ionChange)="amountChange($event)"
(ionFocus)="isTyping = true"
(ionBlur)="isTyping = false"
clearInput=true></ion-input>
(ionBlur)="isTyping = false"></ion-input>
<button
*ngIf="!fixedAmount && isTyping"
ion-button clear item-end icon-only color="dark"
(touchstart)="clear()"
(mousedown)="clear()">
<ion-icon name="close"></ion-icon>
</button>
<button ion-button outline item-end (click)="changeUnit()">
{{ wallet.getPreferredUnit() }}
</button>
Expand Down
50 changes: 33 additions & 17 deletions src/components/my-amount/my-amount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import { Wallet } from '../../providers/providers'
export class MyAmountComponent {
@Input() label: string
@Input() placeholder: string
@Input() fixedAmount: string
@Output() satoshisChange = new EventEmitter()
@ViewChild('amount') amountEl
@ViewChild('amount', { read: ElementRef }) amountElNative

private inputEl: any
private amountSATOSHIS: string
private touch: boolean = false
private inputTouch: boolean = false
private blurTimer: number
Expand All @@ -37,16 +37,29 @@ export class MyAmountComponent {
if (!this.isTyping) {
this.updateInputField()
}
this.amountSATOSHIS = this.wallet.convertUnit(this.fromUnit, 'SATS', this.fromAmount) || '0'
this.satoshisChange.emit(parseFloat(this.amountSATOSHIS))
this.satoshisChange.emit(this.getSatoshis())
}
}
}

setFixedAmount(a: string) {
this.fixedAmount = a
this.fromUnit = 'SATS'
this.fromAmount = this.fixedAmount
this.updateInputField()
this.satoshisChange.emit(this.getSatoshis())
}

ngAfterViewInit() {
this.inputEl = this.amountElNative.nativeElement.querySelector('input')
this.wallet.subscribePreferredUnit(this.preferredUnitCallback)
this.wallet.subscribePrice(this.priceCallback)
if (parseFloat(this.fixedAmount) >= 0) {
this.fromUnit = 'SATS'
this.fromAmount = this.fixedAmount
this.updateInputField()
this.satoshisChange.emit(this.getSatoshis())
}
}

ngOnDestroy() {
Expand All @@ -65,13 +78,9 @@ export class MyAmountComponent {
}
this.fromUnit = this.wallet.getPreferredUnit()
if (this.inputEl.checkValidity()) {
this.fromAmount = undefined
this.amountSATOSHIS = undefined
this.satoshisChange.emit(undefined)
this.setFromAmount(undefined)
} else {
this.fromAmount = '0'
this.amountSATOSHIS = '0'
this.satoshisChange.emit(0)
this.setFromAmount(0)
}
}

Expand All @@ -82,14 +91,10 @@ export class MyAmountComponent {
}
this.fromUnit = this.wallet.getPreferredUnit()
if (this.amountEl.value.length === 0 && this.inputEl.checkValidity()) {
this.fromAmount = undefined
this.amountSATOSHIS = undefined
this.satoshisChange.emit(undefined)
this.setFromAmount(undefined)
return
}
this.fromAmount = '' + parseFloat(this.amountEl.value) || '0'
this.amountSATOSHIS = this.wallet.convertUnit(this.fromUnit, 'SATS', this.amountEl.value) || '0'
this.satoshisChange.emit(parseFloat(this.amountSATOSHIS))
this.setFromAmount(parseFloat(this.amountEl.value))
}

changeUnit() {
Expand All @@ -113,11 +118,22 @@ export class MyAmountComponent {
}
}

setFromAmount(a: number) {
if (typeof a === 'undefined') {
this.fromAmount = undefined
} else if (isNaN(a)) {
this.fromAmount = '0'
} else {
this.fromAmount = a.toString()
}
this.satoshisChange.emit(this.getSatoshis())
}

getSatoshis() {
if (typeof this.amountSATOSHIS === 'undefined') {
if (typeof this.fromAmount === 'undefined') {
return undefined
}
return parseFloat(this.amountSATOSHIS)
return parseFloat(this.wallet.convertUnit(this.fromUnit, 'SATS', this.fromAmount)) || 0
}

setFocus() {
Expand Down
73 changes: 3 additions & 70 deletions src/pages/home/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,9 @@ export class HomePage {
if (info.outputs.length === 0) {
return false
}
if (info.outputs.map(output => output.satoshis).reduce((acc, curr) => acc + curr) > 0) {
await this.sign(info)
} else {
info.outputs = info.outputs.slice(0, 1)
await this.navCtrl.push('SendPage', {
info: info
})
}
await this.navCtrl.push('SendPage', {
info: info
})
return true
}

Expand Down Expand Up @@ -410,66 +405,4 @@ export class HomePage {
})
}

async sign(info: any) {
try {
let satoshis: number = info.outputs.map(output => output.satoshis).reduce((acc, curr) => acc + curr)
if (satoshis > this.wallet.getCacheBalance()) {
throw new Error('not enough fund')
}
info.outputs = info.outputs.filter(output => output.satoshis > 0)
info.outputs.forEach((output) => {
if (typeof output.address !== 'undefined') {
let af: string = this.wallet.getAddressFormat(output.address)
if (typeof af === 'undefined') {
throw new Error('invalid address')
}
let legacyAddr: string = this.wallet.convertAddress(af, 'legacy', output.address)
output.script = this.wallet.scriptFromAddress(legacyAddr)
} else if (typeof output.script === 'undefined') {
throw new Error('invalid output')
}
})
} catch (err) {
console.log(err)
let errMessage = err.message
if (err.message === 'not enough fund') {
errMessage = this.translate.instant('ERR_NOT_ENOUGH_FUND')
} else if (err.message === 'invalid address') {
errMessage = this.translate.instant('ERR_INVALID_ADDR')
} else if (err.message === 'invalid output') {
errMessage = this.translate.instant('ERR_INVALID_OUTPUT')
}
this.alertCtrl.create({
enableBackdropDismiss: false,
title: this.translate.instant('ERROR'),
message: errMessage,
buttons: ['ok']
}).present()
return
}

let loader = this.loadingCtrl.create({
content: this.translate.instant('SIGNING')+'...'
})
await loader.present()

try {
let signedTx: { satoshis: number, hex: string, fee: number } = await this.wallet.makeSignedTx(info.outputs)
await loader.dismiss()
await this.navCtrl.push('ConfirmPage', {
info: Object.assign(info, signedTx)
})
} catch (err) {
console.log(err)
await loader.dismiss()
await this.alertCtrl.create({
enableBackdropDismiss: false,
title: this.translate.instant('ERROR'),
message: err.message,
buttons: ['ok']
}).present()
}
}


}
11 changes: 7 additions & 4 deletions src/pages/send/send.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@
type="text"
readonly></ion-input>
</ion-item>
<my-amount #myAmount placeholder="{{ 'MAX_AMOUNT_HINT' | translate }}"></my-amount>
<my-amount
#myAmount
[fixedAmount]="outputSum > 0 ? outputSum.toString() : null"
placeholder="{{ 'MAX_AMOUNT_HINT' | translate }}"></my-amount>
</ion-list>

<div text-center>
<button ion-button clear icon-left (click)="sign()">
<ion-icon name="checkmark"></ion-icon>
{{ 'NEXT' | translate }}
<button ion-button clear icon-left (click)="send()" [disabled]="!canLeave || !wallet.isOnline()">
<ion-icon name="paper-plane"></ion-icon>
{{ 'SEND' | translate }}
</button>
</div>

Expand Down
Loading

0 comments on commit 1be3815

Please sign in to comment.