Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
fix(i18n): parse fiat amounts to number type
Browse files Browse the repository at this point in the history
We need to pass a number to `<FormattedNumber>` for it to properly
display the currency values. In some cases we were passing a
pre-formatted string which was causing some currency amount to render
as NaN.
  • Loading branch information
mrfelton committed Sep 19, 2018
1 parent 2d0a897 commit a0e77b1
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions app/lib/utils/btc.js
Expand Up @@ -2,12 +2,6 @@

import sb from 'satoshi-bitcoin'

////////////////
// Helpers /////
////////////////

const numberWithCommas = x => x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')

//////////////////////
// BTC to things /////
/////////////////////
Expand All @@ -24,8 +18,9 @@ export function btcToBits(btc) {
}

export function btcToFiat(btc, price) {
const amount = parseFloat(btc * price).toFixed(2)
return btc > 0 && amount <= 0 ? '< 0.01' : numberWithCommas(amount)
if (btc === undefined || btc === null || btc === '') return null

return parseFloat(btc * price)
}

////////////////////////////
Expand Down

0 comments on commit a0e77b1

Please sign in to comment.