From c926d7d1514e96166e8e1c91d9a83beae22cc2a3 Mon Sep 17 00:00:00 2001 From: Cafe137 Date: Thu, 8 Feb 2024 15:26:43 +0100 Subject: [PATCH] refactor: use bee-js wait for stamp instead of custom --- package-lock.json | 14 ++++++------- package.json | 2 +- src/command/stamp/buy.ts | 45 ++++------------------------------------ 3 files changed, 12 insertions(+), 49 deletions(-) diff --git a/package-lock.json b/package-lock.json index c51b69b6..2baca4b0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "2.7.0", "license": "BSD-3-Clause", "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", @@ -1227,9 +1227,9 @@ } }, "node_modules/@ethersphere/bee-js": { - "version": "6.7.2", - "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-6.7.2.tgz", - "integrity": "sha512-cLwegviwhjXnilOLvvovCLvcgJgxpqTKTQjJ6pmqkR7628ymni3MzJystn70d3Jlai9Xj+Xqju2yyfVtAi0GSg==", + "version": "6.7.3", + "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-6.7.3.tgz", + "integrity": "sha512-04AXGXP148DousgjVInyGUlHZnWwTGIgiH5leCACJ6daAUnnJQm7CjQgXIH5y72gGPX1XyzXDlqBlB8zLkihkQ==", "dependencies": { "@ethersphere/swarm-cid": "^0.1.0", "@types/readable-stream": "^2.3.13", @@ -10667,9 +10667,9 @@ } }, "@ethersphere/bee-js": { - "version": "6.7.2", - "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-6.7.2.tgz", - "integrity": "sha512-cLwegviwhjXnilOLvvovCLvcgJgxpqTKTQjJ6pmqkR7628ymni3MzJystn70d3Jlai9Xj+Xqju2yyfVtAi0GSg==", + "version": "6.7.3", + "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-6.7.3.tgz", + "integrity": "sha512-04AXGXP148DousgjVInyGUlHZnWwTGIgiH5leCACJ6daAUnnJQm7CjQgXIH5y72gGPX1XyzXDlqBlB8zLkihkQ==", "requires": { "@ethersphere/swarm-cid": "^0.1.0", "@types/readable-stream": "^2.3.13", diff --git a/package.json b/package.json index 6aac3f59..cc55914f 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/command/stamp/buy.ts b/src/command/stamp/buy.ts index 1be65bd2..7e998236 100644 --- a/src/command/stamp/buy.ts +++ b/src/command/stamp/buy.ts @@ -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' @@ -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() @@ -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) @@ -106,42 +106,5 @@ export class Buy extends StampCommand implements LeafCommand { } finally { spinner.stop() } - - if (this.waitUsable) { - await this.waitToBecomeUsable() - } - } - - private async waitToBecomeUsable(): Promise { - 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() } }