Skip to content

Commit 0aab27e

Browse files
authored
Add the ability to unset default account in CLI (#5263)
You can now use `wallet:use --unset` to unset the default account
1 parent a33e3eb commit 0aab27e

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed
Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* This Source Code Form is subject to the terms of the Mozilla Public
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* 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'
55
import { IronfishCommand } from '../../command'
66
import { RemoteFlags } from '../../flags'
77

@@ -10,21 +10,32 @@ export class UseCommand extends IronfishCommand {
1010

1111
static args = {
1212
account: Args.string({
13-
required: true,
1413
description: 'Name of the account',
1514
}),
1615
}
1716

1817
static flags = {
1918
...RemoteFlags,
19+
unset: Flags.boolean({
20+
description: 'Clear the default account',
21+
}),
2022
}
2123

2224
async start(): Promise<void> {
23-
const { args } = await this.parse(UseCommand)
25+
const { args, flags } = await this.parse(UseCommand)
2426
const { account } = args
27+
const { unset } = flags
28+
29+
if (!account && !unset) {
30+
this.error('You must provide the name of an account')
31+
}
2532

2633
const client = await this.connectRpc()
2734
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+
}
2940
}
3041
}

ironfish/src/rpc/routes/wallet/useAccount.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import { routes } from '../router'
77
import { AssertHasRpcContext } from '../rpcContext'
88
import { getAccount } from './utils'
99

10-
export type UseAccountRequest = { account: string }
10+
export type UseAccountRequest = { account?: string }
1111
export type UseAccountResponse = undefined
1212

1313
export const UseAccountRequestSchema: yup.ObjectSchema<UseAccountRequest> = yup
1414
.object({
15-
account: yup.string().defined(),
15+
account: yup.string().optional(),
1616
})
1717
.defined()
1818

@@ -26,8 +26,12 @@ routes.register<typeof UseAccountRequestSchema, UseAccountResponse>(
2626
async (request, context): Promise<void> => {
2727
AssertHasRpcContext(request, context, 'wallet')
2828

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)
3135
request.end()
3236
},
3337
)

0 commit comments

Comments
 (0)