Skip to content

fix: wait for the bitcoin network before an on-chain payment after resume - #975

Closed
ovitrif wants to merge 3 commits into
masterfrom
fix/send-waits-for-electrum-reconnect
Closed

ovitrif wants to merge 3 commits into
masterfrom
fix/send-waits-for-electrum-reconnect

Conversation

@ovitrif

@ovitrif ovitrif commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #976
Refs:

Description

  • Shows the send sheet's existing "Connecting to network" screen for on-chain payments after Bitkit returns from at least 30 s in the background, until a wallet sync succeeds again, then continues to the payment on its own. A Pubky Shop payment opened right after resume no longer starts on a connection the Electrum server has dropped, and the user sees why they are waiting instead of a blank delay.
  • Retries the sync every 3 s while waiting. After 20 s the sheet shows the existing "Connection issues" screen, which keeps retrying and continues on its own once the network is back.
  • Reuses the existing connecting and connection-issues screens and their strings, so no new copy needs translation.

Out of Scope

Design

N/A — no design available; reuses the existing send sheet connecting screen.

Preview

Regtest staging, iPhone 17 Pro simulator (iOS 26.5), 2x, built with #971. Bitkit goes to the background for 40 s while a local Electrum bridge drops its connection, then a bitcoin: link opens the payment like a Shop deep link. "Connecting to network" shows while the first sync fails on the dropped connection, the amount screen opens on its own once a sync succeeds, and the payment is sent.

c2x.mp4

QA Notes

Journeys

N/A

Manual Tests

  • Leave Bitkit for 30 s or more, then open a Pubky Shop on-chain payment → "Connecting to network" shows until the wallet syncs, then the payment screen opens on its own and the payment goes through — needs an Electrum server that drops idle connections.
  • Same, with networking off → after 20 s "Connection issues" shows; turn networking back on → the payment screen opens on its own.

Automated Checks

  • added OnchainConnectionMonitorTests.swift — a short background stay never waits; a long one waits until a sync succeeds, retrying failures; an unfinished wait resumes after a short background stay.

…sume

After a stay in the background long enough for the Electrum server to drop the connection, show the send sheet's connecting screen for on-chain payments until a wallet sync succeeds again, then continue on its own; after 20 s it shows the existing connection-issues screen.
@ovitrif ovitrif self-assigned this Oct 16, 2026
@ovitrif ovitrif added this to the 3.0.0 milestone Oct 16, 2026
@ovitrif
ovitrif marked this pull request as ready for review October 16, 2026 15:20
@ovitrif
ovitrif requested review from a team, ben-kaufman and coreyphillips and removed request for a team October 16, 2026 15:20
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T15:24:20.893915Z 59a2863 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ovitrif
ovitrif removed the request for review from coreyphillips October 16, 2026 15:22

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 59a2863a24

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


return false
// After a long stay in the background, wait until a sync proves the on-chain connection works again.
return OnchainConnectionMonitor.shared.isReconnecting

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Gate scan-time balance validation on reconnection

When a payment URI is handled during this reconnect window, AppViewModel.handleScannedData still treats a running node as fresh and validates the request against cached on-chain balances before SendSheet is created. If funds arrived during the long background stay and the old balance is insufficient, the scan is rejected immediately, so this overlay is never displayed and the successful retry cannot revalidate the payment. The reconnect state must also defer that pre-sheet balance check.

Useful? React with 👍 / 👎.

@greptile-apps

greptile-apps Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change reaches wallet reconnect and on-chain payment flows.

The PR appears safe to merge, with a non-blocking connection-warning issue for already-validated payments.

Findings

  1. P2 Connection warning never appears ▶

Summary

Adds an on-chain reconnect wait after at least 30 seconds in the background.

  • On-chain sends wait for a successful wallet sync after long background stays.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Return after 30 seconds] --> B[Show connecting screen]
    B --> C[Try wallet sync]
    C -->|Failure| D[Wait three seconds]
    D --> C
    C -->|Success| E[Continue payment]
    B --> F{20 seconds passed}
    F -->|Not yet validated| G[Show connection issues]
    F -->|Already validated| H[Keep connecting screen]
Loading

Reviews (1) · Last reviewed commit: "chore: name the changelog fragment after..." · Reviewed by Greptile

Comment on lines +219 to +220
// After a long stay in the background, wait until a sync proves the on-chain connection works again.
return OnchainConnectionMonitor.shared.isReconnecting

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Connection warning never appears

An already-validated on-chain sheet now shows the reconnect screen after a long background stay, but its 20-second timer exits because hasValidatedAfterSync is still true. If the device has Internet access but Electrum stays unreachable, users keep seeing “Connecting to network” instead of “Connection issues.” Let the reconnect timeout run even when payment validation has finished, and cover this resume path in a test.

Knowledge Base Used: Payments and transfers

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@ovitrif ovitrif removed this from the 3.0.0 milestone Oct 16, 2026
@ovitrif
ovitrif enabled auto-merge October 16, 2026 15:25

@talosmachina talosmachina left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 finding (1 P1). Adds OnchainConnectionMonitor: after 30 s or more in the background, on-chain sends wait on the existing connecting screen until a wallet sync succeeds (retrying every 3 s), then resume validation on their own. Reviewed 59a2863, full tier, reasoned from code and CI: iOS does not build on this machine.

What I checked, and 5 candidates I ruled out

Read in full: OnchainConnectionMonitor.swift, OnchainConnectionMonitorTests.swift, SendSheet.swift (shouldShowSyncOverlay, setUpSend, validatePaymentAfterSync, handleSyncTimeout, the syncTimeoutPhase task), AppScene.handleScenePhaseChange, LightningService.sync, TabBar.onSendPress, SheetViewModel.sendSheetItem.
CI at review time: validate, detect-changes, Greptile green; Run Tests, Run Integration Tests and build-local still pending.

Ruled out

  • Retry loop surviving backgrounding: appDidEnterBackground cancels the task; Task.sleep throws on cancel and the loop checks isCancelled, and the third test pins the resume on the next activation.
  • A late success after cancel clearing isReconnecting: the guard !Task.isCancelled after sync() covers it.
  • Validation running twice when the overlay ends: the new onChange branch requires !hasValidatedAfterSync, which every exit of performPaymentValidationAfterSync sets except .waiting.
  • Concurrent syncWallets with the foreground wallet.sync(): both go through ServiceQueue.background(.ldk), which serialises them.
  • USDT and Paykit asset-selection sends caught by the wait: the early return in shouldShowSyncOverlay excludes paykitUsesUsdt and the asset-selection root before the new line.
  • Cold reader: the finding stood; it rated it P2 since the scan button still reaches Lightning. Kept at P1 because Send itself is blocked on every long resume until a sync lands.

Merge confidence: 3/5, the one P1 on the empty Send sheet; the test jobs had not finished and the branch was not built here.

Comment thread Bitkit/Views/Wallets/Send/SendSheet.swift Outdated
Only a send with an on-chain target waits for the network after resume; the options screen stays reachable for scan, paste and Lightning.
@ovitrif

ovitrif commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator Author

Combined into #971 so RC3 needs one iOS e2e run and one review instead of three.

@ovitrif ovitrif closed this Oct 16, 2026
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