Skip to content

Commit

Permalink
feat(wallet): fix wallet locking
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcnk committed Dec 13, 2023
1 parent 1eed257 commit be8c281
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
5 changes: 4 additions & 1 deletion packages/features/src/common/components/CommandMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ import {
import React from 'react'
import { useNavigate } from 'react-router-dom'

import { useAccount } from '../hooks/useAccount'

interface CommandMenuProps {
open: boolean
setOpen: (open: boolean) => void
}

export const CommandMenu = ({ open, setOpen }: CommandMenuProps) => {
const navigate = useNavigate()
const { lockWallet } = useAccount()

const COMMAND_GROUPS = [
{
Expand Down Expand Up @@ -105,7 +108,7 @@ export const CommandMenu = ({ open, setOpen }: CommandMenuProps) => {
{
name: 'Lock Wallet',
icon: LockIcon,
onSelect: () => console.log('not yet'),
onSelect: lockWallet,
testId: 'commandMenu__lockWallet'
}
]
Expand Down
11 changes: 10 additions & 1 deletion packages/features/src/common/hooks/useAccount.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { Mina } from '@palladxyz/mina-core'
import { getSessionPersistence } from '@palladxyz/persistence'
import { useToast } from '@palladxyz/ui'
import { useVault } from '@palladxyz/vault'
import easyMeshGradient from 'easy-mesh-gradient'
import { useMemo } from 'react'
import { useNavigate } from 'react-router-dom'
import useSWR from 'swr'

import { useAppStore } from '../store/app'

export const useAccount = () => {
const navigate = useNavigate()
const { toast } = useToast()
const currentWallet = useVault((state) => state.getCurrentWallet())
const getAccountInfo = useVault((state) => state.getAccountInfo)
Expand Down Expand Up @@ -43,11 +46,17 @@ export const useAccount = () => {
title: 'Wallet address was copied.'
})
}
const lockWallet = async () => {
await getSessionPersistence().setItem('spendingPassword', '')
await useVault.persist.rehydrate()
return navigate('/unlock')
}
return {
...swr,
minaBalance,
gradientBackground,
copyWalletAddress,
publicKey
publicKey,
lockWallet
}
}
4 changes: 2 additions & 2 deletions packages/features/src/overview/components/AvatarMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useNavigate } from 'react-router-dom'
import { useAccount } from '../../common/hooks/useAccount'

export const AvatarMenu = () => {
const { gradientBackground } = useAccount()
const { gradientBackground, lockWallet } = useAccount()
const navigate = useNavigate()
return (
<DropdownMenu>
Expand All @@ -31,7 +31,7 @@ export const AvatarMenu = () => {
<SettingsIcon className="mr-2 h-4 w-4" />
<span>Settings</span>
</DropdownMenuItem>
<DropdownMenuItem onClick={() => console.log('not yet')}>
<DropdownMenuItem onClick={lockWallet}>
<LockIcon className="mr-2 h-4 w-4" />
<span>Lock Wallet</span>
</DropdownMenuItem>
Expand Down
2 changes: 1 addition & 1 deletion packages/mina-graphql/test/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Provider', () => {
expect(response.delegate).toBeDefined()
expect(response.publicKey).toBeDefined()
})
test('getAccountInfo (mainnet)', async () => {
test.skip('getAccountInfo (mainnet)', async () => {
const args: AccountInfoArgs = {
publicKey: 'B62qkAqbeE4h1M5hop288jtVYxK1MsHVMMcBpaWo8qdsAztgXaHH1xq' // this must be a public key that doesn't exist yet on mainnet
}
Expand Down
3 changes: 2 additions & 1 deletion packages/vault/test/wallet/walletFlow.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
constructTransaction,
FromBip39MnemonicWordsProps,
GroupedCredentials,
MinaPayload,
MinaSpecificArgs,
Network
Expand Down Expand Up @@ -184,7 +185,7 @@ describe('WalletTest', () => {
// get key agent
const instance = keyAgent1?.keyAgent
const signedTx = await instance!.sign(
groupedCredential?.credential,
groupedCredential?.credential as GroupedCredentials,
constructedTx,
args
)
Expand Down

0 comments on commit be8c281

Please sign in to comment.