Skip to content

Commit 6b9d96d

Browse files
committed
feat: add balance history section to account page
1 parent 5e7986b commit 6b9d96d

File tree

19 files changed

+464
-32
lines changed

19 files changed

+464
-32
lines changed

src/core/accounts/account.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const Account = new Record({
77
account_is_loading_open: true,
88
account_is_loading_blocks_change_summary: true,
99
account_is_loading_blocks_send_summary: true,
10+
account_is_loading_balance_history: false,
1011

1112
account: null,
1213
alias: null,
@@ -22,6 +23,7 @@ export const Account = new Record({
2223
telemetry: new Map(),
2324
delegators: new List(),
2425
open: new Map(),
26+
balance_history: new List(),
2527

2628
blocks_summary: new Map(),
2729

src/core/accounts/actions.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ export const accountsActions = {
2121
GET_ACCOUNT_BLOCKS_SUMMARY_PENDING: 'GET_ACCOUNT_BLOCKS_SUMMARY_PENDING',
2222
GET_ACCOUNT_BLOCKS_SUMMARY_FULFILLED: 'GET_ACCOUNT_BLOCKS_SUMMARY_FULFILLED',
2323

24+
GET_ACCOUNT_BALANCE_HISTORY: 'GET_ACCOUNT_BALANCE_HISTORY',
25+
GET_ACCOUNT_BALANCE_HISTORY_FAILED: 'GET_ACCOUNT_BALANCE_HISTORY_FAILED',
26+
GET_ACCOUNT_BALANCE_HISTORY_PENDING: 'GET_ACCOUNT_BALANCE_HISTORY_PENDING',
27+
GET_ACCOUNT_BALANCE_HISTORY_FULFILLED:
28+
'GET_ACCOUNT_BALANCE_HISTORY_FULFILLED',
29+
2430
filter: ({ field, value, label } = {}) => ({
2531
type: accountsActions.FILTER_REPRESENTATIVES,
2632
payload: {
@@ -138,6 +144,36 @@ export const accountsActions = {
138144
params,
139145
data
140146
}
147+
}),
148+
149+
getAccountBalanceHistory: (account) => ({
150+
type: accountsActions.GET_ACCOUNT_BALANCE_HISTORY,
151+
payload: {
152+
account
153+
}
154+
}),
155+
156+
getAccountBalanceHistoryFailed: (params, error) => ({
157+
type: accountsActions.GET_ACCOUNT_BALANCE_HISTORY_FAILED,
158+
payload: {
159+
params,
160+
error
161+
}
162+
}),
163+
164+
getAccountBalanceHistoryPending: (params) => ({
165+
type: accountsActions.GET_ACCOUNT_BALANCE_HISTORY_PENDING,
166+
payload: {
167+
params
168+
}
169+
}),
170+
171+
getAccountBalanceHistoryFulfilled: (params, data) => ({
172+
type: accountsActions.GET_ACCOUNT_BALANCE_HISTORY_FULFILLED,
173+
payload: {
174+
params,
175+
data
176+
}
141177
})
142178
}
143179

@@ -164,3 +200,9 @@ export const accountOpenRequestActions = {
164200
pending: accountsActions.getAccountOpenPending,
165201
fulfilled: accountsActions.getAccountOpenFulfilled
166202
}
203+
204+
export const accountBalanceHistoryRequestActions = {
205+
failed: accountsActions.getAccountBalanceHistoryFailed,
206+
pending: accountsActions.getAccountBalanceHistoryPending,
207+
fulfilled: accountsActions.getAccountBalanceHistoryFulfilled
208+
}

src/core/accounts/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ export {
33
representativesRequestActions,
44
accountRequestActions,
55
accountOpenRequestActions,
6-
accountBlocksSummaryRequestActions
6+
accountBlocksSummaryRequestActions,
7+
accountBalanceHistoryRequestActions
78
} from './actions'
89
export { accountsReducer } from './reducer'
910
export { accountSagas } from './sagas'

src/core/accounts/reducer.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Map } from 'immutable'
1+
import { Map, List } from 'immutable'
22

33
import { accountsActions } from './actions'
44
import { createAccount } from './account'
@@ -98,6 +98,34 @@ export function accountsReducer(state = initialState, { payload, type }) {
9898
)
9999
})
100100

101+
case accountsActions.GET_ACCOUNT_BALANCE_HISTORY_PENDING:
102+
return state.setIn(
103+
['items', payload.params.account, 'account_is_loading_balance_history'],
104+
true
105+
)
106+
107+
case accountsActions.GET_ACCOUNT_BALANCE_HISTORY_FAILED:
108+
return state.setIn(
109+
['items', payload.params.account, 'account_is_loading_balance_history'],
110+
false
111+
)
112+
113+
case accountsActions.GET_ACCOUNT_BALANCE_HISTORY_FULFILLED:
114+
return state.withMutations((state) => {
115+
state.setIn(
116+
['items', payload.params.account, 'balance_history'],
117+
List(payload.data)
118+
)
119+
state.setIn(
120+
[
121+
'items',
122+
payload.params.account,
123+
'account_is_loading_balance_history'
124+
],
125+
false
126+
)
127+
})
128+
101129
default:
102130
return state
103131
}

src/core/accounts/sagas.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { takeEvery, fork, call, takeLatest } from 'redux-saga/effects'
1+
import { takeEvery, fork, call, takeLatest, select } from 'redux-saga/effects'
22

33
import {
44
getRepresentatives,
55
getAccount,
66
getAccountOpen,
7-
getAccountBlocksSummary
7+
getAccountBlocksSummary,
8+
get_account_balance_history,
9+
get_request_history
810
} from '@core/api'
911
import { accountsActions } from './actions'
1012

@@ -21,6 +23,15 @@ export function* loadAccount({ payload }) {
2123
yield fork(getAccountBlocksSummary, { account, type: 'change', limit: 10 })
2224
}
2325

26+
export function* loadAccountBalanceHistory({ payload }) {
27+
const { account } = payload
28+
const request_history = yield select(get_request_history)
29+
if (request_history.has(`GET_ACCOUNT_BALANCE_HISTORY_${account}`)) {
30+
return
31+
}
32+
yield call(get_account_balance_history, { account })
33+
}
34+
2435
//= ====================================
2536
// WATCHERS
2637
// -------------------------------------
@@ -33,11 +44,19 @@ export function* watchGetAccount() {
3344
yield takeLatest(accountsActions.GET_ACCOUNT, loadAccount)
3445
}
3546

47+
export function* watchGetAccountBalanceHistory() {
48+
yield takeLatest(
49+
accountsActions.GET_ACCOUNT_BALANCE_HISTORY,
50+
loadAccountBalanceHistory
51+
)
52+
}
53+
3654
//= ====================================
3755
// ROOT
3856
// -------------------------------------
3957

4058
export const accountSagas = [
4159
fork(watchGetRepresentatives),
42-
fork(watchGetAccount)
60+
fork(watchGetAccount),
61+
fork(watchGetAccountBalanceHistory)
4362
]

src/core/api/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ export {
1818
getDaily,
1919
get_blocks_confirmed_summary,
2020
get_accounts_unconfirmed_summary,
21-
get_blocks_unconfirmed_summary
21+
get_blocks_unconfirmed_summary,
22+
get_account_balance_history,
23+
get_price_history
2224
} from './sagas'
2325

2426
export { api_reducer } from './reducer'

src/core/api/reducer.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Map } from 'immutable'
22

33
import { nanodb_actions } from '@core/nanodb/actions'
4+
import { accountsActions } from '@core/accounts/actions'
45

56
const initialState = new Map({
67
request_history: new Map()
@@ -35,6 +36,27 @@ export function api_reducer(state = initialState, { payload, type }) {
3536
'GET_ACCOUNTS_UNCONFIRMED_SUMMARY'
3637
])
3738

39+
case accountsActions.GET_ACCOUNT_BALANCE_HISTORY_PENDING:
40+
return state.setIn(
41+
[
42+
'request_history',
43+
`GET_ACCOUNT_BALANCE_HISTORY_${payload.params.account}`
44+
],
45+
true
46+
)
47+
48+
case accountsActions.GET_ACCOUNT_BALANCE_HISTORY_FAILED:
49+
return state.deleteIn([
50+
'request_history',
51+
`GET_ACCOUNT_BALANCE_HISTORY_${payload.params.account}`
52+
])
53+
54+
case nanodb_actions.GET_PRICE_HISTORY_PENDING:
55+
return state.setIn(['request_history', 'GET_PRICE_HISTORY'], true)
56+
57+
case nanodb_actions.GET_PRICE_HISTORY_FAILED:
58+
return state.deleteIn(['request_history', 'GET_PRICE_HISTORY'])
59+
3860
default:
3961
return state
4062
}

src/core/api/sagas.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ import {
2222
representativesRequestActions,
2323
accountRequestActions,
2424
accountOpenRequestActions,
25-
accountBlocksSummaryRequestActions
25+
accountBlocksSummaryRequestActions,
26+
accountBalanceHistoryRequestActions
2627
} from '@core/accounts/actions'
2728
import { blockRequestActions } from '@core/blocks/actions'
2829
import { dailyRequestActions } from '@core/ledger/actions'
2930
import {
3031
block_confirmed_summary_request_actions,
3132
accounts_unconfirmed_summary_request_actions,
32-
blocks_unconfirmed_summary_request_actions
33+
blocks_unconfirmed_summary_request_actions,
34+
price_history_request_actions
3335
} from '@core/nanodb/actions'
3436

3537
function* fetchAPI(apiFunction, actions, opts = {}) {
@@ -143,3 +145,15 @@ export const get_blocks_unconfirmed_summary = fetch.bind(
143145
api.get_blocks_unconfirmed_summary,
144146
blocks_unconfirmed_summary_request_actions
145147
)
148+
149+
export const get_account_balance_history = fetch.bind(
150+
null,
151+
api.get_account_balance_history,
152+
accountBalanceHistoryRequestActions
153+
)
154+
155+
export const get_price_history = fetch.bind(
156+
null,
157+
api.get_price_history,
158+
price_history_request_actions
159+
)

src/core/api/service.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ export const api = {
9595
get_blocks_unconfirmed_summary() {
9696
const url = `${API_URL}/nanodb/blocks/unconfirmed/summary`
9797
return { url }
98+
},
99+
get_account_balance_history({ account }) {
100+
const url = `${API_URL}/nanodb/accounts/${account}/balance_history`
101+
return { url }
102+
},
103+
get_price_history() {
104+
const url = `${API_URL}/nanodb/price_history`
105+
return { url }
98106
}
99107
}
100108

src/core/nanodb/actions.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ export const nanodb_actions = {
2424
GET_BLOCKS_UNCONFIRMED_SUMMARY_FULFILLED:
2525
'GET_BLOCKS_UNCONFIRMED_SUMMARY_FULFILLED',
2626

27+
GET_PRICE_HISTORY: 'GET_PRICE_HISTORY',
28+
GET_PRICE_HISTORY_FAILED: 'GET_PRICE_HISTORY_FAILED',
29+
GET_PRICE_HISTORY_PENDING: 'GET_PRICE_HISTORY_PENDING',
30+
GET_PRICE_HISTORY_FULFILLED: 'GET_PRICE_HISTORY_FULFILLED',
31+
2732
get_blocks_confirmed_summary: (period = '10m') => ({
2833
type: nanodb_actions.GET_BLOCKS_CONFIRMED_SUMMARY,
2934
payload: {
@@ -103,6 +108,33 @@ export const nanodb_actions = {
103108
params,
104109
data
105110
}
111+
}),
112+
113+
get_price_history: () => ({
114+
type: nanodb_actions.GET_PRICE_HISTORY
115+
}),
116+
117+
get_price_history_failed: (params, error) => ({
118+
type: nanodb_actions.GET_PRICE_HISTORY_FAILED,
119+
payload: {
120+
params,
121+
error
122+
}
123+
}),
124+
125+
get_price_history_pending: (params) => ({
126+
type: nanodb_actions.GET_PRICE_HISTORY_PENDING,
127+
payload: {
128+
params
129+
}
130+
}),
131+
132+
get_price_history_fulfilled: (params, data) => ({
133+
type: nanodb_actions.GET_PRICE_HISTORY_FULFILLED,
134+
payload: {
135+
params,
136+
data
137+
}
106138
})
107139
}
108140

@@ -123,3 +155,9 @@ export const blocks_unconfirmed_summary_request_actions = {
123155
fulfilled: nanodb_actions.get_blocks_unconfirmed_summary_fulfilled,
124156
pending: nanodb_actions.get_blocks_unconfirmed_summary_pending
125157
}
158+
159+
export const price_history_request_actions = {
160+
failed: nanodb_actions.get_price_history_failed,
161+
fulfilled: nanodb_actions.get_price_history_fulfilled,
162+
pending: nanodb_actions.get_price_history_pending
163+
}

0 commit comments

Comments
 (0)