Skip to content

Commit

Permalink
Merge pull request binary-com#55 from farhan-nurzi-deriv/WALL-608/sho…
Browse files Browse the repository at this point in the history
…w-deposit-options

fix: test failed because of livechatwidget
  • Loading branch information
suisin-deriv committed Jul 31, 2023
2 parents bffbc65 + be119f7 commit 64acaf5
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 62 deletions.
124 changes: 63 additions & 61 deletions packages/core/src/App/Components/Elements/LiveChat/use-livechat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,68 +39,70 @@ const useLiveChat = (has_cookie_account = false, active_loginid?: string) => {
}, []);

const liveChatSetup = (is_logged_in: boolean) => {
window.LiveChatWidget.init();
window.LiveChatWidget?.on('ready', () => {
let client_first_name = '';
let client_last_name = '';
const domain = /^(.)*deriv\.(com|me|be)$/gi.test(window.location.hostname)
? deriv_urls.DERIV_HOST_NAME
: 'binary.sx';
const client_information = Cookies.getJSON('client_information', {
domain,
});
const utm_data = Cookies.getJSON('utm_data', { domain });

const { utm_source, utm_medium, utm_campaign } = utm_data || {};

const { loginid, email, landing_company_shortcode, currency, residence, first_name, last_name } =
client_information || {};

client_first_name = first_name ?? ' ';
client_last_name = last_name ?? ' ';

/* the session variables are sent to CS team dashboard to notify user has logged in
and also acts as custom variables to trigger targeted engagement */
const session_variables = {
is_logged_in: !!is_logged_in,
loginid: loginid ?? ' ',
landing_company_shortcode: landing_company_shortcode ?? ' ',
currency: currency ?? ' ',
residence: residence ?? ' ',
email: email ?? ' ',
utm_source: utm_source ?? ' ',
utm_medium: utm_medium ?? ' ',
utm_campaign: utm_campaign ?? ' ',
};
window.LiveChatWidget?.call('set_session_variables', session_variables);

if (is_logged_in) {
// client logged in
// prepfill name and email
window.LiveChatWidget?.call('set_customer_email', session_variables.email);
window.LiveChatWidget?.call('set_customer_name', `${client_first_name} ${client_last_name}`);

// prefill name and email fields after chat has ended
if (window.LC_API?.on_chat_ended) {
window.LC_API.on_chat_ended = () => {
window.LiveChatWidget?.call('set_customer_email', session_variables.email);
window.LiveChatWidget?.call('set_customer_name', `${client_first_name} ${client_last_name}`);
};
}
} else {
// client not logged in
// clear name and email fields
window.LiveChatWidget?.call('set_customer_email', ' ');
window.LiveChatWidget?.call('set_customer_name', ' ');
// clear name and email fields after chat has ended
if (window.LC_API?.on_chat_ended) {
window.LC_API.on_chat_ended = () => {
window.LiveChatWidget?.call('set_customer_email', ' ');
window.LiveChatWidget?.call('set_customer_name', ' ');
};
if (window.LiveChatWidget) {
window.LiveChatWidget.init();
window.LiveChatWidget.on('ready', () => {
let client_first_name = '';
let client_last_name = '';
const domain = /^(.)*deriv\.(com|me|be)$/gi.test(window.location.hostname)
? deriv_urls.DERIV_HOST_NAME
: 'binary.sx';
const client_information = Cookies.getJSON('client_information', {
domain,
});
const utm_data = Cookies.getJSON('utm_data', { domain });

const { utm_source, utm_medium, utm_campaign } = utm_data || {};

const { loginid, email, landing_company_shortcode, currency, residence, first_name, last_name } =
client_information || {};

client_first_name = first_name ?? ' ';
client_last_name = last_name ?? ' ';

/* the session variables are sent to CS team dashboard to notify user has logged in
and also acts as custom variables to trigger targeted engagement */
const session_variables = {
is_logged_in: !!is_logged_in,
loginid: loginid ?? ' ',
landing_company_shortcode: landing_company_shortcode ?? ' ',
currency: currency ?? ' ',
residence: residence ?? ' ',
email: email ?? ' ',
utm_source: utm_source ?? ' ',
utm_medium: utm_medium ?? ' ',
utm_campaign: utm_campaign ?? ' ',
};
window.LiveChatWidget.call('set_session_variables', session_variables);

if (is_logged_in) {
// client logged in
// prepfill name and email
window.LiveChatWidget.call('set_customer_email', session_variables.email);
window.LiveChatWidget.call('set_customer_name', `${client_first_name} ${client_last_name}`);

// prefill name and email fields after chat has ended
if (window.LC_API?.on_chat_ended) {
window.LC_API.on_chat_ended = () => {
window.LiveChatWidget.call('set_customer_email', session_variables.email);
window.LiveChatWidget.call('set_customer_name', `${client_first_name} ${client_last_name}`);
};
}
} else {
// client not logged in
// clear name and email fields
window.LiveChatWidget.call('set_customer_email', ' ');
window.LiveChatWidget.call('set_customer_name', ' ');
// clear name and email fields after chat has ended
if (window.LC_API?.on_chat_ended) {
window.LC_API.on_chat_ended = () => {
window.LiveChatWidget.call('set_customer_email', ' ');
window.LiveChatWidget.call('set_customer_name', ' ');
};
}
}
}
});
});
}
};

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('<OneTimeDepositModal />', () => {
expect(screen.getByTestId('dt_initial_loader')).toBeInTheDocument();
});

it('should close modal when iframe if user unable to deposit because they have deposited', () => {
it('should close modal if user unable to deposit because they have deposited', () => {
const history = createBrowserHistory();
(useDepositLocked as jest.Mock).mockReturnValueOnce(true);
const wrapper = ({ children }: { children: JSX.Element }) => (
Expand Down

0 comments on commit 64acaf5

Please sign in to comment.