@@ -4,7 +4,6 @@ import TransportNodeHid, {
4
4
} from '@ledgerhq/hw-transport-node-hid-noevents' ;
5
5
import AppAda , { utils } from '@cardano-foundation/ledgerjs-hw-app-cardano' ;
6
6
import TrezorConnect , {
7
- CardanoPublicKey ,
8
7
DEVICE ,
9
8
DEVICE_EVENT ,
10
9
Features ,
@@ -33,6 +32,7 @@ import { HardwareWalletChannels } from './createHardwareWalletIPCChannels';
33
32
import { Device } from './hardwareWallets/ledger/deviceDetection/types' ;
34
33
import { DeviceDetectionPayload } from './hardwareWallets/ledger/deviceDetection/deviceDetection' ;
35
34
import { initTrezorConnect , reinitTrezorConnect } from '../trezor/connection' ;
35
+ import { getTrezorDeviceFeatures } from './hardwareWallets/trezor/getTrezorDeviceFeatures' ;
36
36
37
37
type ListenerType = {
38
38
unsubscribe : ( ...args : Array < any > ) => any ;
@@ -154,6 +154,9 @@ class EventObserver {
154
154
}
155
155
}
156
156
157
+ const wait = ( ms : number ) : Promise < void > =>
158
+ new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
159
+
157
160
export const handleHardwareWalletRequests = async (
158
161
mainWindow : BrowserWindow ,
159
162
{
@@ -285,13 +288,9 @@ export const handleHardwareWalletRequests = async (
285
288
if ( isTrezor ) {
286
289
logger . info ( '[HW-DEBUG] getHardwareWalletTransportChannel::TREZOR ' ) ;
287
290
288
- try {
289
- deviceFeatures = await TrezorConnect . getFeatures ( {
290
- device : {
291
- path : devicePath ,
292
- } ,
293
- } ) ;
291
+ deviceFeatures = await getTrezorDeviceFeatures ( ) ;
294
292
293
+ try {
295
294
logger . info ( '[TREZOR-CONNECT] Called TrezorConnect.getFeatures()' ) ;
296
295
297
296
if ( deviceFeatures && deviceFeatures . success ) {
@@ -466,6 +465,9 @@ export const handleHardwareWalletRequests = async (
466
465
}
467
466
} ) ;
468
467
deriveAddressChannel . onRequest ( async ( params ) => {
468
+ await reinitTrezorConnect ( ) ;
469
+ resetTrezorListeners ( ) ;
470
+
469
471
const {
470
472
addressType,
471
473
spendingPathStr,
@@ -766,7 +768,8 @@ export const handleHardwareWalletRequests = async (
766
768
resetTrezorListeners ( ) ;
767
769
768
770
logger . info ( '[TREZOR-CONNECT] Calling TrezorConnect.getFeatures()' ) ;
769
- const deviceFeatures = await TrezorConnect . getFeatures ( ) ;
771
+
772
+ const deviceFeatures = await getTrezorDeviceFeatures ( ) ;
770
773
771
774
if ( deviceFeatures . success ) {
772
775
logger . info (
@@ -880,6 +883,13 @@ export const handleHardwareWalletRequests = async (
880
883
881
884
resetTrezorActionChannel . onRequest ( async ( ) => {
882
885
logger . info ( '[TREZOR-CONNECT] Called TrezorConnect.cancel()' ) ;
883
- TrezorConnect . cancel ( 'Method_Cancel' ) ;
886
+
887
+ try {
888
+ TrezorConnect . cancel ( ) ;
889
+ } catch ( error ) {
890
+ logger . warn (
891
+ '[TREZOR-CONNECT] Failed to cancel the operation:' + error . error
892
+ ) ;
893
+ }
884
894
} ) ;
885
895
} ;
0 commit comments