Skip to content

Commit e336921

Browse files
authored
Merge pull request #261 from blocknative/enhancement/clear-accounts
Clear hardware accs when derivation path changed. Closes #260
2 parents b2740ec + 6ecb160 commit e336921

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

src/modules/select/wallets/ledger.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,20 @@ async function ledgerProvider(options: {
138138
}
139139

140140
async function setPath(path: string, custom?: boolean) {
141-
if (custom) {
142-
if (!isValidPath(path)) {
143-
return false
144-
}
145-
146-
const address = await getAddress(path)
141+
if (!isValidPath(path)) {
142+
return false
143+
}
147144

148-
// over-ride any exsting addresses for the case of accountSelect being called
145+
if (path !== dPath) {
146+
// clear any exsting addresses if different path
149147
addressToPath = new Map()
148+
}
149+
150+
if (custom) {
151+
const address = await getAddress(path)
150152
addressToPath.set(address, path)
151153
customPath = true
154+
152155
return true
153156
}
154157

src/modules/select/wallets/trezor.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,18 +137,22 @@ async function trezorProvider(options: {
137137
}
138138

139139
async function setPath(path: string, custom?: boolean) {
140-
if (custom) {
141-
if (!isValidPath(path)) {
142-
return false
143-
}
140+
if (!isValidPath(path)) {
141+
return false
142+
}
144143

144+
if (path !== dPath) {
145+
// clear any exsting addresses if different path
146+
addressToPath = new Map()
147+
}
148+
149+
if (custom) {
145150
try {
146151
const address = await getAddress(path)
147-
148-
// over-ride any exsting addresses for the case of accountSelect being called
149-
addressToPath = new Map()
150152
addressToPath.set(address, path)
153+
dPath = path
151154
customPath = true
155+
152156
return true
153157
} catch (error) {
154158
throw new Error(

0 commit comments

Comments
 (0)