Skip to content

fix: handle typed trezor device busy#1065

Merged
piotr-iohk merged 7 commits into
masterfrom
fix/trezor-device-busy-handling
Jul 9, 2026
Merged

fix: handle typed trezor device busy#1065
piotr-iohk merged 7 commits into
masterfrom
fix/trezor-device-busy-handling

Conversation

@piotr-iohk

@piotr-iohk piotr-iohk commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Refs #1030

Companion to synonymdev/bitkit-ios#617.

This PR adds Android parity for typed Trezor DeviceBusy handling introduced in bitkit-core 0.3.9. Locked or busy Trezor errors now map to a friendly unlock prompt instead of raw technical strings, and transient busy failures retry automatically during connect and xpub fetch.

Description

  • Adds isTrezorDeviceBusy() that walks the cause chain for TrezorException.DeviceBusy (including when wrapped in AppError).
  • Introduces a thin shared TrezorErrorPresenter used by connect and transfer flows.
  • Treats device-busy as retryable in TrezorRepo connect retry logic and adds bounded xpub-fetch retries during pairing.
  • Maps busy failures to hardware__device_busy in the hardware connect sheet and TO_SPENDING transfer errors.
  • Hoists busy and user-cancellation handling in transfer failure handling so wrapped reconnect/compose errors still show the unlock prompt.

Out of scope for this PR (remaining #1030 work): passphrase wallets, BLE ping/backoff polish, phone-lock-during-broadcast network recovery.

Preview

N/A

QA Notes

Manual Tests

  • 1. Lock Trezor → Hardware Connect → Found → Connect: shows unlock prompt, not a raw error string.
  • 2. Lock Trezor → TO_SPENDING → Open Trezor Connect: shows error toast with unlock prompt; unlock and retry succeeds.
  • 3. regression: Cancel on Trezor during TO_SPENDING sign: no error toast, flow returns to sign screen.
  • 4. regression: Trezor powered off → connect sheet: generic connect error, not busy message.
  • 5. regression: TO_SPENDING happy path with unlocked Trezor: funding tx broadcasts and channel order progresses.

Note: on-device QA did not surface typed DeviceBusy in logs — locked Trezor often hits the compose/sign wait path instead. Unit tests cover the typed busy classification.

Automated Checks

  • Unit tests added: busy cause-chain detection in TrezorExceptionExtTest.kt.
  • Unit tests added: presenter mapping in TrezorErrorPresenterTest.kt.
  • Unit tests added: connect retry, busy error mapping, and xpub retry in TrezorRepoTest.kt.
  • Unit tests added: connect sheet busy message in HwConnectViewModelTest.kt.
  • Unit tests added: busy toast and busy-during-reconnect in TransferViewModelTest.kt.
  • Local: TransferViewModelTest, TrezorRepoTest, TrezorExceptionExtTest pass; just lint passes.

Made with Cursor

@greptile-apps

greptile-apps Bot commented Jul 9, 2026

Copy link
Copy Markdown

Greptile Summary

This PR improves Android handling for locked or busy Trezor devices.

  • Adds cause-chain detection for typed Trezor busy errors.
  • Maps busy errors to a shared unlock prompt.
  • Stops busy connect and auto-reconnect paths from continuing retry loops.
  • Adds bounded account xpub retries during pairing.
  • Adds tests for busy detection, presentation, connect retry behavior, and transfer handling.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
app/src/main/java/to/bitkit/repositories/TrezorRepo.kt Updates Trezor connect, auto-reconnect, error mapping, and xpub-fetch handling for typed busy failures.
app/src/main/java/to/bitkit/viewmodels/TransferViewModel.kt Routes transfer-side busy and cancellation failures before wrapped reconnect or funding error handling.
app/src/main/java/to/bitkit/ui/sheets/hardware/HwConnectViewModel.kt Shows the unlock prompt for busy connect failures and keeps the generic message for other failures.
app/src/main/java/to/bitkit/utils/TrezorErrorPresenter.kt Adds shared user-facing Trezor error message selection.
app/src/main/java/to/bitkit/ext/TrezorExceptionExt.kt Adds typed busy-error detection across throwable cause chains.

Reviews (4): Last reviewed commit: "fix: classify typed trezor errors in tra..." | Re-trigger Greptile

Comment thread app/src/main/java/to/bitkit/repositories/TrezorRepo.kt Outdated
Comment thread app/src/main/java/to/bitkit/viewmodels/TransferViewModel.kt

@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: 0f534a1398

ℹ️ 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".

Comment thread app/src/main/java/to/bitkit/repositories/TrezorRepo.kt Outdated
Comment thread app/src/test/java/to/bitkit/viewmodels/TransferViewModelTest.kt
@piotr-iohk piotr-iohk marked this pull request as draft July 9, 2026 14:59
Fail fast on DeviceBusy during BLE reconnect and connect retries.
Block pairing when xpub reads exhaust transient retries (iOS parity).
Fix TrezorErrorPresenter fallback evaluation order.

Co-authored-by: Cursor <cursoragent@cursor.com>
@piotr-iohk piotr-iohk marked this pull request as ready for review July 9, 2026 15:17
Comment thread app/src/main/java/to/bitkit/repositories/TrezorRepo.kt

@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: afca19993c

ℹ️ 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".

Comment thread app/src/main/java/to/bitkit/repositories/TrezorRepo.kt Outdated
Comment thread app/src/main/java/to/bitkit/repositories/TrezorRepo.kt
@piotr-iohk piotr-iohk marked this pull request as draft July 9, 2026 15:30
Stop auto-reconnect retries on device busy.
Preserve actual transient cause on xpub exhaustion instead of
synthesizing DeviceBusy. Rethrow cancellations from connect and
auto-reconnect via runSuspendCatching.

Co-authored-by: Cursor <cursoragent@cursor.com>
@piotr-iohk piotr-iohk marked this pull request as ready for review July 9, 2026 15:43

@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: 2d8ee03585

ℹ️ 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".

Comment thread app/src/main/java/to/bitkit/repositories/TrezorRepo.kt
@piotr-iohk piotr-iohk marked this pull request as draft July 9, 2026 15:58
Typed TrezorException variants like Timeout carry blank messages,
so string-marker matching missed them in both the transient xpub
classifier and the connect retry check.

Co-authored-by: Cursor <cursoragent@cursor.com>
@piotr-iohk piotr-iohk marked this pull request as ready for review July 9, 2026 16:01
@piotr-iohk piotr-iohk self-assigned this Jul 9, 2026
@piotr-iohk piotr-iohk requested a review from coreyphillips July 9, 2026 16:16
@piotr-iohk piotr-iohk enabled auto-merge July 9, 2026 16:54
@piotr-iohk piotr-iohk merged commit bda21e5 into master Jul 9, 2026
40 of 42 checks passed
@piotr-iohk piotr-iohk deleted the fix/trezor-device-busy-handling branch July 9, 2026 17:17
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