|
@@ -5,9 +5,8 @@ import { Modals, Routes, Loading, Footer, Status } from "./components";
|
|
|
|
|
|
import * as get from "./lib/getters";
|
|
import * as get from "./lib/getters";
|
|
import { bootstrap, getTokenomics, queryJstats } from "./lib/queries";
|
|
import { bootstrap, getTokenomics, queryJstats } from "./lib/queries";
|
|
-import { getMints, updateOpenings, updateWorkers } from "./lib/groups";
|
|
|
|
import {
|
|
import {
|
|
- updateElection,
|
|
|
|
|
|
+ // updateElection,
|
|
getCouncilApplicants,
|
|
getCouncilApplicants,
|
|
getCouncilSize,
|
|
getCouncilSize,
|
|
getVotes,
|
|
getVotes,
|
|
@@ -21,6 +20,7 @@ import {
|
|
getLastReward,
|
|
getLastReward,
|
|
getTotalStake,
|
|
getTotalStake,
|
|
} from "./lib/validators";
|
|
} from "./lib/validators";
|
|
|
|
+import { getBlockHash, getEvents, getTimestamp } from "./jslib";
|
|
import { apiLocation, wsLocation, historyDepth } from "./config";
|
|
import { apiLocation, wsLocation, historyDepth } from "./config";
|
|
import { initialState } from "./state";
|
|
import { initialState } from "./state";
|
|
import axios from "axios";
|
|
import axios from "axios";
|
|
@@ -54,20 +54,18 @@ class App extends React.Component<IProps, IState> {
|
|
|
|
|
|
async updateStatus(api: ApiPromise, id: number): Promise<Status> {
|
|
async updateStatus(api: ApiPromise, id: number): Promise<Status> {
|
|
console.debug(`#${id}: Updating status`);
|
|
console.debug(`#${id}: Updating status`);
|
|
- this.updateActiveProposals();
|
|
|
|
- //getMints(api).then((mints) => this.save(`mints`, mints));
|
|
|
|
|
|
+ //this.updateActiveProposals();
|
|
getTokenomics().then((tokenomics) => this.save(`tokenomics`, tokenomics));
|
|
getTokenomics().then((tokenomics) => this.save(`tokenomics`, tokenomics));
|
|
|
|
|
|
let { status, councils } = this.state;
|
|
let { status, councils } = this.state;
|
|
- status.election = await updateElection(api);
|
|
|
|
- if (status.election?.stage) this.getElectionStatus(api);
|
|
|
|
|
|
+ //status.election = await updateElection(api);
|
|
|
|
+ //if (status.election?.stage) this.getElectionStatus(api);
|
|
councils.forEach((c) => {
|
|
councils.forEach((c) => {
|
|
if (c?.round > status.council) status.council = c;
|
|
if (c?.round > status.council) status.council = c;
|
|
});
|
|
});
|
|
|
|
|
|
- let hash: string = await api.rpc.chain.getBlockHash(1);
|
|
|
|
- if (hash)
|
|
|
|
- status.startTime = (await api.query.timestamp.now.at(hash)).toNumber();
|
|
|
|
|
|
+ let hash: string = await getBlockHash(api, 1);
|
|
|
|
+ if (hash) status.startTime = await getTimestamp(api, hash);
|
|
|
|
|
|
const nextMemberId = await await api.query.members.nextMemberId();
|
|
const nextMemberId = await await api.query.members.nextMemberId();
|
|
status.members = nextMemberId - 1;
|
|
status.members = nextMemberId - 1;
|
|
@@ -151,23 +149,11 @@ class App extends React.Component<IProps, IState> {
|
|
const { status, validators } = this.state;
|
|
const { status, validators } = this.state;
|
|
const era = Number(await api.query.staking.currentEra());
|
|
const era = Number(await api.query.staking.currentEra());
|
|
if (era === old) return era;
|
|
if (era === old) return era;
|
|
- this.updateWorkingGroups(api);
|
|
|
|
this.updateValidatorPoints(api, status.era);
|
|
this.updateValidatorPoints(api, status.era);
|
|
if (era > status.era || !validators.length) this.updateValidators(api);
|
|
if (era > status.era || !validators.length) this.updateValidators(api);
|
|
return era;
|
|
return era;
|
|
}
|
|
}
|
|
|
|
|
|
- async updateWorkingGroups(api: ApiPromise): Promise<void> {
|
|
|
|
- const { members, openings, workers } = this.state;
|
|
|
|
- updateWorkers(api, workers, members).then((workers) => {
|
|
|
|
- this.save("workers", workers);
|
|
|
|
- updateOpenings(api, openings, members).then((openings) =>
|
|
|
|
- this.save("openings", openings)
|
|
|
|
- );
|
|
|
|
- });
|
|
|
|
- //return this.save("council", await api.query.council.activeCouncil());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
updateValidators(api: ApiPromise) {
|
|
updateValidators(api: ApiPromise) {
|
|
getValidators(api).then((validators) => {
|
|
getValidators(api).then((validators) => {
|
|
this.save("validators", validators);
|
|
this.save("validators", validators);
|
|
@@ -292,34 +278,42 @@ class App extends React.Component<IProps, IState> {
|
|
}
|
|
}
|
|
|
|
|
|
// startup from bottom up
|
|
// startup from bottom up
|
|
|
|
+ async handleBlock(api: ApiPromise, header: Header) {
|
|
|
|
+ let { blocks = [], status } = this.state;
|
|
|
|
+ const id = header.number.toNumber();
|
|
|
|
+ const isEven = id / 50 === Math.floor(id / 50);
|
|
|
|
+ if (isEven || status.block?.id + 50 < id) this.updateStatus(api, id);
|
|
|
|
+ if (blocks.find((b) => b.id === id)) return;
|
|
|
|
+ const timestamp = (await api.query.timestamp.now()).toNumber();
|
|
|
|
+ const duration = status.block ? timestamp - status.block.timestamp : 6000;
|
|
|
|
+ const hash = await getBlockHash(api, id);
|
|
|
|
+ const events = await getEvents(api, hash);
|
|
|
|
+
|
|
|
|
+ status.block = { id, timestamp, duration, events };
|
|
|
|
+ console.debug(`new finalized head`, status.block);
|
|
|
|
+ this.save("status", status);
|
|
|
|
+ this.setState({ blocks: blocks.concat(status.block) });
|
|
|
|
+ }
|
|
|
|
|
|
connectApi() {
|
|
connectApi() {
|
|
console.debug(`Connecting to ${wsLocation}`);
|
|
console.debug(`Connecting to ${wsLocation}`);
|
|
const provider = new WsProvider(wsLocation);
|
|
const provider = new WsProvider(wsLocation);
|
|
return ApiPromise.create({ provider, types }).then(async (api) => {
|
|
return ApiPromise.create({ provider, types }).then(async (api) => {
|
|
await api.isReady;
|
|
await api.isReady;
|
|
- console.log(`Connected to ${wsLocation}`);
|
|
|
|
|
|
+
|
|
|
|
+ const [chain, nodeName, nodeVersion, runtimeVersion] = await Promise.all([
|
|
|
|
+ api.rpc.system.chain(),
|
|
|
|
+ api.rpc.system.name(),
|
|
|
|
+ api.rpc.system.version(),
|
|
|
|
+ api.runtimeVersion,
|
|
|
|
+ ]);
|
|
|
|
+ console.log(
|
|
|
|
+ `Connected to ${wsLocation}: ${chain} spec:${runtimeVersion.specVersion} (${nodeName} v${nodeVersion})`
|
|
|
|
+ );
|
|
this.setState({ connected: true });
|
|
this.setState({ connected: true });
|
|
- this.updateWorkingGroups(api);
|
|
|
|
-
|
|
|
|
- api.rpc.chain.subscribeNewHeads(async (header: Header) => {
|
|
|
|
- let { blocks, status } = this.state;
|
|
|
|
- const id = header.number.toNumber();
|
|
|
|
- const isEven = id / 50 === Math.floor(id / 50);
|
|
|
|
- if (isEven || status.block?.id + 50 < id) this.updateStatus(api, id);
|
|
|
|
-
|
|
|
|
- if (blocks.find((b) => b.id === id)) return;
|
|
|
|
- const timestamp = (await api.query.timestamp.now()).toNumber();
|
|
|
|
- const duration = status.block
|
|
|
|
- ? timestamp - status.block.timestamp
|
|
|
|
- : 6000;
|
|
|
|
- status.block = { id, timestamp, duration };
|
|
|
|
- this.save("status", status);
|
|
|
|
-
|
|
|
|
- blocks = blocks.filter((i) => i.id !== id).concat(status.block);
|
|
|
|
- this.setState({ blocks });
|
|
|
|
- });
|
|
|
|
- return api;
|
|
|
|
|
|
+ api.rpc.chain.subscribeFinalizedHeads((header: Header) =>
|
|
|
|
+ this.handleBlock(api, header)
|
|
|
|
+ );
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
@@ -352,7 +346,7 @@ class App extends React.Component<IProps, IState> {
|
|
|
|
|
|
async loadData() {
|
|
async loadData() {
|
|
console.debug(`Loading data`);
|
|
console.debug(`Loading data`);
|
|
- "status members assets providers councils council election workers categories channels proposals posts threads mints openings tokenomics transactions reports validators nominators stashes stakes rewardPoints stars"
|
|
|
|
|
|
+ "status members assets providers councils council election workers categories channels proposals posts threads openings tokenomics transactions reports validators nominators staches stakes rewardPoints stars"
|
|
.split(" ")
|
|
.split(" ")
|
|
.map((key) => this.load(key));
|
|
.map((key) => this.load(key));
|
|
getTokenomics().then((tokenomics) => this.save(`tokenomics`, tokenomics));
|
|
getTokenomics().then((tokenomics) => this.save(`tokenomics`, tokenomics));
|