Skip to content

Commit

Permalink
feat: add cheque withdraw-all command (#519)
Browse files Browse the repository at this point in the history
* feat: add cheque withdraw-all command

* feat: print more info

* style: newline

* style: newline
  • Loading branch information
Cafe137 authored Jun 26, 2024
1 parent 1fefbc3 commit 764f958
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/command/cheque/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
28 changes: 28 additions & 0 deletions src/command/cheque/withdraw-all.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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)
}
}

0 comments on commit 764f958

Please sign in to comment.