Skip to content

Commit

Permalink
Allow iOS "From Messages" value to auto fill SMS verification code (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
SailingSteve authored and Ivan Kordonets committed Dec 17, 2023
1 parent 8bd08d5 commit 7bf8d74
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/js/common/components/Settings/SettingsVerifySecretCode.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ class SettingsVerifySecretCode extends Component {
componentWillUnmount () {
// console.log('SettingsVerifySecretCode componentWillUnmount');
this.voterStoreListener.remove();
if (this.closeVerifyModalLocalTimer) {
clearTimeout(this.closeVerifyModalLocalTimer);
}
if (this.clearSecretCodeVerificationStatusTimer) {
clearTimeout(this.clearSecretCodeVerificationStatusTimer);
}
Expand Down Expand Up @@ -232,6 +229,12 @@ class SettingsVerifySecretCode extends Component {
const regex2 = /^[0-9]{7}$/;
const digit = e.target.value;

// Handle iOS verification code "From Messages" auto fill
if (isCordova() && digit.length === 6) {
this.onPaste(e);
return;
}

if (regex2.test(digit)) { // change is fired on paste, resulting in multiple digits
return;
}
Expand Down Expand Up @@ -408,12 +411,17 @@ class SettingsVerifySecretCode extends Component {
onPaste (e) {
// console.log(e.clipboardData.getData('Text'));

const pastedInputArray = e.clipboardData.getData('Text').split('');
// console.log(pastedInputArray);
let charInputArray = '';
if (e.clipboardData) { // Paste
charInputArray = e.clipboardData.getData('Text').split('');
} else if (e.target.value) { // "From Messages" in iOS
charInputArray = e.target.value.split('');
}
// console.log(charInputArray);

const regex = /^[0-9]$/;

const allDigits = pastedInputArray.filter((digit) => regex.test(digit));
const allDigits = charInputArray.filter((digit) => regex.test(digit));

if (allDigits[5]) {
this.setState({
Expand Down Expand Up @@ -533,7 +541,7 @@ class SettingsVerifySecretCode extends Component {
onBlur={this.handleBlur}
onFocus={this.handleFocus}
onChange={this.onDigit1Change}
onPaste={this.onPaste}
onPaste={() => this.onPaste}
type="tel"
value={this.state.digit1}
autoFocus
Expand All @@ -548,7 +556,7 @@ class SettingsVerifySecretCode extends Component {
onBlur={this.handleBlur}
onFocus={this.handleFocus}
onChange={this.onDigit2Change}
onPaste={this.onPaste}
onPaste={() => this.onPaste}
onKeyDown={this.handleKeyDown2}
type="tel"
value={this.state.digit2}
Expand All @@ -563,7 +571,7 @@ class SettingsVerifySecretCode extends Component {
onBlur={this.handleBlur}
onFocus={this.handleFocus}
onChange={this.onDigit3Change}
onPaste={this.onPaste}
onPaste={() => this.onPaste}
onKeyDown={this.handleKeyDown3}
type="tel"
value={this.state.digit3}
Expand All @@ -578,7 +586,7 @@ class SettingsVerifySecretCode extends Component {
onBlur={this.handleBlur}
onFocus={this.handleFocus}
onChange={this.onDigit4Change}
onPaste={this.onPaste}
onPaste={() => this.onPaste}
onKeyDown={this.handleKeyDown4}
type="tel"
value={this.state.digit4}
Expand All @@ -593,7 +601,7 @@ class SettingsVerifySecretCode extends Component {
onBlur={this.handleBlur}
onFocus={this.handleFocus}
onChange={this.onDigit5Change}
onPaste={this.onPaste}
onPaste={() => this.onPaste}
onKeyDown={this.handleKeyDown5}
type="tel"
value={this.state.digit5}
Expand All @@ -608,7 +616,7 @@ class SettingsVerifySecretCode extends Component {
onChange={this.onDigit6Change}
onFocus={this.handleFocus}
onBlur={this.handleDigit6Blur}
onPaste={this.onPaste}
onPaste={() => this.onPaste}
onKeyDown={this.handleKeyDown6}
type="tel"
value={this.state.digit6}
Expand Down

0 comments on commit 7bf8d74

Please sign in to comment.