-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[READY] 456 Create UI for BRLa offramp KYC #493
Open
Sharqiewicz
wants to merge
53
commits into
staging
Choose a base branch
from
456-create-a-ui-for-brl-offramp-kyc
base: staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 42 commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
4c2e152
implement basic PIXKYCForm
Sharqiewicz 033e649
Merge branch 'staging' into 456-create-a-ui-for-brl-offramp-kyc
gianfra-t ce1e17a
Merge branch '471-add-support-for-offramping-brla-digital-token' into…
gianfra-t dc3f8e5
Merge branch 'staging' into 456-create-a-ui-for-brl-offramp-kyc
gianfra-t f3ac457
fixes
gianfra-t 09d28cb
connect BrlaInput and PixKyc components to offramp flow
gianfra-t 3f0dd33
move swap into a separate component
gianfra-t de6ad1d
add placeholder kyc status spinner
gianfra-t 3f4323f
Merge branch 'staging' into 456-create-a-ui-for-brl-offramp-kyc
gianfra-t 55b4157
connecting brla offramp with details modal
gianfra-t e733c4b
refactor PIX form code, add animations
Sharqiewicz b36feda
animate BRL KYC Form, implement unified Input component
Sharqiewicz 8afc550
change OutputTokenType to enum
Sharqiewicz 23a606b
rename Input to Field as it is related with react-hook-form
Sharqiewicz 9042128
Refactor BrlaSwapFields
Sharqiewicz fcc22d0
implement BrlaField component
Sharqiewicz 23f8955
implement KYCForm component
Sharqiewicz 8247d16
implement VerificationStatus component (BRLA)
Sharqiewicz 5adf457
implement useBRLAKYCProcess hook
Sharqiewicz f72318c
add validation for inputs
Sharqiewicz d2bfa32
refactor BrlaExtendedForm
Sharqiewicz 7d2dcc2
rename comments
Sharqiewicz f8cc120
fix Field registers react-hook-form
Sharqiewicz 67f7b14
clean useSubmitOfframp
Sharqiewicz 8b48180
add header to KYCForm
Sharqiewicz 824ccb0
add docs for brla.controller getAccount
Sharqiewicz af4977c
change onSwapConfirm type
Sharqiewicz e74cbf4
fix TokenDefinition type in swap
Sharqiewicz 39eff84
refactor useBRLAKYCProcess
Sharqiewicz d81ad38
create brla logic hooks
Sharqiewicz 1e9e15e
fix Spinner styles
Sharqiewicz 8990b25
animate VerificationStatus
Sharqiewicz c8a618f
show progress kyc after submitting
Sharqiewicz f1cc7ca
shorten logic brla service
Sharqiewicz be625d7
remove placeholder birthdate
Sharqiewicz 052d5e4
add basic yup validation
Sharqiewicz 53e34b7
Merge branch 'staging' into 456-create-a-ui-for-brl-offramp-kyc
Sharqiewicz d870e64
fix brla form types
Sharqiewicz caaa916
remove unnecessary comment
Sharqiewicz 3895349
remove unnecessary signer-service hooks.ts brla
Sharqiewicz 4dd5fc5
Merge branch 'staging' into 456-create-a-ui-for-brl-offramp-kyc
Sharqiewicz 0efce5d
Move brla fields further down in swap form
ebma 929826f
Add placeholder to text fieelds and remove heading
ebma 48ddfdb
Check existence of brla username and password in constructor
ebma c9702d6
Merge branch 'staging' into 456-create-a-ui-for-brl-offramp-kyc
gianfra-t 5c8db69
add address fields, modify kyc states
gianfra-t f62ba6b
Merge branch '456-create-a-ui-for-brl-offramp-kyc' of github.com:pend…
gianfra-t f7d933b
modify store validator, ui states
gianfra-t 362eb86
modifications to kyc status logic from backend
gianfra-t 168258e
add initialize failed message state and action to offramp store, fail…
gianfra-t cea3a2b
use dialog from ref.current, replace dialog visible setter for global…
gianfra-t 9785e21
fix build, remove comments
gianfra-t 4cbb93f
prevent early return issues
gianfra-t File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,113 @@ | ||
import { RefObject } from 'react'; | ||
|
||
import { useKYCProcess } from '../../hooks/brla/useBRLAKYCProcess'; | ||
import { useKYCForm } from '../../hooks/brla/useKYCForm'; | ||
|
||
import { FeeComparisonRef } from '../FeeComparison'; | ||
import { VerificationStatus } from './VerificationStatus'; | ||
import { BrlaFieldProps, ExtendedBrlaFieldOptions } from './BrlaField'; | ||
import { KYCForm } from './KYCForm'; | ||
|
||
interface PIXKYCFormProps { | ||
feeComparisonRef: RefObject<FeeComparisonRef | null>; | ||
setIsOfframpSummaryDialogVisible: (isVisible: boolean) => void; | ||
onSwapConfirm: () => void; | ||
} | ||
|
||
const PIXKYCFORM_FIELDS: BrlaFieldProps[] = [ | ||
{ | ||
id: ExtendedBrlaFieldOptions.PHONE, | ||
label: 'Phone Number', | ||
type: 'text', | ||
placeholder: 'Phone Number', | ||
required: true, | ||
index: 0, | ||
}, | ||
{ | ||
id: ExtendedBrlaFieldOptions.FULL_NAME, | ||
label: 'Full Name', | ||
type: 'text', | ||
placeholder: 'Full Name', | ||
required: true, | ||
index: 1, | ||
}, | ||
{ | ||
id: ExtendedBrlaFieldOptions.CEP, | ||
label: 'CEP', | ||
type: 'text', | ||
placeholder: 'CEP', | ||
required: true, | ||
index: 2, | ||
}, | ||
{ | ||
id: ExtendedBrlaFieldOptions.CITY, | ||
label: 'City', | ||
type: 'text', | ||
placeholder: 'City', | ||
required: true, | ||
index: 3, | ||
}, | ||
{ | ||
id: ExtendedBrlaFieldOptions.STATE, | ||
label: 'State', | ||
type: 'text', | ||
placeholder: 'State', | ||
required: true, | ||
index: 4, | ||
}, | ||
{ | ||
id: ExtendedBrlaFieldOptions.STREET, | ||
label: 'Street', | ||
type: 'text', | ||
placeholder: 'Street', | ||
required: true, | ||
index: 5, | ||
}, | ||
{ | ||
id: ExtendedBrlaFieldOptions.NUMBER, | ||
label: 'Number', | ||
type: 'text', | ||
placeholder: 'Number', | ||
required: true, | ||
index: 6, | ||
}, | ||
{ | ||
id: ExtendedBrlaFieldOptions.DISTRICT, | ||
label: 'District', | ||
type: 'text', | ||
placeholder: 'District', | ||
required: true, | ||
index: 7, | ||
}, | ||
{ | ||
id: ExtendedBrlaFieldOptions.BIRTHDATE, | ||
label: 'Birthdate', | ||
type: 'date', | ||
required: true, | ||
index: 8, | ||
}, | ||
]; | ||
|
||
export const PIXKYCForm = ({ feeComparisonRef, setIsOfframpSummaryDialogVisible }: PIXKYCFormProps) => { | ||
const { verificationStatus, statusMessage, handleFormSubmit, handleBackClick, isSubmitted } = useKYCProcess( | ||
setIsOfframpSummaryDialogVisible, | ||
); | ||
|
||
const { kycForm } = useKYCForm(); | ||
|
||
return ( | ||
<div className="relative"> | ||
{!isSubmitted ? ( | ||
<KYCForm | ||
fields={PIXKYCFORM_FIELDS} | ||
form={kycForm} | ||
onSubmit={handleFormSubmit} | ||
onBackClick={handleBackClick} | ||
feeComparisonRef={feeComparisonRef} | ||
/> | ||
) : ( | ||
<VerificationStatus status={verificationStatus} message={statusMessage} /> | ||
)} | ||
</div> | ||
); | ||
}; |
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,71 @@ | ||
import { FC } from 'react'; | ||
import { useFormContext, useFormState } from 'react-hook-form'; | ||
import { motion } from 'motion/react'; | ||
|
||
import { Field, FieldProps } from '../../Field'; | ||
|
||
export enum StandardBrlaFieldOptions { | ||
TAX_ID = 'taxId', | ||
PIX_ID = 'pixId', | ||
} | ||
|
||
export enum ExtendedBrlaFieldOptions { | ||
PHONE = 'phone', | ||
ADDRESS = 'address', | ||
CEP = 'cep', | ||
CITY = 'city', | ||
STATE = 'state', | ||
STREET = 'street', | ||
NUMBER = 'number', | ||
DISTRICT = 'district', | ||
FULL_NAME = 'fullName', | ||
CPF = 'cpf', | ||
BIRTHDATE = 'birthdate', | ||
EMAIL = 'email', | ||
} | ||
|
||
export type BrlaFieldOptions = StandardBrlaFieldOptions | ExtendedBrlaFieldOptions; | ||
|
||
export interface BrlaFieldProps extends FieldProps { | ||
id: BrlaFieldOptions; | ||
label: string; | ||
index: number; | ||
validationPattern?: { | ||
value: RegExp; | ||
message: string; | ||
}; | ||
} | ||
|
||
export const BrlaField: FC<BrlaFieldProps> = ({ id, label, index, validationPattern, ...rest }) => { | ||
// It required to be inside a FormProvider (react-hook-form) | ||
const { register } = useFormContext(); | ||
const { errors } = useFormState(); | ||
const errorMessage = errors[id]?.message as string; | ||
|
||
return ( | ||
<motion.div | ||
className="mb-4" | ||
initial={{ opacity: 0, y: 20 }} | ||
animate={{ opacity: 1, y: 0 }} | ||
exit={{ opacity: 0, y: -20 }} | ||
transition={{ | ||
duration: 0.4, | ||
delay: index * 0.15, | ||
type: 'spring', | ||
stiffness: 300, | ||
damping: 15, | ||
}} | ||
> | ||
<label htmlFor={id} className="block mb-1"> | ||
{label} | ||
</label> | ||
<Field | ||
id={id} | ||
register={register(id, { required: true, pattern: validationPattern })} | ||
className={`w-full p-2 ${errors[id] ? 'border border-red-500' : ''}`} | ||
{...rest} | ||
/> | ||
{errorMessage && <span className="text-red-500 text-sm mt-1">{errorMessage}</span>} | ||
</motion.div> | ||
); | ||
}; |
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,69 @@ | ||
import { FC } from 'react'; | ||
import { AnimatePresence, motion, MotionProps } from 'motion/react'; | ||
|
||
import { OutputTokenType, OutputTokenTypes } from '../../../constants/tokenConfig'; | ||
import { BrlaField, StandardBrlaFieldOptions } from '../BrlaField'; | ||
|
||
interface BrlaSwapFieldsProps { | ||
toToken: OutputTokenType; | ||
} | ||
|
||
const containerAnimation: MotionProps = { | ||
initial: { opacity: 0, height: 0 }, | ||
animate: { opacity: 1, height: 'auto' }, | ||
exit: { opacity: 0, height: 0 }, | ||
transition: { duration: 0.3 }, | ||
}; | ||
|
||
const STANDARD_FIELDS = [ | ||
{ id: StandardBrlaFieldOptions.TAX_ID, label: 'Tax ID', index: 0 }, | ||
{ id: StandardBrlaFieldOptions.PIX_ID, label: 'PIX ID', index: 1 }, | ||
]; | ||
|
||
/** | ||
* BrlaSwapFields component | ||
* | ||
* Renders PIX payment details form fields when Brazilian Real (BRL) is selected | ||
* as the destination currency in the Swap form. Collects necessary information | ||
* for processing PIX transfers to Brazilian bank accounts. | ||
*/ | ||
|
||
export const BrlaSwapFields: FC<BrlaSwapFieldsProps> = ({ toToken }) => ( | ||
<AnimatePresence> | ||
{toToken === OutputTokenTypes.BRL && ( | ||
<motion.div {...containerAnimation}> | ||
<motion.h2 | ||
className="mb-2 text-2xl font-bold text-center text-blue-700" | ||
initial={{ opacity: 0, y: 15 }} | ||
animate={{ opacity: 1, y: 0 }} | ||
transition={{ | ||
duration: 0.4, | ||
delay: 0.1, | ||
type: 'spring', | ||
stiffness: 300, | ||
damping: 15, | ||
}} | ||
> | ||
PIX Details | ||
</motion.h2> | ||
<motion.p | ||
className="text-gray-400 mb-4" | ||
initial={{ opacity: 0, y: 15 }} | ||
animate={{ opacity: 1, y: 0 }} | ||
transition={{ | ||
duration: 0.4, | ||
delay: 0.2, | ||
type: 'spring', | ||
stiffness: 300, | ||
damping: 15, | ||
}} | ||
> | ||
Which bank account should we send the funds to? | ||
</motion.p> | ||
{STANDARD_FIELDS.map((field) => ( | ||
<BrlaField key={field.id} id={field.id} label={field.label} index={field.index} /> | ||
))} | ||
</motion.div> | ||
)} | ||
</AnimatePresence> | ||
); |
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,54 @@ | ||
import { RefObject, useCallback } from 'react'; | ||
import { motion } from 'motion/react'; | ||
import { FormProvider, UseFormReturn } from 'react-hook-form'; | ||
|
||
import { FeeComparisonRef } from '../../FeeComparison'; | ||
import { BrlaField, BrlaFieldProps } from '../BrlaField'; | ||
import { KYCFormData } from '../../../hooks/brla/useKYCForm'; | ||
|
||
interface KYCFormProps { | ||
fields: BrlaFieldProps[]; | ||
form: UseFormReturn<KYCFormData>; | ||
onSubmit: (formData: KYCFormData) => Promise<void>; | ||
onBackClick: () => void; | ||
feeComparisonRef: RefObject<FeeComparisonRef | null>; | ||
} | ||
|
||
export const KYCForm = ({ form, onSubmit, onBackClick, fields, feeComparisonRef }: KYCFormProps) => { | ||
const { handleSubmit } = form; | ||
|
||
const compareFeesClick = useCallback(() => { | ||
feeComparisonRef.current?.scrollIntoView(); | ||
}, [feeComparisonRef]); | ||
|
||
return ( | ||
<FormProvider {...form}> | ||
<motion.form | ||
initial={{ scale: 0.9, opacity: 0 }} | ||
animate={{ scale: 1, opacity: 1 }} | ||
transition={{ duration: 0.3 }} | ||
className="px-4 pt-4 pb-2 mx-4 mt-8 mb-4 rounded-lg shadow-custom md:mx-auto md:w-96 min-h-[480px] flex flex-col" | ||
onSubmit={handleSubmit(onSubmit)} | ||
> | ||
<h1 className="mt-2 mb-5 text-3xl font-bold text-center text-blue-700">KYC Details</h1> | ||
{fields.map((field) => ( | ||
<BrlaField key={field.id} {...field} /> | ||
))} | ||
|
||
<div className="grid gap-3 mt-8 mb-12"> | ||
<div className="flex gap-3"> | ||
<button type="button" className="btn-vortex-primary-inverse btn flex-1" onClick={onBackClick}> | ||
Back | ||
</button> | ||
<button type="submit" className="btn-vortex-primary btn flex-1"> | ||
Continue | ||
</button> | ||
</div> | ||
<button type="button" className="btn-vortex-primary-inverse btn flex-1" onClick={compareFeesClick}> | ||
Compare Fees | ||
</button> | ||
</div> | ||
</motion.form> | ||
</FormProvider> | ||
); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no right or wrong here but looking at the other functions we should make sure they are also using the same format. The other functions define the endpoint as an extra
const
so either we do it on all of them, or remove the extraconst endpoint
on all of them.