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: Implement 'balance' command to fetch wallet balance #152

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

eshanvaid
Copy link
Contributor

This Pull Request introduces a new command, balance, to the CLI. The balance command is used to fetch the user's balance from their wallet.

Users can fetch their balance in four different ways:

  • balance --usd: Fetches the balance in the USD wallet.
  • balance --btc: Fetches the balance in the BTC wallet.
  • balance or balance --usd --btc: Fetches the balance from both the wallets and specifies the default one.

In the process of making these changes, the hardcoded Wallet type in main.rs has been moved to a new file, types.rs, which is now being exported from lib.rs. This centralizes the handling of types and makes the code more scalable for future expansions.

Issue: #145

None => {
if wallet_info.wallet_currency == WalletCurrency::USD {
wallet_balances += &format!(
"USD wallet{}: {} cents\n",
Copy link
Member

@nicolasburtey nicolasburtey Jun 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we exporting the value always as a string? would be good to have the option to expose it as a json as well (can be done in another PR later in the project)

a key goal behind galoy-cli is to enable scripting. which is why considering json output as much as friendly output is important

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the time being, the main focus of this command is to output the balance in the CLI, hence the string format. However, as you've suggested, as we further develop the cli, the necessity for the function to return a number or a JSON will definitely arise as this function will be used in other functions or tests as well.

@nicolasburtey
Copy link
Member

This Pull Request introduces a new command, balance, to the CLI. The balance command is used to fetch the user's balance from their wallet.

Users can fetch their balance in four different ways:

  • balance --usd: Fetches the balance in the USD wallet.
  • balance --btc: Fetches the balance in the BTC wallet.
  • balance or balance --usd --btc: Fetches the balance from both the wallets and specifies the default one.

In the process of making these changes, the hardcoded Wallet type in main.rs has been moved to a new file, types.rs, which is now being exported from lib.rs. This centralizes the handling of types and makes the code more scalable for future expansions.

Issue: #145

it would be relevant to consider been able to pass an array of WalletId as well as an arguments. right now we only have 2 wallets per account, so this will works, but this assumption of only having 2 wallets will expend eventually for business account.

@eshanvaid
Copy link
Contributor Author

eshanvaid commented Jun 11, 2023

it would be relevant to consider been able to pass an array of WalletId as well as an arguments. right now we only have 2 wallets per account, so this will works, but this assumption of only having 2 wallets will expend eventually for business account.

@nicolasburtey I have addressed this in commit 4a65bd3. The updated command now supports an array of wallet IDs provided as comma-separated values in the wallet-ids option, even in conjunction with --usd and --btc boolean options. So, you can now specify the wallets like --wallet-ids id1,id2,id3. This should accommodate scenarios where more than two wallets need to be considered.

src/utils.rs Outdated Show resolved Hide resolved
@@ -97,6 +100,61 @@ impl GaloyClient {
Ok(me)
}

pub fn fetch_balance(
&self,
wallet: Option<Wallet>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the wallet parameter there?
shouldn't it rather be walletType?
and where is it used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the option to specify --btc or --usd along with the wallet_ids. So here wallet is used when one of these options is given as input.
Renamed it to wallet_type based on your feedback. 626873f

src/client/mod.rs Outdated Show resolved Hide resolved
@sandipndev sandipndev force-pushed the main branch 4 times, most recently from 64ab5f2 to 330afe0 Compare August 3, 2023 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants