PageSourceSearch

https://site.nl/_static/cb72311f9a74ee42/scripts/features/common/wallet-top-up.js

js site.nl collected 2026-09-25 02:56:40 UTC 2,452 bytes, 77 lines download raw bytes

1import { normalizeText } from '../../value-utils.js';
2
3export const BILLING_WALLET_PATH = '/billing/wallet';
4export const PAYMENT_WALLET_PATH = '/payment/wallet';
5export const MINIMUM_WALLET_TOP_UP_AMOUNT_CENTS = 500;
6export const WALLET_TOP_UP_AMOUNT_STORAGE_KEY = 'site:billing:wallet-top-up-amount-cents';
7export const WALLET_TOP_UP_CONTACT_STORAGE_KEY = 'site:billing:wallet-top-up-contact';
8
9const normalizePathname = (value) => {
10  const pathname = normalizeText(value).split(/[?#]/, 1)[0].replace(/\/+$/, '');
11  return pathname || '/';
12};
13
14export const isWalletBillingPathname = (value) => normalizePathname(value) === BILLING_WALLET_PATH;
15
16export const isWalletPaymentPathname = (value) => normalizePathname(value) === PAYMENT_WALLET_PATH;
17
18export const normalizeWalletTopUpAmountCents = (value) => {
19  const normalizedValue = normalizeText(value);
20  if (!/^\d+$/.test(normalizedValue)) {
21    return '';
22  }
23
24  const amount = Number(normalizedValue);
25  if (!Number.isSafeInteger(amount) || amount < MINIMUM_WALLET_TOP_UP_AMOUNT_CENTS) {
26    return '';
27  }
28
29  return String(amount);
30};
31
32const readStorageValue = (storage, key) => {
33  if (!storage || typeof storage.getItem !== 'function') {
34    return '';
35  }
36
37  try {
38    return normalizeText(storage.getItem(key));
39  } catch {
40    return '';
41  }
42};
43
44const writeStorageValue = (storage, key, value) => {
45  if (!storage || typeof storage.setItem !== 'function') {
46    return false;
47  }
48
49  try {
50    storage.setItem(key, value);
51    return true;
52  } catch {
53    return false;
54  }
55};
56
57export const getWalletTopUpAmountCents = (storage = globalThis.window?.localStorage) =>
58  normalizeWalletTopUpAmountCents(readStorageValue(storage, WALLET_TOP_UP_AMOUNT_STORAGE_KEY));
59
60export const getWalletTopUpContact = (storage = globalThis.window?.localStorage) =>
61  readStorageValue(storage, WALLET_TOP_UP_CONTACT_STORAGE_KEY);
62
63export const storeWalletTopUpContact = (contact, storage = globalThis.window?.localStorage) => {
64  const normalizedContact = normalizeText(contact);
65  return normalizedContact ? writeStorageValue(storage, WALLET_TOP_UP_CONTACT_STORAGE_KEY, normalizedContact) : false;
66};
67
68export const clearWalletTopUpState = (storage = globalThis.window?.localStorage) => {
69  if (!storage || typeof storage.removeItem !== 'function') {
70    return;
71  }
72
73  try {
74    storage.removeItem(WALLET_TOP_UP_AMOUNT_STORAGE_KEY);
75    storage.removeItem(WALLET_TOP_UP_CONTACT_STORAGE_KEY);
76  } catch {}
77};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.