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: add cheque withdraw-all command #519

Merged
merged 4 commits into from
Jun 26, 2024
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
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)
}
}
Loading