From 97d5192a43a341c114d88148e13bb8e778714d73 Mon Sep 17 00:00:00 2001 From: Levente Kiss Date: Tue, 5 Dec 2023 16:32:49 +0100 Subject: [PATCH 1/2] feat: display estimated effective volume during buy (#479) --- package-lock.json | 14 +++++++------- package.json | 2 +- src/command/stamp/buy.ts | 2 ++ test/prompt/stamp-prompt.spec.ts | 3 ++- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index 441c51ab..96bef768 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.5.1", + "@ethersphere/bee-js": "^6.7.0", "@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.5.1", - "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-6.5.1.tgz", - "integrity": "sha512-qJPdzMAaoFqXzaKlwDaFko68X+FOP2VL9P+yy964boq/hJeDS3d5avo1KtzSR1pIHWs4aPdREvmQ3tgOdOT5+g==", + "version": "6.7.0", + "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-6.7.0.tgz", + "integrity": "sha512-t1bsUj9BmICuRL6XENTVyZZCfkFuCjc6pQxOekuVFLBd0Qpmyf87iRpVizvZN5IKhVqqw9xCzkg8otJKQdAKNA==", "dependencies": { "@ethersphere/swarm-cid": "^0.1.0", "@types/readable-stream": "^2.3.13", @@ -10667,9 +10667,9 @@ } }, "@ethersphere/bee-js": { - "version": "6.5.1", - "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-6.5.1.tgz", - "integrity": "sha512-qJPdzMAaoFqXzaKlwDaFko68X+FOP2VL9P+yy964boq/hJeDS3d5avo1KtzSR1pIHWs4aPdREvmQ3tgOdOT5+g==", + "version": "6.7.0", + "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-6.7.0.tgz", + "integrity": "sha512-t1bsUj9BmICuRL6XENTVyZZCfkFuCjc6pQxOekuVFLBd0Qpmyf87iRpVizvZN5IKhVqqw9xCzkg8otJKQdAKNA==", "requires": { "@ethersphere/swarm-cid": "^0.1.0", "@types/readable-stream": "^2.3.13", diff --git a/package.json b/package.json index 0d5ebd76..ef49a806 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "typescript": "^4.8.4" }, "dependencies": { - "@ethersphere/bee-js": "^6.5.1", + "@ethersphere/bee-js": "^6.7.0", "@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..0d8c49a7 100644 --- a/src/command/stamp/buy.ts +++ b/src/command/stamp/buy.ts @@ -62,10 +62,12 @@ export class Buy extends StampCommand implements LeafCommand { const estimatedCost = Utils.getStampCostInBzz(this.depth, Number(this.amount)) const estimatedCapacity = new Storage(Utils.getStampMaximumCapacityBytes(this.depth)) + const estimatedEffectiveVolume = new Storage(Utils.getStampEffectiveBytes(this.depth)) const estimatedTtl = Utils.getStampTtlSeconds(Number(this.amount)) this.console.log(createKeyValue('Estimated cost', `${estimatedCost.toFixed(3)} BZZ`)) this.console.log(createKeyValue('Estimated capacity', estimatedCapacity.toString())) + this.console.log(createKeyValue('Estimated effective volume', estimatedEffectiveVolume.toString())) this.console.log(createKeyValue('Estimated TTL', secondsToDhms(estimatedTtl))) this.console.log(createKeyValue('Type', this.immutable ? 'Immutable' : 'Mutable')) diff --git a/test/prompt/stamp-prompt.spec.ts b/test/prompt/stamp-prompt.spec.ts index bdc61bee..82231815 100644 --- a/test/prompt/stamp-prompt.spec.ts +++ b/test/prompt/stamp-prompt.spec.ts @@ -8,7 +8,8 @@ describeCommand('Postage stamp price estimation prompt', ({ consoleMessages }) = await invokeTestCli(['stamp', 'buy', '--depth', '24', '--amount', '596046400']) expect(consoleMessages[0]).toBe('Estimated cost: 1.000 BZZ') expect(consoleMessages[1]).toBe('Estimated capacity: 64.00 GB') - expect(consoleMessages[2]).toBe('Estimated TTL: 1 day 10 hours 29 minutes 36 seconds') + expect(consoleMessages[2]).toBe('Estimated effective volume: 41.17 GB') + expect(consoleMessages[3]).toBe('Estimated TTL: 1 day 10 hours 29 minutes 36 seconds') expect(inquirer.prompt).toHaveBeenCalledWith({ message: 'Confirm the purchase', name: 'value', From ff0e7a86e7ff18deed158aeb92ae901408188bea Mon Sep 17 00:00:00 2001 From: Levente Kiss Date: Mon, 12 Feb 2024 15:37:39 +0100 Subject: [PATCH 2/2] chore: requested change - user friendly msg for a condition --- src/command/stamp/buy.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/command/stamp/buy.ts b/src/command/stamp/buy.ts index 0d8c49a7..35a3d6d7 100644 --- a/src/command/stamp/buy.ts +++ b/src/command/stamp/buy.ts @@ -67,7 +67,14 @@ export class Buy extends StampCommand implements LeafCommand { this.console.log(createKeyValue('Estimated cost', `${estimatedCost.toFixed(3)} BZZ`)) this.console.log(createKeyValue('Estimated capacity', estimatedCapacity.toString())) - this.console.log(createKeyValue('Estimated effective volume', estimatedEffectiveVolume.toString())) + this.console.log( + createKeyValue( + 'Estimated effective volume', + estimatedEffectiveVolume.getBytes() === 0 + ? "It's likely to be smaller than estimated capacity" + : estimatedEffectiveVolume.toString(), + ), + ) this.console.log(createKeyValue('Estimated TTL', secondsToDhms(estimatedTtl))) this.console.log(createKeyValue('Type', this.immutable ? 'Immutable' : 'Mutable'))