Skip to content

Commit

Permalink
pin updates and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
0xk0stas committed Oct 19, 2023
1 parent 0cdea38 commit aa4d57e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
29 changes: 24 additions & 5 deletions src/views/Home/components/ExistingUser/ExistingUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function copyToClipboard(text: string) { // Specify the type of the 'text' param
}

function ExistingUser({ address, email, secretWords, userGid }: { address: string, email: string, secretWords: string[], userGid: string }) {

const [isWordsVisible, setWordsVisible] = useState(false);
const [isPinModalOpen, setPinModalOpen] = useState(false);
const [pin, setPin] = useState('');
Expand Down Expand Up @@ -121,8 +122,23 @@ function ExistingUser({ address, email, secretWords, userGid }: { address: strin
}, [address]);




let isPinCorrect = false;
if (secretWords.length > 0) {
const decryptedWord = decrypt(secretWords[0], encryptionKey);

// pin correct if word is only with letters
isPinCorrect = /^[a-z]+$/.test(decryptedWord);
}

useEffect(() => {
if (pin.length == 4 && !isPinCorrect) {
setShowError(true);
}
if (isPinCorrect) {
setShowError(false);
}
},[isPinCorrect, pin]);

return (
<Container maxW={'800px'}>
Expand Down Expand Up @@ -204,7 +220,7 @@ function ExistingUser({ address, email, secretWords, userGid }: { address: strin
{/* Rest of your code */}
</VStack>

{isWordsVisible && (
{isWordsVisible && !showError && (
<Grid templateColumns="repeat(6, 1fr)" gap={6}>
{secretWords.map((word, index) => (
<Text key={index} as="span" border="1px solid black" padding="1" m={1}>
Expand All @@ -230,11 +246,14 @@ function ExistingUser({ address, email, secretWords, userGid }: { address: strin
<ModalBody>
<FormControl>
<Input
type="password"
type="number"
placeholder="Enter 4-digit PIN"
value={pin}
onChange={(e) => {
setPin(e.target.value)
const re = /^[0-9\b]{0,4}$/; // regex to accept only digits and max 4
if (e.target.value === '' || re.test(e.target.value)) {
setPin(e.target.value)
}
}}
/>
</FormControl>
Expand All @@ -246,7 +265,7 @@ function ExistingUser({ address, email, secretWords, userGid }: { address: strin
</ModalFooter>
</ModalContent>
</Modal>
{showError && (
{showError && encryptionKey != '' && (
<Alert status="error">
<AlertIcon />
Incorrect PIN. Please try again.
Expand Down
10 changes: 8 additions & 2 deletions src/views/Home/components/NewUserForm/CreatePin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,15 @@ function CreatePin({ setPin, pin, onCreatePinClick }: CreatePinProps) {
/>
</Flex>
<Input
type="number"
placeholder="Enter 4-digit PIN"
value={pin}
placeholder='Type your pin' onChange={handlePinChange}
borderColor={'1px solid #E2E8F0'}
onChange={(e) => {
const re = /^[0-9\b]{0,4}$/; // regex to accept only digits and max 4
if (e.target.value === '' || re.test(e.target.value)) {
setPin(e.target.value)
}
}}
/>
<Button
border={'1px solid black'}
Expand Down

0 comments on commit aa4d57e

Please sign in to comment.