Skip to content

Commit

Permalink
fix(autofill otp): added failure case for autofill otp
Browse files Browse the repository at this point in the history
  • Loading branch information
opensrc0 committed Mar 24, 2024
1 parent b9a68a2 commit 8548e37
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions __app/component/AutoFillOtp/AutoFillOtp.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
import { handleError, handleSuccess } from '../services/handlerService';

const abortAutoFill = (abort, time) => {
setTimeout(() => {
// abort after two minutes
abort.abort();
}, time * 60 * 1000);
};

const AutoFillOtp = (successCb, failureCb) => {
function AutoFillOtp({
successCb,
successMsg,
failureCb,
failureMsg,
}) {
if ('OTPCredential' in window) {
const abort = new AbortController();
abortAutoFill(abort, 1);
abortAutoFill(abort, 3);
navigator.credentials.get({
otp: { transport: ['sms'] },
signal: abort.signal,
}).then((otp) => {
const { code } = otp;
successCb(code);
}).catch((error) => {
failureCb(error);
});
handleSuccess({ disbaleToast: false, msgType: 'SUCCESSFUL', msg: successMsg, successCb, data: code });
}).catch((error) => handleError({ disbaleToast: false, msgType: 'ERROR', msg: error, failureCb }));
} else {
return handleError({ disbaleToast: false, msgType: 'UN_SUPPORTED_FEATURE', msg: failureMsg.unSupported, failureCb });
}
};
}

export default AutoFillOtp;

0 comments on commit 8548e37

Please sign in to comment.