Skip to content

Commit

Permalink
fix(Transactions): refresh transactions if not in a successful state
Browse files Browse the repository at this point in the history
  • Loading branch information
plondon committed Jun 5, 2018
1 parent f1e1b3a commit 459b05f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
Expand Up @@ -15,7 +15,7 @@ export default ({ coreSagas }) => {
}
yield put(actions.form.initialize('bchTransactions', initialValues))
const bchTransactionsR = yield select(selectors.core.data.bch.getTransactions)
if (!Remote.Success.is(bchTransactionsR)) yield put(actions.core.data.bch.fetchData(defaultSource))
if (!Remote.Success.is(bchTransactionsR)) yield put(actions.core.data.bch.fetchData(defaultSource, true))
} catch (e) {
yield put(actions.logs.logErrorMessage(logLocation, 'initialized', e))
}
Expand Down
@@ -1,6 +1,7 @@
import { select, put } from 'redux-saga/effects'
import { equals, isEmpty, path } from 'ramda'
import { equals, path } from 'ramda'
import { actions, selectors } from 'data'
import { Remote } from 'blockchain-wallet-v4/src'

export default ({ coreSagas }) => {
const logLocation = 'components/ethTransactions/sagas'
Expand All @@ -11,9 +12,8 @@ export default ({ coreSagas }) => {
search: ''
}
yield put(actions.form.initialize('ethTransactions', initialValues))
const ethTransactions = yield select(selectors.core.data.ethereum.getTransactions)
// Add context here
if (isEmpty(ethTransactions)) yield put(actions.core.data.ethereum.fetchData())
const ethTransactionsR = yield select(selectors.core.data.ethereum.getTransactions)
if (!Remote.Success.is(ethTransactionsR)) yield put(actions.core.data.ethereum.fetchData(true))
} catch (e) {
yield put(actions.logs.logErrorMessage(logLocation, 'initialized', e))
}
Expand Down
Expand Up @@ -27,6 +27,6 @@ export const fetchRatesSuccess = (data) => ({ type: AT.FETCH_ETHEREUM_RATES_SUCC
export const fetchRatesFailure = (error) => ({ type: AT.FETCH_ETHEREUM_RATES_FAILURE, payload: error })

// FETCH_ETHEREUM_TRANSACTIONS
export const fetchTransactionsLoading = () => ({ type: AT.FETCH_ETHEREUM_TRANSACTIONS_LOADING })
export const fetchTransactionsLoading = (reset) => ({ type: AT.FETCH_ETHEREUM_TRANSACTIONS_LOADING, payload: { reset } })
export const fetchTransactionsSuccess = (transactions, reset) => ({ type: AT.FETCH_ETHEREUM_TRANSACTIONS_SUCCESS, payload: { transactions, reset } })
export const fetchTransactionsFailure = (error) => ({ type: AT.FETCH_ETHEREUM_TRANSACTIONS_FAILURE, payload: error })
Expand Up @@ -67,7 +67,10 @@ export default (state = INITIAL_STATE, action) => {
return assoc('rates', Remote.Failure(payload), state)
}
case AT.FETCH_ETHEREUM_TRANSACTIONS_LOADING: {
return over(lensProp('transactions'), append(Remote.Loading), state)
const { reset } = payload
return reset
? assoc('transactions', [Remote.Loading], state)
: over(lensProp('transactions'), append(Remote.Loading), state)
}
case AT.FETCH_ETHEREUM_TRANSACTIONS_SUCCESS: {
const { transactions, reset } = payload
Expand Down
Expand Up @@ -45,7 +45,7 @@ export default ({ api }) => {
const address = defaultAccountR.getOrFail('Could not get ethereum context.')
const pages = reset ? [] : yield select(S.getTransactions)
const nextPage = length(pages)
yield put(A.fetchTransactionsLoading())
yield put(A.fetchTransactionsLoading(reset))
const data = yield call(api.getEthereumTransactions, address, nextPage)
const latestBlock = yield call(api.getEthereumLatestBlock)
yield call(accountSaga, data, latestBlock)
Expand Down

0 comments on commit 459b05f

Please sign in to comment.