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

Commit

Permalink
fix(wallet): refetch fiat tickers when forms open
Browse files Browse the repository at this point in the history
Refetch fiat ticker data every time one of our payment forms are open
in order to help ensure that conversion rates are up to date. Covers
the Pay, Request and CreateChannel forms.

Fix #1953
  • Loading branch information
mrfelton committed Apr 6, 2019
1 parent 9c75d64 commit 82c00bd
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 5 deletions.
4 changes: 3 additions & 1 deletion renderer/components/Channels/ChannelCreateForm.js
Expand Up @@ -88,6 +88,7 @@ class ChannelCreateForm extends React.Component {
}).isRequired,
currency: PropTypes.string.isRequired,
currencyName: PropTypes.string.isRequired,
fetchTickers: PropTypes.func.isRequired,
intl: intlShape.isRequired,
isQueryingFees: PropTypes.bool,
onchainFees: PropTypes.shape({
Expand All @@ -110,7 +111,8 @@ class ChannelCreateForm extends React.Component {
}

componentDidMount() {
const { queryFees } = this.props
const { fetchTickers, queryFees } = this.props
fetchTickers()
queryFees()
}

Expand Down
5 changes: 4 additions & 1 deletion renderer/components/Pay/Pay.js
Expand Up @@ -77,6 +77,8 @@ class Pay extends React.Component {
cryptoCurrencyTicker: PropTypes.string.isRequired,
/** Ticker symbol of the currently selected cryptocurrency. */
cryptoName: PropTypes.string.isRequired,
/** Fetch fiat ticker data. */
fetchTickers: PropTypes.func.isRequired,
/** Amount value to populate the amountCrypto field with when the form first loads. */
initialAmountCrypto: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
/** Amount value to populate the amountFiat field with when the form first loads. */
Expand Down Expand Up @@ -134,10 +136,11 @@ class Pay extends React.Component {

// Set a flag so that we can trigger form submission in componentDidUpdate once the form is loaded.
componentDidMount() {
const { payReq, queryFees } = this.props
const { fetchTickers, payReq, queryFees } = this.props
if (payReq) {
this.setState({ isPayReqSetOnMount: true })
}
fetchTickers()
queryFees()
}

Expand Down
4 changes: 4 additions & 0 deletions renderer/components/Request/Request.js
Expand Up @@ -25,6 +25,8 @@ class Request extends React.Component {
cryptoCurrencyTicker: PropTypes.string.isRequired,
/** Boolean indicating wether the form is being processed. If true, form buttons are disabled. */
cryptoName: PropTypes.string.isRequired,
/** Fetch fiat ticker data. */
fetchTickers: PropTypes.func.isRequired,
/** Lnd invoice object for the payment request */
intl: intlShape.isRequired,
/** Lightning Payment request. */
Expand All @@ -44,6 +46,8 @@ class Request extends React.Component {
amountInput = React.createRef()

componentDidMount() {
const { fetchTickers } = this.props
fetchTickers()
this.focusAmountInput()
}

Expand Down
3 changes: 2 additions & 1 deletion renderer/containers/Channels/ChannelCreateForm.js
@@ -1,6 +1,6 @@
import { connect } from 'react-redux'
import ChannelCreateForm from 'components/Channels/ChannelCreateForm'
import { tickerSelectors } from 'reducers/ticker'
import { fetchTickers, tickerSelectors } from 'reducers/ticker'
import { openChannel } from 'reducers/channels'
import { queryFees } from 'reducers/pay'
import { balanceSelectors } from 'reducers/balance'
Expand All @@ -20,6 +20,7 @@ const mapStateToProps = state => ({
})

const mapDispatchToProps = {
fetchTickers,
openChannel,
queryFees,
updateContactFormSearchQuery,
Expand Down
3 changes: 2 additions & 1 deletion renderer/containers/Pay.js
@@ -1,6 +1,6 @@
import { connect } from 'react-redux'
import { Pay } from 'components/Pay'
import { tickerSelectors } from 'reducers/ticker'
import { fetchTickers, tickerSelectors } from 'reducers/ticker'
import { setPayReq, queryFees, queryRoutes } from 'reducers/pay'
import { changeFilter } from 'reducers/activity'
import { sendCoins } from 'reducers/transaction'
Expand All @@ -24,6 +24,7 @@ const mapStateToProps = state => ({
const mapDispatchToProps = {
changeFilter,
closeModal,
fetchTickers,
payInvoice,
setPayReq,
sendCoins,
Expand Down
3 changes: 2 additions & 1 deletion renderer/containers/Request.js
@@ -1,6 +1,6 @@
import { connect } from 'react-redux'
import { Request } from 'components/Request'
import { tickerSelectors } from 'reducers/ticker'
import { fetchTickers, tickerSelectors } from 'reducers/ticker'
import { createInvoice, invoiceSelectors } from 'reducers/invoice'
import { showNotification } from 'reducers/notification'

Expand All @@ -15,6 +15,7 @@ const mapStateToProps = state => ({

const mapDispatchToProps = {
createInvoice,
fetchTickers,
showNotification,
}

Expand Down

0 comments on commit 82c00bd

Please sign in to comment.