mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-02-22 23:08:07 +01:00
FIX: keep balance and units in BTC (closes #67)
This commit is contained in:
parent
8dff3d0222
commit
b72a9c10f1
3 changed files with 15 additions and 6 deletions
13
loc/index.js
13
loc/index.js
|
@ -2,6 +2,7 @@ import Localization from 'react-localization';
|
|||
import { AsyncStorage } from 'react-native';
|
||||
import { AppStorage } from '../class';
|
||||
import { BitcoinUnit } from '../models/bitcoinUnits';
|
||||
let currency = require('../currency');
|
||||
let BigNumber = require('bignumber.js');
|
||||
let strings;
|
||||
|
||||
|
@ -62,13 +63,15 @@ strings.transactionTimeToReadable = function(time) {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param balance {Number} Float amount of bitcoins
|
||||
* @param unit {String} Value from models/bitcoinUnits.js
|
||||
* @returns {string}
|
||||
*/
|
||||
strings.formatBalance = (balance, unit) => {
|
||||
const conversion = 100000000;
|
||||
if (unit === undefined) {
|
||||
if (balance < 0.1 && balance !== 0) {
|
||||
let b = new BigNumber(balance);
|
||||
return b.multipliedBy(1000).toString() + ' ' + BitcoinUnit.MBTC;
|
||||
}
|
||||
return balance + ' ' + BitcoinUnit.BTC;
|
||||
} else {
|
||||
if (balance !== 0) {
|
||||
|
@ -81,6 +84,8 @@ strings.formatBalance = (balance, unit) => {
|
|||
return (b.times(conversion).toString() + ' ' + BitcoinUnit.SATOSHIS).replace(/\./g, '');
|
||||
} else if (unit === BitcoinUnit.SATS) {
|
||||
return (b.times(conversion).toString() + ' ' + BitcoinUnit.SATS).replace(/\./g, '');
|
||||
} else if (unit === BitcoinUnit.LOCAL_CURRENCY) {
|
||||
return currency.satoshiToLocalCurrency(b.times(conversion).toNumber());
|
||||
}
|
||||
}
|
||||
return balance + ' ' + BitcoinUnit.BTC;
|
||||
|
|
|
@ -4,4 +4,5 @@ export const BitcoinUnit = Object.freeze({
|
|||
BITS: 'bits',
|
||||
SATOSHIS: 'satoshis',
|
||||
SATS: 'sats',
|
||||
LOCAL_CURRENCY: 'local_currency',
|
||||
});
|
||||
|
|
|
@ -64,7 +64,7 @@ export default class WalletTransactions extends Component {
|
|||
isTransactionsLoading: false,
|
||||
wallet: wallet,
|
||||
dataSource: wallet.getTransactions(),
|
||||
walletBalanceUnit: BitcoinUnit.MBTC,
|
||||
walletBalanceUnit: BitcoinUnit.BTC,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -176,13 +176,16 @@ export default class WalletTransactions extends Component {
|
|||
|
||||
changeWalletBalanceUnit() {
|
||||
if (this.state.walletBalanceUnit === undefined || this.state.walletBalanceUnit === BitcoinUnit.BTC) {
|
||||
this.setState({ walletBalanceUnit: BitcoinUnit.MBTC });
|
||||
// this.setState({ walletBalanceUnit: BitcoinUnit.MBTC });
|
||||
this.setState({ walletBalanceUnit: BitcoinUnit.LOCAL_CURRENCY });
|
||||
} else if (this.state.walletBalanceUnit === BitcoinUnit.MBTC) {
|
||||
this.setState({ walletBalanceUnit: BitcoinUnit.BITS });
|
||||
} else if (this.state.walletBalanceUnit === BitcoinUnit.BITS) {
|
||||
this.setState({ walletBalanceUnit: BitcoinUnit.SATOSHIS });
|
||||
} else if (this.state.walletBalanceUnit === BitcoinUnit.SATOSHIS) {
|
||||
this.setState({ walletBalanceUnit: BitcoinUnit.BTC });
|
||||
} else if (this.state.walletBalanceUnit === BitcoinUnit.LOCAL_CURRENCY) {
|
||||
this.setState({ walletBalanceUnit: BitcoinUnit.MBTC });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue