Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use bee-js wait for stamp instead of custom #494

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
}
Loading