@@ -47,7 +47,7 @@ function trezor(options: TrezorOptions & CommonWalletOptions): WalletModule {
47
47
interface : {
48
48
name : 'Trezor' ,
49
49
connect : provider . enable ,
50
- disconnect : ( ) => provider . stop ( ) ,
50
+ disconnect : provider . disconnect ,
51
51
address : {
52
52
get : async ( ) => provider . getPrimaryAddress ( )
53
53
} ,
@@ -56,8 +56,8 @@ function trezor(options: TrezorOptions & CommonWalletOptions): WalletModule {
56
56
} ,
57
57
balance : {
58
58
get : async ( ) => {
59
- const accounts = provider . getPrimaryAddress ( )
60
- return accounts [ 0 ] && provider . getBalance ( accounts [ 0 ] )
59
+ const address = provider . getPrimaryAddress ( )
60
+ return address && provider . getBalance ( address )
61
61
}
62
62
}
63
63
}
@@ -124,6 +124,14 @@ async function trezorProvider(options: {
124
124
provider . getBalance = getBalance
125
125
provider . getBalances = getBalances
126
126
provider . send = provider . sendAsync
127
+ provider . disconnect = disconnect
128
+
129
+ function disconnect ( ) {
130
+ dPath = ''
131
+ addressToPath = new Map ( )
132
+ enabled = false
133
+ provider . stop ( )
134
+ }
127
135
128
136
function setPath ( path : string ) {
129
137
dPath = path
@@ -151,6 +159,10 @@ async function trezorProvider(options: {
151
159
}
152
160
153
161
async function getPublicKey ( ) {
162
+ if ( ! dPath ) {
163
+ throw new Error ( 'a derivation path is needed to get the public key' )
164
+ }
165
+
154
166
const result = await TrezorConnect . getPublicKey ( {
155
167
path : dPath ,
156
168
coin : 'eth'
@@ -187,8 +199,6 @@ async function trezorProvider(options: {
187
199
188
200
const addressInfo = generateAddresses ( accountInfo , addressToPath . size )
189
201
190
- console . log ( { addressInfo } )
191
-
192
202
addressInfo . forEach ( ( { dPath, address } ) => {
193
203
addressToPath . set ( address , dPath )
194
204
} )
0 commit comments