Skip to content

Commit

Permalink
accounting for 0 spendposttime
Browse files Browse the repository at this point in the history
  • Loading branch information
patnir committed Mar 21, 2024
1 parent 8497a4f commit 6fd79da
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 93 deletions.
19 changes: 12 additions & 7 deletions ironfish-cli/src/commands/wallet/notes/combine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ import { getExplorer } from '../../../utils/explorer'
import { selectFee } from '../../../utils/fees'
import { fetchNotes } from '../../../utils/note'
import { getSpendPostTimeInMs } from '../../../utils/spendPostTime'
import { TransactionTimer } from '../../../utils/timer'
import { displayTransactionSummary, watchTransaction } from '../../../utils/transaction'
import {
displayTransactionSummary,
TransactionTimer,
watchTransaction,
} from '../../../utils/transaction'

export class CombineNotesCommand extends IronfishCommand {
static description = `Combine notes into a single note`
Expand Down Expand Up @@ -300,11 +303,13 @@ export class CombineNotesCommand extends IronfishCommand {

const transactionTimer = new TransactionTimer(spendPostTime, raw)

this.log(
`Time to combine: ${TimeUtils.renderSpan(transactionTimer.getEstimateInMs(), {
hideMilliseconds: true,
})}`,
)
if (spendPostTime > 0) {
this.log(
`Time to combine: ${TimeUtils.renderSpan(transactionTimer.getEstimateInMs(), {
hideMilliseconds: true,
})}`,
)
}

if (!flags.confirm) {
const confirmed = await CliUx.ux.confirm('Do you confirm (Y/N)?')
Expand Down
85 changes: 0 additions & 85 deletions ironfish-cli/src/utils/timer.ts

This file was deleted.

14 changes: 13 additions & 1 deletion ironfish-cli/src/utils/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ export class TransactionTimer {
private timer: NodeJS.Timer | undefined

constructor(spendPostTime: number, raw: RawTransaction) {
this.estimateInMs = Math.max(Math.ceil(spendPostTime * raw.spends.length), 1000)
// if spendPostTime is 0, there means that there was an issue measuring the spendPostTime
// we will not show the progress bar in this case

this.estimateInMs =
spendPostTime > 0 ? Math.max(Math.ceil(spendPostTime * raw.spends.length), 1000) : -1
}

getEstimateInMs(): number {
Expand All @@ -46,6 +50,10 @@ export class TransactionTimer {
}

start() {
if (this.estimateInMs <= 0) {
return
}

this.progressBar = CliUx.ux.progress({
format: '{title}: [{bar}] {percentage}% | {estimate}',
}) as ProgressBar
Expand All @@ -72,6 +80,10 @@ export class TransactionTimer {
}

end() {
if (this.estimateInMs <= 0) {
return
}

if (!this.progressBar || !this.startTime || !this.timer) {
return
}
Expand Down

0 comments on commit 6fd79da

Please sign in to comment.