mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-02-22 06:52:41 +01:00
FIX: Remove BTC trailing zeros. Save to disk onBlur for preferred balance unit.
This commit is contained in:
parent
44ab347ee0
commit
91a2ecb1dc
6 changed files with 53 additions and 29 deletions
|
@ -24,7 +24,6 @@ import { HDLegacyP2PKHWallet } from './class/hd-legacy-p2pkh-wallet';
|
|||
import { HDLegacyBreadwalletWallet } from './class/hd-legacy-breadwallet-wallet';
|
||||
import { HDSegwitP2SHWallet } from './class/hd-segwit-p2sh-wallet';
|
||||
import { LightningCustodianWallet } from './class/lightning-custodian-wallet';
|
||||
import { BitcoinUnit } from './models/bitcoinUnits';
|
||||
let loc = require('./loc/');
|
||||
/** @type {AppStorage} */
|
||||
let BlueApp = require('./BlueApp');
|
||||
|
@ -1049,7 +1048,7 @@ export class WalletsCarousel extends Component {
|
|||
color: '#fff',
|
||||
}}
|
||||
>
|
||||
{loc.formatBalance(Number(item.getBalance()), BitcoinUnit.BTC, item.getPreferredBalanceUnit())}
|
||||
{loc.formatBalance(Number(item.getBalance()), item.getPreferredBalanceUnit())}
|
||||
</Text>
|
||||
<Text style={{ backgroundColor: 'transparent' }} />
|
||||
<Text
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
</dict>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>162</string>
|
||||
<string>164</string>
|
||||
<key>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
|
|
15
loc/index.js
15
loc/index.js
|
@ -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
|
||||
|
@ -89,7 +101,8 @@ strings.formatBalanceWithoutSuffix = (balance, toUnit) => {
|
|||
}
|
||||
if (balance !== 0) {
|
||||
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) {
|
||||
const value = new BigNumber(balance)
|
||||
.multipliedBy(0.0001)
|
||||
|
|
|
@ -185,6 +185,7 @@ export default class SendDetails extends Component {
|
|||
}
|
||||
|
||||
processBIP70Invoice(text) {
|
||||
try {
|
||||
if (BitcoinBIP70TransactionDecode.matchesPaymentURL(text)) {
|
||||
this.setState(
|
||||
{
|
||||
|
@ -192,7 +193,8 @@ export default class SendDetails extends Component {
|
|||
},
|
||||
() => {
|
||||
Keyboard.dismiss();
|
||||
BitcoinBIP70TransactionDecode.decode(text).then(response => {
|
||||
BitcoinBIP70TransactionDecode.decode(text)
|
||||
.then(response => {
|
||||
this.setState({
|
||||
address: response.address,
|
||||
amount: loc.formatBalanceWithoutSuffix(response.amount, BitcoinUnit.BTC),
|
||||
|
@ -201,11 +203,16 @@ export default class SendDetails extends Component {
|
|||
bip70TransactionExpiration: response.expires,
|
||||
isLoading: false,
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
alert(error.errorMessage);
|
||||
this.setState({ address: text.replace(' ', ''), isLoading: false, bip70TransactionExpiration: null, amount: 0 });
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
} catch (error) {
|
||||
this.setState({ address: text.replace(' ', ''), isLoading: false, bip70TransactionExpiration: null, amount: 0 });
|
||||
return false;
|
||||
}
|
||||
|
@ -480,6 +487,8 @@ export default class SendDetails extends Component {
|
|||
onChangeText={text => {
|
||||
if (!this.processBIP70Invoice(text)) {
|
||||
this.setState({ address: text.replace(' ', ''), isLoading: false, bip70TransactionExpiration: null });
|
||||
} else {
|
||||
this.setState({ address: text.replace(' ', ''), isLoading: false, bip70TransactionExpiration: null });
|
||||
}
|
||||
}}
|
||||
placeholder={loc.send.details.address}
|
||||
|
|
|
@ -17,6 +17,7 @@ import { Icon } from 'react-native-elements';
|
|||
import { NavigationEvents } from 'react-navigation';
|
||||
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
|
||||
import PropTypes from 'prop-types';
|
||||
import { BitcoinUnit } from '../../models/bitcoinUnits';
|
||||
const BigNumber = require('bignumber.js');
|
||||
let EV = require('../../events');
|
||||
let A = require('../../analytics');
|
||||
|
@ -345,10 +346,7 @@ export default class WalletsList extends Component {
|
|||
containerStyle: { marginTop: 0 },
|
||||
}}
|
||||
hideChevron
|
||||
rightTitle={new BigNumber((rowData.item.value && rowData.item.value) || 0)
|
||||
.dividedBy(100000000)
|
||||
.toFixed(8)
|
||||
.toString()}
|
||||
rightTitle={loc.formatBalanceWithoutSuffix(rowData.item.value && rowData.item.value, BitcoinUnit.BTC)}
|
||||
rightTitleStyle={{
|
||||
fontWeight: '600',
|
||||
fontSize: 16,
|
||||
|
|
|
@ -189,7 +189,7 @@ export default class WalletTransactions extends Component {
|
|||
walletPreviousPreferredUnit = BitcoinUnit.BTC;
|
||||
}
|
||||
|
||||
this.setState({ wallet: wallet, walletPreviousPreferredUnit: walletPreviousPreferredUnit }, () => BlueApp.saveToDisk());
|
||||
this.setState({ wallet: wallet, walletPreviousPreferredUnit: walletPreviousPreferredUnit });
|
||||
}
|
||||
|
||||
renderWalletHeader = () => {
|
||||
|
@ -288,6 +288,10 @@ export default class WalletTransactions extends Component {
|
|||
);
|
||||
};
|
||||
|
||||
async onWillBlur() {
|
||||
await BlueApp.saveToDisk();
|
||||
}
|
||||
|
||||
render() {
|
||||
const { navigate } = this.props.navigation;
|
||||
return (
|
||||
|
@ -296,6 +300,7 @@ export default class WalletTransactions extends Component {
|
|||
onWillFocus={() => {
|
||||
this.refreshFunction();
|
||||
}}
|
||||
onWillBlur={() => this.onWillBlur()}
|
||||
/>
|
||||
{this.renderWalletHeader()}
|
||||
<View style={{ flex: 1, backgroundColor: '#FFFFFF' }}>
|
||||
|
|
Loading…
Add table
Reference in a new issue