Oleksandr Korniienko преди 3 години
родител
ревизия
0ed644be8e

+ 1 - 2
src/components/ValidatorReport/ValidatorReport.tsx

@@ -34,7 +34,6 @@ const useStyles = makeStyles(() =>
   }),
 )
 
-
 const ValidatorReport = () => {
   const dateFormat = 'yyyy-MM-DD'
   const [activeValidators, setActiveValidators] = useState([])
@@ -253,7 +252,7 @@ const ValidatorReportCard = (props: { stash: string, report: Reports }) => {
   const updateScoringPeriodText = () => {
     if (props.report.report.length > 0) {
       const scoringDateFormat = 'DD-MM-yyyy'
-      const report = `Validator Date: ${moment(props.report.startTime).format(scoringDateFormat)} - ${moment(props.report.startTime).format(scoringDateFormat)}\nDescription: I was an active validator from era/block ${props.report.startEra}/${props.report.startBlock} to era/block ${props.report.endEra}/${props.report.endBlock}\nwith stash account ${props.stash}. (I was active in all the eras in this range and found a total of ${props.report.totalBlocks} blocks)`
+      const report = `Validator Date: ${moment(props.report.startTime).format(scoringDateFormat)} - ${moment(props.report.endTime).format(scoringDateFormat)}\nDescription: I was an active validator from era/block ${props.report.startEra}/${props.report.startBlock} to era/block ${props.report.endEra}/${props.report.endBlock}\nwith stash account ${props.stash}. (I was active in all the eras in this range and found a total of ${props.report.totalBlocks} blocks)`
       setScoringPeriodText(report)
     } else {
       setScoringPeriodText('')

+ 0 - 11
src/components/ValidatorReport/debug.ts

@@ -1,11 +0,0 @@
-import moment from 'moment'
-
-moment.defaultFormat = 'YYYY-MM-DD HH:mm:ss'
-
-export const log = (...values: any[]) => {
-  // console.log(`[${moment().format()}]:`, ...values);
-}
-
-export const error = (...values: any[]) => {
-  console.error(`[${moment().format()}]:`, ...values)
-}

+ 2 - 17
src/components/ValidatorReport/get-status.ts

@@ -1,6 +1,4 @@
-import { log } from './debug'
 import { JoyApi } from './joyApi'
-import { EraStatus } from './Types'
 import { PromiseAllObj } from './utils'
 
 const api = new JoyApi()
@@ -8,21 +6,8 @@ const api = new JoyApi()
 export async function getChainState() {
   await api.init
 
-  const status = await PromiseAllObj({
-    totalIssuance: await api.totalIssuance(),
+  return await PromiseAllObj({
     finalizedBlockHeight: await api.finalizedBlockHeight(),
     validators: await api.validatorsData(),
-    system: await api.systemData(),
   })
-
-  log(status)
-  return status
-}
-
-export async function getValidatorStatistics(address: string, blockStart: number): Promise<EraStatus> {
-  await api.init
-  const status = await PromiseAllObj({
-    status: await api.getActiveErasForBlock(address, blockStart),
-  })
-  return status as unknown as EraStatus
-}
+}

+ 5 - 60
src/components/ValidatorReport/joyApi.ts

@@ -1,11 +1,10 @@
-import { WsProvider, ApiPromise } from '@polkadot/api'
+import { ApiPromise, WsProvider } from '@polkadot/api'
 import { types } from '@joystream/types'
 import { AccountId, Hash } from '@polkadot/types/interfaces'
 import { config } from 'dotenv'
 import BN from 'bn.js'
 import { Option, Vec } from '@polkadot/types'
-import { log } from './debug'
-import { ActiveEra } from './Types'
+import { wsLocation } from '../../config'
 
 config()
 
@@ -15,13 +14,9 @@ export class JoyApi {
   api!: ApiPromise
 
   constructor(endpoint?: string) {
-    const wsEndpoint = endpoint || process.env.REACT_APP_WS_PROVIDER || 'ws://127.0.0.1:9944'
-    this.endpoint = wsEndpoint
-    this.isReady = (async () => {
-      const api = await new ApiPromise({ provider: new WsProvider(wsEndpoint), types })
-        .isReadyOrError
-      return api
-    })()
+    this.endpoint = wsLocation
+    this.isReady = (async () =>
+      await new ApiPromise({ provider: new WsProvider(wsLocation), types }).isReadyOrError)()
   }
 
   get init(): Promise<JoyApi> {
@@ -31,29 +26,6 @@ export class JoyApi {
     })
   }
 
-  async totalIssuance(blockHash?: Hash) {
-    const issuance =
-      blockHash === undefined
-        ? await this.api.query.balances.totalIssuance()
-        : await this.api.query.balances.totalIssuance.at(blockHash)
-
-    return issuance.toNumber()
-  }
-
-  async systemData() {
-    const [chain, nodeName, nodeVersion] = await Promise.all([
-      this.api.rpc.system.chain(),
-      this.api.rpc.system.name(),
-      this.api.rpc.system.version(),
-    ])
-
-    return {
-      chain: chain.toString(),
-      nodeName: nodeName.toString(),
-      nodeVersion: nodeVersion.toString(),
-    }
-  }
-
   async finalizedHash() {
     return this.api.rpc.chain.getFinalizedHead()
   }
@@ -64,33 +36,6 @@ export class JoyApi {
     return number.toNumber()
   }
 
-  async getActiveErasForBlock(address: string, blockStart: number): Promise<ActiveEra[] | undefined> {
-    const stash = address
-    const startHash = (await this.api.rpc.chain.getBlockHash(blockStart))
-    const startEra = (await this.api.query.staking.activeEra.at(startHash)).unwrap().index.toNumber()
-    const startTimestamp = new Date((await this.api.query.timestamp.now.at(startHash)).toNumber()).toISOString()
-    const eraPoints = await this.api.query.staking.erasRewardPoints.at(startHash, startEra)
-    let data = undefined
-    eraPoints.individual.forEach((points, author) => {
-      log(`Author Points [${author}]`)
-      log(`Individual Points [${points}]`)
-      if (author.toString() === stash) {
-        const pn = Number(points.toBigInt())
-        const activeEra: ActiveEra = {
-          id: blockStart,
-          era: startEra,
-          hash: startHash.toString(),
-          block: blockStart,
-          date: startTimestamp,
-          points: pn,
-        }
-        log(`Era [${activeEra.era}], Block [${activeEra.block}], Date [${activeEra.date}], Points [${activeEra.points}], Hash [${activeEra.hash}]`)
-        data = activeEra
-      }
-    })
-    return data
-  }
-
   async findActiveValidators(hash: Hash, searchPreviousBlocks: boolean): Promise<AccountId[]> {
     const block = await this.api.rpc.chain.getBlock(hash)