Browse Source
Merge pull request #821 from LN-Zap/fix/satoshis-crash
fix(utils): dont pass non-whole num to toBitcoin()
renovate/lint-staged-8.x
Tom Kirkpatrick
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
4 additions and
1 deletions
-
app/lib/utils/btc.js
|
|
@ -54,7 +54,10 @@ export function bitsToFiat(bits, price) { |
|
|
|
export function satoshisToBtc(satoshis) { |
|
|
|
if (satoshis === undefined || satoshis === null || satoshis === '') return null |
|
|
|
|
|
|
|
const btcAmount = sb.toBitcoin(satoshis).toFixed(8) |
|
|
|
// Make sure we are not passing a non-whole number to sb.toBitcoin(). If the number isn't whole we round up
|
|
|
|
const numSats = satoshis % 1 === 0 ? satoshis : Math.ceil(satoshis) |
|
|
|
|
|
|
|
const btcAmount = sb.toBitcoin(numSats).toFixed(8) |
|
|
|
return btcAmount > 0 ? btcAmount : btcAmount * -1 |
|
|
|
} |
|
|
|
|
|
|
|