Skip to content

Commit

Permalink
refactor: use bee-js wait for stamp instead of custom (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cafe137 authored Feb 8, 2024
1 parent ab3e13e commit 64b08c8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 49 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"typescript": "^4.8.4"
},
"dependencies": {
"@ethersphere/bee-js": "^6.7.2",
"@ethersphere/bee-js": "^6.7.3",
"@fairdatasociety/bmt-js": "^2.1.0",
"bignumber.js": "^9.1.0",
"chalk": "^2.4.2",
Expand Down
45 changes: 4 additions & 41 deletions src/command/stamp/buy.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Utils } from '@ethersphere/bee-js'
import { LeafCommand, Option } from 'furious-commander'
import { printStamp } from '../../service/stamp'
import { secondsToDhms, sleep } from '../../utils'
import { secondsToDhms } from '../../utils'
import { createSpinner } from '../../utils/spinner'
import { Storage } from '../../utils/storage'
import { createKeyValue, deletePreviousLine } from '../../utils/text'
import { createKeyValue } from '../../utils/text'
import { VerbosityLevel } from '../root-command/command-log'
import { StampCommand } from './stamp-command'

Expand Down Expand Up @@ -87,7 +86,7 @@ export class Buy extends StampCommand implements LeafCommand {
return
}

const spinner = createSpinner('Buying postage stamp. This may take a few minutes.')
const spinner = createSpinner('Creating postage batch. This may take up to 5 minutes.')

if (this.verbosity !== VerbosityLevel.Quiet && !this.curl) {
spinner.start()
Expand All @@ -98,6 +97,7 @@ export class Buy extends StampCommand implements LeafCommand {
label: this.label,
gasPrice: this.gasPrice?.toString(),
immutableFlag: this.immutable,
waitForUsable: this.waitUsable === false ? false : true,
})
spinner.stop()
this.console.quiet(batchId)
Expand All @@ -106,42 +106,5 @@ export class Buy extends StampCommand implements LeafCommand {
} finally {
spinner.stop()
}

if (this.waitUsable) {
await this.waitToBecomeUsable()
}
}

private async waitToBecomeUsable(): Promise<void> {
const spinner = createSpinner('Waiting for postage stamp to become usable...')

if (this.verbosity !== VerbosityLevel.Quiet && !this.curl) {
spinner.start()
}
let running = true

while (running) {
try {
const stamp = await this.beeDebug.getPostageBatch(this.postageBatchId)

if (!stamp.usable) {
await sleep(1000)
continue
}

spinner.stop()

if (this.verbosity === VerbosityLevel.Verbose) {
if (!this.curl) {
deletePreviousLine()
}
printStamp(stamp, this.console, { showTtl: true })
}
running = false
} catch {
await sleep(1000)
}
}
spinner.stop()
}
}

0 comments on commit 64b08c8

Please sign in to comment.