From 055722b509a3c403defcaa758a712b5ad7e59ce4 Mon Sep 17 00:00:00 2001 From: saranshbalyan-1234 Date: Sun, 8 Oct 2023 23:13:47 +0530 Subject: [PATCH 1/4] auto submit magic code during first submit only --- src/components/MagicCodeInput.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/MagicCodeInput.js b/src/components/MagicCodeInput.js index 454aacc8a03b..6b53650bccf5 100644 --- a/src/components/MagicCodeInput.js +++ b/src/components/MagicCodeInput.js @@ -95,6 +95,7 @@ function MagicCodeInput(props) { const [input, setInput] = useState(''); const [focusedIndex, setFocusedIndex] = useState(0); const [editIndex, setEditIndex] = useState(0); + const [firstSubmit, setFirstSubmit] = useState(true); const blurMagicCodeInput = () => { inputRefs.current[editIndex].blur(); @@ -116,9 +117,12 @@ function MagicCodeInput(props) { const validateAndSubmit = () => { const numbers = decomposeString(props.value, props.maxLength); - if (!props.shouldSubmitOnComplete || _.filter(numbers, (n) => ValidationUtils.isNumeric(n)).length !== props.maxLength || props.network.isOffline) { + if (!firstSubmit || !props.shouldSubmitOnComplete || _.filter(numbers, (n) => ValidationUtils.isNumeric(n)).length !== props.maxLength || props.network.isOffline) { return; } + if (firstSubmit) { + setFirstSubmit(false); + } // Blurs the input and removes focus from the last input and, if it should submit // on complete, it will call the onFulfill callback. blurMagicCodeInput(); From 6bfd5d737f3dc204f623cc32dfb2f5d01acc5864 Mon Sep 17 00:00:00 2001 From: Saransh Balyan <57568571+saranshbalyan-1234@users.noreply.github.com> Date: Tue, 17 Oct 2023 15:04:38 +0530 Subject: [PATCH 2/4] Update MagicCodeInput.js --- src/components/MagicCodeInput.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/MagicCodeInput.js b/src/components/MagicCodeInput.js index 6b53650bccf5..4bef07210d75 100644 --- a/src/components/MagicCodeInput.js +++ b/src/components/MagicCodeInput.js @@ -95,7 +95,7 @@ function MagicCodeInput(props) { const [input, setInput] = useState(''); const [focusedIndex, setFocusedIndex] = useState(0); const [editIndex, setEditIndex] = useState(0); - const [firstSubmit, setFirstSubmit] = useState(true); + const [wasSubmitted, setWasSubmitted] = useState(true); const blurMagicCodeInput = () => { inputRefs.current[editIndex].blur(); From bc7de34d5c834e4cafb44d2dd8f2bd3a15f260c3 Mon Sep 17 00:00:00 2001 From: Saransh Balyan <57568571+saranshbalyan-1234@users.noreply.github.com> Date: Tue, 17 Oct 2023 15:11:23 +0530 Subject: [PATCH 3/4] Update MagicCodeInput.js --- src/components/MagicCodeInput.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/MagicCodeInput.js b/src/components/MagicCodeInput.js index b8b89e6a8484..fb682c0032a1 100644 --- a/src/components/MagicCodeInput.js +++ b/src/components/MagicCodeInput.js @@ -125,11 +125,11 @@ function MagicCodeInput(props) { const validateAndSubmit = () => { const numbers = decomposeString(props.value, props.maxLength); - if (!firstSubmit || !props.shouldSubmitOnComplete || _.filter(numbers, (n) => ValidationUtils.isNumeric(n)).length !== props.maxLength || props.network.isOffline) { + if (!wasSubmitted || !props.shouldSubmitOnComplete || _.filter(numbers, (n) => ValidationUtils.isNumeric(n)).length !== props.maxLength || props.network.isOffline) { return; } - if (firstSubmit) { - setFirstSubmit(false); + if (wasSubmitted) { + setWasSubmitted(false); } // Blurs the input and removes focus from the last input and, if it should submit // on complete, it will call the onFulfill callback. From 3651dfd702fa18262415b25725d3ce98b8e1c07d Mon Sep 17 00:00:00 2001 From: Saransh Balyan <57568571+saranshbalyan-1234@users.noreply.github.com> Date: Tue, 17 Oct 2023 15:23:42 +0530 Subject: [PATCH 4/4] Update MagicCodeInput.js --- src/components/MagicCodeInput.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/MagicCodeInput.js b/src/components/MagicCodeInput.js index fb682c0032a1..3a9cc6845194 100644 --- a/src/components/MagicCodeInput.js +++ b/src/components/MagicCodeInput.js @@ -103,7 +103,7 @@ function MagicCodeInput(props) { const [input, setInput] = useState(''); const [focusedIndex, setFocusedIndex] = useState(0); const [editIndex, setEditIndex] = useState(0); - const [wasSubmitted, setWasSubmitted] = useState(true); + const [wasSubmitted, setWasSubmitted] = useState(false); const blurMagicCodeInput = () => { inputRefs.current[editIndex].blur(); @@ -125,11 +125,11 @@ function MagicCodeInput(props) { const validateAndSubmit = () => { const numbers = decomposeString(props.value, props.maxLength); - if (!wasSubmitted || !props.shouldSubmitOnComplete || _.filter(numbers, (n) => ValidationUtils.isNumeric(n)).length !== props.maxLength || props.network.isOffline) { + if (wasSubmitted || !props.shouldSubmitOnComplete || _.filter(numbers, (n) => ValidationUtils.isNumeric(n)).length !== props.maxLength || props.network.isOffline) { return; } - if (wasSubmitted) { - setWasSubmitted(false); + if (!wasSubmitted) { + setWasSubmitted(true); } // Blurs the input and removes focus from the last input and, if it should submit // on complete, it will call the onFulfill callback.