Skip to content
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
16 changes: 16 additions & 0 deletions src/command/stamp/buy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { BatchId, Utils } from '@ethersphere/bee-js'
import { Dates, Numbers } from 'cafe-utility'
import chalk from 'chalk'
import { BigNumber } from 'ethers'
import { LeafCommand, Option } from 'furious-commander'
import { exit } from 'process'
import { isChainStateReady } from '../../utils/chainsync'
import { createSpinner } from '../../utils/spinner'
import { createKeyValue } from '../../utils/text'
Expand Down Expand Up @@ -78,6 +80,20 @@ export class Buy extends StampCommand implements LeafCommand {
}

const estimatedCost = Utils.getStampCost(this.depth, BigInt(this.amount))
const { bzzBalance } = await this.bee.getWalletBalance()

if (estimatedCost.gt(bzzBalance)) {
this.console.error('You do not have enough BZZ to create this postage stamp.')
this.console.error(`Estimated cost: ${estimatedCost.toDecimalString()} xBZZ`)
this.console.error(`Available balance: ${bzzBalance.toDecimalString()} xBZZ`)

this.console.log('')
this.console.log('Visit the following link to learn how to fund your Bee node:')
this.console.log(chalk.blue('https://docs.ethswarm.org/docs/bee/installation/fund-your-node/'))

exit(1)
}

const estimatedCapacity = Numbers.convertBytes(Utils.getStampEffectiveBytes(this.depth))
const estimatedTtl = Utils.getStampDuration(BigInt(this.amount), Number(chainState.currentPrice), 5)

Expand Down
14 changes: 14 additions & 0 deletions src/command/stamp/create.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { BatchId, Duration, Size } from '@ethersphere/bee-js'
import { Dates, Numbers } from 'cafe-utility'
import chalk from 'chalk'
import { LeafCommand, Option } from 'furious-commander'
import { exit } from 'process'
import { isChainStateReady } from '../../utils/chainsync'
import { createSpinner } from '../../utils/spinner'
import { createKeyValue } from '../../utils/text'
Expand Down Expand Up @@ -85,6 +87,18 @@ export class Create extends StampCommand implements LeafCommand {
const estimatedCost = await this.bee.getStorageCost(size, duration)
const { bzzBalance } = await this.bee.getWalletBalance()

if (estimatedCost.gt(bzzBalance)) {
this.console.error('You do not have enough BZZ to create this postage stamp.')
this.console.error(`Estimated cost: ${estimatedCost.toDecimalString()} xBZZ`)
this.console.error(`Available balance: ${bzzBalance.toDecimalString()} xBZZ`)

this.console.log('')
this.console.log('Visit the following link to learn how to fund your Bee node:')
this.console.log(chalk.blue('https://docs.ethswarm.org/docs/bee/installation/fund-your-node/'))

exit(1)
}

this.console.log('')
this.console.log(createKeyValue('Cost', `${estimatedCost.toDecimalString()} xBZZ`))
this.console.log(createKeyValue('Available', `${bzzBalance.toDecimalString()} xBZZ`))
Expand Down
Loading