feat(wallet): /pay slash command parser and composer integration (Task 5)

Implements Task 5 of Phase 1:

New files:
- ParsedPayCommand.kt: Sealed interface for parse results
  - WithAddressRecipient: Pay to Cardano address
  - WithMatrixRecipient: Pay to Matrix user (requires lookup)
  - AmountOnly: Amount specified, prompt for recipient
  - Empty: Open payment flow with no prefilled data
  - ParseError: Parse error with human-readable reason

- SlashCommandParser.kt: Full /pay command parser
  - Handles: /pay, /pay 10, /pay 10 ADA, /pay 10 tADA
  - Matrix recipients: /pay 10 ADA @user:server
  - Cardano addresses: /pay 10 ADA addr1...
  - Validates amounts (decimal support, max supply check)
  - Validates addresses (prefix, length, network match)
  - Comprehensive error messages

- SlashCommandParserTest.kt: 40+ unit tests covering all patterns

Modified files:
- ResolvedSuggestion.kt: Added Command type for slash commands
- SuggestionsProcessor.kt: /pay shows as autocomplete suggestion
- MarkdownTextEditorState.kt: Command insertion in text editor
- MessageComposerPresenter.kt: Command handling in InsertSuggestion

Note: MessageComposerPresenter sendMessage interception deferred to
Task 6 (requires PaymentFlowPresenter for navigation).
This commit is contained in:
Kayos 2026-03-27 10:38:21 -07:00
parent 880454847e
commit db4c262b27
18 changed files with 1935 additions and 6 deletions

View file

@ -64,5 +64,33 @@ Development Android emulator is live and available:
Connect via: `adb connect 192.168.0.5:5555`
---
## Task 5: /pay Slash Command Parser + SuggestionsProcessor Extension
### Completed
- ✅ `ParsedPayCommand.kt` - Sealed interface for parse results (WithAddressRecipient, WithMatrixRecipient, AmountOnly, Empty, ParseError)
- ✅ `SlashCommandParser.kt` - Full parser implementation with:
- Amount parsing (integers, decimals, up to 6 decimal places for lovelace precision)
- Unit support (ADA, tADA for testnet, lovelace)
- Matrix user ID validation (@user:server format)
- Cardano address validation (addr1/addr_test1 prefixes, length checks, network mismatch detection)
- Comprehensive error messages
- ✅ `ResolvedSuggestion.kt` - Added `Command(command: String, description: String)` type
- ✅ `SuggestionsProcessor.kt` - Added /pay command suggestion with filtering
- ✅ `MarkdownTextEditorState.kt` - Added Command case to insertSuggestion()
- ✅ `MessageComposerPresenter.kt` - Added Command handling in InsertSuggestion event
- ✅ `SlashCommandParserTest.kt` - Comprehensive unit tests (40+ test cases)
### What's Still Needed (Task 6)
- ⚠️ MessageComposerPresenter interception of /pay on send (requires PaymentFlowPresenter from Task 6)
- ⚠️ Navigation to payment flow when /pay is sent
- ⚠️ Integration with PaymentFlowNode for actual payment execution
### Testing Notes
- Tests use plain JUnit with Truth assertions
- Parser handles edge cases: whitespace, case sensitivity, decimal precision, network mismatches
- Testnet support via `tADA` unit or `addr_test1` addresses
---
*Last updated: 2026-03-27*