Skip to content

Commit

Permalink
feat(algo): fix refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip London committed Jun 25, 2020
1 parent 34b0918 commit 2f81e44
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default () => {
yield put(actions.core.data.eth.fetchData())
yield put(actions.core.data.xlm.fetchData())
yield put(actions.core.data.eth.fetchErc20Data('pax'))
yield put(actions.components.interest.fetchInterestAccountBalance())
yield put(actions.components.interest.fetchInterestBalance())
yield put(actions.components.simpleBuy.fetchSBBalances())
yield put(actions.components.simpleBuy.fetchSBOrders())
// Rates
Expand All @@ -39,6 +39,9 @@ export default () => {
case contains('/xlm/transactions', pathname):
yield call(refreshXlmTransactions)
break
case contains('/algo/transactions', pathname):
yield call(refreshAlgoTransactions)
break
case contains('/lockbox/', pathname):
yield put(actions.lockbox.initializeDashboard(pathname.split('/')[3]))
break
Expand Down Expand Up @@ -66,6 +69,8 @@ export default () => {
yield put(actions.core.data.xlm.fetchTransactions('', true))
}
} catch (e) {
// eslint-disable-next-line
console.log(e)
yield put(
actions.logs.logErrorMessage(
'components/refresh/sagas',
Expand Down Expand Up @@ -96,6 +101,10 @@ export default () => {
yield put(actions.core.data.xlm.fetchTransactions(null, true))
}

const refreshAlgoTransactions = function * () {
yield put(actions.core.data.algo.fetchTransactions(null, true))
}

return {
refreshClicked,
refreshBchTransactions,
Expand Down
12 changes: 10 additions & 2 deletions packages/blockchain-wallet-v4/src/redux/data/algo/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,22 @@ export const algoReducer = (
transactions: [Remote.Failure(action.payload)]
}
case AT.FETCH_ALGO_TRANSACTIONS_LOADING:
const { reset } = action.payload
return {
...state,
transactions: [...state.transactions, Remote.Loading]
transactions: reset
? [Remote.Loading]
: [...state.transactions, Remote.Loading]
}
case AT.FETCH_ALGO_TRANSACTIONS_SUCCESS:
return {
...state,
transactions: [...state.transactions, Remote.Success(action.payload)]
transactions: [
Remote.Success(action.payload.transactions),
...state.transactions.filter(
(tx, i) => i !== state.transactions.length - 1
)
]
}
default: {
return state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ export default ({ api }) => {

return function * coreDataAlgoSaga () {
yield takeLatest(AT.FETCH_ALGO_RATES, dataAlgoSagas.fetchRates)
yield takeLatest(
AT.FETCH_ALGO_TRANSACTIONS,
dataAlgoSagas.fetchTransactions
)
}
}
45 changes: 43 additions & 2 deletions packages/blockchain-wallet-v4/src/redux/data/algo/sagas.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import { call, put } from 'redux-saga/effects'
import { call, put, select } from 'redux-saga/effects'
import { flatten, last, length } from 'ramda'

import { APIType } from 'core/network/api'
import Remote from '../../../remote'

import * as A from './actions'
import * as S from './selectors'
import { SBOrderType } from 'core/types'
import moment from 'moment'
import simpleBuySagas from '../simpleBuy/sagas'

const TX_PER_PAGE = 10

export default ({ api }: { api: APIType }) => {
const { fetchSBOrders } = simpleBuySagas({ api })

const fetchRates = function * () {
try {
yield put(A.fetchRatesLoading())
Expand All @@ -15,7 +25,38 @@ export default ({ api }: { api: APIType }) => {
}
}

const fetchTransactions = function * (
action: ReturnType<typeof A.fetchTransactions>
) {
try {
const { payload } = action
const { reset } = payload
const pages = yield select(S.getTransactions)
const offset = reset ? 0 : length(pages) * TX_PER_PAGE
const transactionsAtBound = yield select(S.getTransactionsAtBound)
if (Remote.Loading.is(last(pages))) return
if (transactionsAtBound && !reset) return
yield put(A.fetchTransactionsLoading(reset))
let txs: Array<any> = []
const txPage: Array<any> = txs
const sbPage: Array<SBOrderType> = yield call(
fetchSBOrders,
txPage,
offset,
true,
'ALGO'
)
const page = flatten([txPage, sbPage]).sort((a, b) => {
return moment(b.insertedAt).valueOf() - moment(a.insertedAt).valueOf()
})
yield put(A.fetchTransactionsSuccess(page, reset, true))
} catch (e) {
yield put(A.fetchTransactionsFailure(e.message))
}
}

return {
fetchRates
fetchRates,
fetchTransactions
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ export const getRates = (state: RootState) => {
export const getTransactions = (state: RootState) => {
return state.dataPath.algo.transactions
}

export const getTransactionsAtBound = (state: RootState) => {
return state.dataPath.algo.transactions_at_bound
}

0 comments on commit 2f81e44

Please sign in to comment.