Skip to content

Commit

Permalink
fix: correctly clear local storage
Browse files Browse the repository at this point in the history
when unloadAgent is called
  • Loading branch information
travis committed Nov 14, 2023
1 parent 745aa82 commit cdde2e2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions examples/react/w3console/src/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Logo } from '../brand'
import { Fragment, useState } from 'react'
import { Dialog, Transition } from '@headlessui/react'
import { Bars3Icon, XMarkIcon } from '@heroicons/react/24/outline'
import { useKeyring } from '@w3ui/react-keyring'
import { useNavigate } from 'react-router-dom'

const navLinks = [
{ name: 'Terms', href: '/terms' },
Expand All @@ -14,6 +16,12 @@ interface SidebarComponentProps {
}

function Sidebar ({ sidebar = <div></div> }: SidebarComponentProps): JSX.Element {
const navigate = useNavigate()
const [, { unloadAgent }] = useKeyring()
async function logout () {
await unloadAgent()
navigate('/')
}
return (
<nav className='flex-none w-64 bg-gray-900 text-white px-4 pb-4 border-r border-gray-800 h-screen'>
<div className='flex flex-col justify-between h-full'>
Expand All @@ -25,6 +33,7 @@ function Sidebar ({ sidebar = <div></div> }: SidebarComponentProps): JSX.Element
<a className='text-xs block text-center mt-2' href={link.href}>{link.name}</a>
))}
</div>
<button onClick={() => unloadAgent()}>log out</button>
</div>
</div>
</nav>
Expand Down
4 changes: 2 additions & 2 deletions packages/react-keyring/src/providers/Keyring.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function KeyringProvider ({
connection
}: KeyringProviderProps): JSX.Element {
const [agent, setAgent] = useState<Agent>()
const [account, setAccount] = useLocalStorageState<string>(W3UI_ACCOUNT_LOCALSTORAGE_KEY)
const [account, setAccount, { removeItem: unsetAccount }] = useLocalStorageState<string>(W3UI_ACCOUNT_LOCALSTORAGE_KEY)
const [space, setSpace] = useState<Space>()
const [spaces, setSpaces] = useState<Space[]>([])
const [issuer, setIssuer] = useState<Signer>()
Expand Down Expand Up @@ -161,7 +161,7 @@ export function KeyringProvider ({
setSpaces([])
setIssuer(undefined)
setAgent(undefined)
setAccount(undefined)
unsetAccount()
}

const resetAgent = async (): Promise<void> => {
Expand Down

0 comments on commit cdde2e2

Please sign in to comment.