-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for dfns wallet api
- Loading branch information
1 parent
2a2c239
commit b31fca7
Showing
30 changed files
with
1,036 additions
and
16 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
72 changes: 72 additions & 0 deletions
72
src/app/components/modals/dfns-modal/components/dfns-modal-credentials-form.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,72 @@ | ||
import { Button, FormControl, FormErrorMessage, FormLabel, Input, VStack } from '@chakra-ui/react'; | ||
import { DFNSCustomerConfiguration } from '@models/configuration'; | ||
import { useForm } from '@tanstack/react-form'; | ||
|
||
interface DFNSModalRegisterFormProps { | ||
onSubmit: ( | ||
credentialCode: string, | ||
selectedDFNSOrganization: DFNSCustomerConfiguration | ||
) => Promise<void>; | ||
selectedDFNSOrganization: DFNSCustomerConfiguration; | ||
} | ||
|
||
export function DFNSModalRegisterForm({ | ||
onSubmit, | ||
selectedDFNSOrganization, | ||
}: DFNSModalRegisterFormProps): React.JSX.Element { | ||
const formAPI = useForm({ | ||
defaultValues: { | ||
credentialCode: '', | ||
}, | ||
onSubmit: async ({ value }) => { | ||
await onSubmit(value.credentialCode, selectedDFNSOrganization); | ||
}, | ||
}); | ||
|
||
return ( | ||
<VStack w={'100%'}> | ||
<form | ||
onSubmit={e => { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
void formAPI.handleSubmit(); | ||
}} | ||
> | ||
<VStack spacing={4} w={'100%'}> | ||
<formAPI.Field | ||
name="credentialCode" | ||
validators={{ | ||
onChange: ({ value }) => { | ||
if (!value) return 'Credential Code is required'; | ||
if (value.length < 9) return 'Credential Code must be at least 9 characters'; | ||
return undefined; | ||
}, | ||
}} | ||
children={field => ( | ||
<FormControl isInvalid={!!field.state.meta.errorMap.onChange}> | ||
<FormLabel color={'white.01'} fontSize={'md'}> | ||
Credential Code | ||
</FormLabel> | ||
<Input | ||
type="string" | ||
value={field.state.value} | ||
onChange={e => field.handleChange(e.target.value)} | ||
placeholder="xxxxxxxxx" | ||
/> | ||
<FormErrorMessage>{field.state.meta.errorMap.onChange}</FormErrorMessage> | ||
</FormControl> | ||
)} | ||
/> | ||
<formAPI.Subscribe | ||
selector={state => [state.canSubmit]} | ||
children={([canSubmit]) => ( | ||
<Button variant={'dfns'} type="submit" isDisabled={!canSubmit}> | ||
Submit | ||
</Button> | ||
)} | ||
/> | ||
</VStack> | ||
</form> | ||
</VStack> | ||
); | ||
} |
25 changes: 25 additions & 0 deletions
25
src/app/components/modals/dfns-modal/components/dfns-modal-error-box.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,25 @@ | ||
import { HStack, Text } from '@chakra-ui/react'; | ||
|
||
interface DFNSModalErrorBoxProps { | ||
error: string | undefined; | ||
} | ||
|
||
export function DFNSModalErrorBox({ error }: DFNSModalErrorBoxProps): React.JSX.Element | false { | ||
return ( | ||
!!error && ( | ||
<HStack | ||
p={'5%'} | ||
w={'375px'} | ||
spacing={4} | ||
border={'1px solid'} | ||
borderRadius={'md'} | ||
borderColor={'red'} | ||
justifyContent={'center'} | ||
> | ||
<Text fontFamily={'Inter'} fontSize={'xs'} fontWeight={'600'}> | ||
{error} | ||
</Text> | ||
</HStack> | ||
) | ||
); | ||
} |
78 changes: 78 additions & 0 deletions
78
src/app/components/modals/dfns-modal/components/dfns-modal-form.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,78 @@ | ||
import { Button, FormControl, FormErrorMessage, FormLabel, Input, VStack } from '@chakra-ui/react'; | ||
import { DFNSCustomerConfiguration } from '@models/configuration'; | ||
import { useForm } from '@tanstack/react-form'; | ||
|
||
interface DFNSModalLoginFormProps { | ||
onSubmit: (email: string, selectedDFNSOrganization: DFNSCustomerConfiguration) => Promise<void>; | ||
selectedDFNSOrganization: DFNSCustomerConfiguration; | ||
} | ||
|
||
const validateEmail = (email: string) => { | ||
if (!email) return 'Email address is required'; | ||
|
||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | ||
if (!emailRegex.test(email)) return 'Please enter a valid email address'; | ||
|
||
const [localPart] = email.split('@'); | ||
if (localPart.length > 64) return 'Local part of email cannot exceed 64 characters'; | ||
if (email.length > 254) return 'Email address cannot exceed 254 characters'; | ||
|
||
return undefined; | ||
}; | ||
|
||
export function DFNSModalLoginForm({ | ||
onSubmit, | ||
selectedDFNSOrganization, | ||
}: DFNSModalLoginFormProps): React.JSX.Element { | ||
const formAPI = useForm({ | ||
defaultValues: { | ||
email: '', | ||
}, | ||
onSubmit: async ({ value }) => { | ||
await onSubmit(value.email, selectedDFNSOrganization); | ||
}, | ||
}); | ||
|
||
return ( | ||
<VStack w={'100%'}> | ||
<form | ||
onSubmit={e => { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
void formAPI.handleSubmit(); | ||
}} | ||
> | ||
<VStack spacing={4} w={'100%'}> | ||
<formAPI.Field | ||
name="email" | ||
validators={{ | ||
onChange: ({ value }) => validateEmail(value), | ||
}} | ||
children={field => ( | ||
<FormControl isInvalid={!!field.state.meta.errorMap.onChange}> | ||
<FormLabel color={'white.01'} fontSize={'md'}> | ||
E-Mail Address | ||
</FormLabel> | ||
<Input | ||
type="email" | ||
value={field.state.value} | ||
onChange={e => field.handleChange(e.target.value)} | ||
placeholder="[email protected]" | ||
/> | ||
<FormErrorMessage>{field.state.meta.errorMap.onChange}</FormErrorMessage> | ||
</FormControl> | ||
)} | ||
/> | ||
<formAPI.Subscribe | ||
selector={state => [state.canSubmit]} | ||
children={([canSubmit]) => ( | ||
<Button variant={'dfns'} type="submit" isDisabled={!canSubmit}> | ||
Submit | ||
</Button> | ||
)} | ||
/> | ||
</VStack> | ||
</form> | ||
</VStack> | ||
); | ||
} |
43 changes: 43 additions & 0 deletions
43
src/app/components/modals/dfns-modal/components/dfns-modal-layout.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,43 @@ | ||
import { ReactNode } from 'react'; | ||
|
||
import { | ||
Image, | ||
Modal, | ||
ModalBody, | ||
ModalCloseButton, | ||
ModalContent, | ||
ModalHeader, | ||
ModalOverlay, | ||
VStack, | ||
} from '@chakra-ui/react'; | ||
|
||
interface DFNSModalLayoutProps { | ||
logo: string; | ||
isOpen: boolean; | ||
onClose: () => void; | ||
children: ReactNode; | ||
} | ||
|
||
export function DFNSModalLayout({ | ||
logo, | ||
isOpen, | ||
onClose, | ||
children, | ||
}: DFNSModalLayoutProps): React.JSX.Element { | ||
return ( | ||
<Modal isOpen={isOpen} onClose={onClose} variant={'dfns'}> | ||
<ModalOverlay /> | ||
<ModalContent> | ||
<ModalHeader> | ||
<Image src={logo} alt={'DFNS Logo'} boxSize={'100px'} objectFit={'contain'} /> | ||
</ModalHeader> | ||
<ModalCloseButton /> | ||
<ModalBody> | ||
<VStack minHeight={'425px'} spacing={'25px'}> | ||
{children} | ||
</VStack> | ||
</ModalBody> | ||
</ModalContent> | ||
</Modal> | ||
); | ||
} |
19 changes: 19 additions & 0 deletions
19
src/app/components/modals/dfns-modal/components/dfns-modal-loading-stack.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,19 @@ | ||
import { HStack, Spinner, Text } from '@chakra-ui/react'; | ||
|
||
interface DFNSModalLoadingStackProps { | ||
isLoading: [boolean, string]; | ||
} | ||
export function DFNSModalLoadingStack({ | ||
isLoading, | ||
}: DFNSModalLoadingStackProps): React.JSX.Element | false { | ||
return ( | ||
isLoading[0] && ( | ||
<HStack py={'5%'} w={'375px'} spacing={4} bgColor={'#D6D7EB'} justifyContent={'center'}> | ||
<Text fontFamily={'Inter'} fontSize={'sm'} fontWeight={'600'} color={'#170C33'}> | ||
{isLoading[1]} | ||
</Text> | ||
<Spinner size={'sm'} color="#170C33" /> | ||
</HStack> | ||
) | ||
); | ||
} |
28 changes: 28 additions & 0 deletions
28
src/app/components/modals/dfns-modal/components/dfns-modal-navigator-button-stack.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,28 @@ | ||
import { Button, Text, VStack } from '@chakra-ui/react'; | ||
|
||
interface DFNSModalNavigatorButtonProps { | ||
isRegister: boolean; | ||
setIsRegister: (isRegister: boolean) => void; | ||
isVisible: boolean; | ||
} | ||
|
||
export function DFNSModalNavigatorButton({ | ||
isRegister, | ||
setIsRegister, | ||
isVisible, | ||
}: DFNSModalNavigatorButtonProps): React.JSX.Element | false { | ||
if (!isVisible) return false; | ||
|
||
return ( | ||
<VStack w={'100%'} spacing={'25px'}> | ||
<Text fontSize="sm" color="gray.500"> | ||
{!isRegister | ||
? 'New user? Click the button below to register with your DFNS credential code.' | ||
: 'Existing user? Sign in with your e-mail address.'} | ||
</Text> | ||
<Button variant={'dfns'} onClick={() => setIsRegister(!isRegister)}> | ||
{isRegister ? 'Login' : 'Register'} | ||
</Button> | ||
</VStack> | ||
); | ||
} |
23 changes: 23 additions & 0 deletions
23
...-modal/components/dfns-modal-select-address-menu/components/dfns-modal-address-button.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,23 @@ | ||
import { Button, HStack, Text } from '@chakra-ui/react'; | ||
import { truncateAddress } from 'dlc-btc-lib/utilities'; | ||
|
||
interface DFNSModalAddressButtonProps { | ||
addressInformation: { address: string | undefined; walletID: string }; | ||
setWalletID: (walletID: string) => void; | ||
} | ||
|
||
export function DFNSModalAddressButton({ | ||
addressInformation, | ||
setWalletID, | ||
}: DFNSModalAddressButtonProps): React.JSX.Element { | ||
const { address, walletID } = addressInformation; | ||
return ( | ||
<Button variant={'bitcoinAddress'} w={'100%'} h={'15px'} onClick={() => setWalletID(walletID)}> | ||
<HStack w={'375px'} justifyContent={'center'}> | ||
<Text fontSize={'xs'} fontWeight={'bold'}> | ||
{truncateAddress(address!)} | ||
</Text> | ||
</HStack> | ||
</Button> | ||
); | ||
} |
Oops, something went wrong.