Skip to content
This repository has been archived by the owner on Nov 14, 2019. It is now read-only.

Improve ux of account commands #100

Merged
merged 6 commits into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/account-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@ export abstract class WithPassphrase extends WithoutPassphrase {
static flags = {
...WithoutPassphrase.flags,
passphrase: flags.string({
description: 'Passphrase to unlock your account'
description: 'Passphrase of the account'
})
}

async getPassphrase(): Promise<string | null> {
const {flags} = this.parse()
if (flags.passphrase) {
return flags.passphrase
}
const passphrase = await cli.prompt('Type your passphrase', {type: 'hide'})
return passphrase
if (flags.passphrase) return flags.passphrase
return cli.prompt('Type the passphrase of the account', {type: 'hide'})
NicolasMahe marked this conversation as resolved.
Show resolved Hide resolved
}
}
12 changes: 6 additions & 6 deletions src/commands/account/create.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import {WithPassphrase as Command} from '../../account-command'

export default class AccountCreate extends Command {
static description = 'Create a new account'
static description = 'Create an account'

static flags = {
...Command.flags,
}

async run() {
this.spinner.start('Create account')
const passphrase = await this.getPassphrase()
this.spinner.start('Creating account')
const data = await this.execute({
instanceHash: await this.engineServiceInstance(Command.SERVICE_NAME),
taskKey: 'create',
inputs: JSON.stringify({
passphrase: await this.getPassphrase(),
})
inputs: JSON.stringify({passphrase})
})
this.spinner.stop(data.address)
this.spinner.stop()
this.log(`Account address ${data.address}`)
return data
}
}
11 changes: 6 additions & 5 deletions src/commands/account/delete.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {WithPassphrase as Command} from '../../account-command'

export default class AccountDelete extends Command {
static description = 'Delete an existing account'
static description = 'Delete an account'

static flags = {
...Command.flags,
Expand All @@ -14,17 +14,18 @@ export default class AccountDelete extends Command {

async run() {
const {args} = this.parse(AccountDelete)

this.spinner.start('Delete account')
const passphrase = await this.getPassphrase()
this.spinner.start(`Deleting account ${args.ADDRESS}`)
const data = await this.execute({
instanceHash: await this.engineServiceInstance(Command.SERVICE_NAME),
taskKey: 'delete',
inputs: JSON.stringify({
passphrase: await this.getPassphrase(),
address: args.ADDRESS,
passphrase
})
})
this.spinner.stop(data.address)
this.spinner.stop()
this.log(`Account ${data.address} deleted`)
return data
}
}
6 changes: 3 additions & 3 deletions src/commands/account/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ export default class AccountExport extends Command {

async run() {
const {args} = this.parse(AccountExport)

this.spinner.start('Export account')
const passphrase = await this.getPassphrase()
this.spinner.start(`Exporting account ${args.ADDRESS}`)
const data = await this.execute({
instanceHash: await this.engineServiceInstance(Command.SERVICE_NAME),
taskKey: 'export',
inputs: JSON.stringify({
passphrase: await this.getPassphrase(),
address: args.ADDRESS,
passphrase,
})
})
this.spinner.stop()
Expand Down
13 changes: 7 additions & 6 deletions src/commands/account/import-private-key.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
import {WithPassphrase as Command} from '../../account-command'

export default class AccountImportPK extends Command {
static description = 'Import a account from a private key'
static description = 'Import an account with a private key'

static flags = {
...Command.flags,
}

static args = [{
name: 'PRIVATE_KEY',
description: 'Private key for your account',
description: 'Private key of the account',
required: true,
}]

async run() {
const {args} = this.parse(AccountImportPK)

this.spinner.start('Import account')
const passphrase = await this.getPassphrase()
this.spinner.start('Importing account')
const data = await this.execute({
instanceHash: await this.engineServiceInstance(Command.SERVICE_NAME),
taskKey: 'importFromPrivateKey',
inputs: JSON.stringify({
passphrase: await this.getPassphrase(),
privateKey: args.PRIVATE_KEY,
passphrase,
})
})
this.spinner.stop(data.address)
this.spinner.stop()
this.log(`Account ${data.address} imported`)
return data
}
}
13 changes: 7 additions & 6 deletions src/commands/account/import.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
import {WithPassphrase as Command} from '../../account-command'

export default class AccountImport extends Command {
static description = 'Import a account'
static description = 'Import an account'

static flags = {
...Command.flags,
}

static args = [{
name: 'ACCOUNT',
description: 'Account saved from a previous account',
description: 'Previously exported account in JSON',
NicolasMahe marked this conversation as resolved.
Show resolved Hide resolved
required: true
}]

async run() {
const {args} = this.parse(AccountImport)

this.spinner.start('Import account')
const passphrase = await this.getPassphrase()
this.spinner.start('Importing account')
const data = await this.execute({
instanceHash: await this.engineServiceInstance(Command.SERVICE_NAME),
taskKey: 'import',
inputs: JSON.stringify({
passphrase: await this.getPassphrase(),
account: JSON.parse(args.ACCOUNT),
passphrase,
})
})
this.spinner.stop(data.address)
this.spinner.stop()
this.log(`Account ${data.address} imported`)
return data
}
}
4 changes: 3 additions & 1 deletion src/commands/account/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {cli} from 'cli-ux'
import {WithoutPassphrase as Command} from '../../account-command'

export default class AccountList extends Command {
static description = 'List all existing accounts'
static description = 'List accounts'

static flags = {
...Command.flags,
Expand All @@ -12,11 +12,13 @@ export default class AccountList extends Command {

async run() {
const {flags} = this.parse(AccountList)
this.spinner.start('Listing accounts')
const data = await this.execute({
instanceHash: await this.engineServiceInstance(Command.SERVICE_NAME),
taskKey: 'list',
inputs: JSON.stringify({})
})
this.spinner.stop()
cli.table(data.addresses, {
address: {header: 'ADDRESS', get: (x: any) => x},
}, {printLine: this.log, ...flags})
Expand Down