mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-26 08:55:56 +01:00
Removed bitcoin-unit
This commit is contained in:
parent
bc1fa41269
commit
bf154a39d5
3 changed files with 15 additions and 56 deletions
57
loc/index.js
57
loc/index.js
|
@ -2,8 +2,8 @@ import Localization from 'react-localization';
|
|||
import { AsyncStorage } from 'react-native';
|
||||
import { AppStorage } from '../class';
|
||||
import { BitcoinUnit } from '../models/bitcoinUnits';
|
||||
const BTCUnits = require('bitcoin-units');
|
||||
const currency = require('../currency');
|
||||
const BigNumber = require('bignumber.js');
|
||||
let strings;
|
||||
|
||||
// first-time loading sequence
|
||||
|
@ -69,63 +69,36 @@ strings.transactionTimeToReadable = function(time) {
|
|||
* @param unit {String} Value from models/bitcoinUnits.js
|
||||
* @returns {string}
|
||||
*/
|
||||
strings.formatBalance = (balance, fromUnit, toUnit) => {
|
||||
strings.formatBalance = (balance, toUnit) => {
|
||||
if (toUnit === undefined) {
|
||||
balance = Number(balance);
|
||||
return balance + ' ' + BitcoinUnit.BTC;
|
||||
}
|
||||
if (fromUnit === BitcoinUnit.LOCAL_CURRENCY) {
|
||||
return currency.satoshiToLocalCurrency(
|
||||
BTCUnits(balance, BitcoinUnit.BTC)
|
||||
.to(BitcoinUnit.SATS)
|
||||
.value(),
|
||||
);
|
||||
}
|
||||
if (toUnit === BitcoinUnit.BTC) {
|
||||
balance = Number(balance);
|
||||
return BTCUnits(balance, fromUnit)
|
||||
.to(BitcoinUnit.BTC)
|
||||
.format();
|
||||
return balance + ' BTC';
|
||||
} else if (toUnit === BitcoinUnit.SATS) {
|
||||
balance = Number(balance);
|
||||
return BTCUnits(balance, BitcoinUnit.BTC)
|
||||
.to(BitcoinUnit.SATS)
|
||||
.format();
|
||||
const value = new BigNumber(balance).multipliedBy(0.001);
|
||||
return parseInt(value.toString().replace('.', '')).toString() + ' sats';
|
||||
} else if (toUnit === BitcoinUnit.LOCAL_CURRENCY) {
|
||||
const satoshis = BTCUnits(balance, BitcoinUnit.BTC)
|
||||
.to(BitcoinUnit.SATS)
|
||||
.value();
|
||||
return currency.satoshiToLocalCurrency(satoshis);
|
||||
const value = new BigNumber(balance).multipliedBy(0.001);
|
||||
return currency.satoshiToLocalCurrency(parseInt(value.toString().replace('.', '')));
|
||||
}
|
||||
};
|
||||
|
||||
strings.formatBalanceWithoutSuffix = (balance, fromUnit, toUnit) => {
|
||||
balance = Number(balance);
|
||||
strings.formatBalanceWithoutSuffix = (balance, toUnit) => {
|
||||
if (toUnit === undefined) {
|
||||
return balance;
|
||||
}
|
||||
if (balance !== 0) {
|
||||
if (fromUnit === BitcoinUnit.LOCAL_CURRENCY) {
|
||||
return BTCUnits(balance, BitcoinUnit.SATS)
|
||||
.to(BitcoinUnit.SATS)
|
||||
.toString();
|
||||
}
|
||||
if (toUnit === BitcoinUnit.BTC || toUnit === undefined) {
|
||||
return BTCUnits(balance, fromUnit)
|
||||
.to(BitcoinUnit.BTC)
|
||||
.value()
|
||||
.toFixed(8)
|
||||
.toString();
|
||||
return new BigNumber(balance).dividedBy(100000000).toFixed(8);
|
||||
} else if (toUnit === BitcoinUnit.SATS) {
|
||||
return String(
|
||||
BTCUnits(balance, fromUnit)
|
||||
.to(BitcoinUnit.SATS)
|
||||
.format(),
|
||||
)
|
||||
.replace(' satoshis', '')
|
||||
.replace(' satoshi', '');
|
||||
const value = new BigNumber(balance)
|
||||
.multipliedBy(0.0001)
|
||||
.toString()
|
||||
.replace('.', '');
|
||||
return parseFloat(value).toLocaleString();
|
||||
} else if (toUnit === BitcoinUnit.LOCAL_CURRENCY) {
|
||||
return currency.satoshiToLocalCurrency(BTCUnits(balance, fromUnit).to(BitcoinUnit.SATS));
|
||||
return currency.satoshiToLocalCurrency(balance);
|
||||
}
|
||||
}
|
||||
return balance;
|
||||
|
|
13
package-lock.json
generated
13
package-lock.json
generated
|
@ -2747,11 +2747,6 @@
|
|||
"resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.36.tgz",
|
||||
"integrity": "sha512-t70bfa7HYEA1D9idDbmuv7YbsbVkQ+Hp+8KFSul4aE5e/i1bjCNIRYJZlA8Q8p0r9T8cF/RVvwUgRA//FydEyg=="
|
||||
},
|
||||
"big.js": {
|
||||
"version": "5.2.2",
|
||||
"resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz",
|
||||
"integrity": "sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ=="
|
||||
},
|
||||
"bigi": {
|
||||
"version": "1.4.2",
|
||||
"resolved": "https://registry.npmjs.org/bigi/-/bigi-1.4.2.tgz",
|
||||
|
@ -2795,14 +2790,6 @@
|
|||
"resolved": "https://registry.npmjs.org/bitcoin-ops/-/bitcoin-ops-1.4.1.tgz",
|
||||
"integrity": "sha512-pef6gxZFztEhaE9RY9HmWVmiIHqCb2OyS4HPKkpc6CIiiOa3Qmuoylxc5P2EkU3w+5eTSifI9SEZC88idAIGow=="
|
||||
},
|
||||
"bitcoin-units": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/bitcoin-units/-/bitcoin-units-0.3.0.tgz",
|
||||
"integrity": "sha512-CxmCxfoYDKQhKXMvT1HnShVL1E6rT5IUkVenhrFDphrRGKQHJUTGtK68UY7JnAQKqJA4510cC5MO6aEd/8v1EQ==",
|
||||
"requires": {
|
||||
"big.js": "^5.2.2"
|
||||
}
|
||||
},
|
||||
"bitcoinjs-lib": {
|
||||
"version": "3.3.2",
|
||||
"resolved": "https://registry.npmjs.org/bitcoinjs-lib/-/bitcoinjs-lib-3.3.2.tgz",
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
"bignumber.js": "^7.0.0",
|
||||
"bip21": "^2.0.2",
|
||||
"bip39": "^2.5.0",
|
||||
"bitcoin-units": "^0.3.0",
|
||||
"bitcoinjs-lib": "^3.3.2",
|
||||
"buffer": "^5.2.1",
|
||||
"buffer-reverse": "^1.0.1",
|
||||
|
|
Loading…
Add table
Reference in a new issue