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

feat: display estimated effective volume during buy (#479) #485

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions src/command/stamp/buy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,19 @@ 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.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'))

Expand Down
3 changes: 2 additions & 1 deletion test/prompt/stamp-prompt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading