Skip to content

fix(receive): handle additional receive liquidity edge cases - #1222

Open
pwltr wants to merge 3 commits into
masterfrom
fix/additional-cjit
Open

fix(receive): handle additional receive liquidity edge cases#1222
pwltr wants to merge 3 commits into
masterfrom
fix/additional-cjit

Conversation

@pwltr

@pwltr pwltr commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Description

Ports the receive liquidity/CJIT behavior from bitkit-ios synonymdev/bitkit-ios#711.

  • Adds a pure ReceiveLiquidityDecision helper for Lightning invoice vs additional CJIT routing.
  • Prevents Savings and Auto edits from routing into CJIT while still updating the shared receive amount.
  • Prevents normal Lightning invoices when there is no ready channel, zero inbound liquidity, or a fixed amount exceeds inbound liquidity.
  • Adds Spending-only additional CJIT routing for amounts above inbound liquidity, including below-min routing to amount entry and real max validation using Blocktank default LSP balance.
  • Makes Auto fall back to Savings/on-chain QR when Lightning cannot receive the edited amount.
  • Resets Receive sheet session state on close/reopen and defaults fresh sessions to Auto when available, otherwise Savings.
  • Keeps direct Spending additional-CJIT creation from regenerating the normal receive invoice before CJIT confirmation navigation.
  • Polishes Receive details spacing and copy card address text wrapping.

Preview

Screen.Recording.2026-09-03.at.12.35.19.mov

QA Notes

Manual checks:

  • Savings edit above inbound returns to Savings/on-chain QR and does not route to CJIT.
  • Auto edit above inbound falls back to Savings/on-chain QR.
  • Spending edit below CJIT minimum routes to CJIT amount entry.
  • Spending edit with valid CJIT amount creates additional CJIT and opens confirmation.
  • Spending edit above real CJIT maximum routes to amount entry and shows max validation.
  • Receive sheet close/reopen starts fresh on Auto when available, otherwise Savings.
  • Auto details show both on-chain and Lightning copy cards with expected spacing.

Automated checks:

  • ReceiveLiquidityDecisionTest.kt
  • ReceiveInvoiceUtilsTest.kt
  • EditInvoiceVMTest.kt

@pwltr
pwltr force-pushed the fix/additional-cjit branch from b894427 to 53e0156 Compare September 2, 2026 17:28
@pwltr
pwltr force-pushed the fix/additional-cjit branch from 53e0156 to 314445d Compare September 3, 2026 10:38
@pwltr
pwltr marked this pull request as ready for review September 3, 2026 10:38
@greptile-apps

greptile-apps Bot commented Sep 3, 2026

Copy link
Copy Markdown

Greptile Summary

This PR centralizes receive-liquidity decisions and updates invoice creation, CJIT limits, receive navigation, session reset behavior, and receive-detail presentation.

  • Adds source-aware Lightning and additional-CJIT routing.
  • Computes and enforces a CJIT maximum from Blocktank channel-size options.
  • Resets receive-sheet state and adjusts Auto, Savings, and Spending navigation.
  • Adds focused unit tests and receive-liquidity documentation.

Confidence Score: 4/5

The PR should not merge until the CJIT maximum is derived from current Blocktank options rather than potentially stale cached limits.

A previously populated Blocktank info object bypasses refresh during maximum calculation, so the receive flow can enforce an outdated channel-size limit and repeat it after a server rejection.

Files Needing Attention: app/src/main/java/to/bitkit/repositories/BlocktankRepo.kt

Important Files Changed

Filename Overview
app/src/main/java/to/bitkit/models/ReceiveLiquidityDecision.kt Adds a pure, tested decision model for ordinary Lightning invoices and source-aware additional-liquidity routing.
app/src/main/java/to/bitkit/repositories/BlocktankRepo.kt Adds channel-size validation and maximum-CJIT calculation, but derives the maximum from potentially stale cached Blocktank options.
app/src/main/java/to/bitkit/repositories/WalletRepo.kt Gates invoice generation and channel-event refreshes on ready-channel inbound capacity.
app/src/main/java/to/bitkit/ui/screens/wallets/receive/EditInvoiceVM.kt Coordinates source-specific liquidity decisions and Blocktank limit lookup for edited receive amounts.
app/src/main/java/to/bitkit/ui/screens/wallets/receive/ReceiveAmountScreen.kt Adds maximum CJIT validation, input clamping, and dedicated maximum-exceeded feedback.
app/src/main/java/to/bitkit/ui/screens/wallets/receive/ReceiveQrScreen.kt Updates receive-tab availability, fallback selection, and details layout according to Lightning receive capability.
app/src/main/java/to/bitkit/ui/screens/wallets/receive/ReceiveSheet.kt Tracks the edit source and routes initial versus additional CJIT flows to their corresponding confirmation screens.
app/src/main/java/to/bitkit/ui/ContentView.kt Keys each receive-sheet instance so remembered navigation and CJIT state reset on close and reopen.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Edit receive amount] --> B{Selected source}
    B -->|Savings or Auto| C[Update shared receive invoice]
    B -->|Spending| D{Amount exceeds inbound liquidity?}
    D -->|No| C
    D -->|Yes| E{Geo-blocked?}
    E -->|Yes| F[Geo-block screen]
    E -->|No| G{Within current CJIT limits?}
    G -->|No| H[CJIT amount entry]
    G -->|Yes| I[Create additional CJIT]
    I --> J[Additional-liquidity confirmation]
    H --> J
Loading

Reviews (1): Last reviewed commit: "fix(receive): handle additional receive ..." | Re-trigger Greptile

Comment thread app/src/main/java/to/bitkit/repositories/BlocktankRepo.kt Outdated
@pwltr
pwltr requested review from jvsena42 and ovitrif September 3, 2026 11:37

@ovitrif ovitrif left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

QA Notes

Pixel_8_Pro emulator (sdk_gphone16k_arm64), regtest via network Electrum/Blocktank.

  • Savings edit above inbound stayed on the on-chain QR and did not route to CJIT.
  • Auto edit above inbound fell back to Savings/on-chain QR.
  • Spending edit below the CJIT minimum routed to CJIT amount entry.
  • Spending edit with a valid additional-CJIT amount opened confirmation.
  • Spending edit above the real CJIT maximum stayed on amount entry and clamped to max.
  • Receive sheet close/reopen started fresh on Auto.
  • Auto details showed both on-chain and Lightning copy cards.

Approve.

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