Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patch for "Cannot use Trezor Model T #247" #252

Closed
wants to merge 1 commit into from

Conversation

Toporin
Copy link

@Toporin Toporin commented Feb 28, 2025

According to my tests, this simple patch resolve #247

Solve #247

@Toporin
Copy link
Author

Toporin commented Feb 28, 2025

Code analysis by Claude.ai:

The fundamental problem is that DeviceRequestResponse event isn't properly updating the _deviceRequest CompletableDeferred object.

Looking at the logs, this sequence stands out:

SATODEBUG SideEffects HandleSideEffect() PassphraseBottomSheet.getResult: azerty
postEvent: DeviceRequestResponse(data=azerty)
SATODEBUG GreenViewModel handleEvent() event: DeviceRequestResponse(data=azerty)
SATODEBUG GreenViewModel handleEvent() DeviceRequestResponse event: DeviceRequestResponse(data=azerty), deviceRequest: null
SATODEBUG After completing deviceRequest: null, isCompleted: null

Notice that deviceRequest is null when handling the response. This explains why the runBlocking call in requestPassphrase() never completes - the CompletableDeferred is never completed.

Here's what's happening:

  1. requestPassphrase() creates a CompletableDeferred and stores it in _deviceRequest
  2. The PassphraseBottomSheet displays and gets the result "azerty"
  3. The Events.DeviceRequestResponse event is posted
  4. In the event handler, _deviceRequest is unexpectedly null, so nothing completes the deferred

The issue is likely that the DeviceRequestResponse event is being handled in a different instance of the ViewModel than the one that created the _deviceRequest. This can happen if:

  1. You're using multiple ViewModel instances
  2. The ViewModel is being recreated between the request and response

The fix would be to ensure the same ViewModel instance handles both the request and response. Try one of these approaches:

  1. Make _deviceRequest a companion object property to be shared across instances:
companion object {
    private var _deviceRequest: CompletableDeferred<String>? = null
}
  1. Or use a more global solution like a shared singleton:
object DeviceRequestManager {
    var deviceRequest: CompletableDeferred<String>? = null
}
  1. Or pass the CompletableDeferred through your navigation system as a parameter.

Given your architecture, I recommend option 1 as the simplest fix. Make _deviceRequest a companion object property in GreenViewModel, which would ensure it's shared across all instances of the ViewModel.

@angelix
Copy link
Collaborator

angelix commented Mar 12, 2025

Thanks @Toporin for the MR.
While your solution works, we decided to fix it a bit different in 3b543a9.

@angelix angelix closed this Mar 12, 2025
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.

Cannot use Trezor Model T
2 participants