FIX: Remove BTC trailing zeros. Save to disk onBlur for preferred balance unit.

This commit is contained in:
Marcos Rodriguez Vélez 2018-12-23 08:05:33 -05:00
parent 44ab347ee0
commit 91a2ecb1dc
6 changed files with 53 additions and 29 deletions

View file

@ -24,7 +24,6 @@ import { HDLegacyP2PKHWallet } from './class/hd-legacy-p2pkh-wallet';
import { HDLegacyBreadwalletWallet } from './class/hd-legacy-breadwallet-wallet'; import { HDLegacyBreadwalletWallet } from './class/hd-legacy-breadwallet-wallet';
import { HDSegwitP2SHWallet } from './class/hd-segwit-p2sh-wallet'; import { HDSegwitP2SHWallet } from './class/hd-segwit-p2sh-wallet';
import { LightningCustodianWallet } from './class/lightning-custodian-wallet'; import { LightningCustodianWallet } from './class/lightning-custodian-wallet';
import { BitcoinUnit } from './models/bitcoinUnits';
let loc = require('./loc/'); let loc = require('./loc/');
/** @type {AppStorage} */ /** @type {AppStorage} */
let BlueApp = require('./BlueApp'); let BlueApp = require('./BlueApp');
@ -1049,7 +1048,7 @@ export class WalletsCarousel extends Component {
color: '#fff', color: '#fff',
}} }}
> >
{loc.formatBalance(Number(item.getBalance()), BitcoinUnit.BTC, item.getPreferredBalanceUnit())} {loc.formatBalance(Number(item.getBalance()), item.getPreferredBalanceUnit())}
</Text> </Text>
<Text style={{ backgroundColor: 'transparent' }} /> <Text style={{ backgroundColor: 'transparent' }} />
<Text <Text

View file

@ -34,7 +34,7 @@
</dict> </dict>
</array> </array>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>162</string> <string>164</string>
<key>ITSAppUsesNonExemptEncryption</key> <key>ITSAppUsesNonExemptEncryption</key>
<false/> <false/>
<key>LSRequiresIPhoneOS</key> <key>LSRequiresIPhoneOS</key>

View file

@ -63,6 +63,18 @@ strings.transactionTimeToReadable = function(time) {
} }
}; };
function removeTrailingZeros(value) {
value = value.toString();
if (value.indexOf('.') === -1) {
return value;
}
while ((value.slice(-1) === '0' || value.slice(-1) === '.') && value.indexOf('.') !== -1) {
value = value.substr(0, value.length - 1);
}
return value;
}
/** /**
* *
* @param balance {Number} Float amount of bitcoins * @param balance {Number} Float amount of bitcoins
@ -89,7 +101,8 @@ strings.formatBalanceWithoutSuffix = (balance, toUnit) => {
} }
if (balance !== 0) { if (balance !== 0) {
if (toUnit === BitcoinUnit.BTC || toUnit === undefined) { if (toUnit === BitcoinUnit.BTC || toUnit === undefined) {
return new BigNumber(balance).dividedBy(100000000).toFixed(8); const value = new BigNumber(balance).dividedBy(100000000).toFixed(8);
return removeTrailingZeros(value);
} else if (toUnit === BitcoinUnit.SATS) { } else if (toUnit === BitcoinUnit.SATS) {
const value = new BigNumber(balance) const value = new BigNumber(balance)
.multipliedBy(0.0001) .multipliedBy(0.0001)

View file

@ -185,27 +185,34 @@ export default class SendDetails extends Component {
} }
processBIP70Invoice(text) { processBIP70Invoice(text) {
if (BitcoinBIP70TransactionDecode.matchesPaymentURL(text)) { try {
this.setState( if (BitcoinBIP70TransactionDecode.matchesPaymentURL(text)) {
{ this.setState(
isLoading: true, {
}, isLoading: true,
() => { },
Keyboard.dismiss(); () => {
BitcoinBIP70TransactionDecode.decode(text).then(response => { Keyboard.dismiss();
this.setState({ BitcoinBIP70TransactionDecode.decode(text)
address: response.address, .then(response => {
amount: loc.formatBalanceWithoutSuffix(response.amount, BitcoinUnit.BTC), this.setState({
memo: response.memo, address: response.address,
fee: response.fee, amount: loc.formatBalanceWithoutSuffix(response.amount, BitcoinUnit.BTC),
bip70TransactionExpiration: response.expires, memo: response.memo,
isLoading: false, fee: response.fee,
}); bip70TransactionExpiration: response.expires,
}); isLoading: false,
}, });
); })
.catch(error => {
alert(error.errorMessage);
this.setState({ address: text.replace(' ', ''), isLoading: false, bip70TransactionExpiration: null, amount: 0 });
});
},
);
}
return true; return true;
} else { } catch (error) {
this.setState({ address: text.replace(' ', ''), isLoading: false, bip70TransactionExpiration: null, amount: 0 }); this.setState({ address: text.replace(' ', ''), isLoading: false, bip70TransactionExpiration: null, amount: 0 });
return false; return false;
} }
@ -480,6 +487,8 @@ export default class SendDetails extends Component {
onChangeText={text => { onChangeText={text => {
if (!this.processBIP70Invoice(text)) { if (!this.processBIP70Invoice(text)) {
this.setState({ address: text.replace(' ', ''), isLoading: false, bip70TransactionExpiration: null }); this.setState({ address: text.replace(' ', ''), isLoading: false, bip70TransactionExpiration: null });
} else {
this.setState({ address: text.replace(' ', ''), isLoading: false, bip70TransactionExpiration: null });
} }
}} }}
placeholder={loc.send.details.address} placeholder={loc.send.details.address}

View file

@ -17,6 +17,7 @@ import { Icon } from 'react-native-elements';
import { NavigationEvents } from 'react-navigation'; import { NavigationEvents } from 'react-navigation';
import ReactNativeHapticFeedback from 'react-native-haptic-feedback'; import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { BitcoinUnit } from '../../models/bitcoinUnits';
const BigNumber = require('bignumber.js'); const BigNumber = require('bignumber.js');
let EV = require('../../events'); let EV = require('../../events');
let A = require('../../analytics'); let A = require('../../analytics');
@ -345,10 +346,7 @@ export default class WalletsList extends Component {
containerStyle: { marginTop: 0 }, containerStyle: { marginTop: 0 },
}} }}
hideChevron hideChevron
rightTitle={new BigNumber((rowData.item.value && rowData.item.value) || 0) rightTitle={loc.formatBalanceWithoutSuffix(rowData.item.value && rowData.item.value, BitcoinUnit.BTC)}
.dividedBy(100000000)
.toFixed(8)
.toString()}
rightTitleStyle={{ rightTitleStyle={{
fontWeight: '600', fontWeight: '600',
fontSize: 16, fontSize: 16,

View file

@ -189,7 +189,7 @@ export default class WalletTransactions extends Component {
walletPreviousPreferredUnit = BitcoinUnit.BTC; walletPreviousPreferredUnit = BitcoinUnit.BTC;
} }
this.setState({ wallet: wallet, walletPreviousPreferredUnit: walletPreviousPreferredUnit }, () => BlueApp.saveToDisk()); this.setState({ wallet: wallet, walletPreviousPreferredUnit: walletPreviousPreferredUnit });
} }
renderWalletHeader = () => { renderWalletHeader = () => {
@ -288,6 +288,10 @@ export default class WalletTransactions extends Component {
); );
}; };
async onWillBlur() {
await BlueApp.saveToDisk();
}
render() { render() {
const { navigate } = this.props.navigation; const { navigate } = this.props.navigation;
return ( return (
@ -296,6 +300,7 @@ export default class WalletTransactions extends Component {
onWillFocus={() => { onWillFocus={() => {
this.refreshFunction(); this.refreshFunction();
}} }}
onWillBlur={() => this.onWillBlur()}
/> />
{this.renderWalletHeader()} {this.renderWalletHeader()}
<View style={{ flex: 1, backgroundColor: '#FFFFFF' }}> <View style={{ flex: 1, backgroundColor: '#FFFFFF' }}>