-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(autofill otp): added failure case for autofill otp
- Loading branch information
Showing
1 changed file
with
14 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |