-
Notifications
You must be signed in to change notification settings - Fork 115
/
opening.ts
110 lines (100 loc) · 4.04 KB
/
opening.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import WorkingGroupsCommandBase from '../../base/WorkingGroupsCommandBase'
import { displayTable, displayCollapsedRow, displayHeader, shortAddress, memberHandle } from '../../helpers/display'
import { formatBalance } from '@polkadot/util'
import { flags } from '@oclif/command'
import moment from 'moment'
import { OpeningDetails } from '../../Types'
import chalk from 'chalk'
import ExitCodes from '../../ExitCodes'
import { UpcomingWorkingGroupOpeningDetailsFragment } from '../../graphql/generated/queries'
import { DEFAULT_DATE_FORMAT } from '../../Consts'
export default class WorkingGroupsOpening extends WorkingGroupsCommandBase {
static description = 'Shows detailed information about working group opening / upcoming opening by id'
static flags = {
id: flags.string({
required: true,
description: 'Opening / upcoming opening id (depending on --upcoming flag)',
}),
upcoming: flags.boolean({
description: 'Whether the opening is an upcoming opening',
}),
...WorkingGroupsCommandBase.flags,
}
openingDetails(opening: OpeningDetails): void {
displayHeader('Opening details')
displayCollapsedRow({
'Opening ID': opening.openingId,
'Opening type': opening.type.type,
'Created': `#${opening.createdAtBlock}`,
'Reward per block': opening.rewardPerBlock ? formatBalance(opening.rewardPerBlock) : '-',
})
}
openingStakingPolicy(opening: OpeningDetails): void {
displayHeader('Staking policy')
displayCollapsedRow({
'Stake amount': formatBalance(opening.stake.value),
'Unstaking period': opening.stake.unstakingPeriod.toLocaleString() + ' blocks',
})
}
upcomingOpeningDetails(upcomingOpening: UpcomingWorkingGroupOpeningDetailsFragment): void {
displayHeader('Upcoming opening details')
displayCollapsedRow({
'Upcoming Opening ID': upcomingOpening.id,
'Expected start': upcomingOpening.expectedStart
? moment(upcomingOpening.expectedStart).format(DEFAULT_DATE_FORMAT)
: '?',
'Reward per block': upcomingOpening.rewardPerBlock ? formatBalance(upcomingOpening.rewardPerBlock) : '?',
})
}
upcomingOpeningStakingPolicy(upcomingOpening: UpcomingWorkingGroupOpeningDetailsFragment): void {
if (upcomingOpening.stakeAmount) {
displayHeader('Staking policy')
displayCollapsedRow({
'Stake amount': formatBalance(upcomingOpening.stakeAmount),
})
}
}
openingMetadata(opening: OpeningDetails | UpcomingWorkingGroupOpeningDetailsFragment): void {
const { metadata } = opening
if (metadata) {
displayHeader('Metadata')
this.jsonPrettyPrint(
JSON.stringify({
...metadata,
expectedEnding: metadata.expectedEnding
? moment(metadata.expectedEnding).format(DEFAULT_DATE_FORMAT)
: undefined,
})
)
}
}
openingApplications(opening: OpeningDetails): void {
displayHeader(`Applications (${opening.applications.length})`)
const applicationsRows = opening.applications.map((a) => ({
'ID': a.applicationId,
Member: memberHandle(a.member),
'Role Acc': shortAddress(a.roleAccount),
'Reward Acc': shortAddress(a.rewardAccount),
'Staking Acc': a.stakingAccount ? shortAddress(a.stakingAccount) : 'NONE',
}))
displayTable(applicationsRows, 5)
}
async run(): Promise<void> {
const { id, upcoming } = this.parse(WorkingGroupsOpening).flags
if (upcoming) {
const upcomingOpening = await this.getQNApi().upcomingWorkingGroupOpeningById(id)
if (!upcomingOpening) {
this.error(`Upcoming opening by id ${chalk.magentaBright(id)} was not found!`, { exit: ExitCodes.InvalidInput })
}
this.upcomingOpeningDetails(upcomingOpening)
this.upcomingOpeningStakingPolicy(upcomingOpening)
this.openingMetadata(upcomingOpening)
} else {
const opening = await this.getApi().groupOpening(this.group, parseInt(id))
this.openingDetails(opening)
this.openingStakingPolicy(opening)
this.openingMetadata(opening)
this.openingApplications(opening)
}
}
}