From 6abc7814c6fb5042bc43a865d4fc7c1c165d5f6b Mon Sep 17 00:00:00 2001 From: mistakia <1823355+mistakia@users.noreply.github.com> Date: Tue, 12 Mar 2024 01:17:52 -0400 Subject: [PATCH] feat: create `/live` page --- src/core/api/index.js | 3 +- src/core/api/sagas.js | 7 + src/core/api/service.js | 4 + src/core/nanodb/actions.js | 44 ++++++ src/core/nanodb/index.js | 7 + src/core/nanodb/reducer.js | 16 ++ src/core/nanodb/sagas.js | 25 +++ src/core/reducers.js | 4 +- src/core/sagas.js | 4 +- src/styles/toggle-button-group.styl | 14 ++ src/styles/variables.styl | 1 + src/views/components/app/app.js | 1 + .../components/metric-card/metric-card.js | 10 +- .../components/metric-card/metric-card.styl | 1 + src/views/components/posts/posts.js | 4 +- src/views/components/posts/posts.styl | 15 -- .../pages/confirmations/confirmations.js | 145 ++++++++++++++++++ .../pages/confirmations/confirmations.styl | 46 ++++++ src/views/pages/confirmations/index.js | 20 +++ src/views/routes.js | 2 + 20 files changed, 349 insertions(+), 24 deletions(-) create mode 100644 src/core/nanodb/actions.js create mode 100644 src/core/nanodb/index.js create mode 100644 src/core/nanodb/reducer.js create mode 100644 src/core/nanodb/sagas.js create mode 100644 src/styles/toggle-button-group.styl create mode 100644 src/views/pages/confirmations/confirmations.js create mode 100644 src/views/pages/confirmations/confirmations.styl create mode 100644 src/views/pages/confirmations/index.js diff --git a/src/core/api/index.js b/src/core/api/index.js index d6cb0a01..57612311 100644 --- a/src/core/api/index.js +++ b/src/core/api/index.js @@ -15,5 +15,6 @@ export { getNetworkStats, getWeight, getWeightHistory, - getDaily + getDaily, + get_block_confirmed_summary } from './sagas' diff --git a/src/core/api/sagas.js b/src/core/api/sagas.js index 11e40ef4..a7f84e1a 100644 --- a/src/core/api/sagas.js +++ b/src/core/api/sagas.js @@ -26,6 +26,7 @@ import { } from '@core/accounts/actions' import { blockRequestActions } from '@core/blocks/actions' import { dailyRequestActions } from '@core/ledger/actions' +import { block_confirmed_summary_request_actions } from '@core/nanodb/actions' function* fetchAPI(apiFunction, actions, opts = {}) { const { token } = yield select(getApp) @@ -120,3 +121,9 @@ export const getWeightHistory = fetch.bind( weightHistoryRequestActions ) export const getDaily = fetch.bind(null, api.getDaily, dailyRequestActions) + +export const get_block_confirmed_summary = fetch.bind( + null, + api.get_block_confirmed_summary, + block_confirmed_summary_request_actions +) diff --git a/src/core/api/service.js b/src/core/api/service.js index 80ed44b4..b0746746 100644 --- a/src/core/api/service.js +++ b/src/core/api/service.js @@ -81,6 +81,10 @@ export const api = { getWeightHistory() { const url = `${API_URL}/weight/history` return { url } + }, + get_block_confirmed_summary({ period = '10m' }) { + const url = `${API_URL}/nanodb/blocks/confirmed/summary?period=${period}` + return { url } } } diff --git a/src/core/nanodb/actions.js b/src/core/nanodb/actions.js new file mode 100644 index 00000000..8aa533b2 --- /dev/null +++ b/src/core/nanodb/actions.js @@ -0,0 +1,44 @@ +export const nanodb_actions = { + GET_BLOCK_CONFIRMED_SUMMARY: 'GET_BLOCK_CONFIRMED_SUMMARY', + + GET_BLOCK_CONFIRMED_SUMMARY_FAILED: 'GET_BLOCK_CONFIRMED_SUMMARY_FAILED', + GET_BLOCK_CONFIRMED_SUMMARY_PENDING: 'GET_BLOCK_CONFIRMED_SUMMARY_PENDING', + GET_BLOCK_CONFIRMED_SUMMARY_FULFILLED: + 'GET_BLOCK_CONFIRMED_SUMMARY_FULFILLED', + + get_block_confirmed_summary: (period = '10m') => ({ + type: nanodb_actions.GET_BLOCK_CONFIRMED_SUMMARY, + payload: { + period + } + }), + + get_block_confirmed_summary_failed: (params, error) => ({ + type: nanodb_actions.GET_BLOCK_CONFIRMED_SUMMARY_FAILED, + payload: { + params, + error + } + }), + + get_block_confirmed_summary_pending: (params) => ({ + type: nanodb_actions.GET_BLOCK_CONFIRMED_SUMMARY_PENDING, + payload: { + params + } + }), + + get_block_confirmed_summary_fulfilled: (params, data) => ({ + type: nanodb_actions.GET_BLOCK_CONFIRMED_SUMMARY_FULFILLED, + payload: { + params, + data + } + }) +} + +export const block_confirmed_summary_request_actions = { + failed: nanodb_actions.get_block_confirmed_summary_failed, + fulfilled: nanodb_actions.get_block_confirmed_summary_fulfilled, + pending: nanodb_actions.get_block_confirmed_summary_pending +} diff --git a/src/core/nanodb/index.js b/src/core/nanodb/index.js new file mode 100644 index 00000000..7ef4ff18 --- /dev/null +++ b/src/core/nanodb/index.js @@ -0,0 +1,7 @@ +export { + nanodb_actions, + block_confirmed_summary_request_actions +} from './actions' + +export { nanodb_reducer } from './reducer' +export { nanodb_sagas } from './sagas' diff --git a/src/core/nanodb/reducer.js b/src/core/nanodb/reducer.js new file mode 100644 index 00000000..8dd47ba8 --- /dev/null +++ b/src/core/nanodb/reducer.js @@ -0,0 +1,16 @@ +import { Map } from 'immutable' + +import { nanodb_actions } from './actions' + +export function nanodb_reducer(state = Map(), action) { + switch (action.type) { + case nanodb_actions.GET_BLOCK_CONFIRMED_SUMMARY_FULFILLED: + return state.set( + `block_confirmed_summary_${action.payload.params.period}`, + action.payload.data + ) + + default: + return state + } +} diff --git a/src/core/nanodb/sagas.js b/src/core/nanodb/sagas.js new file mode 100644 index 00000000..b88c38fe --- /dev/null +++ b/src/core/nanodb/sagas.js @@ -0,0 +1,25 @@ +import { takeEvery, fork, call } from 'redux-saga/effects' + +import { get_block_confirmed_summary } from '@core/api' +import { nanodb_actions } from './actions' + +export function* load_block_confirmed_summary({ payload }) { + yield call(get_block_confirmed_summary, payload) +} + +//= ==================================== +// WATCHERS +// ------------------------------------- + +export function* watch_get_block_confirmed_summary() { + yield takeEvery( + nanodb_actions.GET_BLOCK_CONFIRMED_SUMMARY, + load_block_confirmed_summary + ) +} + +//= ==================================== +// ROOT +// ------------------------------------- + +export const nanodb_sagas = [fork(watch_get_block_confirmed_summary)] diff --git a/src/core/reducers.js b/src/core/reducers.js index 6c7a6b4e..aad52788 100644 --- a/src/core/reducers.js +++ b/src/core/reducers.js @@ -13,6 +13,7 @@ import { networkReducer } from './network' import { notificationReducer } from './notifications' import { postsReducer } from './posts' import { postlistsReducer } from './postlists' +import { nanodb_reducer } from './nanodb' const rootReducer = (history) => combineReducers({ @@ -28,7 +29,8 @@ const rootReducer = (history) => network: networkReducer, notification: notificationReducer, posts: postsReducer, - postlists: postlistsReducer + postlists: postlistsReducer, + nanodb: nanodb_reducer }) export default rootReducer diff --git a/src/core/sagas.js b/src/core/sagas.js index 237db53f..b121138b 100644 --- a/src/core/sagas.js +++ b/src/core/sagas.js @@ -10,6 +10,7 @@ import { githubIssuesSagas } from './github-issues' import { ledgerSagas } from './ledger' import { networkSagas } from './network' import { postlistSagas } from './postlists' +import { nanodb_sagas } from './nanodb' export default function* rootSage() { yield all([ @@ -22,6 +23,7 @@ export default function* rootSage() { ...githubIssuesSagas, ...ledgerSagas, ...networkSagas, - ...postlistSagas + ...postlistSagas, + ...nanodb_sagas ]) } diff --git a/src/styles/toggle-button-group.styl b/src/styles/toggle-button-group.styl new file mode 100644 index 00000000..0dd023ef --- /dev/null +++ b/src/styles/toggle-button-group.styl @@ -0,0 +1,14 @@ +.toggle-button-group + flex 0 0 auto + border-radius 4px + border 1px solid $borderColor + background #ffffff + + .MuiToggleButton-root + border none + margin 4px + font-size 10px + padding 3px 8px + &:not(:first-child) + &:first-child + border-radius 4px \ No newline at end of file diff --git a/src/styles/variables.styl b/src/styles/variables.styl index 0f0a0dd1..39968701 100644 --- a/src/styles/variables.styl +++ b/src/styles/variables.styl @@ -1,4 +1,5 @@ $backgroundColor = #F0F0F0 +$textColor = #444444 $borderColor = #D0D0D0 diff --git a/src/views/components/app/app.js b/src/views/components/app/app.js index 5ae1193f..1306392f 100644 --- a/src/views/components/app/app.js +++ b/src/views/components/app/app.js @@ -10,6 +10,7 @@ import '@styles/typography.styl' import '@styles/doc.styl' import '@styles/header.styl' import '@styles/markdown.styl' +import '@styles/toggle-button-group.styl' export default class App extends React.Component { async componentDidMount() { diff --git a/src/views/components/metric-card/metric-card.js b/src/views/components/metric-card/metric-card.js index 32a71039..c8e880e2 100644 --- a/src/views/components/metric-card/metric-card.js +++ b/src/views/components/metric-card/metric-card.js @@ -19,7 +19,7 @@ export default class MetricCard extends React.Component { render() { const { - metrics, + metrics = [], title, subtitle, max, @@ -27,7 +27,8 @@ export default class MetricCard extends React.Component { tooltip, field, selectedField, - selectedLabel + selectedLabel, + body } = this.props const isSelectedField = field === selectedField const rows = metrics.map((p, i) => { @@ -66,7 +67,7 @@ export default class MetricCard extends React.Component { )} -