Skip to content

Commit c32a583

Browse files
authored
Merge pull request #14423 from guardian/20250819-1508-refactoring
refactor getGateDisplayCount
2 parents f3b3add + cc6408b commit c32a583

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

dotcom-rendering/src/components/SignInGateSelector.importable.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -375,23 +375,22 @@ const decideShowDefaultGate = (): ShowGateValues => {
375375
};
376376

377377
const getGateDisplayCount = (): number => {
378-
const rawValue = storage.local.getRaw('gate_display_count');
379-
const count = parseInt(rawValue ?? '0', 10);
380-
return count;
378+
const count = parseInt(
379+
storage.local.getRaw('gate_display_count') ?? '0',
380+
10,
381+
);
382+
if (Number.isInteger(count)) {
383+
return count;
384+
}
385+
return 0;
381386
};
382387

383388
const incrementGateDisplayCount = () => {
384389
const count = getGateDisplayCount();
385-
const now = new Date();
386-
const oneYearFromNow = new Date(now.getTime() + 365 * 86400);
387390
const newCount = count + 1;
388391
// Using `storage.local.set`, instead of `storage.local.setRaw`
389392
// because `setRaw` doesn't allow for specifying the duration.
390-
storage.local.set(
391-
'gate_display_count',
392-
newCount.toString(),
393-
oneYearFromNow,
394-
);
393+
storage.local.setRaw('gate_display_count', newCount.toString());
395394
};
396395

397396
const buildAuxiaGateDisplayData = async (

0 commit comments

Comments
 (0)