Skip to content

Commit

Permalink
fix - transactions pages issue with endless scroll.
Browse files Browse the repository at this point in the history
refactoring - balances
  • Loading branch information
Lyncee59 committed Jun 18, 2018
1 parent 526860b commit f1682d5
Show file tree
Hide file tree
Showing 36 changed files with 239 additions and 321 deletions.
Expand Up @@ -11,9 +11,9 @@ export default ({ coreSagas }) => {
const bchTransactions = yield select(selectors.core.data.bch.getTransactions)
const ethTransactions = yield select(selectors.core.data.ethereum.getTransactions)
if (!Remote.Success.is(logsR)) yield put(actions.core.data.misc.fetchLogs())
if (isEmpty(btcTransactions)) yield put(actions.core.data.bitcoin.fetchData('', true))
if (isEmpty(bchTransactions)) yield put(actions.core.data.bch.fetchData('', true))
if (isEmpty(ethTransactions)) yield put(actions.core.data.ethereum.fetchData())
if (isEmpty(btcTransactions)) yield put(actions.core.data.bitcoin.fetchTransactions('', true))
if (isEmpty(bchTransactions)) yield put(actions.core.data.bch.fetchTransactions('', true))
if (isEmpty(ethTransactions)) yield put(actions.core.data.ethereum.fetchTransactions())
} catch (e) {
yield put(actions.logs.logErrorMessage('components/activityList/sagas', 'initialized', e))
}
Expand Down
@@ -1,6 +1,5 @@
import { select, put } from 'redux-saga/effects'
import { equals, path, prop } from 'ramda'
import { Remote } from 'blockchain-wallet-v4/src'
import { actions, selectors } from 'data'

export default ({ coreSagas }) => {
Expand All @@ -14,8 +13,7 @@ export default ({ coreSagas }) => {
search: ''
}
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, true))
yield put(actions.core.data.bch.fetchTransactions(defaultSource, true))
} catch (e) {
yield put(actions.logs.logErrorMessage(logLocation, 'initialized', e))
}
Expand All @@ -38,7 +36,7 @@ export default ({ coreSagas }) => {
const threshold = 250
const { yMax, yOffset } = action.payload
if (yMax - yOffset < threshold) {
yield put(actions.core.data.bch.fetchData(source, false))
yield put(actions.core.data.bch.fetchTransactions(source, false))
}
} catch (e) {
yield put(actions.logs.logErrorMessage(logLocation, 'scrollUpdated', e))
Expand All @@ -55,7 +53,7 @@ export default ({ coreSagas }) => {
switch (field) {
case 'source':
const onlyShow = equals(payload, 'all') ? '' : (payload.xpub || payload.address)
yield put(actions.core.data.bch.fetchData(onlyShow, true))
yield put(actions.core.data.bch.fetchTransactions(onlyShow, true))
}
} catch (e) {
yield put(actions.logs.logErrorMessage(logLocation, 'formChanged', e))
Expand Down
Expand Up @@ -8,15 +8,13 @@ export default ({ coreSagas }) => {

const initialized = function * () {
try {
const defaultSource = ''
const initialValues = {
source: defaultSource,
source: '',
status: '',
search: ''
}
yield put(actions.form.initialize('btcTransactions', initialValues))
const btcTransactionsR = yield select(selectors.core.data.bitcoin.getTransactions)
if (!Remote.Success.is(btcTransactionsR)) yield put(actions.core.data.bitcoin.fetchData(defaultSource, true))
yield put(actions.core.data.bitcoin.fetchTransactions(initialValues.source))
} catch (e) {
yield put(actions.logs.logErrorMessage(logLocation, 'initialized', e))
}
Expand All @@ -40,7 +38,7 @@ export default ({ coreSagas }) => {
const { yMax, yOffset } = action.payload

if (yMax - yOffset < threshold) {
yield put(actions.core.data.bitcoin.fetchData(source, false))
yield put(actions.core.data.bitcoin.fetchTransactions(source, false))
}
} catch (e) {
yield put(actions.logs.logErrorMessage(logLocation, 'scrollUpdated', e))
Expand All @@ -57,7 +55,7 @@ export default ({ coreSagas }) => {
switch (field) {
case 'source':
const onlyShow = equals(payload, 'all') ? '' : (payload.xpub || payload.address)
yield put(actions.core.data.bitcoin.fetchData(onlyShow, true))
yield put(actions.core.data.bitcoin.fetchTransactions(onlyShow, true))
}
} catch (e) {
yield put(actions.logs.logErrorMessage(logLocation, 'formChanged', e))
Expand Down
@@ -1,7 +1,6 @@
import { select, put } from 'redux-saga/effects'
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 @@ -12,8 +11,7 @@ export default ({ coreSagas }) => {
search: ''
}
yield put(actions.form.initialize('ethTransactions', initialValues))
const ethTransactionsR = yield select(selectors.core.data.ethereum.getTransactions)
if (!Remote.Success.is(ethTransactionsR)) yield put(actions.core.data.ethereum.fetchData(true))
yield put(actions.core.data.ethereum.fetchTransactions())
} catch (e) {
yield put(actions.logs.logErrorMessage(logLocation, 'initialized', e))
}
Expand All @@ -27,7 +25,7 @@ export default ({ coreSagas }) => {
const { yMax, yOffset } = action.payload

if (yMax - yOffset < threshold) {
yield put(actions.core.data.ethereum.fetchData())
yield put(actions.core.data.ethereum.fetchTransactions())
}
} catch (e) {
yield put(actions.logs.logErrorMessage(logLocation, 'scrollUpdated', e))
Expand All @@ -41,7 +39,7 @@ export default ({ coreSagas }) => {
if (!equals('ethTransactions', form)) return
switch (field) {
case 'source':
yield put(actions.core.data.ethereum.fetchData())
yield put(actions.core.data.ethereum.fetchTransactions())
}
} catch (e) {
yield put(actions.logs.logErrorMessage(logLocation, 'formChanged', e))
Expand Down
Expand Up @@ -139,7 +139,7 @@ export default ({ coreSagas }) => {
if (path(['description', 'length'], payment.value())) {
yield put(actions.core.kvStore.bch.setTxNotesBch(payment.value().txId, payment.value().description))
}
yield put(actions.core.data.bch.fetchData('', true))
yield put(actions.core.data.bch.fetchData())
yield put(actions.router.push('/bch/transactions'))
yield put(actions.alerts.displaySuccess(C.SEND_BCH_SUCCESS))
} catch (e) {
Expand Down
Expand Up @@ -214,7 +214,7 @@ export default ({ coreSagas }) => {
payment = yield payment.sign(password)
payment = yield payment.publish()
yield put(A.sendBtcPaymentUpdated(Remote.of(payment.value())))
yield put(actions.core.data.bitcoin.fetchData('', true))
yield put(actions.core.data.bitcoin.fetchData())
if (path(['description', 'length'], payment.value())) {
yield put(actions.core.wallet.setTransactionNote(payment.value().txId, payment.value().description))
}
Expand Down
Expand Up @@ -2,7 +2,6 @@ import React from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'

import { Remote } from 'blockchain-wallet-v4/src'
import { actions } from 'data'
import { getData } from './selectors'
import Error from './template.error'
Expand All @@ -16,13 +15,11 @@ class BchBalance extends React.PureComponent {
}

componentWillMount () {
if (Remote.NotAsked.is(this.props.data)) {
this.props.actions.fetchSpendableBalance()
}
this.props.actions.fetchData()
}

handleRefresh () {
this.props.actions.fetchSpendableBalance()
this.props.actions.fetchData()
}

render () {
Expand Down
@@ -1,3 +1,15 @@
import { selectors } from 'data'
import { createDeepEqualSelector } from 'services/ReselectHelper'
import { add, traverse, reduce } from 'ramda'
import { Remote } from 'blockchain-wallet-v4/src'

export const getData = selectors.core.data.bch.getSpendableBalance
export const getData = state => createDeepEqualSelector(
[
selectors.core.kvStore.bch.getSpendableContext
],
(context) => {
const getBalance = address => selectors.core.data.bch.getFinalBalance(address, state)
const balancesR = traverse(Remote.of, getBalance, context)
return balancesR.map(xs => reduce(add, 0, xs))
}
)(state)
Expand Up @@ -2,7 +2,6 @@ import React from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'

import { Remote } from 'blockchain-wallet-v4/src'
import { actions } from 'data'
import { getData } from './selectors'
import Error from './template.error'
Expand All @@ -16,13 +15,11 @@ class BchWatchOnlyBalance extends React.PureComponent {
}

componentWillMount () {
if (Remote.NotAsked.is(this.props.data)) {
this.props.actions.fetchUnspendableBalance()
}
this.props.actions.fetchData()
}

handleRefresh () {
this.props.actions.fetchUnspendableBalance()
this.props.actions.fetchData()
}

render () {
Expand Down
@@ -1,3 +1,15 @@
import { selectors } from 'data'
import { createDeepEqualSelector } from 'services/ReselectHelper'
import { add, traverse, reduce } from 'ramda'
import { Remote } from 'blockchain-wallet-v4/src'

export const getData = selectors.core.data.bch.getUnspendableBalance
export const getData = state => createDeepEqualSelector(
[
selectors.core.kvStore.bch.getUnspendableContext
],
(context) => {
const getBalance = address => selectors.core.data.bch.getFinalBalance(address, state)
const balancesR = traverse(Remote.of, getBalance, context)
return balancesR.map(xs => reduce(add, 0, xs))
}
)(state)
Expand Up @@ -2,7 +2,6 @@ import React from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'

import { Remote } from 'blockchain-wallet-v4/src'
import { actions } from 'data'
import { getData } from './selectors'
import Error from './template.error'
Expand All @@ -16,13 +15,11 @@ class BtcBalance extends React.PureComponent {
}

componentWillMount () {
if (Remote.NotAsked.is(this.props.data)) {
this.props.actions.fetchSpendableBalance()
}
this.props.actions.fetchData()
}

handleRefresh () {
this.props.actions.fetchSpendableBalance()
this.props.actions.fetchData()
}

render () {
Expand Down
@@ -1,3 +1,15 @@
import { selectors } from 'data'
import { createDeepEqualSelector } from 'services/ReselectHelper'
import { add, traverse, reduce } from 'ramda'
import { Remote } from 'blockchain-wallet-v4/src'

export const getData = selectors.core.data.bitcoin.getSpendableBalance
export const getData = state => createDeepEqualSelector(
[
selectors.core.wallet.getSpendableContext
],
(context) => {
const getBalance = address => selectors.core.data.bitcoin.getFinalBalance(address, state)
const balancesR = traverse(Remote.of, getBalance, context)
return balancesR.map(xs => reduce(add, 0, xs))
}
)(state)
Expand Up @@ -2,7 +2,6 @@ import React from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'

import { Remote } from 'blockchain-wallet-v4/src'
import { actions } from 'data'
import { getData } from './selectors'
import Error from './template.error'
Expand All @@ -16,13 +15,11 @@ class BtcWatchOnlyBalance extends React.PureComponent {
}

componentWillMount () {
if (Remote.NotAsked.is(this.props.data)) {
this.props.actions.fetchUnspendableBalance()
}
this.props.actions.fetchData()
}

handleRefresh () {
this.props.actions.fetchUnspendableBalance()
this.props.actions.fetchData()
}

render () {
Expand Down
@@ -1,3 +1,15 @@
import { selectors } from 'data'
import { createDeepEqualSelector } from 'services/ReselectHelper'
import { add, traverse, reduce } from 'ramda'
import { Remote } from 'blockchain-wallet-v4/src'

export const getData = selectors.core.data.bitcoin.getUnspendableBalance
export const getData = state => createDeepEqualSelector(
[
selectors.core.wallet.getUnspendableContext
],
(context) => {
const getBalance = address => selectors.core.data.bitcoin.getFinalBalance(address, state)
const balancesR = traverse(Remote.of, getBalance, context)
return balancesR.map(xs => reduce(add, 0, xs))
}
)(state)
Expand Up @@ -2,7 +2,6 @@ import React from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'

import { Remote } from 'blockchain-wallet-v4/src'
import { actions } from 'data'
import { getData } from './selectors'
import Error from './template.error'
Expand All @@ -16,9 +15,7 @@ class EthBalance extends React.PureComponent {
}

componentWillMount () {
if (Remote.NotAsked.is(this.props.data)) {
this.props.actions.fetchData()
}
this.props.actions.fetchData()
}

handleRefresh () {
Expand Down
@@ -1,23 +1,32 @@
import { lift } from 'ramda'
import { add, lift, reduce, traverse } from 'ramda'
import { selectors } from 'data'
import { Exchange, Remote } from 'blockchain-wallet-v4/src'
import * as Currency from 'blockchain-wallet-v4/src/exchange/currency'
import { createDeepEqualSelector } from 'services/ReselectHelper'

export const getBtcBalance = createDeepEqualSelector(
[selectors.core.data.bitcoin.getSpendableBalance],
(btcBalanceR) => Remote.of(btcBalanceR.getOrElse(0))
)
export const getBtcBalance = state => createDeepEqualSelector(
[
selectors.core.wallet.getSpendableContext
],
(context) => {
const getBalance = address => selectors.core.data.bitcoin.getFinalBalance(address, state)
const balancesR = traverse(Remote.of, getBalance, context)
return balancesR.map(xs => reduce(add, 0, xs))
}
)(state)

export const getBchBalance = createDeepEqualSelector(
[selectors.core.data.bch.getSpendableBalance],
(bchBalanceR) => Remote.of(bchBalanceR.getOrElse(0))
)
export const getBchBalance = state => createDeepEqualSelector(
[
selectors.core.kvStore.bch.getSpendableContext
],
(context) => {
const getBalance = address => selectors.core.data.bch.getFinalBalance(address, state)
const balancesR = traverse(Remote.of, getBalance, context)
return balancesR.map(xs => reduce(add, 0, xs))
}
)(state)

export const getEthBalance = createDeepEqualSelector(
[selectors.core.data.ethereum.getBalance],
(ethBalanceR) => Remote.of(ethBalanceR.getOrElse(0))
)
export const getEthBalance = selectors.core.data.ethereum.getBalance

export const getBtcBalanceInfo = createDeepEqualSelector(
[
Expand Down
12 changes: 0 additions & 12 deletions packages/blockchain-wallet-v4/src/redux/data/bch/actionTypes.js
Expand Up @@ -30,15 +30,3 @@ export const FETCH_BCH_TRANSACTION_HISTORY_LOADING = '@CORE.FETCH_BCH_TRANSACTIO
export const FETCH_BCH_TRANSACTION_HISTORY_SUCCESS = '@CORE.FETCH_BCH_TRANSACTION_HISTORY_SUCCESS'
export const FETCH_BCH_TRANSACTION_HISTORY_FAILURE = '@CORE.FETCH_BCH_TRANSACTION_HISTORY_FAILURE'
export const CLEAR_BCH_TRANSACTION_HISTORY = '@CORE.CLEAR_BCH_TRANSACTION_HISTORY'

// FETCH_BCH_TRANSACTION_HISTORY
export const FETCH_BCH_SPENDABLE_BALANCE = '@CORE.FETCH_BCH_SPENDABLE_BALANCE'
export const FETCH_BCH_SPENDABLE_BALANCE_LOADING = '@CORE.FETCH_BCH_SPENDABLE_BALANCE_LOADING'
export const FETCH_BCH_SPENDABLE_BALANCE_SUCCESS = '@CORE.FETCH_BCH_SPENDABLE_BALANCE_SUCCESS'
export const FETCH_BCH_SPENDABLE_BALANCE_FAILURE = '@CORE.FETCH_BCH_SPENDABLE_BALANCE_FAILURE'

// FETCH_BCH_TRANSACTION_HISTORY
export const FETCH_BCH_UNSPENDABLE_BALANCE = '@CORE.FETCH_BCH_UNSPENDABLE_BALANCE'
export const FETCH_BCH_UNSPENDABLE_BALANCE_LOADING = '@CORE.FETCH_BCH_UNSPENDABLE_BALANCE_LOADING'
export const FETCH_BCH_UNSPENDABLE_BALANCE_SUCCESS = '@CORE.FETCH_BCH_UNSPENDABLE_BALANCE_SUCCESS'
export const FETCH_BCH_UNSPENDABLE_BALANCE_FAILURE = '@CORE.FETCH_BCH_UNSPENDABLE_BALANCE_FAILURE'

0 comments on commit f1682d5

Please sign in to comment.