diff --git a/src/command/cheque/index.ts b/src/command/cheque/index.ts index 808de981..0c605099 100644 --- a/src/command/cheque/index.ts +++ b/src/command/cheque/index.ts @@ -3,11 +3,12 @@ import { Cashout } from './cashout' import { Deposit } from './deposit' import { List } from './list' import { Withdraw } from './withdraw' +import { WithdrawAll } from './withdraw-all' export class Cheque implements GroupCommand { public readonly name = 'cheque' public readonly description = 'Deposit, withdraw and manage cheques' - public subCommandClasses = [List, Cashout, Deposit, Withdraw] + public subCommandClasses = [List, Cashout, Deposit, Withdraw, WithdrawAll] } diff --git a/src/command/cheque/withdraw-all.ts b/src/command/cheque/withdraw-all.ts new file mode 100644 index 00000000..38bbb690 --- /dev/null +++ b/src/command/cheque/withdraw-all.ts @@ -0,0 +1,28 @@ +import { Numbers } from 'cafe-utility' +import { LeafCommand } from 'furious-commander' +import { createKeyValue } from '../../utils/text' +import { ChequeCommand } from './cheque-command' + +export class WithdrawAll extends ChequeCommand implements LeafCommand { + public readonly name = 'withdraw-all' + + public readonly alias = 'wa' + + public readonly description = 'Withdraw all available tokens from the chequebook to the overlay address' + + public async run(): Promise { + await super.init() + + const balance = await this.bee.getChequebookBalance() + + if (balance.availableBalance === '0') { + this.console.error('No tokens to withdraw.') + + return + } + this.console.log(`Withdrawing ${Numbers.fromDecimals(balance.availableBalance, 16)} xBZZ from the chequebook`) + const response = await this.bee.withdrawTokens(balance.availableBalance) + this.console.log(createKeyValue('Tx', response)) + this.console.quiet(response) + } +}