Skip to content

Commit

Permalink
Niloofar/Deprecation of Old Utils (deriv-com#14350)
Browse files Browse the repository at this point in the history
* refactor: deprecated old utils

* build: trigger build
  • Loading branch information
niloofar-deriv authored Mar 29, 2024
1 parent 7963348 commit 43bae74
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/account-v2/src/modules/AddressFields/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ const regexChecks = {
nonJerseyPostcode: /^(?!\s*je.*)[a-z0-9\s-]*/i,
};

/**
* @deprecated Please use 'ValidationConstants.messagesHints.addressPermittedSpecialCharacters' from '@deriv-com/utils' instead of this.
*/
export const addressPermittedSpecialCharactersMessage = ". , ' : ; ( ) ° @ # / -";

/**
* @deprecated Please use 'ValidationConstants.patterns' from '@deriv-com/utils' instead of this.
*/
export const addressDetailValidations = (countryCode: string, isSvg: boolean) => ({
addressCity: Yup.string()
.required('City is required')
Expand Down
3 changes: 3 additions & 0 deletions packages/api-v2/src/utils/crypto.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* @returns {Promise<string>} A Promise that resolves to the SHA-256 hash of the input object as a hexadecimal string.
* @throws {Error} Throws an error if the hashing operation fails or if the input is not a valid object.
*/
/**
* @deprecated Please use 'ObjectUtils.hashObject' from '@deriv-com/utils' instead of this.
*/
export const hashObject = async <T extends object>(object: T) => {
const messageBuffer = new TextEncoder().encode(JSON.stringify(object));
const hashBuffer = await crypto.subtle.digest('SHA-256', messageBuffer);
Expand Down
3 changes: 3 additions & 0 deletions packages/api/src/APIProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ const queryClient = getSharedQueryClientContext();
* @param {string | null | undefined} loginid - The login ID (can be a string, null, or undefined).
* @returns {string} Returns the WS environment: 'custom', 'real', or 'demo'.
*/
/**
* @deprecated Please use 'WebSocketUtils.getEnvironmentFromLoginid' from '@deriv-com/utils' instead of this.
*/
const getEnvironment = (loginid: string | null | undefined) => {
const customServerURL = window.localStorage.getItem('config.server_url');
if (customServerURL) return 'custom';
Expand Down
3 changes: 3 additions & 0 deletions packages/api/src/utils/crypto.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* @returns {Promise<string>} A Promise that resolves to the SHA-256 hash of the input object as a hexadecimal string.
* @throws {Error} Throws an error if the hashing operation fails or if the input is not a valid object.
*/
/**
* @deprecated Please use 'ObjectUtils.hashObject' from '@deriv-com/utils' instead of this.
*/
export const hashObject = async <T extends object>(object: T) => {
const messageBuffer = new TextEncoder().encode(JSON.stringify(object));
const hashBuffer = await crypto.subtle.digest('SHA-256', messageBuffer);
Expand Down
4 changes: 3 additions & 1 deletion packages/p2p-v2/src/utils/currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ export const CURRENCY_TYPE = {
* console.log(formattedAmount); // "$1,234.57"
* ```
*/

/**
* @deprecated Please use 'FormatUtils.formatMoney' from '@deriv-com/utils' instead of this.
*/
export const formatMoney = (
currencyValue: string,
amount: number | string,
Expand Down
3 changes: 3 additions & 0 deletions packages/p2p/src/stores/general-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ export default class GeneralStore extends BaseStore {
});
}

/**
* @deprecated Please use 'LocalStorageUtils.getValue' from '@deriv-com/utils' instead of this.
*/
getLocalStorageSettings = () => {
return JSON.parse(localStorage.getItem('p2p_settings') || '{}');
};
Expand Down
3 changes: 3 additions & 0 deletions packages/shared/src/utils/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export const isTestLink = () => {

export const isLocal = () => /localhost(:\d+)?$/i.test(window.location.hostname);

/**
* @deprecated Please use 'WebSocketUtils.getAppId' from '@deriv-com/utils' instead of this.
*/
export const getAppId = () => {
let app_id = null;
const user_app_id = ''; // you can insert Application ID of your registered application here
Expand Down
3 changes: 3 additions & 0 deletions packages/shared/src/utils/currency/currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ export const getFormattedText = (number: number, currency: string) => {
return `${addComma(number, getDecimalPlaces(currency), isCryptocurrency(currency))} ${currency}`;
};

/**
* @deprecated Please use 'FormatUtils.formatMoney' from '@deriv-com/utils' instead of this.
*/
export const formatMoney = (
currency_value: string,
amount: number | string,
Expand Down
4 changes: 3 additions & 1 deletion packages/shared/src/utils/url/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ export const deriv_urls = Object.freeze({
BINARYBOT_PRODUCTION: `https://bot.${domain_url}`,
BINARYBOT_STAGING: `https://staging-bot.${domain_url}`,
});

/**
* @deprecated Please use 'URLConstants.whatsApp' from '@deriv-com/utils' instead of this.
*/
export const whatsapp_url = 'https://wa.me/35699578341';
6 changes: 6 additions & 0 deletions packages/shared/src/utils/url/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { deriv_urls } from './constants';

/**
* @deprecated Please use 'URLUtils.getQueryParameter' from '@deriv-com/utils' instead of this.
*/
export const getlangFromUrl = () => {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const lang = urlParams.get('lang');
return lang;
};

/**
* @deprecated Please use 'URLUtils.getQueryParameter' from '@deriv-com/utils' instead of this.
*/
export const getActionFromUrl = () => {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
Expand Down
6 changes: 6 additions & 0 deletions packages/shared/src/utils/url/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export const params = (href?: string | URL) => {
return arr_params;
};

/**
* @deprecated Please use 'URLUtils.normalizePath' from '@deriv-com/utils' instead of this.
*/
export const normalizePath = (path: string) => (path ? path.replace(/(^\/|\/$|[^a-zA-Z0-9-_./()#])/g, '') : '');

export const urlFor = (
Expand Down Expand Up @@ -133,6 +136,9 @@ export const setUrlLanguage = (lang: string) => {

// TODO: cleanup options param usage
// eslint-disable-next-line no-unused-vars
/**
* @deprecated Please use 'URLUtils.getDerivStaticURL' from '@deriv-com/utils' instead of this.
*/
export const getStaticUrl = (path = '', _options = {}, is_document = false, is_eu_url = false) => {
const host = is_eu_url ? deriv_urls.DERIV_COM_PRODUCTION_EU : deriv_urls.DERIV_COM_PRODUCTION;
let lang = default_language?.toLowerCase();
Expand Down
9 changes: 9 additions & 0 deletions packages/tradershub/src/helpers/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,24 @@ export const derivUrls = Object.freeze({
SMARTTRADER_STAGING: `https://staging-smarttrader.${domainUrl}`,
});

/**
* @deprecated Please use 'URLUtils.normalizePath' from '@deriv-com/utils' instead of this.
*/
export const normalizePath = (path: string) => (path ? path.replace(/(^\/|\/$|[^a-zA-Z0-9-_./()#])/g, '') : '');

/**
* @deprecated Please use 'URLUtils.getQueryParameter' from '@deriv-com/utils' instead of this.
*/
export const getlangFromUrl = () => {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const lang = urlParams.get('lang');
return lang;
};

/**
* @deprecated Please use 'URLUtils.getQueryParameter' from '@deriv-com/utils' instead of this.
*/
export const getActionFromUrl = () => {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
Expand Down
3 changes: 3 additions & 0 deletions packages/tradershub/src/utils/getAccountsFromLocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ type TLocalStorageAccountsList = {
/**
* Gets the current user `accounts` list from the `localStorage`.
*/
/**
* @deprecated Please use 'LocalStorageUtils.getValue' from '@deriv-com/utils' instead of this.
*/
export const getAccountsFromLocalStorage = () => {
const data = localStorage.getItem('client.accounts');

Expand Down
3 changes: 3 additions & 0 deletions packages/utils/src/getActiveLoginIDFromLocalStorage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/**
* Gets the active `loginid` for the current user from the `localStorage`.
*/
/**
* @deprecated Please use 'WebSocketUtils.getActiveLoginid' from '@deriv-com/utils' instead of this.
*/
const getActiveLoginIDFromLocalStorage = (loginid_key = 'active_loginid') => {
const active_custom_loginid = localStorage.getItem(loginid_key);
return active_custom_loginid ?? undefined;
Expand Down
3 changes: 3 additions & 0 deletions packages/utils/src/getLocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const checkIsStringifiedObject = (s: string) => {
* @param {string} key - The localStorage key.
* @returns {any} - The value stored in localStorage for the given key, or null if the key does not exist or has no value.
*/
/**
* @deprecated Please use 'LocalStorageUtils.getValue' from '@deriv-com/utils' instead of this.
*/
export const getLocalStorage = (key: string) => {
const data = localStorage.getItem(key);
return data ? checkIsStringifiedObject(data) : null;
Expand Down
15 changes: 15 additions & 0 deletions packages/wallets/src/helpers/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,31 @@ export const derivUrls = Object.freeze({
SMARTTRADER_STAGING: `https://staging-smarttrader.${domainUrl}`,
});

/**
* @deprecated Please use 'URLConstants.whatsApp' from '@deriv-com/utils' instead of this.
*/
export const whatsappUrl = 'https://wa.me/35699578341';

let defaultLanguage: string;

/**
* @deprecated Please use 'URLUtils.normalizePath' from '@deriv-com/utils' instead of this.
*/
export const normalizePath = (path: string) => (path ? path.replace(/(^\/|\/$|[^a-zA-Z0-9-_./()#])/g, '') : '');

/**
* @deprecated Please use 'URLUtils.getQueryParameter' from '@deriv-com/utils' instead of this.
*/
export const getlangFromUrl = () => {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const lang = urlParams.get('lang');
return lang;
};

/**
* @deprecated Please use 'URLUtils.getQueryParameter' from '@deriv-com/utils' instead of this.
*/
export const getActionFromUrl = () => {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
Expand Down Expand Up @@ -87,6 +99,9 @@ export const isStaging = (domain = window.location.hostname) => {
return isStagingDerivApp;
};

/**
* @deprecated Please use 'URLUtils.getDerivStaticURL' from '@deriv-com/utils' instead of this.
*/
export const getStaticUrl = (path = '', isDocument = false, isEuUrl = false) => {
const host = isEuUrl ? derivUrls.DERIV_COM_PRODUCTION_EU : derivUrls.DERIV_COM_PRODUCTION;
let lang = defaultLanguage?.toLowerCase();
Expand Down

0 comments on commit 43bae74

Please sign in to comment.