From 6bc57e5985704deec1bf89060d9e5be29cc450c2 Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Fri, 3 Mar 2017 16:14:27 +0100 Subject: [PATCH] Refactor of enabled content --- app/common/lib/ledgerUtil.js | 34 ++ .../preferences/payment/disabledContent.js | 25 +- .../preferences/payment/enabledContent.js | 347 ++++++++++++++++++ .../components/preferences/paymentsTab.js | 248 +------------ app/renderer/components/settings.js | 6 +- app/renderer/components/styles/payment.js | 22 ++ less/about/preferences.less | 110 +----- 7 files changed, 436 insertions(+), 356 deletions(-) create mode 100644 app/renderer/components/preferences/payment/enabledContent.js create mode 100644 app/renderer/components/styles/payment.js diff --git a/app/common/lib/ledgerUtil.js b/app/common/lib/ledgerUtil.js index e442536b21c..7a4f94fb565 100644 --- a/app/common/lib/ledgerUtil.js +++ b/app/common/lib/ledgerUtil.js @@ -5,6 +5,8 @@ 'use strict' const {responseHasContent} = require('./httpUtil') +const moment = require('moment') +moment.locale(navigator.language) /** * Is page an actual page being viewed by the user? (not an error page, etc) @@ -39,3 +41,35 @@ module.exports.shouldTrackView = (view, responseList) => { } return false } + +module.exports.btcToCurrencyString = (btc, ledgerData) => { + const balance = Number(btc || 0) + const currency = ledgerData.get('currency') || 'USD' + + if (balance === 0) { + return `0 ${currency}` + } + + if (ledgerData.get('btc') && typeof ledgerData.get('amount') === 'number') { + const btcValue = ledgerData.get('btc') / ledgerData.get('amount') + const fiatValue = (balance / btcValue).toFixed(2) + let roundedValue = Math.floor(fiatValue) + const diff = fiatValue - roundedValue + + if (diff > 0.74) { + roundedValue += 0.75 + } else if (diff > 0.49) { + roundedValue += 0.50 + } else if (diff > 0.24) { + roundedValue += 0.25 + } + + return `${roundedValue.toFixed(2)} ${currency}` + } + + return `${balance} BTC` +} + +module.exports.formattedTimeFromNow = (timestamp) => { + return moment(new Date(timestamp)).fromNow() +} diff --git a/app/renderer/components/preferences/payment/disabledContent.js b/app/renderer/components/preferences/payment/disabledContent.js index 7896191937b..918626fcc6c 100644 --- a/app/renderer/components/preferences/payment/disabledContent.js +++ b/app/renderer/components/preferences/payment/disabledContent.js @@ -1,9 +1,15 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + const React = require('react') -const ImmutableComponent = require('../../../../../js/components/immutableComponent') -const globalStyles = require('../../styles/global') const {StyleSheet, css} = require('aphrodite/no-important') -// icons +const ImmutableComponent = require('../../../../../js/components/immutableComponent') + +// style +const globalStyles = require('../../styles/global') +const paymentStyles = require('../../styles/payment') const PIA = require('../../../../extensions/brave/img/private_internet_access.png') const PIA2 = require('../../../../extensions/brave/img/private_internet_access_2x.png') const BitGo = require('../../../../extensions/brave/img/bitgo.png') @@ -57,10 +63,14 @@ const styles = StyleSheet.create({ }, textSide: { - fontSize: '12px', + fontSize: paymentStyles.font.regular, margin: '50px 0 20px 12px' }, + walletBarMargin: { + marginTop: paymentStyles.margin.bar + }, + h3: { fontSize: '18px', paddingBottom: '0.5em' @@ -75,10 +85,6 @@ const styles = StyleSheet.create({ fontWeight: 'bold' }, - walletBarMargin: { - marginTop: '15px' - }, - paymentsSidebar: { opacity: 0.8, width: '200px', @@ -103,8 +109,7 @@ const styles = StyleSheet.create({ }, paymentsSidebarCoinbase: { - backgroundImage: `-webkit-image-set(url(${CoinBase}) 1x, - url(${CoinBase2}) 2x)`, + backgroundImage: `-webkit-image-set(url(${CoinBase}) 1x, url(${CoinBase2}) 2x)`, width: '100px', height: '35px', margin: '0 0 20px 12px', diff --git a/app/renderer/components/preferences/payment/enabledContent.js b/app/renderer/components/preferences/payment/enabledContent.js new file mode 100644 index 00000000000..775b1bbbef7 --- /dev/null +++ b/app/renderer/components/preferences/payment/enabledContent.js @@ -0,0 +1,347 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +const React = require('react') +const {StyleSheet, css} = require('aphrodite') + +// components +const Button = require('../../../../../js/components/button') +const {FormTextbox} = require('../../textbox') +const {FormDropdown} = require('../../dropdown') +const {SettingsList, SettingItem} = require('../../settings') +const LedgerTable = require('./ledgerTable') + +// util +const ImmutableComponent = require('../../../../../js/components/immutableComponent') +const {btcToCurrencyString, formattedTimeFromNow} = require('../../../../common/lib/ledgerUtil') +const {l10nErrorText} = require('../../../../common/lib/httpUtil') +const {changeSetting} = require('../../../lib/settingsUtil') + +// style +const globalStyles = require('../../styles/global') +const paymentStyles = require('../../styles/payment') +const cx = require('../../../../../js/lib/classSet') + +const getSetting = require('../../../../../js/settings').getSetting +const settings = require('../../../../../js/constants/settings') +const aboutActions = require('../../../../../js/about/aboutActions') + +// TODO: report when funds are too low +// TODO: support non-USD currency +class EnabledContent extends ImmutableComponent { + walletButton (ledgerData) { + const buttonText = ledgerData.get('created') + ? 'addFundsTitle' + : (ledgerData.get('creating') ? 'creatingWallet' : 'createWallet') + const onButtonClick = ledgerData.get('created') + ? this.props.showOverlay.bind(this, 'addFunds') + : (ledgerData.get('creating') ? () => {} : this.createWallet(ledgerData)) + + return