diff --git a/src/javascript/app/common/contract_manager.js b/src/javascript/app/common/contract_manager.js deleted file mode 100644 index 70ac041ea93..00000000000 --- a/src/javascript/app/common/contract_manager.js +++ /dev/null @@ -1,59 +0,0 @@ -/* eslint-disable class-methods-use-this */ -import { triggerContractChange } from '../hooks/events'; - -class ContractManager { - constructor() { - if (!window.contract) { - window.contract = {}; - } - } - - set(data) { - if (typeof data === 'object') { - const oldValues = {}; - const newValues = {}; - Object.entries(data).forEach(([key, value]) => { - if (window.contract[key] !== value) { - oldValues[key] = window.contract[key]; - newValues[key] = value; - } - window.contract[key] = value; - }); - if (Object.keys(newValues).length > 0) { - // Trigger a custom event with old and new values - window.dispatchEvent(new CustomEvent('contractChange', { - detail: { oldValues, newValues }, - })); - - triggerContractChange(); - } - } - } - - get(key) { - return window.contract[key]; - } - - getAll() { - return { ...window.contract }; - } - - // Method to clear all data from window.contract - clear() { - const oldValues = { ...window.contract }; - window.contract = {}; - window.dispatchEvent(new CustomEvent('contractChange', { - detail: { oldValues, newValues: {} }, - })); - triggerContractChange(); - } - - // Method to check if a key exists in window.contract - has(key) { - return Object.prototype.hasOwnProperty.call(window.contract, key); - } -} - -const contractManager = new ContractManager(); - -export default contractManager; diff --git a/src/javascript/app/common/currency.js b/src/javascript/app/common/currency.js index 24149f5851b..035404c19ee 100644 --- a/src/javascript/app/common/currency.js +++ b/src/javascript/app/common/currency.js @@ -1,4 +1,4 @@ -const tradeManager = require('./trade_manager').default; +const dataManager = require('./data_manager').default; const CurrencyBase = require('../../_common/base/currency_base'); const localize = require('../../_common/localize').localize; @@ -23,7 +23,7 @@ const getCurrencyList = (currencies) => { currency_list.fiat.push({ value: currency, text: currency_name }); } }); - tradeManager.set({ + dataManager.setTrade({ currency_list, }); diff --git a/src/javascript/app/common/data_manager.js b/src/javascript/app/common/data_manager.js new file mode 100644 index 00000000000..5729f1ec916 --- /dev/null +++ b/src/javascript/app/common/data_manager.js @@ -0,0 +1,165 @@ +import { + triggerBarrierChange, + triggerContractChange, + triggerPurchaseChange, + triggerTimeChange, + triggerTradeChange, +} from '../hooks/events'; + +const changeTypeMap = { + trade : 'tradeChange', + purchase: 'purchaseChange', + contract: 'contractChange', +}; + +class DataManager { + constructor() { + this.data = { + trade : {}, + purchase: {}, + contract: {}, + }; + } + + set(data, data_type, optional_trigger) { + if (typeof data === 'object') { + const oldValues = {}; + const newValues = {}; + Object.entries(data).forEach(([key, value]) => { + if (this.data[data_type][key] !== value) { + oldValues[key] = this.data[data_type][key]; + newValues[key] = value; + } + this.data[data_type][key] = value; + }); + if (Object.keys(newValues).length > 0) { + // Trigger a custom event with old and new values + window.dispatchEvent(new CustomEvent(changeTypeMap[data_type], { + detail: { oldValues, newValues }, + })); + + switch (data_type) { + case 'trade': + if (optional_trigger === 'barrier') { + triggerBarrierChange(); + } else if (optional_trigger === 'time') { + triggerTimeChange(); + } else { + triggerTradeChange(); + } + break; + + case 'purchase': + triggerPurchaseChange(); + break; + + case 'contract': + triggerContractChange(); + break; + + default: + break; + } + + } + } + } + + get(key, data_type) { + return this.data[data_type][key]; + } + + getAll(data_type) { + return { ...this.data[data_type] }; + } + + clear(data_type) { + const oldValues = { ...this.data[data_type] }; + this.data[data_type] = {}; + + window.dispatchEvent(new CustomEvent(changeTypeMap[data_type], { + detail: { oldValues, newValues: {} }, + })); + if (data_type === 'trade') { + triggerTradeChange(); + } + if (data_type === 'purchase') { + triggerPurchaseChange(); + } + if (data_type === 'contract') { + triggerContractChange(); + } + } + + has(key, data_type) { + return Object.prototype.hasOwnProperty.call(this.data[data_type], key); + } + + // methods for trade + setTrade(data, optional_trigger) { + this.set(data, 'trade', optional_trigger); + } + + getTrade(key) { + return this.get(key, 'trade'); + } + + getAllTrades() { + return this.getAll('trade'); + } + + clearTrades() { + this.clear('trade'); + } + + hasTrade(key) { + return this.has(key, 'trade'); + } + + // methods for purchase + setPurchase(data) { + this.set(data, 'purchase'); + } + + getPurchase(key) { + return this.get(key, 'purchase'); + } + + getAllPurchases() { + return this.getAll('purchase'); + } + + clearPurchases() { + this.clear('purchase'); + } + + hasPurchase(key) { + return this.has(key, 'purchase'); + } + + // methods for contract + setContract(data) { + this.set(data, 'contract'); + } + + getContract(key) { + return this.get(key, 'contract'); + } + + getAllContracts() { + return this.getAll('contract'); + } + + clearContracts() { + this.clear('contract'); + } + + hasContract(key) { + return this.has(key, 'contract'); + } + +} + +const dataManager = new DataManager(); + +export default dataManager; diff --git a/src/javascript/app/common/helpers.js b/src/javascript/app/common/helpers.js index a3119018f7f..ae59297e28c 100644 --- a/src/javascript/app/common/helpers.js +++ b/src/javascript/app/common/helpers.js @@ -2,7 +2,7 @@ import React from 'react'; import { Tooltip } from '@deriv-com/quill-ui'; import parse from 'html-react-parser'; import moment from 'moment'; -import tradeManager from './trade_manager'; +import dataManager from './data_manager'; import { getLocalTime } from '../base/clock'; import common_independent from '../pages/trade/common_independent'; @@ -24,32 +24,6 @@ const TimeTooltipWrapper = (element, time) => { ); }; -const handleNumeric = (event, regex_string) => { - let input_value = event.target.value; - const regex = new RegExp(regex_string) || /[^0-9.]/g; - - input_value = input_value - .split('') - .filter((char, index, array) => { - const tempValue = array.slice(0, index + 1).join(''); - return !regex.test(tempValue); - }) - .join(''); - - if (input_value.match(/[+-]/g) && input_value.match(/[+-]/g).length > 1) { - input_value = input_value.replace(/[+-]/g, ''); - } - - const decimal_count = (input_value.match(/\./g) || []).length; - if (decimal_count > 1) { - input_value = input_value.replace(/\./g, (match, offset) => - offset === input_value.indexOf('.') ? match : '' - ); - } - - return input_value; -}; - const setMinMaxTime = (selector, check_end_time) => { const $date_start = $('#date_start'); const $time_start = $('#time_start'); @@ -125,17 +99,16 @@ const setMinMaxTimeObj = (options) => { } } - tradeManager.set({ + dataManager.setTrade({ starttime_obj, expirytime_obj, - },'time'); + }, 'time'); }; export { parseData, triggerClick, TimeTooltipWrapper, - handleNumeric, setMinMaxTime, }; diff --git a/src/javascript/app/common/purchase_manager.js b/src/javascript/app/common/purchase_manager.js deleted file mode 100644 index 3b426f35c2c..00000000000 --- a/src/javascript/app/common/purchase_manager.js +++ /dev/null @@ -1,59 +0,0 @@ -/* eslint-disable class-methods-use-this */ -import { triggerPurchaseChange } from '../hooks/events'; - -class PurchaseManager { - constructor() { - if (!window.purchase) { - window.purchase = {}; - } - } - - set(data) { - if (typeof data === 'object') { - const oldValues = {}; - const newValues = {}; - Object.entries(data).forEach(([key, value]) => { - if (window.purchase[key] !== value) { - oldValues[key] = window.purchase[key]; - newValues[key] = value; - } - window.purchase[key] = value; - }); - if (Object.keys(newValues).length > 0) { - // Trigger a custom event with old and new values - window.dispatchEvent(new CustomEvent('purchaseChange', { - detail: { oldValues, newValues }, - })); - - triggerPurchaseChange(); - } - } - } - - get(key) { - return window.purchase[key]; - } - - getAll() { - return { ...window.purchase }; - } - - // Method to clear all data from window.purchase - clear() { - const oldValues = { ...window.purchase }; - window.purchase = {}; - window.dispatchEvent(new CustomEvent('purchaseChange', { - detail: { oldValues, newValues: {} }, - })); - triggerPurchaseChange(); - } - - // Method to check if a key exists in window.purchase - has(key) { - return Object.prototype.hasOwnProperty.call(window.purchase, key); - } -} - -const purchaseManager = new PurchaseManager(); - -export default purchaseManager; diff --git a/src/javascript/app/common/trade_manager.js b/src/javascript/app/common/trade_manager.js deleted file mode 100644 index b3e184b998b..00000000000 --- a/src/javascript/app/common/trade_manager.js +++ /dev/null @@ -1,64 +0,0 @@ -/* eslint-disable class-methods-use-this */ -import { triggerBarrierChange, triggerTimeChange, triggerTradeChange } from '../hooks/events'; - -class TradeManager { - constructor() { - if (!window.trade) { - window.trade = {}; - } - } - - set(data, optional) { - if (typeof data === 'object') { - const oldValues = {}; - const newValues = {}; - Object.entries(data).forEach(([key, value]) => { - if (window.trade[key] !== value) { - oldValues[key] = window.trade[key]; - newValues[key] = value; - } - window.trade[key] = value; - }); - if (Object.keys(newValues).length > 0) { - // Trigger a custom event with old and new values - window.dispatchEvent(new CustomEvent('tradeChange', { - detail: { oldValues, newValues }, - })); - if (optional === 'barrier') { - triggerBarrierChange(); - } else if (optional === 'time') { - triggerTimeChange(); - } else { - triggerTradeChange(); - } - } - } - } - - get(key) { - return window.trade[key]; - } - - getAll() { - return { ...window.trade }; - } - - // Method to clear all data from window.trade - clear() { - const oldValues = { ...window.trade }; - window.trade = {}; - window.dispatchEvent(new CustomEvent('tradeChange', { - detail: { oldValues, newValues: {} }, - })); - triggerTradeChange(); - } - - // Method to check if a key exists in window.trade - has(key) { - return Object.prototype.hasOwnProperty.call(window.trade, key); - } -} - -const tradeManager = new TradeManager(); - -export default tradeManager; diff --git a/src/javascript/app/components/loading-spinner.js b/src/javascript/app/components/loading-spinner.js index 8a3fd2adf5f..368790f2109 100644 --- a/src/javascript/app/components/loading-spinner.js +++ b/src/javascript/app/components/loading-spinner.js @@ -1,4 +1,4 @@ -import contractManager from '../common/contract_manager'; +import dataManager from '../common/data_manager'; const assertContainerExists = (content_id) => { if (!content_id) { @@ -28,7 +28,7 @@ export const show = (content_id) => { * @param content_id */ export const hide = (content_id) => { - contractManager.set({ + dataManager.setContract({ hidePageLoader: true, }); diff --git a/src/javascript/app/pages/bottom/explanation.jsx b/src/javascript/app/pages/bottom/explanation.jsx index 4a6db9c2589..d069d64a9ad 100644 --- a/src/javascript/app/pages/bottom/explanation.jsx +++ b/src/javascript/app/pages/bottom/explanation.jsx @@ -5,7 +5,7 @@ import { contractExplanationData } from './data/explanation.js'; import Language from '../../../_common/language'; import Url from '../../../_common/url'; import { localize } from '../../../_common/localize.js'; -import contractManager from '../../common/contract_manager.js'; +import dataManager from '../../common/data_manager.js'; import { useContractChange } from '../../hooks/events.js'; export const Explanation = ({ explanationOnly = false }) => { @@ -15,7 +15,7 @@ export const Explanation = ({ explanationOnly = false }) => { const hasContractChanges = useContractChange(); useEffect(() => { - const actualFormName = contractManager.get('explanationFormName'); + const actualFormName = dataManager.getContract('explanationFormName'); setFormName(null); setTimeout(() => { diff --git a/src/javascript/app/pages/bottom/tabs.jsx b/src/javascript/app/pages/bottom/tabs.jsx index 16aa7e812de..58319fb3fca 100644 --- a/src/javascript/app/pages/bottom/tabs.jsx +++ b/src/javascript/app/pages/bottom/tabs.jsx @@ -1,4 +1,3 @@ -/* eslint-disable no-console */ import React, { useEffect, useState } from 'react'; import ReactDOM from 'react-dom'; import { SegmentedControlSingleChoice, Skeleton } from '@deriv-com/quill-ui'; @@ -6,9 +5,8 @@ import { Explanation } from './explanation.jsx'; import { getElementById } from '../../../_common/common_functions'; import WebtraderChart from '../trade/charts/webtrader_chart'; import { useMarketChange, useContractChange } from '../../hooks/events'; - import { localize } from '../../../_common/localize'; -import contractManager from '../../common/contract_manager.js'; +import dataManager from '../../common/data_manager.js'; import LastDigit from '../trade/last_digit.jsx'; const Graph = ({ renderGraph }) => { @@ -71,7 +69,7 @@ const BottomTabs = () => { : tabs; useEffect(() => { - setFormName(contractManager.get('explanationFormName')); + setFormName(dataManager.getContract('explanationFormName')); }, [hasContractChange, hasMarketChange]); useEffect(() => { diff --git a/src/javascript/app/pages/form/barrier-fields.jsx b/src/javascript/app/pages/form/barrier-fields.jsx index 864f95cf101..aa5d10b7f83 100644 --- a/src/javascript/app/pages/form/barrier-fields.jsx +++ b/src/javascript/app/pages/form/barrier-fields.jsx @@ -6,7 +6,7 @@ import { // eslint-disable-next-line import/no-unresolved import { StandaloneCircleInfoRegularIcon } from '@deriv/quill-icons/Standalone'; import { useBarrierChange } from '../../hooks/events.js'; -import tradeManager from '../../common/trade_manager.js'; +import dataManager from '../../common/data_manager.js'; import { localize } from '../../../_common/localize.js'; import Defaults, { PARAM_NAMES } from '../trade/defaults.js'; @@ -21,7 +21,7 @@ const BarrierFields = ({ formName, handleAmountChange }) => { useEffect(() => { setBarrierData((oldData) => ({ ...oldData, - ...tradeManager.getAll(), + ...dataManager.getAllTrades(), })); }, [hasBarrierChange]); diff --git a/src/javascript/app/pages/form/form-component.jsx b/src/javascript/app/pages/form/form-component.jsx index 7229b5a51ed..fa0d8dcdf7a 100644 --- a/src/javascript/app/pages/form/form-component.jsx +++ b/src/javascript/app/pages/form/form-component.jsx @@ -21,7 +21,7 @@ import { } from '../../hooks/events.js'; import common_functions from '../../../_common/common_functions.js'; import { localize } from '../../../_common/localize.js'; -import tradeManager from '../../common/trade_manager.js'; +import dataManager from '../../common/data_manager.js'; export const FormComponent = () => { const [tradeData, setTradeData] = useState({}); @@ -32,7 +32,7 @@ export const FormComponent = () => { useEffect(() => { setTradeData((oldData) => ({ ...oldData, - ...tradeManager.getAll(), + ...dataManager.getAllTrades(), })); }, [hasTradeChange, hasSessionChange]); diff --git a/src/javascript/app/pages/form/time-selection.jsx b/src/javascript/app/pages/form/time-selection.jsx index a57efd45d77..c4147e20b47 100644 --- a/src/javascript/app/pages/form/time-selection.jsx +++ b/src/javascript/app/pages/form/time-selection.jsx @@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react'; import { CustomDropdown, DropdownItem, useDropdown } from '@deriv-com/quill-ui'; import moment from 'moment/moment'; import { useTimeChange } from '../../hooks/events'; -import tradeManager from '../../common/trade_manager.js'; +import dataManager from '../../common/data_manager.js'; import { setMinMaxTime } from '../../common/helpers.js'; const TimeContent = ({ time, onUpdate, elementId }) => { @@ -12,8 +12,8 @@ const TimeContent = ({ time, onUpdate, elementId }) => { const { close } = useDropdown(); useEffect(() => { - setStartTimeData(tradeManager.get('starttime_obj')); - setExpiryTimeData(tradeManager.get('expirytime_obj')); + setStartTimeData(dataManager.getTrade('starttime_obj')); + setExpiryTimeData(dataManager.getTrade('expirytime_obj')); }, [hasTimeChange]); const formatTime = (timeObj) => { diff --git a/src/javascript/app/pages/loader.jsx b/src/javascript/app/pages/loader.jsx index 6e0c7c02b31..d68996fcb80 100644 --- a/src/javascript/app/pages/loader.jsx +++ b/src/javascript/app/pages/loader.jsx @@ -1,12 +1,11 @@ /* eslint-disable import/no-unresolved */ -/* eslint-disable no-console */ import React, { useEffect, useState } from 'react'; import ReactDOM from 'react-dom'; import { Skeleton } from '@deriv-com/quill-ui'; import Portal from './portal'; import { getElementById } from '../../_common/common_functions'; import { useContractChange } from '../hooks/events'; -import contractManager from '../common/contract_manager'; +import dataManager from '../common/data_manager'; const PurchaseSectionLoader = ({ hideBottom }) => ( <> @@ -46,7 +45,7 @@ const Loader = () => { const page = getPageType().name; useEffect(() => { - const hidePageLoader = contractManager.get('hidePageLoader'); + const hidePageLoader = dataManager.getContract('hidePageLoader'); if (hidePageLoader){ setLoading(false); diff --git a/src/javascript/app/pages/trade/analysis.js b/src/javascript/app/pages/trade/analysis.js index 25f28886fc0..58180200df0 100644 --- a/src/javascript/app/pages/trade/analysis.js +++ b/src/javascript/app/pages/trade/analysis.js @@ -6,7 +6,7 @@ const getElementById = require('../../../_common/common_functions').getElementB const getLanguage = require('../../../_common/language').get; const TabSelector = require('../../../_common/tab_selector'); const Url = require('../../../_common/url'); -const contractManager = require('../../common/contract_manager').default; +const dataManager = require('../../common/data_manager').default; /* * This file contains the code related to loading of trading page bottom analysis @@ -36,7 +36,7 @@ const TradingAnalysis = (() => { const tab_form_name = tab_obj[form_name] || form_name; form_name = map_obj[form_name] || form_name; - contractManager.set({ + dataManager.setContract({ actualFormName : form_name, explanationFormName: tab_form_name, }); diff --git a/src/javascript/app/pages/trade/barriers.js b/src/javascript/app/pages/trade/barriers.js index 61ae9ee2ca2..19d15d05955 100644 --- a/src/javascript/app/pages/trade/barriers.js +++ b/src/javascript/app/pages/trade/barriers.js @@ -2,7 +2,7 @@ const moment = require('moment'); const Contract = require('./contract'); const Defaults = require('./defaults'); const Tick = require('./tick'); -const tradeManager = require('../../common/trade_manager').default; +const dataManager = require('../../common/data_manager').default; const addComma = require('../../../_common/base/currency_base').addComma; const elementTextContent = require('../../../_common/common_functions').elementTextContent; const getElementById = require('../../../_common/common_functions').getElementById; @@ -87,7 +87,7 @@ const Barriers = (() => { showHideRelativeTip(barrier.barrier, [tooltip, span]); barrier_data.show_barrier = true; barrier_data.show_barrier_highlow = false; - tradeManager.set({ + dataManager.setTrade({ barrier_data, }, 'barrier'); return; @@ -170,7 +170,7 @@ const Barriers = (() => { Defaults.set(BARRIER_LOW, low_elm.value); barrier_data.show_barrier = false; barrier_data.show_barrier_highlow = true; - tradeManager.set({ + dataManager.setTrade({ barrier_data, }, 'barrier'); return; @@ -215,9 +215,9 @@ const Barriers = (() => { } } - tradeManager.set({ + dataManager.setTrade({ barrier_error, - },'barrier'); + }, 'barrier'); }; const showHideRelativeTip = (barrier, arr_el) => { diff --git a/src/javascript/app/pages/trade/common.js b/src/javascript/app/pages/trade/common.js index 1d01e2ada60..ee807098644 100644 --- a/src/javascript/app/pages/trade/common.js +++ b/src/javascript/app/pages/trade/common.js @@ -9,8 +9,7 @@ const FormsWrapperElement = require('../form/contract-form-wrapper.jsx'); const TabsElement = require('../bottom/tabs.jsx'); const formatMoney = require('../../common/currency').formatMoney; const ActiveSymbols = require('../../common/active_symbols'); -const purchaseManager = require('../../common/purchase_manager.js').default; -const contractManager = require('../../common/contract_manager.js').default; +const dataManager = require('../../common/data_manager.js').default; const elementInnerHtml = require('../../../_common/common_functions').elementInnerHtml; const getElementById = require('../../../_common/common_functions').getElementById; const localize = require('../../../_common/localize').localize; @@ -52,7 +51,7 @@ const commonTrading = (() => { const contract_to_show = /^(callputequal)$/.test(selected) ? 'risefall' : selected; if (!contracts_element) { - contractManager.set({ + dataManager.setContract({ contractsTree : contracts_tree, contracts : all_contracts, formName : selected || Defaults.get('formname'), @@ -158,7 +157,7 @@ const commonTrading = (() => { showHideOverlay('contract_confirmation_container', 'none'); showHideOverlay('contracts_list', 'flex'); $('.purchase_button').text(localize('Purchase')); - purchaseManager.set({ + dataManager.setPurchase({ showPurchaseResults: false, }); }; @@ -254,7 +253,7 @@ const commonTrading = (() => { } else { node.show(); elementInnerHtml(node, comment); - purchaseManager.set({ + dataManager.setPurchase({ [`${position}Comment`]: comment, }); } @@ -476,13 +475,13 @@ const commonTrading = (() => { requireHighstock, showPriceOverlay: () => { showHideOverlay('loading_container2', 'block'); - purchaseManager.set({ + dataManager.setPurchase({ isPurchaseFormDisabled: true, }); }, hidePriceOverlay: () => { showHideOverlay('loading_container2', 'none'); - purchaseManager.set({ + dataManager.setPurchase({ isPurchaseFormDisabled: false, }); }, diff --git a/src/javascript/app/pages/trade/common_independent.js b/src/javascript/app/pages/trade/common_independent.js index 4572944d6f4..7583939ce28 100644 --- a/src/javascript/app/pages/trade/common_independent.js +++ b/src/javascript/app/pages/trade/common_independent.js @@ -1,30 +1,30 @@ const moment = require('moment'); const Defaults = require('./defaults'); -const purchaseManager = require('../../common/purchase_manager').default; +const dataManager = require('../../common/data_manager').default; const getElementById = require('../../../_common/common_functions').getElementById; const getPropertyValue = require('../../../_common/utility').getPropertyValue; /* * Display price/spot movement variation to depict price moved up or down */ -const displayPriceMovement = (element, old_value, current_value,data_key) => { +const displayPriceMovement = (element, old_value, current_value, data_key) => { element.classList.remove('price_moved_down'); element.classList.remove('price_moved_up'); - purchaseManager.set({ + dataManager.setPurchase({ [data_key]: '', }); if (parseFloat(current_value) > parseFloat(old_value)) { element.classList.remove('price_moved_down'); element.classList.add('price_moved_up'); - purchaseManager.set({ + dataManager.setPurchase({ [data_key]: 'price_moved_up', }); } else if (parseFloat(current_value) < parseFloat(old_value)) { element.classList.remove('price_moved_up'); element.classList.add('price_moved_down'); - purchaseManager.set({ + dataManager.setPurchase({ [data_key]: 'price_moved_down', }); } diff --git a/src/javascript/app/pages/trade/duration.js b/src/javascript/app/pages/trade/duration.js index 08dfabd4c1c..7125bb36423 100644 --- a/src/javascript/app/pages/trade/duration.js +++ b/src/javascript/app/pages/trade/duration.js @@ -17,7 +17,7 @@ const toReadableFormat = require('../../../_common/string_util').toReadableFor const createElement = require('../../../_common/utility').createElement; const getPropertyValue = require('../../../_common/utility').getPropertyValue; const elementInnerHtml = require('../../../_common/common_functions').elementInnerHtml; -const tradeManager = require('../../common/trade_manager').default; +const dataManager = require('../../common/data_manager').default; /* * Handles duration processing display @@ -153,7 +153,7 @@ const Durations = (() => { Object.values(list).forEach(option => { duration_options.push({ text: duration_list[option].text, value: option }); }); - tradeManager.set({ + dataManager.setTrade({ duration_options, }); @@ -452,7 +452,7 @@ const Durations = (() => { requested = selectEndDate(selected_date); } } - tradeManager.set({ + dataManager.setTrade({ endtime_data, }); return requested; @@ -507,7 +507,7 @@ const Durations = (() => { fragment.appendChild(option); } target.appendChild(fragment); - tradeManager.set({ + dataManager.setTrade({ expiry_type_options, }); }; @@ -686,7 +686,7 @@ const Durations = (() => { duration_data.message = `${localize('Minimum:')} ${duration_data.min}`; } } - tradeManager.set({ + dataManager.setTrade({ duration_data, }); }; diff --git a/src/javascript/app/pages/trade/markets/contracts-dropdown.jsx b/src/javascript/app/pages/trade/markets/contracts-dropdown.jsx index 8ff05b3a740..4791e07f1c8 100644 --- a/src/javascript/app/pages/trade/markets/contracts-dropdown.jsx +++ b/src/javascript/app/pages/trade/markets/contracts-dropdown.jsx @@ -1,13 +1,13 @@ import { Divider, DropdownItem, DropdownTitle, useDropdown } from '@deriv-com/quill-ui'; import React, { useEffect, useRef, useState } from 'react'; import { triggerContractChange, useContractChange } from '../../../hooks/events'; -import contractManager from '../../../common/contract_manager'; +import dataManager from '../../../common/data_manager'; import Defaults, { PARAM_NAMES } from '../defaults'; export const ContractDropdown = () => { const { close } = useDropdown(); const hasContractChange = useContractChange(); - const [data, setData] = useState(contractManager.getAll()); + const [data, setData] = useState(dataManager.getAllContracts()); const selectedRef = useRef(null); const containerRef = useRef(null); @@ -24,7 +24,7 @@ export const ContractDropdown = () => { Defaults.set(PARAM_NAMES.FORM_NAME,formName); - contractManager.set({ + dataManager.setContract({ formName, }); @@ -39,7 +39,7 @@ export const ContractDropdown = () => { useEffect(() => { setData(oldData => ({ ...oldData, - ...contractManager.getAll(), + ...dataManager.getAllContracts(), })); }, [hasContractChange]); diff --git a/src/javascript/app/pages/trade/markets/markets-dropdown.jsx b/src/javascript/app/pages/trade/markets/markets-dropdown.jsx index b56fe49d90b..75c352439d0 100644 --- a/src/javascript/app/pages/trade/markets/markets-dropdown.jsx +++ b/src/javascript/app/pages/trade/markets/markets-dropdown.jsx @@ -16,7 +16,7 @@ import ActiveSymbols, { import Defaults, { PARAM_NAMES } from '../defaults'; import { triggerMarketChange } from '../../../hooks/events'; import { localize } from '../../../../_common/localize'; -import contractManager from '../../../common/contract_manager'; +import dataManager from '../../../common/data_manager'; export const getMarketName = () => { const obj = ActiveSymbols.getMarkets(); @@ -39,7 +39,7 @@ export const getMarketName = () => { }; export const getContractName = () => { - const data = contractManager.getAll(); + const data = dataManager.getAllContracts('contract'); let name = ''; // eslint-disable-next-line consistent-return data?.contractsTree?.forEach((contract) => { diff --git a/src/javascript/app/pages/trade/not-available.jsx b/src/javascript/app/pages/trade/not-available.jsx index 116c7ceda64..130f9a3c599 100644 --- a/src/javascript/app/pages/trade/not-available.jsx +++ b/src/javascript/app/pages/trade/not-available.jsx @@ -3,7 +3,7 @@ import ReactDOM from 'react-dom'; import { Text, Button } from '@deriv-com/quill-ui'; import { getElementById } from '../../../_common/common_functions'; import { localize } from '../../../_common/localize.js'; -import contractManager from '../../common/contract_manager.js'; +import dataManager from '../../common/data_manager.js'; const NotAvailable = ({ title, body }) => (
@@ -29,7 +29,7 @@ const NotAvailable = ({ title, body }) => ( ); export const init = ({ ...props }) => { - contractManager.set({ + dataManager.setContract({ hidePageLoader: true, }); ReactDOM.render(, getElementById('content')); diff --git a/src/javascript/app/pages/trade/price.js b/src/javascript/app/pages/trade/price.js index fc39198e81c..2cfea0227f1 100644 --- a/src/javascript/app/pages/trade/price.js +++ b/src/javascript/app/pages/trade/price.js @@ -12,7 +12,7 @@ const BinarySocket = require('../../base/socket'); const formatMoney = require('../../common/currency').formatMoney; const CommonFunctions = require('../../../_common/common_functions'); const { getCurrencyDisplayCode } = require('../../../_common/base/currency_base'); -const purchaseManager = require('../../common/purchase_manager').default; +const dataManager = require('../../common/data_manager').default; const localize = require('../../../_common/localize').localize; const getPropertyValue = require('../../../_common/utility').getPropertyValue; @@ -214,7 +214,7 @@ const Price = (() => { h4.setAttribute('class', `contract_heading ${type}`); CommonFunctions.elementTextContent(h4, display_text); - purchaseManager.set({ + dataManager.setPurchase({ [`${position}DisplayText`] : display_text, [`${position}ContractType`]: type, }); @@ -226,7 +226,7 @@ const Price = (() => { if (!data.display_value) { amount.classList.remove('price_moved_up', 'price_moved_down'); - purchaseManager.set({ + dataManager.setPurchase({ [`${position}AmountClassname`]: '', }); } @@ -235,7 +235,7 @@ const Price = (() => { if (!data.payout) { amount.classList.remove('price_moved_up', 'price_moved_down'); - purchaseManager.set({ + dataManager.setPurchase({ [`${position}AmountClassname`]: '', }); } @@ -245,7 +245,7 @@ const Price = (() => { CommonFunctions.elementTextContent(multiplier, `${localize('Multiplier')}: `); CommonFunctions.elementInnerHtml(contract_multiplier, data.multiplier ? formatMoney(currentCurrency, data.multiplier, false, 0, 2) : '-'); - purchaseManager.set({ + dataManager.setPurchase({ [`${position}Amount`] : data.display_value ? formatMoney(currentCurrency, data.display_value,true) : '-', [`${position}PayoutAmount`]: data.payout ? formatMoney(currentCurrency, data.payout,true) : '-', [`${position}Multiplier`] : data.multiplier ? formatMoney(currentCurrency, data.multiplier, true, 0, 2) : '-', @@ -253,14 +253,14 @@ const Price = (() => { }); if (data.longcode && window.innerWidth > 500) { - purchaseManager.set({ + dataManager.setPurchase({ [`${position}Description`]: data.longcode, }); if (description) description.setAttribute('data-balloon', data.longcode); if (longcode) CommonFunctions.elementTextContent(longcode, data.longcode); } else { - purchaseManager.set({ + dataManager.setPurchase({ [`${position}Description`]: '', }); @@ -270,7 +270,7 @@ const Price = (() => { }; const setPurchaseStatus = (enable) => { - purchaseManager.set({ + dataManager.setPurchase({ [`${position}PurchaseDisabled`]: !enable, }); purchase.parentNode.classList[enable ? 'remove' : 'add']('button-disabled'); @@ -282,7 +282,7 @@ const Price = (() => { setData(); error.show(); CommonFunctions.elementTextContent(error, details.error.message); - purchaseManager.set({ + dataManager.setPurchase({ [`${position}Comment`]: details.error.message, }); } else { @@ -297,7 +297,7 @@ const Price = (() => { if (isLookback(type)) { const multiplier_value = formatMoney(Client.get('currency'), proposal.multiplier, false, 3, 2); CommonFunctions.elementInnerHtml(comment, `${localize('Payout')}: ${getLookBackFormula(type, multiplier_value)}`); - purchaseManager.set({ + dataManager.setPurchase({ [`${position}Comment`]: `${localize('Payout')}: ${getLookBackFormula(type, multiplier_value)}`, }); } else { @@ -462,14 +462,14 @@ const Price = (() => { const container = CommonFunctions.getElementById(`price_container_${position}`); if (position_is_visible[position]) { if (position === 'middle'){ - purchaseManager.set({ + dataManager.setPurchase({ showMidPurchase: true, }); } $(container).fadeIn(0); } else { if (position === 'middle'){ - purchaseManager.set({ + dataManager.setPurchase({ showMidPurchase: false, }); } diff --git a/src/javascript/app/pages/trade/process.js b/src/javascript/app/pages/trade/process.js index 93e8911ef1e..c697e654e97 100644 --- a/src/javascript/app/pages/trade/process.js +++ b/src/javascript/app/pages/trade/process.js @@ -15,9 +15,7 @@ const Symbols = require('./symbols'); const Tick = require('./tick'); const NotAvailable = require('./not-available.jsx'); const BinarySocket = require('../../base/socket'); -const tradeManager = require('../../common/trade_manager.js').default; -const contractManager = require('../../common/contract_manager.js').default; -const purchaseManager = require('../../common/purchase_manager').default; +const dataManager = require('../../common/data_manager.js').default; const getMinPayout = require('../../common/currency').getMinPayout; const isCryptocurrency = require('../../common/currency').isCryptocurrency; const isEuCountry = require('../../common/country_base').isEuCountry; @@ -130,7 +128,7 @@ const Process = (() => { getElementById('trading_socket_container').classList.add('show'); const init_logo = getElementById('trading_init_progress'); - contractManager.set({ + dataManager.setContract({ hidePageLoader: true, }); @@ -154,7 +152,7 @@ const Process = (() => { const processContract = (contracts) => { if (getPropertyValue(contracts, ['error', 'code']) === 'InvalidSymbol') { Price.processForgetProposals(); - purchaseManager.set({ + dataManager.setPurchase({ showPurchaseResults: true, }); getElementById('contract_confirmation_container').style.display = 'block'; @@ -306,12 +304,12 @@ const Process = (() => { el_equals.checked = true; } el_equals.parentElement.setVisibility(1); - tradeManager.set({ + dataManager.setTrade({ show_allow_equals: true, }); } else { el_equals.parentElement.setVisibility(0); - tradeManager.set({ + dataManager.setTrade({ show_allow_equals: false, }); } diff --git a/src/javascript/app/pages/trade/purchase.js b/src/javascript/app/pages/trade/purchase.js index 127541a4af6..b5ce0910cc3 100644 --- a/src/javascript/app/pages/trade/purchase.js +++ b/src/javascript/app/pages/trade/purchase.js @@ -19,7 +19,7 @@ const CommonFunctions = require('../../../_common/common_functions'); const localize = require('../../../_common/localize').localize; const State = require('../../../_common/storage').State; const Url = require('../../../_common/url'); -const purchaseManager = require('../../common/purchase_manager').default; +const dataManager = require('../../common/data_manager').default; const createElement = require('../../../_common/utility').createElement; const getPropertyValue = require('../../../_common/utility').getPropertyValue; @@ -27,7 +27,6 @@ const getPropertyValue = require('../../../_common/utility').getProperty * Purchase object that handles all the functions related to * contract purchase response */ - const Purchase = (() => { const adjustment = 5; @@ -94,7 +93,7 @@ const Purchase = (() => { processPriceRequest(); TopUpVirtualPopup.show(error.message); - purchaseManager.set({ + dataManager.setPurchase({ error: { showPurchaseResults: true, ...error, @@ -106,7 +105,7 @@ const Purchase = (() => { } else { contracts_list.style.display = 'none'; container.style.display = 'block'; - purchaseManager.set({ + dataManager.setPurchase({ showPurchaseResults: true, }); @@ -121,7 +120,7 @@ const Purchase = (() => { const signup_url = `${Url.getStaticUrl()}/signup/`; authorization_error_btn_signup.href = signup_url; - purchaseManager.set({ + dataManager.setPurchase({ error: { ...error, signupUrl: signup_url, @@ -171,7 +170,7 @@ const Purchase = (() => { } } - purchaseManager.set({ + dataManager.setPurchase({ error: { ...error,message }, }); @@ -185,7 +184,7 @@ const Purchase = (() => { message_container.show(); authorization_error.setVisibility(0); confirmation_error.setVisibility(0); - purchaseManager.set({ + dataManager.setPurchase({ error: null, }); @@ -194,13 +193,12 @@ const Purchase = (() => { CommonFunctions.elementTextContent(barrier_element, ''); CommonFunctions.elementTextContent(reference, `${localize('Your transaction reference is')} ${receipt.transaction_id}`); - purchaseManager.set({ + dataManager.setPurchase({ showPurchaseResults: true, pr_heading : localize('Contract Confirmation'), pr_description : receipt.longcode, pr_barrier : '', pr_reference : `${localize('Your transaction reference is')} ${receipt.transaction_id}`, - }); const currency = Client.get('currency'); @@ -217,14 +215,14 @@ const Purchase = (() => { const potential_profit_value = payout_value ? formatMoney(currency, payout_value - cost_value) : undefined; CommonFunctions.elementInnerHtml(cost, `${localize('Total Cost')}

${formatMoney(currency, cost_value)}

`); - purchaseManager.set({ + dataManager.setPurchase({ pr_tableCost : localize('Total Cost'), pr_tableCostValue: formatMoney(currency, cost_value), }); if (isLookback(contract_type)) { CommonFunctions.elementInnerHtml(payout, `${localize('Potential Payout')}

${formula}

`); - purchaseManager.set({ + dataManager.setPurchase({ pr_tablePayout : localize('Potential Payout'), pr_tablePayoutValue: formula, pr_showTableProfit : false, @@ -235,13 +233,12 @@ const Purchase = (() => { CommonFunctions.elementInnerHtml(payout, `${localize('Potential Payout')}

${formatMoney(currency, payout_value)}

`); CommonFunctions.elementInnerHtml(profit, `${localize('Potential Profit')}

${potential_profit_value}

`); - purchaseManager.set({ + dataManager.setPurchase({ pr_tablePayout : localize('Potential Payout'), pr_tablePayoutValue: formatMoney(currency, payout_value), pr_tableProfit : localize('Potential Profit'), pr_tableProfitValue: potential_profit_value, pr_showTableProfit : true, - }); } @@ -266,13 +263,13 @@ const Purchase = (() => { CommonFunctions.elementTextContent(button, localize('View')); button.setAttribute('contract_id', receipt.contract_id); button.show(); - purchaseManager.set({ + dataManager.setPurchase({ pr_showBtn: true, }); $('#confirmation_message_container .open_contract_details').attr('contract_id', receipt.contract_id).setVisibility(1); } else { button.hide(); - purchaseManager.set({ + dataManager.setPurchase({ pr_showBtn: false, }); $('#confirmation_message_container .open_contract_details').setVisibility(0); diff --git a/src/javascript/app/pages/trade/purchase/contract-details.jsx b/src/javascript/app/pages/trade/purchase/contract-details.jsx index 2d0a8c0dac5..745ae9cae2f 100644 --- a/src/javascript/app/pages/trade/purchase/contract-details.jsx +++ b/src/javascript/app/pages/trade/purchase/contract-details.jsx @@ -4,7 +4,7 @@ import { Button, Skeleton, Text } from '@deriv-com/quill-ui'; import { LabelPairedArrowLeftMdRegularIcon } from '@deriv/quill-icons/LabelPaired'; import ContractTable from './contract-table'; import Portal from '../../portal'; -import purchaseManager from '../../../common/purchase_manager'; +import dataManager from '../../../common/data_manager'; import { usePurchaseChange } from '../../../hooks/events'; import { localize } from '../../../../_common/localize'; import { Explanation } from '../../bottom/explanation'; @@ -35,7 +35,7 @@ const AuditSection = ({ data }) => { icon={} color='black' onClick={() => { - purchaseManager.set({ + dataManager.setPurchase({ cd_showAudit: false, }); triggerClick('#contract_purchase_button'); @@ -128,7 +128,7 @@ const DetailsSection = ({ data }) => ( icon={} color='black' onClick={() => { - purchaseManager.set({ + dataManager.setPurchase({ showContractDetailsPopup: false, }); }} @@ -175,7 +175,7 @@ const ContractDetails = () => { useEffect(() => { const handleKeyDown = (event) => { if (event.key === 'Escape') { - purchaseManager.set({ + dataManager.setPurchase({ showContractDetailsPopup: false, }); } @@ -189,7 +189,7 @@ const ContractDetails = () => { }, [hasPurchaseChange]); useEffect(() => { - const newData = purchaseManager.getAll(); + const newData = dataManager.getAllPurchases(); setData((oldData) => ({ ...oldData, diff --git a/src/javascript/app/pages/trade/purchase/purchase.jsx b/src/javascript/app/pages/trade/purchase/purchase.jsx index bc5f9a12855..e23e65c9d13 100644 --- a/src/javascript/app/pages/trade/purchase/purchase.jsx +++ b/src/javascript/app/pages/trade/purchase/purchase.jsx @@ -1,5 +1,4 @@ /* eslint-disable import/no-unresolved */ -/* eslint-disable no-console */ import React, { useEffect, useState } from 'react'; import ReactDOM from 'react-dom'; import { Button, CaptionText, Skeleton, Text, Tooltip } from '@deriv-com/quill-ui'; @@ -9,7 +8,7 @@ import ContractDetails from './contract-details'; import Defaults, { PARAM_NAMES } from '../defaults'; import { getElementById } from '../../../../_common/common_functions'; import { useContractChange, usePurchaseChange } from '../../../hooks/events'; -import purchaseManager from '../../../common/purchase_manager'; +import dataManager from '../../../common/data_manager'; import { localize } from '../../../../_common/localize'; import { parseData, triggerClick } from '../../../common/helpers'; @@ -25,7 +24,7 @@ const Purchase = () => { const isloading = () => !data?.topAmount && !data?.middleAmount && !data?.bottomAmount; const hidePurchaseResults = () => - purchaseManager.set({ + dataManager.setPurchase({ showPurchaseResults: false, error : null, cd_errorMsg : null, @@ -34,7 +33,7 @@ const Purchase = () => { }); useEffect(() => { - const newData = purchaseManager.getAll(); + const newData = dataManager.getAllPurchases(); setShowPopup(!!newData?.showContractDetailsPopup); diff --git a/src/javascript/app/pages/trade/reset.js b/src/javascript/app/pages/trade/reset.js index 903263406a0..cd4ae8df566 100644 --- a/src/javascript/app/pages/trade/reset.js +++ b/src/javascript/app/pages/trade/reset.js @@ -1,5 +1,5 @@ const CommonFunctions = require('../../../_common/common_functions'); -const tradeManager = require('../../common/trade_manager').default; +const dataManager = require('../../common/data_manager').default; const localize = require('../../../_common/localize').localize; /* @@ -36,7 +36,7 @@ const Reset = (() => { CommonFunctions.getElementById('reset_time') .html(localize('The reset time is [_1]', reset_time_str)) .setAttribute('style', ''); - tradeManager.set({ + dataManager.setTrade({ reset_message: localize('The reset time is [_1]', reset_time_str), }); }; @@ -63,7 +63,7 @@ const Reset = (() => { const hideResetTime = () => { CommonFunctions.getElementById('reset_time').style.display = 'none'; - tradeManager.set({ + dataManager.setTrade({ reset_message: null, }); }; diff --git a/src/javascript/app/pages/trade/starttime.js b/src/javascript/app/pages/trade/starttime.js index 3c3d4e117fb..81e0374b724 100644 --- a/src/javascript/app/pages/trade/starttime.js +++ b/src/javascript/app/pages/trade/starttime.js @@ -10,7 +10,7 @@ const localizeForLang = require('../../../_common/localize').forLang; const urlLang = require('../../../_common/language').urlLang; const State = require('../../../_common/storage').State; const createElement = require('../../../_common/utility').createElement; -const tradeManager = require('../../common/trade_manager').default; +const dataManager = require('../../common/data_manager').default; /* * Handles start time display @@ -110,7 +110,7 @@ const StartDates = (() => { Dropdown('#date_start'); Defaults.set(DATE_START, target.value); $('#time_start_row').setVisibility(target.value !== 'now'); - tradeManager.set({ + dataManager.setTrade({ start_dates: start_dates_data, }); } diff --git a/src/javascript/app/pages/trade/tick.js b/src/javascript/app/pages/trade/tick.js index fc550cd151d..f7dbf2c8233 100644 --- a/src/javascript/app/pages/trade/tick.js +++ b/src/javascript/app/pages/trade/tick.js @@ -2,7 +2,7 @@ const moment = require('moment'); const countDecimalPlaces = require('./common_independent').countDecimalPlaces; const displayPriceMovement = require('./common_independent').displayPriceMovement; const underlyings = require('./symbols').underlyings; -const tradeManager = require('../../common/trade_manager').default; +const dataManager = require('../../common/data_manager').default; const addComma = require('../../../_common/base/currency_base').addComma; const elementTextContent = require('../../../_common/common_functions').elementTextContent; const getElementById = require('../../../_common/common_functions').getElementById; @@ -114,14 +114,14 @@ const Tick = (() => { indicative_barrier_tooltip.textContent = addComma((parseFloat(current_tick) + barrier_value), decimal_places); - tradeManager.set({ + dataManager.setTrade({ barrier_indicator: addComma((parseFloat(current_tick) + barrier_value), decimal_places), }, 'barrier'); tooltip.style.display = 'inherit'; span.style.display = 'none'; } else { elementTextContent(indicative_barrier_tooltip, ''); - tradeManager.set({ + dataManager.setTrade({ barrier_indicator: null, }, 'barrier'); tooltip.style.display = 'none'; @@ -133,14 +133,14 @@ const Tick = (() => { value = isNaN(value) ? 0 : value; indicative_high_barrier_tooltip.textContent = (parseFloat(current_tick) + value).toFixed(decimal_places); - tradeManager.set({ + dataManager.setTrade({ barrier_indicator_high: (parseFloat(current_tick) + value).toFixed(decimal_places), }, 'barrier'); high_tooltip.style.display = 'inherit'; high_span.style.display = 'none'; } else { elementTextContent(indicative_high_barrier_tooltip, ''); - tradeManager.set({ + dataManager.setTrade({ barrier_indicator_high: null, }, 'barrier'); high_tooltip.style.display = 'none'; @@ -151,14 +151,14 @@ const Tick = (() => { value = parseFloat(low_barrier_element.value); value = isNaN(value) ? 0 : value; indicative_low_barrier_tooltip.textContent = (parseFloat(current_tick) + value).toFixed(decimal_places); - tradeManager.set({ + dataManager.setTrade({ barrier_indicator_low: (parseFloat(current_tick) + value).toFixed(decimal_places), }, 'barrier'); low_tooltip.style.display = 'inherit'; low_span.style.display = 'none'; } else { elementTextContent(indicative_low_barrier_tooltip, ''); - tradeManager.set({ + dataManager.setTrade({ barrier_indicator_low: null, }, 'barrier'); low_tooltip.style.display = 'none'; @@ -168,7 +168,7 @@ const Tick = (() => { elementTextContent(indicative_barrier_tooltip, ''); elementTextContent(indicative_high_barrier_tooltip, ''); elementTextContent(indicative_low_barrier_tooltip, ''); - tradeManager.set({ + dataManager.setTrade({ barrier_indicator : null, barrier_indicator_high: null, barrier_indicator_low : null, diff --git a/src/javascript/app/pages/trade/tick_trade.js b/src/javascript/app/pages/trade/tick_trade.js index cc2d2689104..30ee82564bd 100644 --- a/src/javascript/app/pages/trade/tick_trade.js +++ b/src/javascript/app/pages/trade/tick_trade.js @@ -8,7 +8,7 @@ const isEmptyObject = require('../../../_common/utility').isEmptyObject; const ChartSettings = require('../../common/chart_settings'); const addComma = require('../../../_common/base/currency_base').addComma; const CommonFunctions = require('../../../_common/common_functions'); -const purchaseManager = require('../../common/purchase_manager').default; +const dataManager = require('../../common/data_manager').default; const localize = require('../../../_common/localize').localize; const TickDisplay = (() => { @@ -167,7 +167,7 @@ const TickDisplay = (() => { const setBarrierValue = (lbl_barrier) => { CommonFunctions.elementInnerHtml(CommonFunctions.getElementById('contract_purchase_barrier'), `${lbl_barrier}: ${addComma(contract.barrier, display_decimals)}`); - purchaseManager.set({ + dataManager.setPurchase({ pr_barrier: `${lbl_barrier}: ${addComma(contract.barrier, display_decimals)}`, }); }; diff --git a/src/javascript/app/pages/trade/update_values.js b/src/javascript/app/pages/trade/update_values.js index 30b322f5d7b..b9f8a168920 100644 --- a/src/javascript/app/pages/trade/update_values.js +++ b/src/javascript/app/pages/trade/update_values.js @@ -1,5 +1,5 @@ const Client = require('../../base/client'); -const purchaseManager = require('../../common/purchase_manager').default; +const dataManager = require('../../common/data_manager').default; const formatMoney = require('../../common/currency').formatMoney; const localize = require('../../../_common/localize').localize; @@ -12,7 +12,7 @@ const updatePurchaseStatus = (final_price, pnl, profit, localized_contract_statu $payout.html($('
', { text: localize('Buy price') }).append($('

', { html: formatMoney(currency, Math.abs(pnl)) }))); $cost.html($('

', { text: localize('Final price') }).append($('

', { html: formatMoney(currency, final_price) }))); - purchaseManager.set({ + dataManager.setPurchase({ pr_heading : localized_contract_status, pr_tablePayout : localize('Buy price') , pr_tablePayoutValue: formatMoney(currency, Math.abs(pnl)), @@ -22,14 +22,14 @@ const updatePurchaseStatus = (final_price, pnl, profit, localized_contract_statu if (!final_price) { $profit.html($('

', { text: localize('Loss') }).append($('

', { html: formatMoney(currency, pnl) }))); - purchaseManager.set({ + dataManager.setPurchase({ pr_tableProfit : localize('Loss'), pr_tableProfitValue: formatMoney(currency, pnl), }); } else { $profit.html($('

', { text: localize('Profit') }).append($('

', { html: formatMoney(currency, profit) }))); updateContractBalance(Client.get('balance')); - purchaseManager.set({ + dataManager.setPurchase({ pr_tableProfit : localize('Profit'), pr_tableProfitValue: formatMoney(currency, profit), }); @@ -39,7 +39,7 @@ const updatePurchaseStatus = (final_price, pnl, profit, localized_contract_statu const updateContractBalance = (balance) => { $('#contract_purchase_balance').html(localize('Account balance:')).append($('

', { html: formatMoney(Client.get('currency'), balance) })); - purchaseManager.set({ + dataManager.setPurchase({ pr_balance : localize('Account balance:'), pr_balanceValue: formatMoney(Client.get('currency'), balance), }); diff --git a/src/javascript/app/pages/user/view_popup/view_popup.js b/src/javascript/app/pages/user/view_popup/view_popup.js index d3220e171f5..ea3847b48da 100644 --- a/src/javascript/app/pages/user/view_popup/view_popup.js +++ b/src/javascript/app/pages/user/view_popup/view_popup.js @@ -15,8 +15,7 @@ const getElementById = require('../../../../_common/common_functions') const localize = require('../../../../_common/localize').localize; const urlFor = require('../../../../_common/url').urlFor; const Utility = require('../../../../_common/utility'); -const contractManager = require('../../../common/contract_manager').default; -const purchaseManager = require('../../../common/purchase_manager').default; +const dataManager = require('../../../common/data_manager').default; const ViewPopup = (() => { let contract_id, @@ -64,7 +63,7 @@ const ViewPopup = (() => { getContract(); - purchaseManager.set({ + dataManager.setPurchase({ showContractDetailsPopup: true, cd_description : null, }); @@ -147,13 +146,13 @@ const ViewPopup = (() => { containerSetText('trade_details_multiplier', formatMoney(contract.currency, multiplier, false, 3, 2)); if (Lookback.isLookback(contract.contract_type)) { containerSetText('trade_details_payout', Lookback.getFormula(contract.contract_type, formatMoney(contract.currency, multiplier, false, 3, 2))); - purchaseManager.set({ + dataManager.setPurchase({ cd_payout: Lookback.getFormula(contract.contract_type, formatMoney(contract.currency, multiplier, false, 3, 2)), }); } else { containerSetText('trade_details_payout', formatMoney(contract.currency, contract.payout)); - purchaseManager.set({ + dataManager.setPurchase({ cd_payout: formatMoney(contract.currency, contract.payout), }); } @@ -161,7 +160,7 @@ const ViewPopup = (() => { update(); ViewPopupUI.repositionConfirmation(); - purchaseManager.set({ + dataManager.setPurchase({ cd_contractType : ContractTypeDisplay()[contract.contract_type], cd_purchasePrice: formatMoney(contract.currency, contract.buy_price), cd_multiplier : formatMoney(contract.currency, multiplier, false, 3, 2), @@ -181,14 +180,14 @@ const ViewPopup = (() => { if (is_sold_before_start) { $('#trade_details_start_date').parent().setVisibility(0); containerSetText('trade_details_purchase_time', epochToDateTime(contract.purchase_time), '', true); - purchaseManager.set({ + dataManager.setPurchase({ cd_purchaseTime: epochToDateTime(contract.purchase_time), soldBeforeStart: true, }); } else { $('#trade_details_purchase_time').parent().setVisibility(0); containerSetText('trade_details_start_date', epochToDateTime(contract.date_start), '', true); - purchaseManager.set({ + dataManager.setPurchase({ cd_startTime : epochToDateTime(contract.date_start), soldBeforeStart: false, }); @@ -201,7 +200,7 @@ const ViewPopup = (() => { if (contract.barrier_count > 1) { containerSetText('trade_details_barrier', is_sold_before_start ? '-' : addComma(contract.high_barrier), '', true); containerSetText('trade_details_barrier_low', is_sold_before_start ? '-' : addComma(contract.low_barrier), '', true); - purchaseManager.set({ + dataManager.setPurchase({ cd_barrier : is_sold_before_start ? '-' : addComma(contract.high_barrier), cd_barrierLow: is_sold_before_start ? '-' : addComma(contract.low_barrier), }); @@ -220,7 +219,7 @@ const ViewPopup = (() => { '', true); - purchaseManager.set({ + dataManager.setPurchase({ cd_barrier: contract.entry_tick_time && is_sold_before_start ? '-' : (barrier_prefix + formatted_barrier), }); @@ -236,7 +235,7 @@ const ViewPopup = (() => { '', true); - purchaseManager.set({ + dataManager.setPurchase({ cd_barrier : is_sold_before_start ? '-' : contract.entry_spot_display_value, cd_barrierReset: contract.entry_tick_time && is_sold_before_start ? '-' : (barrier_prefix + formatted_barrier), }); @@ -252,7 +251,7 @@ const ViewPopup = (() => { if (current_spot) { containerSetText('trade_details_current_spot > span', current_spot); - purchaseManager.set({ + dataManager.setPurchase({ cd_currentSpot : current_spot, cd_showCurrentSpot: true, }); @@ -260,7 +259,7 @@ const ViewPopup = (() => { $('#trade_details_current_spot').parent().setVisibility(1); } else { $('#trade_details_current_spot').parent().setVisibility(0); - purchaseManager.set({ + dataManager.setPurchase({ cd_showCurrentSpot: false, }); } @@ -272,7 +271,7 @@ const ViewPopup = (() => { updateTimers(); } containerSetText('trade_details_current_date', epochToDateTime(current_spot_time)); - purchaseManager.set({ + dataManager.setPurchase({ cd_currentDate: epochToDateTime(current_spot_time), }); $('#trade_details_current_date').parent().setVisibility(1); @@ -283,14 +282,14 @@ const ViewPopup = (() => { containerSetText('trade_details_ref_id', `${contract.transaction_ids.buy} (${localize('Buy')}) ${contract.transaction_ids.sell ? `
${contract.transaction_ids.sell} (${localize('Sell')})` : ''}`); containerSetText('trade_details_indicative_price', indicative_price ? formatMoney(contract.currency, indicative_price) : '-'); - purchaseManager.set({ + dataManager.setPurchase({ cd_transaction_ids: contract.transaction_ids, cd_indicativePrice: indicative_price ? formatMoney(contract.currency, indicative_price) : '-', }); if (is_ended && !contract.sell_price) { containerSetText('trade_details_profit_loss', localize('Waiting for contract settlement.'), { class: 'pending' }); - purchaseManager.set({ + dataManager.setPurchase({ cd_profitLoss : localize('Waiting for contract settlement.'), cd_profitLossClass: 'pending', }); @@ -299,13 +298,13 @@ const ViewPopup = (() => { `${formatMoney(contract.currency, contract.profit)}(${(contract.profit_percentage > 0 ? '+' : '')}${addComma(contract.profit_percentage, 2)}%)`, { class: (contract.profit >= 0 ? 'profit' : 'loss') } ); - purchaseManager.set({ + dataManager.setPurchase({ cd_profitLoss : `${formatMoney(contract.currency, contract.profit)}(${(contract.profit_percentage > 0 ? '+' : '')}${addComma(contract.profit_percentage, 2)}%)`, cd_profitLossClass: (contract.profit >= 0 ? 'profit' : 'loss'), }); } else { containerSetText('trade_details_profit_loss', '-', { class: 'loss' }); - purchaseManager.set({ + dataManager.setPurchase({ cd_profitLoss : '-', cd_profitLossClass: 'loss', }); @@ -330,7 +329,7 @@ const ViewPopup = (() => { if (!is_started) { containerSetText('trade_details_entry_spot > span', '-'); containerSetText('trade_details_message', localize('Contract has not started yet')); - purchaseManager.set({ + dataManager.setPurchase({ cd_entrySpot: '-', cd_infoMsg : localize('Contract has not started yet'), }); @@ -338,12 +337,12 @@ const ViewPopup = (() => { if (contract.entry_spot > 0) { // only show entry spot if available and contract was not sold before start time containerSetText('trade_details_entry_spot > span', is_sold_before_start ? '-' : contract.entry_spot_display_value); - purchaseManager.set({ + dataManager.setPurchase({ cd_entrySpot: is_sold_before_start ? '-' : contract.entry_spot_display_value, }); } containerSetText('trade_details_message', contract.validation_error && !is_unsupported_contract ? contract.validation_error : ' '); - purchaseManager.set({ + dataManager.setPurchase({ cd_infoMsg: contract.validation_error && !is_unsupported_contract ? contract.validation_error : null, }); if (is_unsupported_contract) { @@ -404,7 +403,7 @@ const ViewPopup = (() => { containerSetText('trade_details_live_remaining', '-'); Clock.setExternalTimer(); // stop timer - purchaseManager.set({ + dataManager.setPurchase({ cd_remainingTime: '-', }); } else { @@ -427,7 +426,7 @@ const ViewPopup = (() => { const updateTimers = () => { const now = Math.max(Math.floor((window.time || 0) / 1000), contract.current_spot_time || 0); containerSetText('trade_details_live_date', epochToDateTime(now)); - purchaseManager.set({ + dataManager.setPurchase({ cd_currentTime: epochToDateTime(now), }); Clock.showLocalTimeOnHover('#trade_details_live_date'); @@ -436,7 +435,7 @@ const ViewPopup = (() => { let remained = contract.date_expiry - now; if (!is_started || contract.status !== 'open' || remained < 0) { containerSetText('trade_details_live_remaining', '-'); - purchaseManager.set({ + dataManager.setPurchase({ cd_remainingTime: '-', }); } else { @@ -449,7 +448,7 @@ const ViewPopup = (() => { containerSetText('trade_details_live_remaining', (days > 0 ? `${days} ${days > 1 ? localize('days') : localize('day')}, ` : '') + moment((remained) * 1000).utc().format('HH:mm:ss')); - purchaseManager.set({ + dataManager.setPurchase({ cd_remainingTime: (days > 0 ? `${days} ${days > 1 ? localize('days') : localize('day')}, ` : '') + moment((remained) * 1000).utc().format('HH:mm:ss'), cd_contractEnded: false, }); @@ -466,7 +465,7 @@ const ViewPopup = (() => { containerSetText('trade_details_indicative_label', localize('Payout')); containerSetText('trade_details_profit_loss_label', localize('Profit/loss')); - purchaseManager.set({ + dataManager.setPurchase({ cd_currentLabel : localize('Contract result'), cd_indicativeLabel: localize('Payout'), cd_profitLossLabel: localize('Profit/loss'), @@ -476,7 +475,7 @@ const ViewPopup = (() => { if (contract.status === 'sold') { containerSetText('trade_details_end_label', localize('Exit time')); containerSetText('trade_details_end_date', epochToDateTime(contract.sell_time), '', true); - purchaseManager.set({ + dataManager.setPurchase({ cd_endLabel: localize('Exit time'), cd_endDate : epochToDateTime(contract.sell_time), }); @@ -484,14 +483,14 @@ const ViewPopup = (() => { if (Lookback.isLookback(contract.contract_type)) { containerSetText('trade_details_spot_label', localize('Close')); containerSetText('trade_details_spottime_label', localize('Close time')); - purchaseManager.set({ + dataManager.setPurchase({ cd_spotLabel : localize('Close'), cd_spotTimeLabel: localize('Close time'), }); } else { containerSetText('trade_details_spot_label', localize('Exit spot')); containerSetText('trade_details_spottime_label', localize('Exit spot time')); - purchaseManager.set({ + dataManager.setPurchase({ cd_spotLabel : localize('Exit spot'), cd_spotTimeLabel: localize('Exit spot time'), }); @@ -540,12 +539,12 @@ const ViewPopup = (() => { if (document.getElementById('sell_details_audit')) { if (show) { setAuditVisibility(1); - purchaseManager.set({ + dataManager.setPurchase({ cd_showAudit: true, }); } else { setAuditButtonsVisibility(1); - purchaseManager.set({ + dataManager.setPurchase({ cd_showAudit: false, }); } @@ -648,7 +647,7 @@ const ViewPopup = (() => { }); }); - purchaseManager.set({ + dataManager.setPurchase({ [`auditData${type}`]: auditData, }); @@ -724,7 +723,7 @@ const ViewPopup = (() => { if (contract.audit_details.contract_start) { createAuditHeader(contract_starts.table); appendAuditLink('trade_details_entry_spot'); - purchaseManager.set({ + dataManager.setPurchase({ cd_showAuditBtn: true, }); } else { @@ -737,7 +736,7 @@ const ViewPopup = (() => { if (contract.audit_details.contract_end) { createAuditHeader(contract_ends.table); appendAuditLink('trade_details_current_spot'); - purchaseManager.set({ + dataManager.setPurchase({ cd_showAuditBtn: true, }); } else { @@ -756,7 +755,7 @@ const ViewPopup = (() => { createAuditHeader(contract_details.table); appendAuditLink('trade_details_entry_spot'); appendAuditLink('trade_details_current_spot'); - purchaseManager.set({ + dataManager.setPurchase({ cd_showAuditBtn: true, }); } else { @@ -838,7 +837,7 @@ const ViewPopup = (() => { ViewPopupUI.showInpagePopup(`

${$container.html()}
`, '', '#sell_bet_desc'); // Pass all contract details to new quill contract detail popup // cd_ prefix is Contract Details - purchaseManager.set({ + dataManager.setPurchase({ cd_description : longcode, cd_showEntrySpot : should_show_entry_spot, cd_showBarrier : should_show_barrier, @@ -885,7 +884,7 @@ const ViewPopup = (() => { $loading.show(); } } else if ($loading){ - contractManager.set({ + dataManager.setContract({ hidePageLoader: true, }); @@ -921,7 +920,7 @@ const ViewPopup = (() => { if (show) { const is_started = !contract.is_forward_starting || contract.current_spot_time > contract.date_start; const $sell_wrapper = $container.find('#contract_sell_wrapper'); - purchaseManager.set({ + dataManager.setPurchase({ cd_showSell: true, }); @@ -929,7 +928,7 @@ const ViewPopup = (() => { if (!sell_text_updated && is_started) { addSellNote($sell_wrapper); $sell_wrapper.find(`#${sell_button_id}`).text(localize('Sell at market')); - purchaseManager.set({ + dataManager.setPurchase({ cd_sellLabel: localize('Sell at market'), }); } @@ -943,7 +942,7 @@ const ViewPopup = (() => { addSellNote($sell_wrapper); } - purchaseManager.set({ + dataManager.setPurchase({ cd_sellLabel: is_started ? localize('Sell at market') : localize('Sell'), }); @@ -958,7 +957,7 @@ const ViewPopup = (() => { }); }); } else { - purchaseManager.set({ + dataManager.setPurchase({ cd_showSell: false, }); @@ -974,7 +973,7 @@ const ViewPopup = (() => { .append($('', { text: `${localize('Note')}: ` })) .append($('', { text: localize('Contract will be sold at the prevailing market price when the request is received by our servers. This price may differ from the indicated price.') }))); - purchaseManager.set({ + dataManager.setPurchase({ cd_sellInfo: `${localize('Note')}: ${localize('Contract will be sold at the prevailing market price when the request is received by our servers. This price may differ from the indicated price.')}`, cd_showSell: true, }); @@ -1001,7 +1000,7 @@ const ViewPopup = (() => { getContract(); } else { $container.find('#errMsg').text(response.error.message).setVisibility(1); - purchaseManager.set({ + dataManager.setPurchase({ cd_errorMsg: response.error.message, }); } @@ -1018,7 +1017,7 @@ const ViewPopup = (() => { `${localize('You have sold this contract at [_1] [_2]', [formatted_sell_price, getCurrencyDisplayCode(contract.currency)])}
${localize('Your transaction reference number is [_1]', response.sell.transaction_id)}`); - purchaseManager.set({ + dataManager.setPurchase({ cd_sellMsg: `${localize('You have sold this contract at [_1] [_2]', [formatted_sell_price, getCurrencyDisplayCode(contract.currency)])}
${localize('Your transaction reference number is [_1]', response.sell.transaction_id)}`,