Browse Source

working-groups:opening - display unstaking periods

Leszek Wiesner 4 years ago
parent
commit
6a862ebd42
3 changed files with 72 additions and 4 deletions
  1. 33 3
      cli/src/Api.ts
  2. 30 0
      cli/src/Types.ts
  3. 9 1
      cli/src/commands/working-groups/opening.ts

+ 33 - 3
cli/src/Api.ts

@@ -3,7 +3,7 @@ import { registerJoystreamTypes } from '@joystream/types/'
 import { ApiPromise, WsProvider } from '@polkadot/api'
 import { QueryableStorageMultiArg } from '@polkadot/api/types'
 import { formatBalance } from '@polkadot/util'
-import { Hash, Balance, Moment } from '@polkadot/types/interfaces'
+import { Hash, Balance, Moment, BlockNumber } from '@polkadot/types/interfaces'
 import { KeyringPair } from '@polkadot/keyring/types'
 import { Codec } from '@polkadot/types/types'
 import { Option, Vec } from '@polkadot/types'
@@ -20,6 +20,9 @@ import {
   GroupOpeningStage,
   GroupOpening,
   GroupApplication,
+  openingPolicyUnstakingPeriodsKeys,
+  UnstakingPeriods,
+  StakingPolicyUnstakingPeriodKey,
 } from './Types'
 import { DerivedFees, DerivedBalances } from '@polkadot/api-derive/types'
 import { CLIError } from '@oclif/errors'
@@ -38,6 +41,7 @@ import {
   ApplicationStageKeys,
   ApplicationId,
   OpeningId,
+  StakingPolicy,
 } from '@joystream/types/hiring'
 import { MemberId, Profile } from '@joystream/types/members'
 import { RewardRelationship, RewardRelationshipId } from '@joystream/types/recurring-rewards'
@@ -401,11 +405,36 @@ export default class Api {
     const applications = await this.groupOpeningApplications(group, wgOpeningId)
     const stage = await this.parseOpeningStage(opening.stage)
     const type = groupOpening.opening_type
+    const { application_staking_policy: applSP, role_staking_policy: roleSP } = opening
     const stakes = {
-      application: opening.application_staking_policy.unwrapOr(undefined),
-      role: opening.role_staking_policy.unwrapOr(undefined),
+      application: applSP.unwrapOr(undefined),
+      role: roleSP.unwrapOr(undefined),
     }
 
+    const unstakingPeriod = (period: Option<BlockNumber>) => period.unwrapOr(new BN(0)).toNumber()
+    const spUnstakingPeriod = (sp: Option<StakingPolicy>, key: StakingPolicyUnstakingPeriodKey) =>
+      sp.isSome ? unstakingPeriod(sp.unwrap()[key]) : 0
+
+    const unstakingPeriods: Partial<UnstakingPeriods> = {
+      review_period_expired_application_stake_unstaking_period_length: spUnstakingPeriod(
+        applSP,
+        'review_period_expired_unstaking_period_length'
+      ),
+      crowded_out_application_stake_unstaking_period_length: spUnstakingPeriod(
+        applSP,
+        'crowded_out_unstaking_period_length'
+      ),
+      review_period_expired_role_stake_unstaking_period_length: spUnstakingPeriod(
+        roleSP,
+        'review_period_expired_unstaking_period_length'
+      ),
+      crowded_out_role_stake_unstaking_period_length: spUnstakingPeriod(roleSP, 'crowded_out_unstaking_period_length'),
+    }
+
+    openingPolicyUnstakingPeriodsKeys.forEach((key) => {
+      unstakingPeriods[key] = unstakingPeriod(groupOpening.policy_commitment[key])
+    })
+
     return {
       wgOpeningId,
       openingId,
@@ -414,6 +443,7 @@ export default class Api {
       stakes,
       applications,
       type,
+      unstakingPeriods: unstakingPeriods as UnstakingPeriods,
     }
   }
 

+ 30 - 0
cli/src/Types.ts

@@ -142,6 +142,35 @@ export type GroupOpeningStakes = {
   role?: StakingPolicy
 }
 
+export const stakingPolicyUnstakingPeriodKeys = [
+  'crowded_out_unstaking_period_length',
+  'review_period_expired_unstaking_period_length',
+] as const
+
+export type StakingPolicyUnstakingPeriodKey = typeof stakingPolicyUnstakingPeriodKeys[number]
+
+export const openingPolicyUnstakingPeriodsKeys = [
+  'fill_opening_failed_applicant_application_stake_unstaking_period',
+  'fill_opening_failed_applicant_role_stake_unstaking_period',
+  'fill_opening_successful_applicant_application_stake_unstaking_period',
+  'terminate_application_stake_unstaking_period',
+  'terminate_role_stake_unstaking_period',
+  'exit_role_application_stake_unstaking_period',
+  'exit_role_stake_unstaking_period',
+] as const
+
+export type OpeningPolicyUnstakingPeriodsKey = typeof openingPolicyUnstakingPeriodsKeys[number]
+export type UnstakingPeriodsKey =
+  | OpeningPolicyUnstakingPeriodsKey
+  | 'crowded_out_application_stake_unstaking_period_length'
+  | 'crowded_out_role_stake_unstaking_period_length'
+  | 'review_period_expired_application_stake_unstaking_period_length'
+  | 'review_period_expired_role_stake_unstaking_period_length'
+
+export type UnstakingPeriods = {
+  [k in UnstakingPeriodsKey]: number
+}
+
 export type GroupOpening = {
   wgOpeningId: number
   openingId: number
@@ -150,6 +179,7 @@ export type GroupOpening = {
   stakes: GroupOpeningStakes
   applications: GroupApplication[]
   type: OpeningType
+  unstakingPeriods: UnstakingPeriods
 }
 
 // Some helper structs for generating human_readable_text in working group opening extrinsic

+ 9 - 1
cli/src/commands/working-groups/opening.ts

@@ -1,7 +1,7 @@
 import WorkingGroupsCommandBase from '../../base/WorkingGroupsCommandBase'
 import { displayTable, displayCollapsedRow, displayHeader } from '../../helpers/display'
 import _ from 'lodash'
-import { OpeningStatus, GroupOpeningStage, GroupOpeningStakes } from '../../Types'
+import { OpeningStatus, GroupOpeningStage, GroupOpeningStakes, NameValueObj, UnstakingPeriodsKey } from '../../Types'
 import { StakingAmountLimitModeKeys, StakingPolicy } from '@joystream/types/hiring'
 import { formatBalance } from '@polkadot/util'
 import chalk from 'chalk'
@@ -65,6 +65,14 @@ export default class WorkingGroupsOpening extends WorkingGroupsCommandBase {
     }
     displayCollapsedRow(openingRow)
 
+    displayHeader('Unstaking periods')
+    const periodsRow: { [k: string]: string } = {}
+    for (const key of Object.keys(opening.unstakingPeriods).sort()) {
+      const displayKey = _.startCase(key) + ':  '
+      periodsRow[displayKey] = opening.unstakingPeriods[key as UnstakingPeriodsKey].toLocaleString() + ' blocks'
+    }
+    displayCollapsedRow(periodsRow)
+
     displayHeader(`Applications (${opening.applications.length})`)
     const applicationsRows = opening.applications.map((a) => ({
       'WG appl. ID': a.wgApplicationId,