Skip to content

Commit

Permalink
Merge branch 'master' into wallet-selector
Browse files Browse the repository at this point in the history
  • Loading branch information
ncoelho authored Aug 7, 2019
2 parents cb197ab + ae519ac commit d2b1885
Show file tree
Hide file tree
Showing 35 changed files with 244 additions and 64 deletions.
77 changes: 70 additions & 7 deletions BlueComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Animated,
ActivityIndicator,
View,
KeyboardAvoidingView,
UIManager,
StyleSheet,
Dimensions,
Expand Down Expand Up @@ -765,16 +766,71 @@ export class BlueUseAllFundsButton extends Component {
};

render() {
return (
<InputAccessoryView nativeID={BlueUseAllFundsButton.InputAccessoryViewID}>
<View style={{ flex: 1, flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center' }}>
<Text style={{ color: BlueApp.settings.alternativeTextColor, fontSize: 16, marginHorizontal: 8 }}>
Total: {this.props.wallet.getBalance()} {BitcoinUnit.BTC}
const inputView = (
<View
style={{
flex: 1,
flexDirection: 'row',
maxHeight: 44,
justifyContent: 'space-between',
alignItems: 'center',
backgroundColor: '#eef0f4',
}}
>
<View style={{ flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'flex-start' }}>
<Text
style={{
color: BlueApp.settings.alternativeTextColor,
fontSize: 16,
marginLeft: 8,
marginRight: 0,
paddingRight: 0,
paddingLeft: 0,
paddingTop: 12,
paddingBottom: 12,
}}
>
Total:
</Text>
<BlueButtonLink title="Use All" onPress={this.props.onUseAllPressed} />
{this.props.wallet.allowSendMax() && this.props.wallet.getBalance() > 0 ? (
<BlueButtonLink
onPress={this.props.onUseAllPressed}
style={{ marginLeft: 8, paddingRight: 0, paddingLeft: 0, paddingTop: 12, paddingBottom: 12 }}
title={`${loc.formatBalanceWithoutSuffix(this.props.wallet.getBalance(), BitcoinUnit.BTC, true).toString()} ${
BitcoinUnit.BTC
}`}
/>
) : (
<Text
style={{
color: BlueApp.settings.alternativeTextColor,
fontSize: 16,
marginLeft: 8,
marginRight: 0,
paddingRight: 0,
paddingLeft: 0,
paddingTop: 12,
paddingBottom: 12,
}}
>
{loc.formatBalanceWithoutSuffix(this.props.wallet.getBalance(), BitcoinUnit.BTC, true).toString()} {BitcoinUnit.BTC}
</Text>
)}
</View>
</InputAccessoryView>
<View style={{ flexDirection: 'row', justifyContent: 'flex-end', alignItems: 'flex-end' }}>
<BlueButtonLink
style={{ paddingRight: 8, paddingLeft: 0, paddingTop: 12, paddingBottom: 12 }}
title="Done"
onPress={Keyboard.dismiss}
/>
</View>
</View>
);
if (Platform.OS === 'ios') {
return <InputAccessoryView nativeID={BlueUseAllFundsButton.InputAccessoryViewID}>{inputView}</InputAccessoryView>;
} else {
return <KeyboardAvoidingView style={{ height: 44 }}>{inputView}</KeyboardAvoidingView>;
}
}
}

Expand Down Expand Up @@ -1923,6 +1979,7 @@ export class BlueBitcoinAmount extends Component {
} else {
localCurrency = loc.formatBalanceWithoutSuffix(amount.toString(), BitcoinUnit.LOCAL_CURRENCY, false);
}
if (amount === BitcoinUnit.MAX) localCurrency = ''; // we dont want to display NaN
return (
<TouchableWithoutFeedback disabled={this.props.pointerEvents === 'none'} onPress={() => this.textInput.focus()}>
<View>
Expand All @@ -1939,6 +1996,12 @@ export class BlueBitcoinAmount extends Component {
}
this.props.onChangeText(text);
}}
onBlur={() => {
if (this.props.onBlur) this.props.onBlur();
}}
onFocus={() => {
if (this.props.onFocus) this.props.onFocus();
}}
placeholder="0"
maxLength={10}
ref={textInput => (this.textInput = textInput)}
Expand Down
4 changes: 4 additions & 0 deletions class/abstract-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ export class AbstractWallet {
return true;
}

allowSendMax(): boolean {
return false;
}

allowRBF() {
return false;
}
Expand Down
4 changes: 4 additions & 0 deletions class/hd-segwit-bech32-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export class HDSegwitBech32Wallet extends AbstractHDWallet {
return true;
}

allowSendMax(): boolean {
return true;
}

/**
* @inheritDoc
*/
Expand Down
22 changes: 22 additions & 0 deletions class/hd-segwit-p2sh-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import bip39 from 'bip39';
import BigNumber from 'bignumber.js';
import b58 from 'bs58check';
import signer from '../models/signer';
import { BitcoinUnit } from '../models/bitcoinUnits';
const bitcoin = require('bitcoinjs-lib');
const bitcoin5 = require('bitcoinjs5');
const HDNode = require('bip32');
Expand Down Expand Up @@ -49,6 +50,10 @@ export class HDSegwitP2SHWallet extends AbstractHDWallet {
return true;
}

allowSendMax(): boolean {
return true;
}

async generate() {
let that = this;
return new Promise(function(resolve) {
Expand Down Expand Up @@ -255,12 +260,29 @@ export class HDSegwitP2SHWallet extends AbstractHDWallet {
}
}

/**
*
* @param utxos
* @param amount Either float (BTC) or string 'MAX' (BitcoinUnit.MAX) to send all
* @param fee
* @param address
* @returns {string}
*/
createTx(utxos, amount, fee, address) {
for (let utxo of utxos) {
utxo.wif = this._getWifForAddress(utxo.address);
}

let amountPlusFee = parseFloat(new BigNumber(amount).plus(fee).toString(10));

if (amount === BitcoinUnit.MAX) {
amountPlusFee = new BigNumber(0);
for (let utxo of utxos) {
amountPlusFee = amountPlusFee.plus(utxo.amount);
}
amountPlusFee = amountPlusFee.dividedBy(100000000).toString(10);
}

return signer.createHDSegwitTransaction(
utxos,
address,
Expand Down
2 changes: 1 addition & 1 deletion loc/cs_CZ.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ module.exports = {
create: 'Create',
setAmount: 'Přijmout částku...',
},
scan_lnurl: 'Scan to receive'
scan_lnurl: 'Scan to receive',
},
buyBitcoin: {
header: 'Koupit Bitcoin',
Expand Down
2 changes: 1 addition & 1 deletion loc/da_DK.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ module.exports = {
create: 'Create',
setAmount: 'Modtag med beløb',
},
scan_lnurl: 'Scan to receive'
scan_lnurl: 'Scan to receive',
},
buyBitcoin: {
header: 'Køb Bitcoin',
Expand Down
2 changes: 1 addition & 1 deletion loc/de_DE.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ module.exports = {
create: 'Create',
setAmount: 'Zu erhaltender Betrag',
},
scan_lnurl: 'Scan to receive'
scan_lnurl: 'Scan to receive',
},
buyBitcoin: {
header: 'Kaufe Bitcoin',
Expand Down
2 changes: 1 addition & 1 deletion loc/el.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ module.exports = {
create: 'Δημιούργησε',
setAmount: 'Λάβε με ποσό',
},
scan_lnurl: 'Scan to receive'
scan_lnurl: 'Scan to receive',
},
buyBitcoin: {
header: 'Αγόρασε Bitcoin',
Expand Down
2 changes: 1 addition & 1 deletion loc/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ module.exports = {
create: 'Create',
setAmount: 'Receive with amount',
},
scan_lnurl: 'Scan to receive'
scan_lnurl: 'Scan to receive',
},
buyBitcoin: {
header: 'Buy Bitcoin',
Expand Down
2 changes: 1 addition & 1 deletion loc/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ module.exports = {
create: 'Create',
setAmount: 'Receive with amount',
},
scan_lnurl: 'Scan to receive'
scan_lnurl: 'Scan to receive',
},
buyBitcoin: {
header: 'Buy Bitcoin',
Expand Down
2 changes: 1 addition & 1 deletion loc/fi_FI.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ module.exports = {
create: 'Luo',
setAmount: 'Vastaanotettava summa',
},
scan_lnurl: 'Scan to receive'
scan_lnurl: 'Scan to receive',
},
buyBitcoin: {
header: 'Osta Bitcoinia',
Expand Down
2 changes: 1 addition & 1 deletion loc/fr_FR.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ module.exports = {
create: 'Create',
setAmount: 'Revevoir avec montant',
},
scan_lnurl: 'Scan to receive'
scan_lnurl: 'Scan to receive',
},
buyBitcoin: {
header: 'Acheter du Bitcoin',
Expand Down
2 changes: 1 addition & 1 deletion loc/hr_HR.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ module.exports = {
create: 'Stvori',
setAmount: 'Odredi iznos za primiti',
},
scan_lnurl: 'Scan to receive'
scan_lnurl: 'Scan to receive',
},
buyBitcoin: {
header: 'Kupovina Bitcoina',
Expand Down
2 changes: 1 addition & 1 deletion loc/hu_HU.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ module.exports = {
create: 'Létrehoz',
setAmount: 'Fogadandó összeg',
},
scan_lnurl: 'Scan to receive'
scan_lnurl: 'Scan to receive',
},
buyBitcoin: {
header: 'Bitcoin vásárlása',
Expand Down
2 changes: 1 addition & 1 deletion loc/id_ID.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ module.exports = {
create: 'Buat',
setAmount: 'Terima sejumlah',
},
scan_lnurl: 'Scan to receive'
scan_lnurl: 'Scan to receive',
},
buyBitcoin: {
header: 'Beli bitcoin',
Expand Down
2 changes: 1 addition & 1 deletion loc/it.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ module.exports = {
create: 'Crea',
setAmount: 'Ricevi con importo',
},
scan_lnurl: 'Scan to receive'
scan_lnurl: 'Scan to receive',
},
buyBitcoin: {
header: 'Compra Bitcoin',
Expand Down
2 changes: 1 addition & 1 deletion loc/jp_JP.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ module.exports = {
create: '作成',
setAmount: '入金額',
},
scan_lnurl: 'Scan to receive'
scan_lnurl: 'Scan to receive',
},
buyBitcoin: {
header: 'Bitcoin の購入',
Expand Down
2 changes: 1 addition & 1 deletion loc/nb_NO.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ module.exports = {
create: 'Lag',
setAmount: 'Motta med beløp',
},
scan_lnurl: 'Scan to receive'
scan_lnurl: 'Scan to receive',
},
buyBitcoin: {
header: 'Kjøp Bitcoin',
Expand Down
2 changes: 1 addition & 1 deletion loc/nl_NL.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ module.exports = {
create: 'Create',
setAmount: 'Ontvang met bedrag',
},
scan_lnurl: 'Scan to receive'
scan_lnurl: 'Scan to receive',
},
buyBitcoin: {
header: 'Koop Bitcoin',
Expand Down
2 changes: 1 addition & 1 deletion loc/pt_BR.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ module.exports = {
create: 'Create',
setAmount: 'Valor a receber',
},
scan_lnurl: 'Receber lendo QR'
scan_lnurl: 'Receber lendo QR',
},
buyBitcoin: {
header: 'Comprar Bitcoin',
Expand Down
2 changes: 1 addition & 1 deletion loc/pt_PT.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ module.exports = {
create: 'Create',
setAmount: 'Receive with amount',
},
scan_lnurl: 'Receber lendo QR'
scan_lnurl: 'Receber lendo QR',
},
settings: {
tabBarLabel: 'Definições',
Expand Down
2 changes: 1 addition & 1 deletion loc/ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ module.exports = {
create: 'Создать',
setAmount: 'Получить сумму',
},
scan_lnurl: 'Scan to receive'
scan_lnurl: 'Scan to receive',
},
settings: {
tabBarLabel: 'Настройки',
Expand Down
2 changes: 1 addition & 1 deletion loc/sv_SE.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ module.exports = {
create: 'Skapa',
setAmount: 'Ta emot med belopp',
},
scan_lnurl: 'Scan to receive'
scan_lnurl: 'Scan to receive',
},
buyBitcoin: {
header: 'Köp bitcoin',
Expand Down
2 changes: 1 addition & 1 deletion loc/th_TH.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ module.exports = {
create: 'สร้าง',
setAmount: 'รับด้วยจำนวน',
},
scan_lnurl: 'Scan to receive'
scan_lnurl: 'Scan to receive',
},
buyBitcoin: {
header: 'ซื้อบิตคอยน์',
Expand Down
2 changes: 1 addition & 1 deletion loc/tr_TR.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ module.exports = {
create: 'Oluştur',
setAmount: 'Miktar ile al',
},
scan_lnurl: 'Scan to receive'
scan_lnurl: 'Scan to receive',
},
buyBitcoin: {
header: 'Bitcoin Satın al',
Expand Down
2 changes: 1 addition & 1 deletion loc/ua.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ module.exports = {
create: 'Create',
setAmount: 'Receive with amount',
},
scan_lnurl: 'Scan to receive'
scan_lnurl: 'Scan to receive',
},
buyBitcoin: {
header: 'Buy Bitcoin',
Expand Down
2 changes: 1 addition & 1 deletion loc/zh_cn.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ module.exports = {
create: '创建',
setAmount: '收款金额',
},
scan_lnurl: 'Scan to receive'
scan_lnurl: 'Scan to receive',
},
buyBitcoin: {
header: '购买比特币',
Expand Down
1 change: 1 addition & 0 deletions models/bitcoinUnits.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export const BitcoinUnit = Object.freeze({
BTC: 'BTC',
SATS: 'sats',
LOCAL_CURRENCY: 'local_currency',
MAX: 'MAX',
});

export const Chain = Object.freeze({
Expand Down
Loading

0 comments on commit d2b1885

Please sign in to comment.