Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

Commit 0ffc502

Browse files
committed
Updated import method of @deriv/p2p
1 parent 2b01829 commit 0ffc502

File tree

1 file changed

+29
-27
lines changed
  • src/javascript/app/pages/cashier

1 file changed

+29
-27
lines changed

src/javascript/app/pages/cashier/dp2p.js

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,20 @@ const DP2P = (() => {
1010
const onLoad = () => {
1111
const is_svg = Client.get('landing_company_shortcode') === 'svg';
1212
if (is_svg) {
13-
import('@deriv/p2p').then((module) => {
14-
const el_dp2p_container = document.getElementById('binary-dp2p');
15-
const shadowed_el_dp2p = el_dp2p_container.attachShadow({ mode: 'closed' });
13+
require.ensure([], (require) => renderP2P(require('@deriv/p2p')), 'dp2p');
14+
} else {
15+
document.getElementById('message_cashier_unavailable').setVisibility(1);
16+
}
17+
};
1618

17-
const el_main_css = document.createElement('style');
18-
// These are styles that are to be injected into the Shadow DOM, so they are in JS and not stylesheets
19-
// They are to be applied to the `:host` selector
20-
el_main_css.innerHTML = `
19+
const renderP2P = (module) => {
20+
const el_dp2p_container = document.getElementById('binary-dp2p');
21+
const shadowed_el_dp2p = el_dp2p_container.attachShadow({ mode: 'closed' });
22+
23+
const el_main_css = document.createElement('style');
24+
// These are styles that are to be injected into the Shadow DOM, so they are in JS and not stylesheets
25+
// They are to be applied to the `:host` selector
26+
el_main_css.innerHTML = `
2127
@import url(${urlForStatic('css/p2p.min.css')});
2228
:host {
2329
--hem:10px;
@@ -59,29 +65,25 @@ const DP2P = (() => {
5965
cursor: pointer;
6066
}
6167
`;
62-
el_main_css.rel = 'stylesheet';
68+
el_main_css.rel = 'stylesheet';
6369

64-
const dp2p_props = {
65-
className : 'theme--light',
66-
websocket_api: BinarySocket,
67-
lang : getLanguage(),
68-
client : {
69-
currency : Client.get('currency'),
70-
is_virtual: Client.get('is_virtual'),
71-
},
72-
};
70+
const dp2p_props = {
71+
className : 'theme--light',
72+
websocket_api: BinarySocket,
73+
lang : getLanguage(),
74+
client : {
75+
currency : Client.get('currency'),
76+
is_virtual: Client.get('is_virtual'),
77+
},
78+
};
7379

74-
ReactDOM.render(
75-
// eslint-disable-next-line no-console
76-
React.createElement(module.default, dp2p_props),
77-
shadowed_el_dp2p
78-
);
80+
ReactDOM.render(
81+
// eslint-disable-next-line no-console
82+
React.createElement(module, dp2p_props),
83+
shadowed_el_dp2p
84+
);
7985

80-
shadowed_el_dp2p.prepend(el_main_css);
81-
});
82-
} else {
83-
document.getElementById('message_cashier_unavailable').setVisibility(1);
84-
}
86+
shadowed_el_dp2p.prepend(el_main_css);
8587
};
8688

8789
const onUnload = () => {

0 commit comments

Comments
 (0)