Skip to content

Commit 26ad584

Browse files
committed
Handled case of unsupported types
1 parent 31faf72 commit 26ad584

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

dist/index.es.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,20 @@ function __generator(thisArg, body) {
8686

8787
var loadedScripts = {};
8888
var srcUrl = 'https://checkout.flutterwave.com/v3.js';
89+
var DEFAULT_VALUE = 3;
8990
var attempt = 1; // Track the attempt count
91+
function isNumber(value) {
92+
return typeof value === 'number';
93+
}
9094
function useFWScript(_a) {
91-
var _b = _a.maxAttempt, maxAttempt = _b === void 0 ? 3 : _b, _c = _a.retryDuration, retryDuration = _c === void 0 ? 3 : _c;
95+
var _b = _a.maxAttempt, maxAttempt = _b === void 0 ? DEFAULT_VALUE : _b, _c = _a.retryDuration, retryDuration = _c === void 0 ? DEFAULT_VALUE : _c;
9296
var _d = React.useState({
9397
loaded: false,
9498
error: false,
9599
}), state = _d[0], setState = _d[1];
96-
// Prevent values lower than 1
97-
maxAttempt = maxAttempt < 1 ? 1 : maxAttempt;
98-
retryDuration = retryDuration < 1 ? 1 : retryDuration;
100+
// Validate and sanitize variables
101+
maxAttempt = isNumber(maxAttempt) ? Math.max(1, maxAttempt) : DEFAULT_VALUE; // Ensure minimum of 1 for maxAttempt, revert to the default value otherwise
102+
retryDuration = isNumber(retryDuration) ? Math.max(1, retryDuration) : DEFAULT_VALUE; // Ensure minimum of 1 for retryDuration, revert to the default value otherwise
99103
React.useEffect(function () {
100104
if (loadedScripts.hasOwnProperty('src')) {
101105
setState({

dist/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,20 @@ function __generator(thisArg, body) {
110110

111111
var loadedScripts = {};
112112
var srcUrl = 'https://checkout.flutterwave.com/v3.js';
113+
var DEFAULT_VALUE = 3;
113114
var attempt = 1; // Track the attempt count
115+
function isNumber(value) {
116+
return typeof value === 'number';
117+
}
114118
function useFWScript(_a) {
115-
var _b = _a.maxAttempt, maxAttempt = _b === void 0 ? 3 : _b, _c = _a.retryDuration, retryDuration = _c === void 0 ? 3 : _c;
119+
var _b = _a.maxAttempt, maxAttempt = _b === void 0 ? DEFAULT_VALUE : _b, _c = _a.retryDuration, retryDuration = _c === void 0 ? DEFAULT_VALUE : _c;
116120
var _d = React__namespace.useState({
117121
loaded: false,
118122
error: false,
119123
}), state = _d[0], setState = _d[1];
120-
// Prevent values lower than 1
121-
maxAttempt = maxAttempt < 1 ? 1 : maxAttempt;
122-
retryDuration = retryDuration < 1 ? 1 : retryDuration;
124+
// Validate and sanitize variables
125+
maxAttempt = isNumber(maxAttempt) ? Math.max(1, maxAttempt) : DEFAULT_VALUE; // Ensure minimum of 1 for maxAttempt, revert to the default value otherwise
126+
retryDuration = isNumber(retryDuration) ? Math.max(1, retryDuration) : DEFAULT_VALUE; // Ensure minimum of 1 for retryDuration, revert to the default value otherwise
123127
React__namespace.useEffect(function () {
124128
if (loadedScripts.hasOwnProperty('src')) {
125129
setState({

src/script.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,22 @@ interface ScriptStatusInterface {
1111
}
1212

1313
const srcUrl = 'https://checkout.flutterwave.com/v3.js';
14+
const DEFAULT_VALUE = 3;
1415
let attempt = 1;// Track the attempt count
1516

16-
export default function useFWScript({ maxAttempt = 3, retryDuration = 3 }: ScriptDownloadRetryStrategy): readonly [boolean, boolean] {
17+
function isNumber(value: any): value is number {
18+
return typeof value === 'number';
19+
}
20+
21+
export default function useFWScript({ maxAttempt = DEFAULT_VALUE, retryDuration = DEFAULT_VALUE }: ScriptDownloadRetryStrategy): readonly [boolean, boolean] {
1722
const [state, setState] = React.useState<ScriptStatusInterface>({
1823
loaded: false,
1924
error: false,
2025
});
2126

22-
// Prevent values lower than 1
23-
maxAttempt = maxAttempt < 1 ? 1 : maxAttempt;
24-
retryDuration = retryDuration < 1 ? 1 : retryDuration;
27+
// Validate and sanitize variables
28+
maxAttempt = isNumber(maxAttempt) ? Math.max(1, maxAttempt) : DEFAULT_VALUE; // Ensure minimum of 1 for maxAttempt, revert to the default value otherwise
29+
retryDuration = isNumber(retryDuration) ? Math.max(1, retryDuration) : DEFAULT_VALUE; // Ensure minimum of 1 for retryDuration, revert to the default value otherwise
2530

2631
React.useEffect((): (() => void) | void => {
2732
if (loadedScripts.hasOwnProperty('src')) {

0 commit comments

Comments
 (0)