diff --git a/src/core/accounts/selectors.js b/src/core/accounts/selectors.js index e6ff2b1b..ae3e1fd3 100644 --- a/src/core/accounts/selectors.js +++ b/src/core/accounts/selectors.js @@ -29,7 +29,7 @@ export function getFilteredRepresentatives(state) { (r) => fuzzySearch(search, r.account || '') || fuzzySearch(search, r.alias || '') || - (r.telemetry.address || '').includes(search) + r.getIn(['telemetry', 'address'], '').includes(search) ) } @@ -83,8 +83,9 @@ export function getRepresentativesTotalWeight(state) { const accounts = getRepresentatives(state) let weight = BigNumber(0) for (const rep of accounts.valueSeq()) { - if (!rep.account_meta.weight) continue - weight = BigNumber(rep.account_meta.weight).plus(weight) + const rep_weight = rep.getIn(['account_meta', 'weight']) + if (!rep_weight) continue + weight = BigNumber(rep_weight).plus(weight) } return weight.toNumber() @@ -94,8 +95,9 @@ export function getOnlineRepresentativesTotalWeight(state) { const accounts = getOnlineRepresentatives(state) let weight = BigNumber(0) for (const rep of accounts.valueSeq()) { - if (!rep.account_meta.weight) continue - weight = BigNumber(rep.account_meta.weight).plus(weight) + const rep_weight = rep.getIn(['account_meta', 'weight']) + if (!rep_weight) continue + weight = BigNumber(rep_weight).plus(weight) } return weight.toNumber() @@ -123,5 +125,8 @@ export function getNetworkUnconfirmedBlockCount(state) { const rep = sorted.first() - return rep.getIn(['telemetry', 'block_count']) - rep.getIn(['telemetry', 'cemented_count']) + return ( + rep.getIn(['telemetry', 'block_count']) - + rep.getIn(['telemetry', 'cemented_count']) + ) } diff --git a/src/views/components/representative-alerts/index.js b/src/views/components/representative-alerts/index.js index 97807ea4..0ae15afd 100644 --- a/src/views/components/representative-alerts/index.js +++ b/src/views/components/representative-alerts/index.js @@ -33,7 +33,7 @@ const mapStateToProps = createSelector( const lowUptime = reps.filter((a) => { const uptime = a.get('uptime') const online = uptime.filter((u) => u.online) - const total = uptime.length + const total = uptime.size const pct = online / total return pct < 0.75 }) diff --git a/src/views/components/representative-alerts/representative-alerts.js b/src/views/components/representative-alerts/representative-alerts.js index d3a8133c..a5082a9f 100644 --- a/src/views/components/representative-alerts/representative-alerts.js +++ b/src/views/components/representative-alerts/representative-alerts.js @@ -121,22 +121,30 @@ export default class RepresentativeAlerts extends React.Component { )} - {BigNumber(row.account.account_meta.weight) + {BigNumber( + row.account.getIn(['account_meta', 'weight'], 0) + ) .shiftedBy(-30) .toFormat(0)} - {row.account.account_meta.weight && onlineWeight - ? `${BigNumber(row.account.account_meta.weight) + {row.account.getIn(['account_meta', 'weight'], 0) && + onlineWeight + ? `${BigNumber( + row.account.getIn(['account_meta', 'weight'], 0) + ) .dividedBy(onlineWeight) .multipliedBy(100) .toFormat(2)} %` : '-'} - {row.account.telemetry.cemented_behind >= 0 + {row.account.getIn( + ['telemetry', 'cemented_behind'], + -1 + ) >= 0 ? BigNumber( - row.account.telemetry.cemented_behind + row.account.getIn(['telemetry', 'cemented_behind']) ).toFormat(0) : '-'} diff --git a/src/views/components/representatives-bandwidth-by-weight/index.js b/src/views/components/representatives-bandwidth-by-weight/index.js index a896efb9..51c004e1 100644 --- a/src/views/components/representatives-bandwidth-by-weight/index.js +++ b/src/views/components/representatives-bandwidth-by-weight/index.js @@ -66,19 +66,20 @@ const mapStateToProps = createSelector( ] const metrics = thresholds.map((p) => ({ ...p, total: 0 })) for (const rep of accounts.valueSeq()) { - if (!rep.account_meta.weight) continue + const rep_weight = rep.getIn(['account_meta', 'weight'], 0) + if (!rep_weight) continue // add to unknown - if (rep.telemetry.bandwidth_cap === undefined) { - metrics[0].total = BigNumber(rep.account_meta.weight) + if (rep.getIn(['telemetry', 'bandwidth_cap']) === undefined) { + metrics[0].total = BigNumber(rep_weight) .plus(metrics[0].total) .toFixed() continue } // add to unlimited - if (rep.telemetry.bandwidth_cap === 0) { - metrics[1].total = BigNumber(rep.account_meta.weight) + if (rep.getIn(['telemetry', 'bandwidth_cap']) === 0) { + metrics[1].total = BigNumber(rep_weight) .plus(metrics[1].total) .toFixed() continue @@ -88,8 +89,8 @@ const mapStateToProps = createSelector( const lastIdx = Math.max(metrics.length - 1, 0) let i = 2 for (; i < lastIdx; i++) { - if (rep.telemetry.bandwidth_cap <= metrics[i].threshold) { - metrics[i].total = BigNumber(rep.account_meta.weight) + if (rep.getIn(['telemetry', 'bandwidth_cap']) <= metrics[i].threshold) { + metrics[i].total = BigNumber(rep_weight) .plus(metrics[i].total) .toFixed() break @@ -98,7 +99,7 @@ const mapStateToProps = createSelector( // add to catch all if (i === lastIdx) { - metrics[i].total = BigNumber(rep.account_meta.weight) + metrics[i].total = BigNumber(rep_weight) .plus(metrics[i].total) .toFixed() } diff --git a/src/views/components/representatives-cemented-by-weight/index.js b/src/views/components/representatives-cemented-by-weight/index.js index ba0a5702..d481d257 100644 --- a/src/views/components/representatives-cemented-by-weight/index.js +++ b/src/views/components/representatives-cemented-by-weight/index.js @@ -59,22 +59,23 @@ const mapStateToProps = createSelector( ] const metrics = thresholds.map((p) => ({ ...p, total: 0 })) for (const rep of accounts.valueSeq()) { - if (!rep.account_meta.weight) continue + const rep_weight = rep.getIn(['account_meta', 'weight']) + if (!rep_weight) continue - const blocksBehind = rep.telemetry.cemented_behind - if (blocksBehind == null) { - metrics[0].total = BigNumber(rep.account_meta.weight) + const blocks_behind = rep.getIn(['telemetry', 'cemented_behind']) + if (blocks_behind == null) { + metrics[0].total = BigNumber(rep_weight) .plus(metrics[0].total) .toFixed() continue } // stop before the last one (catch-all) - const lastIdx = Math.max(metrics.length - 1, 0) + const last_idx = Math.max(metrics.length - 1, 0) let i = 1 - for (; i < lastIdx; i++) { - if (blocksBehind <= metrics[i].threshold) { - metrics[i].total = BigNumber(rep.account_meta.weight) + for (; i < last_idx; i++) { + if (blocks_behind <= metrics[i].threshold) { + metrics[i].total = BigNumber(rep_weight) .plus(metrics[i].total) .toFixed() break @@ -82,8 +83,8 @@ const mapStateToProps = createSelector( } // add to catch all - if (i === lastIdx) { - metrics[i].total = BigNumber(rep.account_meta.weight) + if (i === last_idx) { + metrics[i].total = BigNumber(rep_weight) .plus(metrics[i].total) .toFixed() } diff --git a/src/views/components/representatives-checked-by-weight/index.js b/src/views/components/representatives-checked-by-weight/index.js index 55c27596..774c38a6 100644 --- a/src/views/components/representatives-checked-by-weight/index.js +++ b/src/views/components/representatives-checked-by-weight/index.js @@ -59,22 +59,23 @@ const mapStateToProps = createSelector( ] const metrics = thresholds.map((p) => ({ ...p, total: 0 })) for (const rep of accounts.valueSeq()) { - if (!rep.account_meta.weight) continue + const rep_weight = rep.getIn(['account_meta', 'weight']) + if (!rep_weight) continue - const blocksBehind = rep.telemetry.block_behind - if (blocksBehind == null) { - metrics[0].total = BigNumber(rep.account_meta.weight) + const blocks_behind = rep.getIn(['telemetry', 'block_behind']) + if (blocks_behind == null) { + metrics[0].total = BigNumber(rep_weight) .plus(metrics[0].total) .toFixed() continue } // stop before the last one (catch-all) - const lastIdx = Math.max(metrics.length - 1, 0) + const last_idx = Math.max(metrics.length - 1, 0) let i = 1 - for (; i < lastIdx; i++) { - if (blocksBehind <= metrics[i].threshold) { - metrics[i].total = BigNumber(rep.account_meta.weight) + for (; i < last_idx; i++) { + if (blocks_behind <= metrics[i].threshold) { + metrics[i].total = BigNumber(rep_weight) .plus(metrics[i].total) .toFixed() break @@ -82,8 +83,8 @@ const mapStateToProps = createSelector( } // add to catch all - if (i === lastIdx) { - metrics[i].total = BigNumber(rep.account_meta.weight) + if (i === last_idx) { + metrics[i].total = BigNumber(rep_weight) .plus(metrics[i].total) .toFixed() } diff --git a/src/views/components/representatives-cluster-charts/representatives-cluster-charts.js b/src/views/components/representatives-cluster-charts/representatives-cluster-charts.js index 294ea1fe..a46af336 100644 --- a/src/views/components/representatives-cluster-charts/representatives-cluster-charts.js +++ b/src/views/components/representatives-cluster-charts/representatives-cluster-charts.js @@ -31,21 +31,29 @@ export default class RepresentativesClusterCharts extends React.Component { const bandwidthData = [] const uncheckedData = [] accounts.forEach((a) => { - if (a.telemetry.cemented_behind > 1000) return - const weight = BigNumber(a.account_meta.weight) + if (a.getIn(['telemetry', 'cemented_behind']) > 1000) return + const weight = BigNumber(a.getIn(['account_meta', 'weight'])) .dividedBy(totalWeight) .multipliedBy(100) .toFixed() - const label = a.alias || a.account - confirmationsData.push([a.telemetry.cemented_behind, weight, label]) - blocksData.push([a.telemetry.block_behind, weight, label]) - peersData.push([a.telemetry.peer_count, weight, label]) - uncheckedData.push([a.telemetry.unchecked_count, weight, label]) + const label = a.getIn(['alias'], a.getIn(['account'])) + confirmationsData.push([ + a.getIn(['telemetry', 'cemented_behind']), + weight, + label + ]) + blocksData.push([a.getIn(['telemetry', 'block_behind']), weight, label]) + peersData.push([a.getIn(['telemetry', 'peer_count']), weight, label]) + uncheckedData.push([ + a.getIn(['telemetry', 'unchecked_count']), + weight, + label + ]) // exclude 0 (unlimited) - if (a.telemetry.bandwidth_cap) + if (a.getIn(['telemetry', 'bandwidth_cap'])) bandwidthData.push([ - a.telemetry.bandwidth_cap / (1024 * 1024), + a.getIn(['telemetry', 'bandwidth_cap']) / (1024 * 1024), weight, label ]) diff --git a/src/views/components/representatives-country-by-weight/index.js b/src/views/components/representatives-country-by-weight/index.js index 97c27874..c1f1d6b0 100644 --- a/src/views/components/representatives-country-by-weight/index.js +++ b/src/views/components/representatives-country-by-weight/index.js @@ -19,17 +19,16 @@ const mapStateToProps = createSelector( } for (const rep of accounts.valueSeq()) { - if (!rep.account_meta.weight) continue + const weight = rep.getIn(['account_meta', 'weight']) + if (!weight) continue - const country = rep.network.country + const country = rep.getIn(['network', 'country']) if (!country) { - countries.unknown = BigNumber(rep.account_meta.weight) - .plus(countries.unknown) - .toFixed() + countries.unknown = BigNumber(weight).plus(countries.unknown).toFixed() continue } - countries[country] = BigNumber(rep.account_meta.weight) + countries[country] = BigNumber(weight) .plus(countries[country] || 0) .toFixed() } diff --git a/src/views/components/representatives-offline/representatives-offline.js b/src/views/components/representatives-offline/representatives-offline.js index d4cccb74..fcca7ba9 100644 --- a/src/views/components/representatives-offline/representatives-offline.js +++ b/src/views/components/representatives-offline/representatives-offline.js @@ -25,7 +25,7 @@ export default class RepresentativesOffline extends React.Component { account: p.account, alias: p.alias, is_online: p.is_online, - weight: p.account_meta.weight || 0, + weight: p.getIn(['account_meta', 'weight'], 0), last_online: p.last_online, diff: (p.last_online || 0) - (p.last_offline || 0) } diff --git a/src/views/components/representatives-provider-by-weight/index.js b/src/views/components/representatives-provider-by-weight/index.js index df21f6e1..9182c928 100644 --- a/src/views/components/representatives-provider-by-weight/index.js +++ b/src/views/components/representatives-provider-by-weight/index.js @@ -19,17 +19,16 @@ const mapStateToProps = createSelector( } for (const rep of accounts.valueSeq()) { - if (!rep.account_meta.weight) continue + const weight = rep.getIn(['account_meta', 'weight']) + if (!weight) continue - const provider = rep.network.asname + const provider = rep.getIn(['network', 'asname']) if (!provider) { - providers.unknown = BigNumber(rep.account_meta.weight) - .plus(providers.unknown) - .toFixed() + providers.unknown = BigNumber(weight).plus(providers.unknown).toFixed() continue } - providers[provider] = BigNumber(rep.account_meta.weight) + providers[provider] = BigNumber(weight) .plus(providers[provider] || 0) .toFixed() } diff --git a/src/views/components/representatives-version-by-weight/index.js b/src/views/components/representatives-version-by-weight/index.js index 47ded3fc..fe410784 100644 --- a/src/views/components/representatives-version-by-weight/index.js +++ b/src/views/components/representatives-version-by-weight/index.js @@ -17,10 +17,11 @@ const mapStateToProps = createSelector( const versions = {} for (const rep of accounts.valueSeq()) { - if (!rep.account_meta.weight) continue + const weight = rep.getIn(['account_meta', 'weight']) + if (!weight) continue const version = rep.version - versions[version] = BigNumber(rep.account_meta.weight) + versions[version] = BigNumber(weight) .plus(versions[version] || 0) .toFixed() } diff --git a/src/views/components/representatives-weight-chart/representatives-weight-chart.js b/src/views/components/representatives-weight-chart/representatives-weight-chart.js index 4e676ddb..58f0d1de 100644 --- a/src/views/components/representatives-weight-chart/representatives-weight-chart.js +++ b/src/views/components/representatives-weight-chart/representatives-weight-chart.js @@ -22,7 +22,7 @@ export default class RepresentativesWeightChart extends React.Component { const weightData = [] accounts.forEach((a) => { - const bn = BigNumber(a.account_meta.weight) + const bn = BigNumber(a.getIn(['account_meta', 'weight'])) const weight = bn.shiftedBy(-30).toFixed(0) const pct = bn.dividedBy(denominator).multipliedBy(100).toFixed(1)