-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathinfo.ts
57 lines (51 loc) · 2.29 KB
/
info.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
import AccountsCommandBase from '../../base/AccountsCommandBase'
import ExitCodes from '../../ExitCodes'
import { validateAddress } from '../../helpers/validation'
import { NameValueObj } from '../../Types'
import { displayHeader, displayNameValueTable } from '../../helpers/display'
import { formatBalance } from '@polkadot/util'
import moment from 'moment'
import { DEFAULT_DATE_FORMAT } from '../../Consts'
export default class AccountInfo extends AccountsCommandBase {
static description = 'Display detailed information about specified account'
static aliases = ['account:inspect']
static args = [
{ name: 'address', required: false, description: 'An address to inspect (can also be provided interavtively)' },
]
async run(): Promise<void> {
let { address } = this.parse(AccountInfo).args
if (!address) {
address = await this.promptForAnyAddress()
} else if (validateAddress(address) !== true) {
this.error('Invalid address', { exit: ExitCodes.InvalidInput })
}
const summary = await this.getApi().getAccountSummary(address)
displayHeader('Account information')
const accountRows: NameValueObj[] = [{ name: 'Address:', value: address }]
if (this.isKeyAvailable(address)) {
const pair = this.getPair(address)
accountRows.push({ name: 'Account name', value: pair.meta.name })
accountRows.push({ name: 'Type', value: pair.type })
const creationDate = pair.meta.whenCreated
? moment(pair.meta.whenCreated as string | number).format(DEFAULT_DATE_FORMAT)
: null
if (creationDate) {
accountRows.push({ name: 'Creation date', value: creationDate })
}
}
displayNameValueTable(accountRows)
displayHeader('Balances')
const balances = summary.balances
const balancesRows: NameValueObj[] = [
{ name: 'Total balance:', value: formatBalance(balances.votingBalance) },
{ name: 'Transferable balance:', value: formatBalance(balances.availableBalance) },
]
if (balances.lockedBalance.gtn(0)) {
balancesRows.push({ name: 'Locked balance:', value: formatBalance(balances.lockedBalance) })
}
if (balances.reservedBalance.gtn(0)) {
balancesRows.push({ name: 'Reserved balance:', value: formatBalance(balances.reservedBalance) })
}
displayNameValueTable(balancesRows)
}
}