Skip to content

Commit e942146

Browse files
authored
Add new date flag and use it in transactions cmd (#5654)
1 parent a5afca5 commit e942146

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

ironfish-cli/src/commands/wallet/transactions/index.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from '@ironfish/sdk'
1515
import { Flags } from '@oclif/core'
1616
import { IronfishCommand } from '../../../command'
17-
import { RemoteFlags } from '../../../flags'
17+
import { DateFlag, RemoteFlags } from '../../../flags'
1818
import * as ui from '../../../ui'
1919
import { getAssetsByIDs, useAccount } from '../../../utils'
2020
import { extractChainportDataFromTransaction } from '../../../utils/chainport'
@@ -75,13 +75,11 @@ export class TransactionsCommand extends IronfishCommand {
7575
options: ['notes', 'transactions', 'transfers'],
7676
helpGroup: 'OUTPUT',
7777
}),
78-
'filter.start': Flags.string({
78+
'filter.start': DateFlag({
7979
description: 'include transactions after this date (inclusive). Example: 2023-04-01',
80-
parse: (input) => Promise.resolve(new Date(input).toISOString()),
8180
}),
82-
'filter.end': Flags.string({
81+
'filter.end': DateFlag({
8382
description: 'include transactions before this date (exclusive). Example: 2023-05-01',
84-
parse: (input) => Promise.resolve(new Date(input).toISOString()),
8583
}),
8684
}
8785

@@ -142,19 +140,16 @@ export class TransactionsCommand extends IronfishCommand {
142140
let hasTransactions = false
143141
let transactionRows: PartialRecursive<TransactionRow>[] = []
144142

145-
const filterStart = flags['filter.start'] && new Date(flags['filter.start']).valueOf()
146-
const filterEnd = flags['filter.end'] && new Date(flags['filter.end']).valueOf()
147-
148143
for await (const { account, transaction } of transactions) {
149144
if (transactionRows.length >= flags.limit) {
150145
break
151146
}
152147

153-
if (filterStart && transaction.timestamp < filterStart.valueOf()) {
148+
if (flags['filter.start'] && transaction.timestamp < flags['filter.start'].valueOf()) {
154149
continue
155150
}
156151

157-
if (filterEnd && transaction.timestamp >= filterEnd.valueOf()) {
152+
if (flags['filter.end'] && transaction.timestamp >= flags['filter.end'].valueOf()) {
158153
continue
159154
}
160155

ironfish-cli/src/flags.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,17 @@ export const EnumLanguageKeyFlag = Flags.custom<LanguageKey, { choices: Array<La
212212
}
213213
},
214214
})
215+
216+
export const DateFlag = Flags.custom<Date>({
217+
parse: async (input, _ctx, opts) => {
218+
const parsed = new Date(input)
219+
220+
if (Number.isNaN(parsed.valueOf())) {
221+
throw new Error(
222+
`The value provided for ${opts.name} is an invalid format. It must be a valid date.`,
223+
)
224+
}
225+
226+
return Promise.resolve(parsed)
227+
},
228+
})

0 commit comments

Comments
 (0)