Skip to content

Extract shared display formatting into Rust #288

@kwsantiago

Description

@kwsantiago

Context

Both keep-desktop and keep-android independently implement display formatting logic that should live in Rust once and be consumed by both platforms. This was identified by comparing against the RMP Architecture Bible patterns, which calls this the "duplicated formatting logic" anti-pattern.

Current duplication

Formatting Desktop (Rust) Android (Kotlin)
npub truncation screen/mod.rs::truncate_npub() NostrFormatting.kt
Timestamps screen/mod.rs::format_timestamp() Various inline SimpleDateFormat calls
Share display names screen/shares.rs::ShareEntry::from_stored() ShareCards.kt
Hex truncation screen/signing_audit.rs::truncate_hex() Inline in composables

Proposed changes

  1. Add display formatting functions to keep-core (or a shared module both platforms already depend on):

    • truncate_npub(npub: &str, prefix: usize, suffix: usize) -> String
    • format_timestamp(epoch_secs: u64) -> String (relative: "2 min ago", "yesterday", etc.)
    • truncate_hex(hex: &str, len: usize) -> String
    • format_share_display_name(name: &str, group_pubkey: &[u8]) -> String
  2. Update keep-desktop screens to call shared functions instead of local copies

  3. Expose via UniFFI in keep-mobile so keep-android can drop its Kotlin implementations

Benefit

Single source of truth for all user-visible string formatting. No more divergence between platforms.

Metadata

Metadata

Assignees

No one assigned

    Labels

    desktopkeep-desktop GUI applicationeasyenhancementNew feature or requestmobilekeep-mobile UniFFI bindingsrustPull requests that update rust code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions