Browse Source

feature(multi-currency): calculates value based on current currency

renovate/lint-staged-8.x
Jack Mallers 8 years ago
parent
commit
dbd3fcaf71
  1. 6
      app/routes/activity/components/Activity.js
  2. 1
      app/routes/activity/components/Activity.scss
  3. 13
      app/routes/activity/components/components/Invoices.js
  4. 22
      app/routes/activity/components/components/Payments.js
  5. 3
      app/routes/activity/containers/ActivityContainer.js
  6. 1
      app/routes/app/components/App.js
  7. 8
      app/routes/app/components/components/Form.js
  8. 25
      app/routes/app/components/components/Nav.js
  9. 2
      app/utils/bitcoin.js

6
app/routes/activity/components/Activity.js

@ -20,7 +20,7 @@ class Activity extends Component {
render() { render() {
const { tab } = this.state const { tab } = this.state
const { activity: { activityLoading, payments, invoices } } = this.props const { ticker, activity: { activityLoading, payments, invoices } } = this.props
if (activityLoading) { return <div>Loading...</div> } if (activityLoading) { return <div>Loading...</div> }
return ( return (
@ -55,9 +55,9 @@ class Activity extends Component {
> >
{ {
tab === 1 ? tab === 1 ?
<Payments key={1} payments={payments} /> <Payments key={1} payments={payments} ticker={ticker} />
: :
<Invoices key={2} invoices={invoices} /> <Invoices key={2} invoices={invoices} ticker={ticker} />
} }
</CSSTransitionGroup> </CSSTransitionGroup>
</div> </div>

1
app/routes/activity/components/Activity.scss

@ -55,6 +55,7 @@
&.active { &.active {
color: #eec27b; color: #eec27b;
font-weight: bold;
} }
} }
} }

13
app/routes/activity/components/components/Invoices.js

@ -2,12 +2,12 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import Moment from 'react-moment' import Moment from 'react-moment'
import 'moment-timezone' import 'moment-timezone'
import { satoshisToBtc } from '../../../../utils/bitcoin' import { satoshisToBtc, satoshisToUsd } from '../../../../utils/bitcoin'
import styles from './Invoices.scss' import styles from './Invoices.scss'
class Invoices extends Component { class Invoices extends Component {
render() { render() {
const { invoices } = this.props const { invoices, ticker } = this.props
return ( return (
<ul className={styles.invoices}> <ul className={styles.invoices}>
<li className={styles.invoiceTitles}> <li className={styles.invoiceTitles}>
@ -31,7 +31,14 @@ class Invoices extends Component {
<div>{invoice.memo}</div> <div>{invoice.memo}</div>
</div> </div>
<div className={styles.right}> <div className={styles.right}>
<div className={invoice.settled ? styles.settled : null}>{satoshisToBtc(invoice.value, 2500)}</div> <div className={invoice.settled ? styles.settled : null}>
{
ticker.currency === 'btc' ?
satoshisToBtc(invoice.value)
:
satoshisToUsd(invoice.value, ticker.btcTicker.price_usd)
}
</div>
</div> </div>
</li> </li>
) )

22
app/routes/activity/components/components/Payments.js

@ -2,12 +2,12 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import Moment from 'react-moment' import Moment from 'react-moment'
import 'moment-timezone' import 'moment-timezone'
import { satoshisToBtc } from '../../../../utils/bitcoin' import { satoshisToBtc, satoshisToUsd } from '../../../../utils/bitcoin'
import styles from './Payments.scss' import styles from './Payments.scss'
class Payments extends Component { class Payments extends Component {
render() { render() {
const { payments } = this.props const { payments, ticker } = this.props
return ( return (
<ul className={styles.payments}> <ul className={styles.payments}>
<li className={styles.paymentTitles}> <li className={styles.paymentTitles}>
@ -36,10 +36,24 @@ class Payments extends Component {
</div> </div>
</div> </div>
<div className={styles.right}> <div className={styles.right}>
<span className={styles.fee}>{payment.fee === '0' ? '0' : satoshisToBtc(payment.fee, 2500)}</span> <span className={styles.fee}>
{
ticker.currency === 'btc' ?
satoshisToBtc(payment.fee)
:
satoshisToUsd(payment.fee, ticker.btcTicker.price_usd)
}
</span>
</div> </div>
<div className={styles.right}> <div className={styles.right}>
<span className={styles.value}>{satoshisToBtc(payment.value, 2500)}</span> <span className={styles.value}>
{
ticker.currency === 'btc' ?
satoshisToBtc(payment.value)
:
satoshisToUsd(payment.value, ticker.btcTicker.price_usd)
}
</span>
</div> </div>
</li> </li>
) )

3
app/routes/activity/containers/ActivityContainer.js

@ -7,7 +7,8 @@ const mapDispatchToProps = {
} }
const mapStateToProps = (state) => ({ const mapStateToProps = (state) => ({
activity: state.activity activity: state.activity,
ticker: state.ticker
}) })
export default connect(mapStateToProps, mapDispatchToProps)(Activity) export default connect(mapStateToProps, mapDispatchToProps)(Activity)

1
app/routes/app/components/App.js

@ -44,6 +44,7 @@ class App extends Component {
payment={payment} payment={payment}
fetchPeers={fetchPeers} fetchPeers={fetchPeers}
peers={peers} peers={peers}
ticker={ticker}
/> />
<Nav <Nav
ticker={ticker} ticker={ticker}

8
app/routes/app/components/components/Form.js

@ -16,6 +16,7 @@ class Form extends Component {
setPubkey, setPubkey,
payment: { amount, message, pubkey }, payment: { amount, message, pubkey },
peers: { peers }, peers: { peers },
ticker: { currency },
isOpen, isOpen,
close close
} = this.props } = this.props
@ -29,7 +30,12 @@ class Form extends Component {
<div className={styles.content}> <div className={styles.content}>
<section className={styles.amountContainer}> <section className={styles.amountContainer}>
<label> <label>
<FaBitcoin /> {
currency === 'btc' ?
<FaBitcoin />
:
<FaDollar />
}
</label> </label>
<input <input
type='text' type='text'

25
app/routes/app/components/components/Nav.js

@ -4,13 +4,12 @@ import { Link } from 'react-router-dom'
import ReactSVG from 'react-svg' import ReactSVG from 'react-svg'
import { MdAccountBalanceWallet, MdSettings } from 'react-icons/lib/md' import { MdAccountBalanceWallet, MdSettings } from 'react-icons/lib/md'
import { FaClockO, FaBitcoin, FaDollar } from 'react-icons/lib/fa' import { FaClockO, FaBitcoin, FaDollar } from 'react-icons/lib/fa'
import { satoshisToBtc } from '../../../../utils/bitcoin' import { satoshisToBtc, satoshisToUsd } from '../../../../utils/bitcoin'
import styles from './Nav.scss' import styles from './Nav.scss'
class Nav extends Component { class Nav extends Component {
render() { render() {
const { ticker, balance, setCurrency, formClicked } = this.props const { ticker, balance, setCurrency, formClicked } = this.props
console.log('ticker: ', ticker)
return ( return (
<nav className={styles.nav}> <nav className={styles.nav}>
<ul className={styles.info}> <ul className={styles.info}>
@ -31,11 +30,27 @@ class Nav extends Component {
<li className={`${styles.balance} ${styles.link}`}> <li className={`${styles.balance} ${styles.link}`}>
<p data-hint='Wallet balance' className='hint--bottom-left'> <p data-hint='Wallet balance' className='hint--bottom-left'>
<span>{ticker.currency === 'btc' ? <FaBitcoin /> : <FaDollar />}</span> <span>{ticker.currency === 'btc' ? <FaBitcoin /> : <FaDollar />}</span>
<span>{satoshisToBtc(balance.walletBalance)}</span> <span>
{
ticker.currency === 'btc' ?
satoshisToBtc(balance.walletBalance)
:
satoshisToUsd(balance.walletBalance, ticker.btcTicker.price_usd)
}
</span>
</p> </p>
<p data-hint='Channel balance' className='hint--bottom-left'> <p data-hint='Channel balance' className='hint--bottom-left'>
<span>{ticker.currency === 'btc' ? <FaBitcoin /> : <FaDollar />}</span> <span>
<span>{satoshisToBtc(balance.channelBalance)}</span> {ticker.currency === 'btc' ? <FaBitcoin /> : <FaDollar />}
</span>
<span>
{
ticker.currency === 'btc' ?
satoshisToBtc(balance.channelBalance)
:
satoshisToUsd(balance.channelBalance, ticker.btcTicker.price_usd)
}
</span>
</p> </p>
</li> </li>
</ul> </ul>

2
app/utils/bitcoin.js

@ -19,5 +19,5 @@ export function satoshisToUsd(satoshis, price) {
} }
export function btcToUsd(btc, price) { export function btcToUsd(btc, price) {
return (btc * price).toFixed(2) return parseFloat((btc * price).toFixed(2)).toLocaleString('en')
} }
Loading…
Cancel
Save