Skip to content

Conversation

@ovitrif
Copy link
Collaborator

@ovitrif ovitrif commented Jan 16, 2026

This PR refactors the toast system to improve architecture, naming, testability, and localization.

Description

Architecture Changes

  1. Replaces ToastEventBus singleton with injectable Toaster that emits events via SharedFlow
  2. Adds ToastText sealed interface for type-safe toast messages (string resource vs raw string)
  3. Moves ToastType enum to top-level
  4. Migrates all ViewModels and Repositories to use the new Toaster via dependency injection

API Improvements

  1. Renames description parameter to body across all toast APIs
  2. Renames visibilityTime: Long to duration: Duration using Kotlin's type-safe Duration API
  3. Removes Context dependency from Toaster - string resolution happens in ToastContent composable
  4. Exposes Toaster via CompositionLocal for direct access in composables
  5. Renames warning()warn() for consistency

API Prettification

  1. Adds ToastText() factory constructors via companion object invoke operators
  2. Renames titleRes/bodyRestitle/body in @stringres overloads (cleaner API)
  3. Removes redundant @Stable annotations from ToastType enum and value classes (inferred by Compose)

Localization & @stringres Support

  1. Adds @StringRes overloads to Toaster (type-safe string resource IDs)
  2. Adds ToastText overloads for mixed resource/literal cases
  3. Adds ToastText.asString() composable extension using stringResource()
  4. Refactors all composables to use @StringRes overloads (fixes LocalContext lint warnings)
  5. Refactors all ViewModels to use @StringRes overloads
  6. Localizes remaining hardcoded toast strings (UTXO load error, migration error, generic error)

Internal Refactoring

  1. Renames ToastQueueManager to ToastQueue and refactors it to inherit from BaseCoroutineScope
  2. Renames ToastView to ToastContent (private) and ToastOverlay to ToastHost (public API)

Documentation & Testing

  1. Adds coding rule to CLAUDE.md to avoid *Manager class naming anti-pattern
  2. Adds comprehensive unit tests for ToastQueue behavior (9 test cases)

API Examples

// @StringRes overloads - clean parameter names
toaster.success(title = R.string.success_title, body = R.string.success_body)
toaster.error(title = R.string.error_title)
toaster.warn(title = R.string.warning_title)

// String literal overloads
toaster.info(title = "Debug info", body = "Some details")

// ToastText overloads for mixed cases - cleaner factory
toaster.error(
    title = ToastText(R.string.error_title),
    body = ToastText(dynamicMessage),
)

Preview

N/A - Internal refactoring with no visible changes.

QA Notes

1. Toast Functionality

  1. Trigger various toast types (success, error, warning, info, lightning)
  2. Verify toasts appear with correct styling and dismiss properly
  3. Test swipe-to-dismiss in all directions (up, left, right)
  4. Verify auto-hide timer works correctly (3 second default)

2. Toast Queue Behavior

  1. Trigger multiple toasts rapidly in succession
  2. Verify they queue and display sequentially
  3. Verify the newest toast shows immediately, replacing the current one

3. Drag Interactions

  1. Start dragging a toast and verify the timer pauses
  2. Release the drag and verify timer resumes with full duration

4. Localization

  1. Change device language and verify toast messages appear in the correct language
  2. Trigger error toasts and verify localized error messages

5. Regression Testing

  • Send a payment and verify success toast appears
  • Go offline and verify warning toast, then reconnect for success toast
  • Copy an address to clipboard and verify info toast
  • Trigger an error condition and verify error toast styling

ovitrif and others added 15 commits January 16, 2026 19:48
- Add ToastText sealed interface for type-safe messages
- Create Toaster singleton with convenience APIs
- Move ToastType to top-level with @stable annotation
- Migrate all ViewModels and Repos to use Toaster
- Delete ToastEventBus in favor of DI pattern

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@ovitrif ovitrif changed the title refactor: improve toast system internals refactor: improve toast apis and internals Jan 17, 2026
ovitrif and others added 2 commits January 17, 2026 03:14
- Add ToastText() factory constructors (invoke operators)
- Remove redundant @stable from ToastType enum and value classes
- Rename titleRes/bodyRes → title/body in @stringres overloads
- Rename warning() → warn() across all overloads
- Update all call sites for the API changes

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace ToastText.Literal() and ToastText.Resource() calls
with the cleaner ToastText() factory constructor.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

2 participants