-
Notifications
You must be signed in to change notification settings - Fork 25
feat: add unit flag for cheque deposit and withraw #686
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
Open
slapec93
wants to merge
14
commits into
master
Choose a base branch
from
feat/it-is-hard-to-specify-bzz-amount-in-cheque-deposit-and-cheque-withdraw-commands
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f51489f
feat: add unit flag for cheque deposit and withraw
bd2259c
fix: update spec and improve CLI output
95570be
test: update test coverage
github-actions[bot] 1e0111b
Merge branch 'master' into feat/it-is-hard-to-specify-bzz-amount-in-c…
slapec93 75a45ac
feat: make coverage report gen skippable via env
83ea667
test: update test coverage
github-actions[bot] 542a038
feat: use validation method and enum
cba1dbd
Merge branch 'feat/it-is-hard-to-specify-bzz-amount-in-cheque-deposit…
cdbce62
chore: madlad update
77e03fe
feat: use new furious command features
f92bed9
test: add more specs for deposit and withdraw
f7b17ae
test: fix
204f9f5
Merge branch 'master' into feat/it-is-hard-to-specify-bzz-amount-in-c…
slapec93 94dc2a4
test: update test coverage
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| import { Argument, LeafCommand } from 'furious-commander' | ||
| import { createKeyValue } from '../../utils/text' | ||
| import { ChequeCommand } from './cheque-command' | ||
| import { Argument, LeafCommand, Option } from 'furious-commander' | ||
| import { createKeyValue, errorText } from '../../utils/text' | ||
| import { ChequeCommand, VALID_UNITS } from './cheque-command' | ||
| import { exit } from 'process' | ||
| import { BZZ } from '@ethersphere/bee-js' | ||
|
|
||
| export class Withdraw extends ChequeCommand implements LeafCommand { | ||
| public readonly name = 'withdraw' | ||
|
|
@@ -12,17 +14,36 @@ export class Withdraw extends ChequeCommand implements LeafCommand { | |
| @Argument({ | ||
| key: 'amount', | ||
| type: 'bigint', | ||
| description: 'Amount of tokens to withdraw in PLUR', | ||
| description: 'Amount of tokens to withdraw', | ||
| required: true, | ||
| minimum: BigInt(1), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This probably needs to have type With type |
||
| }) | ||
| public amount!: bigint | ||
|
|
||
| @Option({ | ||
| key: 'unit', | ||
| type: 'string', | ||
| description: `Unit of the amount; choices: ${VALID_UNITS.join(', ')}`, | ||
| default: 'bzz', | ||
| }) | ||
| public unit!: string | ||
|
|
||
| public async run(): Promise<void> { | ||
| super.init() | ||
|
|
||
| const response = await this.bee.withdrawTokens(this.amount.toString()) | ||
| this.validateUnit() | ||
| const amountInPlur = | ||
| this.unit === 'bzz' ? BZZ.fromDecimalString(this.amount.toString()).toPLURBigInt() : this.amount | ||
|
|
||
| const response = await this.bee.withdrawTokens(amountInPlur.toString()) | ||
| this.console.log(createKeyValue('Tx', response.toHex())) | ||
| this.console.quiet(response.toHex()) | ||
| } | ||
|
|
||
| private validateUnit() { | ||
| if (!VALID_UNITS.includes(this.unit)) { | ||
| this.console.error(errorText(`Invalid unit '${this.unit}'. Valid units are: ${VALID_UNITS.join(', ')}`)) | ||
| exit(1) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably needs to have type
stringWith type
bigintit probably won't accept decimal values such as0.5(truncates to 0, invalid) or1.5(loses decimal part)