File tree Expand file tree Collapse file tree 2 files changed +23
-8
lines changed
ironfish-cli/src/commands/wallet
ironfish/src/rpc/routes/wallet Expand file tree Collapse file tree 2 files changed +23
-8
lines changed Original file line number Diff line number Diff line change 1
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
2
* License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
- import { Args } from '@oclif/core'
4
+ import { Args , Flags } from '@oclif/core'
5
5
import { IronfishCommand } from '../../command'
6
6
import { RemoteFlags } from '../../flags'
7
7
@@ -10,21 +10,32 @@ export class UseCommand extends IronfishCommand {
10
10
11
11
static args = {
12
12
account : Args . string ( {
13
- required : true ,
14
13
description : 'Name of the account' ,
15
14
} ) ,
16
15
}
17
16
18
17
static flags = {
19
18
...RemoteFlags ,
19
+ unset : Flags . boolean ( {
20
+ description : 'Clear the default account' ,
21
+ } ) ,
20
22
}
21
23
22
24
async start ( ) : Promise < void > {
23
- const { args } = await this . parse ( UseCommand )
25
+ const { args, flags } = await this . parse ( UseCommand )
24
26
const { account } = args
27
+ const { unset } = flags
28
+
29
+ if ( ! account && ! unset ) {
30
+ this . error ( 'You must provide the name of an account' )
31
+ }
25
32
26
33
const client = await this . connectRpc ( )
27
34
await client . wallet . useAccount ( { account } )
28
- this . log ( `The default account is now: ${ account } ` )
35
+ if ( account == null ) {
36
+ this . log ( 'The default account has been unset' )
37
+ } else {
38
+ this . log ( `The default account is now: ${ account } ` )
39
+ }
29
40
}
30
41
}
Original file line number Diff line number Diff line change @@ -7,12 +7,12 @@ import { routes } from '../router'
7
7
import { AssertHasRpcContext } from '../rpcContext'
8
8
import { getAccount } from './utils'
9
9
10
- export type UseAccountRequest = { account : string }
10
+ export type UseAccountRequest = { account ? : string }
11
11
export type UseAccountResponse = undefined
12
12
13
13
export const UseAccountRequestSchema : yup . ObjectSchema < UseAccountRequest > = yup
14
14
. object ( {
15
- account : yup . string ( ) . defined ( ) ,
15
+ account : yup . string ( ) . optional ( ) ,
16
16
} )
17
17
. defined ( )
18
18
@@ -26,8 +26,12 @@ routes.register<typeof UseAccountRequestSchema, UseAccountResponse>(
26
26
async ( request , context ) : Promise < void > => {
27
27
AssertHasRpcContext ( request , context , 'wallet' )
28
28
29
- const account = getAccount ( context . wallet , request . data . account )
30
- await context . wallet . setDefaultAccount ( account . name )
29
+ let accountName = null
30
+ if ( request . data . account ) {
31
+ accountName = getAccount ( context . wallet , request . data . account ) . name
32
+ }
33
+
34
+ await context . wallet . setDefaultAccount ( accountName )
31
35
request . end ( )
32
36
} ,
33
37
)
You can’t perform that action at this time.
0 commit comments