-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add cheque withdraw-all command (#519)
* feat: add cheque withdraw-all command * feat: print more info * style: newline * style: newline
- Loading branch information
Showing
2 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |