|
@@ -4,13 +4,8 @@ import "./index.css";
|
|
import { Modals, Routes, Loading, Footer, Status } from "./components";
|
|
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 {
|
|
|
|
- // updateElection,
|
|
|
|
- getCouncilApplicants,
|
|
|
|
- getCouncilSize,
|
|
|
|
- getVotes,
|
|
|
|
-} from "./lib/election";
|
|
|
|
|
|
+import { getTokenomics, queryJstats } from "./lib/queries";
|
|
|
|
+import { getCouncilApplicants, getCouncilSize, getVotes } from "./lib/election";
|
|
import {
|
|
import {
|
|
getStashes,
|
|
getStashes,
|
|
getNominators,
|
|
getNominators,
|
|
@@ -253,6 +248,7 @@ class App extends React.Component<IProps, IState> {
|
|
return (
|
|
return (
|
|
<>
|
|
<>
|
|
<Routes
|
|
<Routes
|
|
|
|
+ selectEvent={this.selectEvent}
|
|
toggleEditKpi={this.toggleEditKpi}
|
|
toggleEditKpi={this.toggleEditKpi}
|
|
toggleFooter={this.toggleFooter}
|
|
toggleFooter={this.toggleFooter}
|
|
toggleStar={this.toggleStar}
|
|
toggleStar={this.toggleStar}
|
|
@@ -261,6 +257,7 @@ class App extends React.Component<IProps, IState> {
|
|
/>
|
|
/>
|
|
|
|
|
|
<Modals
|
|
<Modals
|
|
|
|
+ selectEvent={this.selectEvent}
|
|
toggleEditKpi={this.toggleEditKpi}
|
|
toggleEditKpi={this.toggleEditKpi}
|
|
toggleShowStatus={this.toggleShowStatus}
|
|
toggleShowStatus={this.toggleShowStatus}
|
|
{...this.state}
|
|
{...this.state}
|
|
@@ -278,21 +275,27 @@ class App extends React.Component<IProps, IState> {
|
|
}
|
|
}
|
|
|
|
|
|
// startup from bottom up
|
|
// startup from bottom up
|
|
|
|
+ selectEvent(selectedEvent) {
|
|
|
|
+ this.setState({ selectedEvent });
|
|
|
|
+ }
|
|
|
|
+
|
|
async handleBlock(api: ApiPromise, header: Header) {
|
|
async handleBlock(api: ApiPromise, header: Header) {
|
|
- let { blocks = [], status } = this.state;
|
|
|
|
|
|
+ let { status } = this.state;
|
|
const id = header.number.toNumber();
|
|
const id = header.number.toNumber();
|
|
const isEven = id / 50 === Math.floor(id / 50);
|
|
const isEven = id / 50 === Math.floor(id / 50);
|
|
if (isEven || status.block?.id + 50 < id) this.updateStatus(api, id);
|
|
if (isEven || status.block?.id + 50 < id) this.updateStatus(api, id);
|
|
- if (blocks.find((b) => b.id === id)) return;
|
|
|
|
|
|
+ if (this.state.blocks.find((b) => b.id === id)) return;
|
|
const timestamp = (await api.query.timestamp.now()).toNumber();
|
|
const timestamp = (await api.query.timestamp.now()).toNumber();
|
|
const duration = status.block ? timestamp - status.block.timestamp : 6000;
|
|
const duration = status.block ? timestamp - status.block.timestamp : 6000;
|
|
const hash = await getBlockHash(api, id);
|
|
const hash = await getBlockHash(api, id);
|
|
- const events = await getEvents(api, hash);
|
|
|
|
-
|
|
|
|
|
|
+ const events = (await getEvents(api, hash)).map((e) => {
|
|
|
|
+ const { section, method, data } = e.event;
|
|
|
|
+ return { blockId: id, section, method, data: data.toHuman() };
|
|
|
|
+ });
|
|
status.block = { id, timestamp, duration, events };
|
|
status.block = { id, timestamp, duration, events };
|
|
console.debug(`new finalized head`, status.block);
|
|
console.debug(`new finalized head`, status.block);
|
|
this.save("status", status);
|
|
this.save("status", status);
|
|
- this.setState({ blocks: blocks.concat(status.block) });
|
|
|
|
|
|
+ this.save("blocks", this.state.blocks.concat(status.block));
|
|
}
|
|
}
|
|
|
|
|
|
connectApi() {
|
|
connectApi() {
|
|
@@ -314,9 +317,32 @@ class App extends React.Component<IProps, IState> {
|
|
api.rpc.chain.subscribeFinalizedHeads((header: Header) =>
|
|
api.rpc.chain.subscribeFinalizedHeads((header: Header) =>
|
|
this.handleBlock(api, header)
|
|
this.handleBlock(api, header)
|
|
);
|
|
);
|
|
|
|
+ this.syncBlocks(api)
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ async syncBlocks(api:ApiPromise) {
|
|
|
|
+ const syncAll = true
|
|
|
|
+ const head = this.state.blocks.reduce((max, b) => b.id > max ? b.id : max, 0)
|
|
|
|
+ console.log(`Syncing block events from ${head}`)
|
|
|
|
+
|
|
|
|
+ for (let id = head ; id > 0 ; --id) {
|
|
|
|
+ if (!syncAll) return
|
|
|
|
+ if (this.state.blocks.find(block=> block.id === id)) continue
|
|
|
|
+
|
|
|
|
+ const hash = await getBlockHash(api, id);
|
|
|
|
+ const events = (await getEvents(api, hash)).map((e) => {
|
|
|
|
+ const { section, method, data } = e.event;
|
|
|
|
+ return { blockId: id, section, method, data: data.toHuman() };
|
|
|
|
+ });
|
|
|
|
+ const timestamp = (await api.query.timestamp.now.at(hash)).toNumber();
|
|
|
|
+ const duration = 6000 // TODO update later
|
|
|
|
+ const block = { id, timestamp, duration, events };
|
|
|
|
+ console.debug(`synced block`, block);
|
|
|
|
+ this.save("blocks", this.state.blocks.concat(block));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
save(key: string, data: any) {
|
|
save(key: string, data: any) {
|
|
this.setState({ [key]: data });
|
|
this.setState({ [key]: data });
|
|
const value = JSON.stringify(data);
|
|
const value = JSON.stringify(data);
|
|
@@ -346,11 +372,11 @@ 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 openings tokenomics transactions reports validators nominators staches 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 blocks"
|
|
.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));
|
|
- bootstrap(this.save); // axios requests
|
|
|
|
|
|
+ //bootstrap(this.save); // axios requests
|
|
this.updateCouncils();
|
|
this.updateCouncils();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -368,6 +394,7 @@ class App extends React.Component<IProps, IState> {
|
|
this.toggleFooter = this.toggleFooter.bind(this);
|
|
this.toggleFooter = this.toggleFooter.bind(this);
|
|
this.toggleShowStatus = this.toggleShowStatus.bind(this);
|
|
this.toggleShowStatus = this.toggleShowStatus.bind(this);
|
|
this.getMember = this.getMember.bind(this);
|
|
this.getMember = this.getMember.bind(this);
|
|
|
|
+ this.selectEvent = this.selectEvent.bind(this);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|