Files
explore/lib/cookies.ts
T
0c5a297834 "Add chain" button in the header (#3084)
* redesign "add chain" button

* fix wallet detection

* [skip ci] update default value for ENV

* fix tests

* return button to the footer and add source to mixpanel event

* regcred from helmfile for review

* [skip ci] remove wallets env from values for demo stand

* use react-query to cache detection result

* add cookie to hide button in the topbar

* add prefix to svg ids to fix rabby icon

* update screenshot

* remove unnecessary comment

---------

Co-authored-by: Nick Zenchik <[email protected]>
2025-11-17 18:15:21 +01:00

49 lines
1.5 KiB
TypeScript

import Cookies from 'js-cookie';
import { isBrowser } from 'toolkit/utils/isBrowser';
export enum NAMES {
NAV_BAR_COLLAPSED = 'nav_bar_collapsed',
API_TOKEN = '_explorer_key',
API_TEMP_TOKEN = 'api_temp_token',
REWARDS_API_TOKEN = 'rewards_api_token',
REWARDS_REFERRAL_CODE = 'rewards_ref_code',
TXS_SORT = 'txs_sort',
COLOR_MODE = 'chakra-ui-color-mode',
COLOR_THEME = 'chakra-ui-color-theme',
ADDRESS_IDENTICON_TYPE = 'address_identicon_type',
ADDRESS_FORMAT = 'address_format',
TIME_FORMAT = 'time_format',
INDEXING_ALERT = 'indexing_alert',
ADBLOCK_DETECTED = 'adblock_detected',
MIXPANEL_DEBUG = '_mixpanel_debug',
ADDRESS_NFT_DISPLAY_TYPE = 'address_nft_display_type',
HIDE_ADD_TO_WALLET_BUTTON = 'hide_add_to_wallet_button',
UUID = 'uuid',
SHOW_SCAM_TOKENS = 'show_scam_tokens',
}
export function get(name?: NAMES | undefined | null, serverCookie?: string) {
if (!isBrowser()) {
return serverCookie ? getFromCookieString(serverCookie, name) : undefined;
}
if (name) {
return Cookies.get(name);
}
}
export function set(name: NAMES, value: string, attributes: Cookies.CookieAttributes = {}) {
attributes.path = '/';
return Cookies.set(name, value, attributes);
}
export function remove(name: NAMES, attributes: Cookies.CookieAttributes = {}) {
return Cookies.remove(name, attributes);
}
export function getFromCookieString(cookieString: string, name?: NAMES | undefined | null) {
return cookieString.split(`${ name }=`)[1]?.split(';')[0];
}