File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 11import { BatchId , Utils } from '@ethersphere/bee-js'
22import { Dates , Numbers } from 'cafe-utility'
3+ import chalk from 'chalk'
34import { BigNumber } from 'ethers'
45import { LeafCommand , Option } from 'furious-commander'
6+ import { exit } from 'process'
57import { isChainStateReady } from '../../utils/chainsync'
68import { createSpinner } from '../../utils/spinner'
79import { createKeyValue } from '../../utils/text'
@@ -78,6 +80,20 @@ export class Buy extends StampCommand implements LeafCommand {
7880 }
7981
8082 const estimatedCost = Utils . getStampCost ( this . depth , BigInt ( this . amount ) )
83+ const { bzzBalance } = await this . bee . getWalletBalance ( )
84+
85+ if ( estimatedCost . gt ( bzzBalance ) ) {
86+ this . console . error ( 'You do not have enough BZZ to create this postage stamp.' )
87+ this . console . error ( `Estimated cost: ${ estimatedCost . toDecimalString ( ) } xBZZ` )
88+ this . console . error ( `Available balance: ${ bzzBalance . toDecimalString ( ) } xBZZ` )
89+
90+ this . console . log ( '' )
91+ this . console . log ( 'Visit the following link to learn how to fund your Bee node:' )
92+ this . console . log ( chalk . blue ( 'https://docs.ethswarm.org/docs/bee/installation/fund-your-node/' ) )
93+
94+ exit ( 1 )
95+ }
96+
8197 const estimatedCapacity = Numbers . convertBytes ( Utils . getStampEffectiveBytes ( this . depth ) )
8298 const estimatedTtl = Utils . getStampDuration ( BigInt ( this . amount ) , Number ( chainState . currentPrice ) , 5 )
8399
Original file line number Diff line number Diff line change 11import { BatchId , Duration , Size } from '@ethersphere/bee-js'
22import { Dates , Numbers } from 'cafe-utility'
3+ import chalk from 'chalk'
34import { LeafCommand , Option } from 'furious-commander'
5+ import { exit } from 'process'
46import { isChainStateReady } from '../../utils/chainsync'
57import { createSpinner } from '../../utils/spinner'
68import { createKeyValue } from '../../utils/text'
@@ -85,6 +87,18 @@ export class Create extends StampCommand implements LeafCommand {
8587 const estimatedCost = await this . bee . getStorageCost ( size , duration )
8688 const { bzzBalance } = await this . bee . getWalletBalance ( )
8789
90+ if ( estimatedCost . gt ( bzzBalance ) ) {
91+ this . console . error ( 'You do not have enough BZZ to create this postage stamp.' )
92+ this . console . error ( `Estimated cost: ${ estimatedCost . toDecimalString ( ) } xBZZ` )
93+ this . console . error ( `Available balance: ${ bzzBalance . toDecimalString ( ) } xBZZ` )
94+
95+ this . console . log ( '' )
96+ this . console . log ( 'Visit the following link to learn how to fund your Bee node:' )
97+ this . console . log ( chalk . blue ( 'https://docs.ethswarm.org/docs/bee/installation/fund-your-node/' ) )
98+
99+ exit ( 1 )
100+ }
101+
88102 this . console . log ( '' )
89103 this . console . log ( createKeyValue ( 'Cost' , `${ estimatedCost . toDecimalString ( ) } xBZZ` ) )
90104 this . console . log ( createKeyValue ( 'Available' , `${ bzzBalance . toDecimalString ( ) } xBZZ` ) )
You can’t perform that action at this time.
0 commit comments