Skip to content

Commit b81f603

Browse files
committed
fix: resets
1 parent 8724907 commit b81f603

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

packages/extension/src/background/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
existsL1,
1212
getL1,
1313
getWallets,
14+
resetAll,
1415
setKeystore,
1516
validatePassword,
1617
} from "./keys/l1"
@@ -116,7 +117,7 @@ async function main() {
116117
}
117118

118119
case "RESET_ALL": {
119-
return browser.storage.local.clear()
120+
return resetAll()
120121
}
121122

122123
case "ADD_WHITELIST": {

packages/extension/src/background/keys/l1.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ export async function validatePassword(password: string) {
3232
let rawWalletTimeoutPid: number | undefined
3333
let rawWallet: ethers.Wallet | undefined
3434

35-
function setRawWallet(wallet: ethers.Wallet) {
35+
function setRawWallet(wallet: ethers.Wallet | undefined) {
3636
rawWallet = wallet
3737
rawWalletTimeoutPid = setTimeout(() => {
3838
rawWallet = undefined
3939
}, 15 * 60 * 60 * 1000) as unknown as number
4040
}
4141

4242
export async function setKeystore(keystore: string) {
43+
setRawWallet(undefined)
4344
await store.setItem("encKeystore", keystore)
4445
}
4546

@@ -67,13 +68,15 @@ async function generateL1(): Promise<ethers.Wallet> {
6768

6869
let recoverPromise: Promise<ethers.Wallet> | undefined
6970
export async function getL1(password: string): Promise<ethers.Wallet> {
71+
console.log("getL1", rawWallet, await existsL1())
7072
if (rawWallet) {
7173
return rawWallet
7274
} else if (await existsL1()) {
7375
if (!recoverPromise) recoverPromise = recoverL1(password)
7476
const recoveredWallet = await recoverPromise
7577
setRawWallet(recoveredWallet)
7678
const encKeyPair = JSON.parse((await store.getItem("encKeystore")) || "{}")
79+
console.log("Set wallets", encKeyPair)
7780
store.setItem("wallets", encKeyPair.wallets ?? [])
7881
if (
7982
(await selectedWalletStore.getItem("SELECTED_WALLET")).address === "" &&
@@ -169,3 +172,8 @@ export async function createAccount(password: string, networkId: string) {
169172
wallets,
170173
}
171174
}
175+
176+
export async function resetAll() {
177+
setRawWallet(undefined)
178+
await browser.storage.local.clear()
179+
}

0 commit comments

Comments
 (0)