From 1b15ce7a604da1752d974a7c5323be936ad3a7a0 Mon Sep 17 00:00:00 2001 From: Jack Mallers Date: Tue, 31 Jul 2018 15:44:35 -0500 Subject: [PATCH] feat(fiat): persist fiatTicker fix(fiat): reorder fiatTickers fix(renderer): correct URLs in renderers refactor(settings): refactor to functional components fix(utils): convert fiat price w/ commas chore(comment): remove un-needed comment refactor(fiat-amount): rename to fiatAmount --- app/components/Contacts/Network.js | 2 +- app/components/Settings/Fiat.js | 42 ++++++++++++++---------------- app/components/Settings/Menu.js | 18 ++++++------- app/lib/utils/btc.js | 9 ++++++- app/reducers/balance.js | 1 - app/reducers/ticker.js | 19 +++++++++----- webpack.config.renderer.dev.js | 2 +- webpack.config.renderer.prod.js | 2 +- 8 files changed, 52 insertions(+), 43 deletions(-) diff --git a/app/components/Contacts/Network.js b/app/components/Contacts/Network.js index 5ceff277..4c7aade1 100644 --- a/app/components/Contacts/Network.js +++ b/app/components/Contacts/Network.js @@ -155,7 +155,7 @@ class Network extends Component { return 'online' } - const usdAmount = btc.satoshisToUsd( + const fiatAmount = btc.satoshisToUsd( balance.channelBalance, currentTicker[ticker.fiatTicker].last ) diff --git a/app/components/Settings/Fiat.js b/app/components/Settings/Fiat.js index 2c8cf03e..3e432e5d 100644 --- a/app/components/Settings/Fiat.js +++ b/app/components/Settings/Fiat.js @@ -5,28 +5,26 @@ import Isvg from 'react-inlinesvg' import checkIcon from 'icons/check.svg' import styles from './Fiat.scss' -const Fiat = ({ fiatTicker, fiatTickers, disableSubMenu, setFiatTicker }) => { - return ( -
-
- - Fiat currency -
- -
- ) -} +const Fiat = ({ fiatTicker, fiatTickers, disableSubMenu, setFiatTicker }) => ( +
+
+ + Fiat currency +
+ +
+) Fiat.propTypes = { fiatTicker: PropTypes.string.isRequired, diff --git a/app/components/Settings/Menu.js b/app/components/Settings/Menu.js index ad8348c3..e44a9fee 100644 --- a/app/components/Settings/Menu.js +++ b/app/components/Settings/Menu.js @@ -3,16 +3,14 @@ import PropTypes from 'prop-types' import FaAngleRight from 'react-icons/lib/fa/angle-right' import styles from './Menu.scss' -const Menu = ({ setActiveSubMenu }) => { - return ( - - ) -} +const Menu = ({ setActiveSubMenu }) => ( + +) Menu.propTypes = { setActiveSubMenu: PropTypes.func.isRequired diff --git a/app/lib/utils/btc.js b/app/lib/utils/btc.js index 0bdbe822..8da945cd 100644 --- a/app/lib/utils/btc.js +++ b/app/lib/utils/btc.js @@ -1,6 +1,13 @@ /* eslint-disable */ import sb from 'satoshi-bitcoin' + +//////////////// +// Helpers ///// +//////////////// + +const numberWithCommas = x => x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') + ////////////////////// // BTC to things ///// ///////////////////// @@ -18,7 +25,7 @@ export function btcToBits(btc) { export function btcToUsd(btc, price) { const amount = parseFloat(btc * price).toFixed(2) - return (btc > 0 && amount <= 0) ? '< 0.01' : amount.toLocaleString('en') + return (btc > 0 && amount <= 0) ? '< 0.01' : numberWithCommas(amount) } //////////////////////////// diff --git a/app/reducers/balance.js b/app/reducers/balance.js index 954c20b3..e9620030 100644 --- a/app/reducers/balance.js +++ b/app/reducers/balance.js @@ -22,7 +22,6 @@ export const fetchBalance = () => async dispatch => { // Receive IPC event for balance export const receiveBalance = (event, { walletBalance, channelBalance }) => dispatch => { - // dispatch({ type: RECEIVE_BALANCE, walletBalance, channelBalance }) dispatch({ type: RECEIVE_BALANCE, walletBalance, channelBalance }) } diff --git a/app/reducers/ticker.js b/app/reducers/ticker.js index ef99349c..fd917eaa 100644 --- a/app/reducers/ticker.js +++ b/app/reducers/ticker.js @@ -1,7 +1,11 @@ import { createSelector } from 'reselect' +import Store from 'electron-store' import { requestTicker } from 'lib/utils/api' import { infoSelectors } from './info' +// Ticker store +const store = new Store({ name: 'ticker' }) + // ------------------------------------ // Constants // ------------------------------------ @@ -35,6 +39,9 @@ export function setCrypto(crypto) { } export function setFiatTicker(fiatTicker) { + // Persist the new fiatTicker in our ticker store + store.set('fiatTicker', fiatTicker) + return { type: SET_FIAT_TICKER, fiatTicker @@ -134,23 +141,23 @@ const initialState = { crypto: '', btcTicker: null, ltcTicker: null, - fiatTicker: 'USD', + fiatTicker: store.get('fiatTicker', 'USD'), fiatTickers: [ 'USD', + 'EUR', + 'JPY', + 'GBP', + 'CAD', + 'KRW', 'AUD', 'BRL', - 'CAD', 'CHF', 'CLP', 'CNY', 'DKK', - 'EUR', - 'GBP', 'HKD', 'INR', 'ISK', - 'JPY', - 'KRW', 'NZD', 'PLN', 'RUB', diff --git a/webpack.config.renderer.dev.js b/webpack.config.renderer.dev.js index 7178f2d0..a9aa4b18 100644 --- a/webpack.config.renderer.dev.js +++ b/webpack.config.renderer.dev.js @@ -228,7 +228,7 @@ export default merge.smart(baseConfig, { "'self'", 'http://localhost:*', 'ws://localhost:*', - 'https://blockchain.info/ticker', + 'https://blockchain.info', 'https://zap.jackmallers.com' ], 'script-src': ["'self'", 'http://localhost:*', "'unsafe-eval'"], diff --git a/webpack.config.renderer.prod.js b/webpack.config.renderer.prod.js index 96b0bcba..ff91c9a4 100644 --- a/webpack.config.renderer.prod.js +++ b/webpack.config.renderer.prod.js @@ -158,7 +158,7 @@ export default merge.smart(baseConfig, { new CspHtmlWebpackPlugin({ 'default-src': "'self'", 'object-src': "'none'", - 'connect-src': ["'self'", 'https://api.coinmarketcap.com', 'https://zap.jackmallers.com'], + 'connect-src': ["'self'", 'https://blockchain.info', 'https://zap.jackmallers.com'], 'script-src': ["'self'"], 'font-src': [ "'self'",