Skip to content

Commit

Permalink
password lock button
Browse files Browse the repository at this point in the history
  • Loading branch information
attente committed Nov 10, 2024
1 parent ab20d40 commit 85b964b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/routes/Wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function Wallet() {
const navigate = useNavigate()

const accountAddress = useObservable(authStore.accountAddress)
const isPasswordSet = useObservable(authStore.isPasswordSet)
const isSigningTxn = useObservable(walletStore.isSigningTxn)
const isSigningMsg = useObservable(walletStore.isSigningMsg)

Expand Down Expand Up @@ -387,6 +388,15 @@ function Wallet() {
onClick={() => setIsNetworkModalOpen(true)}
/>

{isPasswordSet && (
<Button
label="Password Lock"
variant="text"
marginRight="8"
onClick={() => window.location.reload()}
/>
)}

<Button
label="Sign Out"
variant="text"
Expand Down
9 changes: 9 additions & 0 deletions src/stores/AuthStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ export class AuthStore {
networkStore.accountLoaded.set(true)
}
})

getIndexedDB(IndexedDBKey.SECURITY).then(async db => {
this.isPasswordSet.set(!db.get(IndexedDBKey.SECURITY, 'key'))
})
}

isLoadingAccount = observable(true)
isPasswordSet = observable(true)

account: Account | undefined

Expand Down Expand Up @@ -133,6 +138,8 @@ export class AuthStore {
const db = await getIndexedDB(IndexedDBKey.SECURITY)
await db.put(IndexedDBKey.SECURITY, key, 'key')
await db.put(IndexedDBKey.SECURITY, encrypted, 'mnemonic')

this.isPasswordSet.set(false)
}

async encryptRecoveryMnemonicWithPassword(mnemonic: string, address: string, password: string) {
Expand All @@ -148,6 +155,8 @@ export class AuthStore {
// Store encrypted data (minus key) in indexed db
const db = await getIndexedDB(IndexedDBKey.SECURITY)
await db.put(IndexedDBKey.SECURITY, encrypted, 'mnemonic')

this.isPasswordSet.set(true)
}

async decryptRecoveryMnemonic(
Expand Down

0 comments on commit 85b964b

Please sign in to comment.