Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V20190604_0 #145

Merged
merged 25 commits into from
Jun 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
371145b
Fix AlreadySubscribedError
easteregg May 29, 2019
b005f8a
Merge branch 'dev' into fix-already-subscribed
easteregg May 29, 2019
6945a94
Fix RaceCondition
easteregg May 30, 2019
1d76626
Remove idx incrementer, fix id comparison
oskar-binary May 31, 2019
7512758
Merge branch 'dev' into fix-already-subscribed
negarn May 31, 2019
77177b3
Merge pull request #121 from easteregg/fix-already-subscribed
negarn May 31, 2019
3d7bbae
Added datalayer for account switching
msamprz Jun 3, 2019
8419ab8
Removed unnecessary properties from GTM common variables
msamprz Jun 3, 2019
d7af2ca
Merge pull request #135 from msamprz/gtm-switch-event
ashkanx Jun 3, 2019
b7113a5
Replaced `email` property with `currency` in `GTM.getCommonVariables()`
msamprz Jun 3, 2019
216edee
Merge branch 'dev' into gtm-switch-event
ashkanx Jun 3, 2019
d2ba3ee
Merge pull request #139 from msamprz/gtm-switch-event
ashkanx Jun 3, 2019
cf5d9be
fixed condition for 1 hour chartType check
zaki-hanafiah Jun 4, 2019
9c28875
Merge branch 'dev' of github.com:binary-com/deriv-app into oskar/fix_…
oskar-binary Jun 4, 2019
968eb0a
remove forgetProposalOpenContract, forget_id from contract-store
oskar-binary Jun 4, 2019
5053f20
update naming
oskar-binary Jun 4, 2019
b3870b2
Merge pull request #129 from OskarAhl/oskar/fix_position_removePositi…
ashkanx Jun 4, 2019
446b596
Added GTM Store to better manage data updates and datalayer pushes
msamprz Jun 4, 2019
7543431
Merge pull request #144 from msamprz/gtm-switch-event
ashkanx Jun 4, 2019
4204dc1
Merge branch 'dev' into one_hour_chart_type
ashkanx Jun 4, 2019
f164f75
Merge pull request #142 from zakibinary/one_hour_chart_type
ashkanx Jun 4, 2019
98b0b20
Porting `Binary Static`'s GTM service to Deriv's GTM Store [Part 1]
msamprz Jun 4, 2019
1c99038
Merge branch 'dev' into gtm-switch-event
ashkanx Jun 4, 2019
b0c9329
Fixed eslint fail
msamprz Jun 4, 2019
78d1572
Merge pull request #146 from msamprz/gtm-switch-event
ashkanx Jun 4, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 4 additions & 58 deletions src/javascript/_common/base/gtm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ const ClientBase = require('./client_base');
const Login = require('./login');
const ServerTime = require('./server_time');
const BinarySocket = require('./socket_base');
const getElementById = require('../common_functions').getElementById;
const isVisible = require('../common_functions').isVisible;
const getLanguage = require('../language').get;
const LocalStore = require('../storage').LocalStore;
const State = require('../storage').State;
Expand All @@ -16,14 +14,10 @@ const GTM = (() => {
const isGtmApplicable = () => (/^(16303|16929)$/.test(getAppId()));

const getCommonVariables = () => ({
country_ip: State.getResponse('website_status.clients_country'),
language : getLanguage(),
pageTitle : pageTitle(),
pjax : State.get('is_loaded_by_pjax'),
url : document.URL,
language: getLanguage(),
...ClientBase.isLoggedIn() && {
visitorId: ClientBase.get('loginid'),
bom_email: ClientBase.get('email'),
currency : ClientBase.get('currency'),
},
...('is_dark_mode_on' in LocalStore.getObject('ui_store')) && {
theme: LocalStore.getObject('ui_store').is_dark_mode_on ? 'dark' : 'light',
Expand All @@ -39,11 +33,6 @@ const GTM = (() => {
}
};

const pageTitle = () => {
const t = /^.+[:-]\s*(.+)$/.exec(document.title);
return t && t[1] ? t[1] : document.title;
};

const eventHandler = (get_settings) => {
if (!isGtmApplicable()) return;
const login_event = localStorage.getItem('GTM_login');
Expand Down Expand Up @@ -108,47 +97,6 @@ const GTM = (() => {
});
};

const pushPurchaseData = (response) => {
if (!isGtmApplicable() || ClientBase.get('is_virtual')) return;
const buy = response.buy;
if (!buy) return;
const req = response.echo_req.passthrough;
const data = {
event : 'buy_contract',
bom_ui : 'legacy',
bom_symbol : req.symbol,
bom_market : getElementById('contract_markets').value,
bom_currency : req.currency,
bom_contract_type : req.contract_type,
bom_contract_id : buy.contract_id,
bom_transaction_id: buy.transaction_id,
bom_buy_price : buy.buy_price,
bom_payout : buy.payout,
};
Object.assign(data, {
bom_amount : req.amount,
bom_basis : req.basis,
bom_expiry_type: getElementById('expiry_type').value,
});
if (data.bom_expiry_type === 'duration') {
Object.assign(data, {
bom_duration : req.duration,
bom_duration_unit: req.duration_unit,
});
}
if (isVisible(getElementById('barrier'))) {
data.bom_barrier = req.barrier;
} else if (isVisible(getElementById('barrier_high'))) {
data.bom_barrier_high = req.barrier;
data.bom_barrier_low = req.barrier2;
}
if (isVisible(getElementById('prediction'))) {
data.bom_prediction = req.barrier;
}

pushDataLayer(data);
};

const mt5NewAccount = (response) => {
const acc_type = response.mt5_new_account.mt5_account_type ?
`${response.mt5_new_account.account_type}_${response.mt5_new_account.mt5_account_type}` : // financial_cent, demo_cent, ...
Expand All @@ -175,10 +123,10 @@ const GTM = (() => {
if (!isGtmApplicable() || ClientBase.get('is_virtual')) return;
if (!response.transaction || !response.transaction.action) return;
if (!['deposit', 'withdrawal'].includes(response.transaction.action)) return;

const moment_now = window.time || moment().utc();
const storage_key = 'GTM_transactions';

// Remove values from prev days so localStorage doesn't grow to infinity
let gtm_transactions = JSON.parse(localStorage.getItem(storage_key)) || {};
if (Object.prototype.hasOwnProperty.call(gtm_transactions, 'timestamp')) {
Expand Down Expand Up @@ -215,10 +163,8 @@ const GTM = (() => {
return {
pushDataLayer,
eventHandler,
pushPurchaseData,
pushTransactionData,
mt5NewAccount,
setLoginFlag: (event_name) => { if (isGtmApplicable()) localStorage.setItem('GTM_login', event_name); },
};
})();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import React from 'react';
import { expect } from 'chai';
import { configure, shallow } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import RouteWithSubRoutes from '../route-with-sub-routes.jsx';
import { Redirect } from 'react-router-dom';
import React from 'react';
import { expect } from 'chai';
import { configure, shallow } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import { RouteWithSubRoutesRender } from '../route-with-sub-routes.jsx';
import { Redirect } from 'react-router-dom';

configure({ adapter: new Adapter() });

describe('<RouteWithSubRoutes />', () => {
it('should render one <RouteWithSubRoutes /> component', () => {
const wrapper = shallow(<RouteWithSubRoutes />);
it('should render one <RouteWithSubRoutesRender /> component', () => {
const wrapper = shallow(<RouteWithSubRoutesRender />);
expect(wrapper).to.have.length(1);
});
it('should have props as passed as route', () => {
const route = { path: '/', component: Redirect, title: '', exact: true, to: '/root' };
const wrapper = shallow(<RouteWithSubRoutes {...route} />);
const wrapper = shallow(<RouteWithSubRoutesRender {...route} />);
expect(wrapper.prop('exact')).to.equal(true);
expect(wrapper.prop('path')).to.equal('/');
expect(wrapper.prop('render')).to.be.an.instanceof(Function);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { redirectToLogin } from '_common/base/login';
import BinarySocket from '_common/base/socket_base';
import Language from '_common/language';
import routes from 'Constants/routes';
import GTM from 'Utils/gtm';
import { connect } from 'Stores/connect';
import LoginPrompt from '../Elements/login-prompt.jsx';
import { default_title } from '../../Constants/app-config';

Expand Down Expand Up @@ -35,7 +35,7 @@ const RouteWithSubRoutes = route => {
const title = route.title ? `${route.title} | ` : '';
document.title = `${ title }${ default_title }`;
BinarySocket.wait('website_status').then(() => {
GTM.pushDataLayer({ event: 'page_load' });
route.pushDataLayer({ event: 'page_load' });
});
return result;
};
Expand All @@ -47,4 +47,8 @@ const RouteWithSubRoutes = route => {
/>;
};

export default RouteWithSubRoutes;
export { RouteWithSubRoutes as RouteWithSubRoutesRender }; // For tests

export default connect(({ gtm }) => ({
pushDataLayer: gtm.pushDataLayer,
}))(RouteWithSubRoutes);
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AccountSwitcher extends React.Component {
this.props.togglePositionsDrawer(); // TODO: hide drawer inside logout, once it is a mobx action
}
requestLogout().then(this.props.cleanUp);
}
};

componentDidMount() {
document.addEventListener('mousedown', this.handleClickOutside);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@ import Localize from 'App/Components/Elements/localize.jsx';
import DarkModeIcon from 'Images/app/settings/img-theme-dark.svg';
import LightModeIcon from 'Images/app/settings/img-theme-light.svg';
import { connect } from 'Stores/connect';
import GTM from 'Utils/gtm';

const ThemeSelectSettings = ({ is_dark_mode, toggleDarkMode, updateBarrierColor }) => {
const ThemeSelectSettings = ({ is_dark_mode, toggleDarkMode, updateBarrierColor, pushDataLayer }) => {
const darkOnClick = () => {
if (!is_dark_mode) {
const new_dark_mode = toggleDarkMode();
updateBarrierColor(new_dark_mode);
GTM.pushDataLayer({ event: 'switch theme' });
pushDataLayer({ event: 'switch theme' });
}
};

const lightOnClick = () => {
if (is_dark_mode) {
const new_dark_mode = toggleDarkMode();
updateBarrierColor(new_dark_mode);
GTM.pushDataLayer({ event: 'switch theme' });
pushDataLayer({ event: 'switch theme' });
}
};
return (
Expand Down Expand Up @@ -63,10 +62,11 @@ const ThemeSelectSettings = ({ is_dark_mode, toggleDarkMode, updateBarrierColor
);
};

export default connect(({ ui, modules }) => (
export default connect(({ ui, modules, gtm }) => (
{
is_dark_mode : ui.is_dark_mode_on,
toggleDarkMode : ui.toggleDarkMode,
updateBarrierColor: modules.smart_chart.updateBarrierColor,
pushDataLayer : gtm.pushDataLayer,
}
))(ThemeSelectSettings);
12 changes: 6 additions & 6 deletions src/javascript/app/App/Containers/Wip/wip.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@ import Localize from 'App/Components/Elements/localize.jsx';
import Button from 'App/Components/Form/button.jsx';
import { IconWip } from 'Assets/Common/icon-wip.jsx';
import { connect } from 'Stores/connect';
import GTM from 'Utils/gtm';

const onClick = () => {
window.location.href = window.open(urlFor('trading', undefined, undefined, true));
};

const Wip = (ui) => {
const Wip = ({ is_dark_mode, pushDataLayer }) => {
BinarySocket.wait('website_status').then(() => {
GTM.pushDataLayer({ event: 'page_load' });
pushDataLayer({ event: 'page_load' });
});

return (
<div className='work-in-progress'>
<div className='work-in-progress__content'>
<IconWip theme={ui.is_dark_mode ? 'dark' : 'light'} />
<IconWip theme={is_dark_mode ? 'dark' : 'light'} />
<div className='work-in-progress__header'>
<Localize str='Work in progress!' />
</div>
Expand All @@ -38,8 +37,9 @@ const Wip = (ui) => {
);
};

export default connect(({ ui }) => (
export default connect(({ ui, gtm }) => (
{
is_dark_mode: ui.is_dark_mode_on,
is_dark_mode : ui.is_dark_mode_on,
pushDataLayer: gtm.pushDataLayer,
}
))(Wip);
2 changes: 0 additions & 2 deletions src/javascript/app/Services/logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import Client from '_common/base/client_base';
import SocketCache from '_common/base/socket_cache';
import { removeCookies } from '_common/storage';
import WS from './ws-methods';
import GTM from '../Utils/gtm';

export const requestLogout = () =>
WS.logout().then(doLogout);

const doLogout = (response) => {
if (response.logout !== 1) return;
GTM.pushDataLayer({ event: 'log_out' });
removeCookies('affiliate_token', 'affiliate_tracking');
Client.clearAllAccounts();
Client.set('loginid', '');
Expand Down
2 changes: 1 addition & 1 deletion src/javascript/app/Services/socket-general.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { action, flow } from 'mobx';
import { setCurrencies } from '_common/base/currency_base';
import GTM from '_common/base/gtm';
import Login from '_common/base/login';
import ServerTime from '_common/base/server_time';
import BinarySocket from '_common/base/socket_base';
import { State } from '_common/storage';
import { getPropertyValue } from '_common/utility';
import { requestLogout } from './logout';
import WS from './ws-methods';
import GTM from '../Utils/gtm';

let client_store,
common_store;
Expand Down
4 changes: 2 additions & 2 deletions src/javascript/app/Stores/Modules/Contract/Helpers/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ const getExpiryTime = (time) => time || ServerTime.get().unix();

export const getChartType = (start_time, expiry_time) => {
const duration = moment.duration(moment.unix(getExpiryTime(expiry_time)).diff(moment.unix(start_time))).asHours();
// use line chart if duration is less than 1 hour
return (duration < 1) ? 'mountain' : 'candle';
// use line chart if duration is equal or less than 1 hour
return (duration <= 1) ? 'mountain' : 'candle';
};

export const getChartGranularity = (start_time, expiry_time) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export default class ContractStore extends BaseStore {
@observable is_replay_static_chart = false;

// ---- Normal properties ---
forget_id;
chart_type = 'mountain';
is_from_positions = false;
is_ongoing_contract = false;
Expand All @@ -62,7 +61,6 @@ export default class ContractStore extends BaseStore {
// -------------------
@action.bound
drawChart(SmartChartStore, contract_info) {
this.forget_id = contract_info.id;
const { date_start } = contract_info;
const end_time = getEndTime(contract_info);

Expand Down Expand Up @@ -148,7 +146,6 @@ export default class ContractStore extends BaseStore {

@action.bound
onUnmountReplay() {
this.forget_id = null;
this.replay_contract_id = null;
this.digits_info = {};
this.is_ongoing_contract = false;
Expand Down Expand Up @@ -176,7 +173,6 @@ export default class ContractStore extends BaseStore {
this.contract_info = {};
this.digits_info = {};
this.error_message = '';
this.forget_id = null;
this.has_error = false;
this.is_sell_requested = false;
this.is_from_positions = false;
Expand Down Expand Up @@ -212,7 +208,6 @@ export default class ContractStore extends BaseStore {
}
if (+response.proposal_open_contract.contract_id !== +this.replay_contract_id) return;

this.forget_id = response.proposal_open_contract.id;
this.replay_info = response.proposal_open_contract;

// Add indicative status for contract
Expand Down Expand Up @@ -335,10 +330,6 @@ export default class ContractStore extends BaseStore {
SmartChartStore.updateGranularity(granularity);
}

forgetProposalOpenContract() {
WS.forget('proposal_open_contract', this.updateProposal, { id: this.forget_id });
}

waitForChartListener = (SmartChartStore) => {
// TODO: Refactor, timeout interval is required for completed contracts.
// There is an issue when we receive the proposal_open_contract response
Expand Down
24 changes: 11 additions & 13 deletions src/javascript/app/Stores/Modules/Portfolio/portfolio-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,18 @@ export default class PortfolioStore extends BaseStore {
}

@action.bound
transactionHandler(response) {
async transactionHandler(response) {
if ('error' in response) {
this.error = response.error.message;
}
if (!response.transaction) return;
const { contract_id, action: act } = response.transaction;

if (act === 'buy') {
WS.portfolio().then((res) => {
const new_pos = res.portfolio.contracts.find(pos => +pos.contract_id === +contract_id);
if (!new_pos) return;
this.pushNewPosition(new_pos);
});
// subscribe to new contract:
const res = await WS.portfolio();
const new_pos = res.portfolio.contracts.find(pos => +pos.contract_id === +contract_id);
if (!new_pos) return;
this.pushNewPosition(new_pos);
WS.subscribeProposalOpenContract(contract_id.toString(), this.proposalOpenContractHandler, false);
} else if (act === 'sell') {
const i = this.getPositionIndexById(contract_id);
Expand Down Expand Up @@ -194,13 +192,13 @@ export default class PortfolioStore extends BaseStore {

@action.bound
removePositionById(contract_id) {
const is_contract_mode = this.root_store.modules.smart_chart.is_contract_mode;
let i = this.getPositionIndexById(contract_id);
// check if position to be removed is out of range from the maximum amount rendered in drawer
if (this.positions.length > 4) i += 1;
this.positions.splice(i, 1);
const { is_contract_mode } = this.root_store.modules.smart_chart;
const contract_idx = this.getPositionIndexById(contract_id);

this.positions.splice(contract_idx, 1);

// check if contract is in view in contract_mode before removing contract details from chart
if (is_contract_mode && (this.root_store.modules.contract.contract_id === contract_id)) {
if (is_contract_mode && (+this.root_store.modules.contract.contract_id === +contract_id)) {
this.root_store.modules.contract.onCloseContract();
this.root_store.modules.trade.requestProposal();
}
Expand Down
Loading