Skip to content

Commit 7fd94e1

Browse files
committed
Add disconnect method
1 parent 0f1e328 commit 7fd94e1

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/modules/select/wallets/trezor.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function trezor(options: TrezorOptions & CommonWalletOptions): WalletModule {
4747
interface: {
4848
name: 'Trezor',
4949
connect: provider.enable,
50-
disconnect: () => provider.stop(),
50+
disconnect: provider.disconnect,
5151
address: {
5252
get: async () => provider.getPrimaryAddress()
5353
},
@@ -56,8 +56,8 @@ function trezor(options: TrezorOptions & CommonWalletOptions): WalletModule {
5656
},
5757
balance: {
5858
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)
6161
}
6262
}
6363
}
@@ -124,6 +124,14 @@ async function trezorProvider(options: {
124124
provider.getBalance = getBalance
125125
provider.getBalances = getBalances
126126
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+
}
127135

128136
function setPath(path: string) {
129137
dPath = path
@@ -151,6 +159,10 @@ async function trezorProvider(options: {
151159
}
152160

153161
async function getPublicKey() {
162+
if (!dPath) {
163+
throw new Error('a derivation path is needed to get the public key')
164+
}
165+
154166
const result = await TrezorConnect.getPublicKey({
155167
path: dPath,
156168
coin: 'eth'
@@ -187,8 +199,6 @@ async function trezorProvider(options: {
187199

188200
const addressInfo = generateAddresses(accountInfo, addressToPath.size)
189201

190-
console.log({ addressInfo })
191-
192202
addressInfo.forEach(({ dPath, address }) => {
193203
addressToPath.set(address, dPath)
194204
})

0 commit comments

Comments
 (0)