-
Notifications
You must be signed in to change notification settings - Fork 504
/
sagas.js
56 lines (51 loc) · 1.69 KB
/
sagas.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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'
const initialized = function * () {
try {
const initialValues = {
status: '',
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))
} catch (e) {
yield put(actions.logs.logErrorMessage(logLocation, 'initialized', e))
}
}
const scrollUpdated = function * (action) {
try {
const pathname = yield select(selectors.router.getPathname)
if (!equals(pathname, '/eth/transactions')) return
const threshold = 250
const { yMax, yOffset } = action.payload
if (yMax - yOffset < threshold) {
yield put(actions.core.data.ethereum.fetchData())
}
} catch (e) {
yield put(actions.logs.logErrorMessage(logLocation, 'scrollUpdated', e))
}
}
const formChanged = function * (action) {
try {
const form = path(['meta', 'form'], action)
const field = path(['meta', 'field'], action)
if (!equals('ethTransactions', form)) return
switch (field) {
case 'source':
yield put(actions.core.data.ethereum.fetchData())
}
} catch (e) {
yield put(actions.logs.logErrorMessage(logLocation, 'formChanged', e))
}
}
return {
initialized,
formChanged,
scrollUpdated
}
}