Skip to content

refactor: typed Trezor device-busy handling#617

Open
jvsena42 wants to merge 4 commits into
masterfrom
chore/bump-bitkit-core-0.3.9
Open

refactor: typed Trezor device-busy handling#617
jvsena42 wants to merge 4 commits into
masterfrom
chore/bump-bitkit-core-0.3.9

Conversation

@jvsena42

@jvsena42 jvsena42 commented Jul 8, 2026

Copy link
Copy Markdown
Member

Refs #589

This PR switches Trezor locked/busy detection to the typed DeviceBusy error that bitkit-core surfaces since the 0.3.9 bump (a locked device is now mapped from DeviceLocked to DeviceBusy in core), replacing the previous substring matching on stringified error text.

It also consolidates the two near-duplicate Trezor error-to-message mappers — one in the manager, one in the dashboard view model — into a single shared presenter. That closes a gap where the dashboard flow showed a raw technical string for a locked device instead of the friendly "unlock it" prompt.

  • Adds a typed busy check that mirrors the existing cancellation helper, seeing through the app-error wrapper that boxes core errors.
  • Uses the typed check for both the user-facing message and the transient-retry classification, keeps the bounded retry for a busy device, and drops the now-dead locked-device string check.

QA Notes

couldn't simulate the locker on emulator

Manual Tests

  • 1. regression: Lock the Trezor (powered, PIN-locked) → connect from the hardware dashboard: shows the "Trezor is busy, unlock it" message rather than a raw error, and does not loop reconnecting.
  • 2. regression: Lock the Trezor → sign a transfer-to-spending transaction: same busy prompt; after unlocking on device, retry succeeds.
  • 3. regression: Trigger other Trezor errors (timeout, disconnect, cancel on device): user-facing messages are unchanged from before.

Automated Checks

  • Unit tests added: BitkitTests/TrezorDeviceBusyTests.swift covers the typed busy classification (raw and app-error-wrapped) and the shared presenter mapping to the unlock prompt.
  • Ran xcodebuild build-for-testing plus TrezorDeviceBusyTests and TrezorCancellationTests on the iPhone 16 simulator locally: all pass.

Linked Issues/Tasks

Refs #589

Screenshot / Video

cancel-and-retry.mov

… 0.3.9 bitkit-core bump and add regression tests
@jvsena42 jvsena42 self-assigned this Jul 8, 2026
@jvsena42

jvsena42 commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

Waiting for parent PR merge

Base automatically changed from feat/hw-transfer-to-spending to master July 8, 2026 12:05
@jvsena42 jvsena42 marked this pull request as ready for review July 8, 2026 14:25
@jvsena42 jvsena42 requested a review from piotr-iohk July 8, 2026 14:25
@greptile-apps

greptile-apps Bot commented Jul 8, 2026

Copy link
Copy Markdown

Greptile Summary

This PR updates Trezor busy-device handling to use typed errors. The main changes are:

  • Adds shared typed detection for TrezorError.DeviceBusy.
  • Uses the typed busy check for bounded retry classification.
  • Moves Trezor error presentation into a shared presenter.
  • Reuses the shared presenter from the manager and dashboard view model.
  • Adds tests for busy detection and key presenter mappings.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
Bitkit/Extensions/TrezorError+Cancellation.swift Adds typed busy-device detection with AppError unwrapping.
Bitkit/Managers/TrezorManager.swift Uses typed busy detection for retry behavior and shared error presentation.
Bitkit/Utilities/TrezorErrorPresenter.swift Adds the shared Trezor user-message mapper.
Bitkit/ViewModels/Trezor/TrezorViewModel.swift Delegates dashboard Trezor error messages to the shared presenter.
BitkitTests/TrezorDeviceBusyTests.swift Adds tests for typed busy handling and presenter output.

Reviews (2): Last reviewed commit: "Merge branch 'chore/bump-bitkit-core-0.3..." | Re-trigger Greptile

Comment thread Bitkit/Utilities/TrezorErrorPresenter.swift
Comment thread Bitkit/Managers/TrezorManager.swift

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

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread Bitkit/Utilities/TrezorErrorPresenter.swift Outdated
@jvsena42 jvsena42 marked this pull request as ready for review July 8, 2026 17:13
@jvsena42 jvsena42 enabled auto-merge July 8, 2026 17:18
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.

1 participant