-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #167 from palladians/chore/decouple-views-from-routes
chore(wallet): refactor views and decouple views from logic
- Loading branch information
Showing
90 changed files
with
1,875 additions
and
1,244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v20.10.0 | ||
v20.12.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { useNavigate } from 'react-router-dom' | ||
|
||
import { AboutView } from '../views/about' | ||
|
||
export const AboutRoute = () => { | ||
const navigate = useNavigate() | ||
return <AboutView onGoBack={() => navigate(-1)} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
packages/features/src/address-book/routes/address-book.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { useNavigate } from 'react-router-dom' | ||
|
||
import { useAddressBookStore } from '@/common/store/address-book' | ||
|
||
import { AddressBookView } from '../views/address-book' | ||
|
||
export const AddressBookRoute = () => { | ||
const navigate = useNavigate() | ||
const contacts = useAddressBookStore((state) => state.contacts) | ||
return ( | ||
<AddressBookView | ||
contacts={contacts} | ||
onAddClicked={() => navigate('/contacts/new')} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { useNavigate } from 'react-router-dom' | ||
|
||
import { NewAddressView } from '../views/new-address' | ||
|
||
export const NewAddressRoute = () => { | ||
const navigate = useNavigate() | ||
return <NewAddressView onGoBack={() => navigate(-1)} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
packages/features/src/address-book/views/new-address.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { zodResolver } from '@hookform/resolvers/zod' | ||
import { | ||
getSecurePersistence, | ||
getSessionPersistence | ||
} from '@palladxyz/persistence' | ||
import { useVault } from '@palladxyz/vault' | ||
import { FormEvent, useEffect, useState } from 'react' | ||
import { useForm } from 'react-hook-form' | ||
import { useNavigate } from 'react-router-dom' | ||
import { z } from 'zod' | ||
|
||
import { passwordSchema } from '@/common/lib/validation' | ||
|
||
import { UnlockWalletView } from '../views/unlock-wallet' | ||
|
||
const formSchema = z.object({ | ||
spendingPassword: passwordSchema | ||
}) | ||
|
||
export const UnlockWalletRoute = () => { | ||
const [restartAlertVisible, setRestartAlertVisible] = useState(false) | ||
const [showPassword, setShowPassword] = useState(false) | ||
const navigate = useNavigate() | ||
const unlockWalletForm = useForm({ | ||
defaultValues: { | ||
spendingPassword: '' | ||
}, | ||
resolver: zodResolver(formSchema) | ||
}) | ||
const onSubmit = async ({ | ||
spendingPassword | ||
}: { | ||
spendingPassword: string | ||
}) => { | ||
await getSessionPersistence().setItem('spendingPassword', spendingPassword) | ||
await useVault.persist.rehydrate() | ||
setTimeout(() => { | ||
unlockWalletForm.setError('spendingPassword', { | ||
type: 'wrongPassword', | ||
message: 'The spending password is wrong' | ||
}) | ||
}, 100) | ||
} | ||
const togglePassword = (event: FormEvent<HTMLButtonElement>) => { | ||
event.preventDefault() | ||
setShowPassword(!showPassword) | ||
} | ||
useEffect(() => { | ||
const unsub = useVault.persist?.onFinishHydration(async () => { | ||
const authenticated = | ||
(await getSecurePersistence().getItem('foo')) === 'bar' | ||
if (!authenticated) { | ||
await getSessionPersistence().removeItem('spendingPassword') | ||
return unlockWalletForm.setError('spendingPassword', { | ||
type: 'wrongPassword', | ||
message: 'The spending password is wrong' | ||
}) | ||
} | ||
navigate('/dashboard') | ||
}) | ||
return () => unsub?.() | ||
}, []) | ||
return ( | ||
<UnlockWalletView | ||
form={unlockWalletForm} | ||
onSubmit={onSubmit} | ||
restartAlertVisible={restartAlertVisible} | ||
setRestartAlertVisible={setRestartAlertVisible} | ||
showPassword={showPassword} | ||
togglePassword={togglePassword} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.