Skip to content

Commit d7b06f4

Browse files
committed
Allow PIN length to be customizable
1 parent d48ed74 commit d7b06f4

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

demo/src/Screens/Setup.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const Setup = ({ navigation, route }) => {
4848
const [createPin, setCreatePin] = useState('');
4949
const [confirmPin, setConfirmPin] = useState('');
5050
const [recoverPin, setRecoverPin] = useState('');
51+
const PIN_LENGTH = 6;
5152

5253
const configuration = {
5354
realms: [
@@ -131,8 +132,8 @@ const Setup = ({ navigation, route }) => {
131132
if (mode !== Mode.Create) {
132133
return;
133134
}
134-
if (createPin.length === 6) {
135-
// Automatically move to the confirmation step when 6 digits are entered
135+
if (createPin.length === PIN_LENGTH) {
136+
// Automatically move to the confirmation step when PIN_LENGTH digits are entered
136137
setMode(Mode.Confirm);
137138
}
138139
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -142,7 +143,7 @@ const Setup = ({ navigation, route }) => {
142143
if (mode !== Mode.Confirm) {
143144
return;
144145
}
145-
if (confirmPin.length === 6) {
146+
if (confirmPin.length === PIN_LENGTH) {
146147
if (createPin === confirmPin) {
147148
// Store the PIN and navigate to the next screen
148149
storeSecretIdAndSecretAndProceed();
@@ -158,7 +159,7 @@ const Setup = ({ navigation, route }) => {
158159
if (mode !== Mode.Recover) {
159160
return;
160161
}
161-
if (recoverPin.length === 6) {
162+
if (recoverPin.length === PIN_LENGTH) {
162163
recoverSecretAndProceed();
163164
}
164165
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -281,17 +282,17 @@ const Setup = ({ navigation, route }) => {
281282
Toast.hide();
282283
switch (mode) {
283284
case Mode.Create:
284-
if (createPin.length < 6) {
285+
if (createPin.length < PIN_LENGTH) {
285286
setCreatePin(createPin + number);
286287
}
287288
break;
288289
case Mode.Confirm:
289-
if (confirmPin.length < 6) {
290+
if (confirmPin.length < PIN_LENGTH) {
290291
setConfirmPin(confirmPin + number);
291292
}
292293
break;
293294
case Mode.Recover:
294-
if (recoverPin.length < 6) {
295+
if (recoverPin.length < PIN_LENGTH) {
295296
setRecoverPin(recoverPin + number);
296297
}
297298
break;
@@ -374,7 +375,7 @@ const Setup = ({ navigation, route }) => {
374375
<View style={styles.container}>
375376
<Text style={styles.stepText}>{modeTitleMapping[mode]}</Text>
376377
<View style={styles.pinContainer}>
377-
{Array(6)
378+
{Array(PIN_LENGTH)
378379
.fill(0)
379380
.map((_, index) => (
380381
<View key={index} style={styles.pinCircle}>

0 commit comments

Comments
 (0)