Skip to content

Conversation

@codaMW
Copy link

@codaMW codaMW commented Jan 4, 2026

This PR addresses several issues in fiat.rs:

  • Added 🇲🇼 emoji for Malawi Kwacha (MWK)
  • Changed load_fiat_values return type to Result<FiatList> for proper error handling
  • Fixed missing closing brace in the for loop
  • Removed temporary backup file fiat.rs~
  • Added *~ to .gitignore to prevent committing future backup files

Summary by CodeRabbit

  • New Features

    • Added MWK (Malawi Kwacha) as a supported currency.
  • Improvements

    • Enhanced configuration error messages with clearer feedback for missing or invalid settings.
    • Improved environment variable resolution with better fallback handling logic.
  • Chores

    • Updated git ignore patterns for consistency with editor backup files.

✏️ Tip: You can customize this high-level summary in your review settings.

Added mw emoji for the Malawi Kwacha (MWK)
Changed return type to Result<FiatList> to allow use of allow of ? operator
Fixed missing closing brace in for loop
Removed temporary backup file src/fiat.rs~ and updated .gitignore
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 4, 2026

Walkthrough

The PR simplifies build configuration by updating .gitignore patterns, refactors MOSTRO_PUBKEY initialization in the CLI module to resolve from CLI arguments or environment variables with centralized error handling, and introduces Result-based error propagation to the fiat values loader function.

Changes

Cohort / File(s) Summary
Build Configuration
.gitignore
Removed explicit patterns for /target, /.env, /.vscode/, and -bin/; added generic *~ pattern for editor backup files.
CLI Initialization & Environment Resolution
src/cli.rs
Introduced resolver function for MOSTRO_PUBKEY that checks CLI argument first, then environment variable, centralizing initialization logic with improved error messaging and updated imports.
Error Handling & Type Signatures
src/fiat.rs
Changed load_fiat_values() return type from FiatList to Result<FiatList>; added error propagation via map_err for JSON parsing and wrapped result with Ok(); added MWK fiat data entry.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A rabbit hops through config files with glee,
Tidying patterns and resolving envvars—you'll see!
With Results now wrapped and errors caught tight,
The fiat values flow with clarity bright. ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: adding MWK emoji and fixing load_fiat_values compilation by changing its return type to Result.
✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/fiat.rs (1)

40-60: Update caller to handle Result return type.

The function check_currency_ticker calls load_fiat_values() on line 45, but doesn't handle the Result return type after the signature change. This will cause a compilation error.

🔎 Proposed fix
 pub fn check_currency_ticker(currency: String) -> Option<String> {
     let upper = currency.to_uppercase();
     let mut selectedcurrency: Option<String> = None;
     let mut description = String::new();
 
-    let list = load_fiat_values();
+    let list = load_fiat_values().ok()?;
 
     for curr in list.iter() {
         if curr.0 == upper {
             selectedcurrency = Some(curr.0.to_owned());
             description = curr.1.to_owned();
         }
     }
 
     match selectedcurrency.clone() {
         Some(s) => println!("You have selected all offers of {} - {}", s, description),
         None => println!("Mmmmhhh you shouldn't be arrived here...something bad!"),
     }
 
     selectedcurrency
 }

Alternatively, propagate the error by changing the function signature to return Result<Option<String>>.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a2f0716 and 04ca76f.

📒 Files selected for processing (4)
  • .gitignore
  • src/.fiat.rs.un~
  • src/cli.rs
  • src/fiat.rs
🧰 Additional context used
🧠 Learnings (7)
📓 Common learnings
Learnt from: arkanoider
Repo: MostroP2P/mostro-cli PR: 135
File: src/cli.rs:301-306
Timestamp: 2025-09-12T20:02:14.291Z
Learning: The mostro-cli is designed as a test client that allows users to test both regular user operations and admin operations from the terminal. Therefore, MOSTRO_PUBKEY should always be required regardless of whether NSEC_PRIVKEY is present, as both user and admin operations need to know which Mostro instance to interact with.
📚 Learning: 2025-09-12T20:02:14.291Z
Learnt from: arkanoider
Repo: MostroP2P/mostro-cli PR: 135
File: src/cli.rs:301-306
Timestamp: 2025-09-12T20:02:14.291Z
Learning: The mostro-cli is designed as a test client that allows users to test both regular user operations and admin operations from the terminal. Therefore, MOSTRO_PUBKEY should always be required regardless of whether NSEC_PRIVKEY is present, as both user and admin operations need to know which Mostro instance to interact with.

Applied to files:

  • src/cli.rs
📚 Learning: 2025-09-09T19:58:58.506Z
Learnt from: arkanoider
Repo: MostroP2P/mostro-cli PR: 135
File: src/cli/add_invoice.rs:80-82
Timestamp: 2025-09-09T19:58:58.506Z
Learning: In the mostro-cli codebase, when the trade_index parameter isn't needed inside a function like wait_for_dm, it should be made Optional<i64> instead of requiring callers to pass hardcoded values like 0. This makes the API clearer and avoids unnecessary computation for resolving indices when they're not used.

Applied to files:

  • src/cli.rs
📚 Learning: 2025-09-14T14:01:01.728Z
Learnt from: arkanoider
Repo: MostroP2P/mostro-cli PR: 135
File: src/util.rs:614-619
Timestamp: 2025-09-14T14:01:01.728Z
Learning: In the mostro-cli codebase, the user arkanoider indicated that accessing `public_key` without parentheses (as a field) is valid, even though most of the codebase uses `public_key()` method calls. This suggests there may be `Deref` implementation or other Rust features that allow both syntaxes to work.

Applied to files:

  • src/cli.rs
📚 Learning: 2025-09-13T10:31:42.313Z
Learnt from: arkanoider
Repo: MostroP2P/mostro-cli PR: 135
File: src/cli/get_dm.rs:24-29
Timestamp: 2025-09-13T10:31:42.313Z
Learning: In mostro-cli's get_dm.rs, the message filtering is intentional: non-admin users should only receive DirectMessage from users, while messages from Mostro are only fetched when the admin flag is true. Don't include GiftWrap messages for non-admin users.

Applied to files:

  • src/cli.rs
📚 Learning: 2025-09-13T20:48:31.581Z
Learnt from: arkanoider
Repo: MostroP2P/mostro-cli PR: 135
File: src/cli/send_msg.rs:89-110
Timestamp: 2025-09-13T20:48:31.581Z
Learning: In mostro-cli's send_msg.rs, tokio::spawn with async move is valid for sending DMs when PublicKey implements Copy, and arkanoider confirmed this approach works without memory issues or compilation errors.

Applied to files:

  • src/cli.rs
📚 Learning: 2025-09-13T20:48:31.581Z
Learnt from: arkanoider
Repo: MostroP2P/mostro-cli PR: 135
File: src/cli/send_msg.rs:89-110
Timestamp: 2025-09-13T20:48:31.581Z
Learning: In mostro-cli's send_msg.rs, arkanoider confirmed that tokio::spawn with async move is correct and compiles without errors when using PublicKey (which implements Copy). The spawning approach is acceptable for DM sending in this context.

Applied to files:

  • src/cli.rs
🔇 Additional comments (4)
.gitignore (1)

1-1: LGTM!

Standard pattern to ignore editor backup files. Clean addition.

src/cli.rs (2)

373-385: LGTM! Centralizes MOSTRO_PUBKEY resolution with proper error handling.

The resolver correctly prioritizes CLI arguments over environment variables and provides clear error messages. This aligns with the requirement that MOSTRO_PUBKEY should always be set for all operations. Based on learnings, this is correctly enforced for both user and admin operations.


420-421: LGTM! Proper usage of the resolver function.

The implementation correctly uses the resolver with error propagation and parses the result into PublicKey.

src/fiat.rs (1)

1467-1467: LGTM! Proper error handling for JSON parsing.

The error handling correctly uses map_err to wrap parsing errors with context.

}

pub fn load_fiat_values() -> FiatList {
pub fn load_fiat_values() -> Result<FiatList> {
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

head -n 70 src/fiat.rs | cat -n

Repository: MostroP2P/mostro-cli

Length of output: 2269


🏁 Script executed:

rg -n "use.*Result|use.*anyhow" src/fiat.rs

Repository: MostroP2P/mostro-cli

Length of output: 46


🏁 Script executed:

rg "use.*anyhow|use.*Result" --type rust -m 5

Repository: MostroP2P/mostro-cli

Length of output: 1516


🏁 Script executed:

sed -n '62,120p' src/fiat.rs | cat -n

Repository: MostroP2P/mostro-cli

Length of output: 1979


🏁 Script executed:

rg -A 200 "pub fn load_fiat_values" src/fiat.rs | tail -n 20

Repository: MostroP2P/mostro-cli

Length of output: 561


🏁 Script executed:

rg -A 500 "pub fn load_fiat_values" src/fiat.rs | rg -B 2 "^}$|Ok\(|return"

Repository: MostroP2P/mostro-cli

Length of output: 46


🏁 Script executed:

wc -l src/fiat.rs

Repository: MostroP2P/mostro-cli

Length of output: 80


🏁 Script executed:

awk '/pub fn load_fiat_values/,/^}$/' src/fiat.rs | tail -n 30

Repository: MostroP2P/mostro-cli

Length of output: 818


🏁 Script executed:

sed -n '40,60p' src/fiat.rs | cat -n

Repository: MostroP2P/mostro-cli

Length of output: 865


Add missing Result import and fix multiple compilation errors.

The function declares return type Result<FiatList> but is missing use anyhow::Result; import. Additionally:

  • Line 1470: Function returns ok(fiatlist) instead of Ok(fiatlist) (lowercase should be uppercase)
  • Line 45-47: Calling code in check_currency_ticker() doesn't handle the Result type—it assigns the result directly to list and calls .iter() without unwrapping. This needs to handle the Result with either ? operator, .unwrap(), or .unwrap_or_else()
🤖 Prompt for AI Agents
In src/fiat.rs around line 62 (and related spots at lines ~45-47 and ~1470), add
the missing import `use anyhow::Result;`, change the lowercase `ok(fiatlist)`
return at ~1470 to `Ok(fiatlist)`, and update the call site in
check_currency_ticker() (lines 45-47) to handle the Result returned by
load_fiat_values() — either propagate the error with the `?` operator,
explicitly unwrap with `.unwrap()` or supply a fallback via `.unwrap_or_else()`
depending on desired error handling; ensure the variable `list` is assigned the
unwrapped FiatList before calling `.iter()`.

Comment on lines +906 to 915
"MWK": {
"symbol": "MWK",
"name": "Malawian Kwacha",
"symbol_native": "MK",
"decimal_digits": 2,
"rounding": 0,
"code": "MWK,
"emoji": "mw",
"name_plural": "Malawian kwachas"
},
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Fix JSON syntax error and emoji value.

The MWK entry has critical issues:

  1. Line 912: Missing closing quote in "code": "MWK, - should be "code": "MWK",
  2. Line 913: Emoji is incorrectly set to "mw" instead of the Malawi flag emoji "🇲🇼"

These will cause JSON parsing to fail at runtime.

🔎 Proposed fix
       "MWK": {
         "symbol": "MWK",
         "name": "Malawian Kwacha",
         "symbol_native": "MK",
         "decimal_digits": 2,
         "rounding": 0,
-        "code": "MWK,
-        "emoji": "mw",
+        "code": "MWK",
+        "emoji": "🇲🇼",
         "name_plural": "Malawian kwachas"
       },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"MWK": {
"symbol": "MWK",
"name": "Malawian Kwacha",
"symbol_native": "MK",
"decimal_digits": 2,
"rounding": 0,
"code": "MWK,
"emoji": "mw",
"name_plural": "Malawian kwachas"
},
"MWK": {
"symbol": "MWK",
"name": "Malawian Kwacha",
"symbol_native": "MK",
"decimal_digits": 2,
"rounding": 0,
"code": "MWK",
"emoji": "🇲🇼",
"name_plural": "Malawian kwachas"
},
🤖 Prompt for AI Agents
In src/fiat.rs around lines 906 to 915, the MWK JSON entry has a missing closing
quote on the "code" field and the emoji value is incorrect; fix by changing
`"code": "MWK,` to `"code": "MWK",` and set `"emoji": "mw",` to the correct
Malawi flag emoji `"emoji": "🇲🇼",` ensuring proper UTF-8 encoding and valid
JSON quoting.

fiatlist.sort_by(|a, b| a.0.cmp(&b.0));

fiatlist
ok(fiatlist)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Fix return statement - use Ok instead of ok.

The return statement uses lowercase ok(fiatlist) which will cause a compilation error. Rust's Result enum requires uppercase Ok.

🔎 Proposed fix
-    ok(fiatlist)
+    Ok(fiatlist)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ok(fiatlist)
Ok(fiatlist)
🤖 Prompt for AI Agents
In src/fiat.rs around line 1478, the function returns `ok(fiatlist)` which is
invalid because Rust's Result uses the capitalized `Ok`; change the return to
`Ok(fiatlist)` so the function returns the correct Result variant (no other
changes needed unless type mismatches surface).

@grunch
Copy link
Member

grunch commented Jan 6, 2026

Hi @codaMW, why to do these changes on fiat.rs but that module is not enabled? I think the first step is to made a PR where fiat.rs is being enabled

@arkanoider
Copy link
Collaborator

arkanoider commented Jan 7, 2026

Yes please @codaMW check lib.rs file, you won't see fiat module exposed there...

@codaMW
Copy link
Author

codaMW commented Jan 7, 2026 via email

@grunch
Copy link
Member

grunch commented Jan 7, 2026

Hi @codaMW I'm closing this PR as the requests are not being addressed, there are several errors included on this PR, please read all comments and if you want you can create a new clean PR

@grunch grunch closed this Jan 7, 2026
@codaMW
Copy link
Author

codaMW commented Jan 7, 2026 via email

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