1
1
/* eslint-disable no-console */
2
2
import React , { useEffect , useState } from 'react' ;
3
3
import ReactDOM from 'react-dom' ;
4
- import parse from 'html-react-parser' ;
5
4
import { SegmentedControlSingleChoice } from '@deriv-com/quill-ui' ;
6
- import { contractExplanationData } from './explanation_data.js ' ;
5
+ import { Explanation } from './explanation.jsx ' ;
7
6
import { getElementById } from '../../../_common/common_functions' ;
8
7
import WebtraderChart from '../trade/charts/webtrader_chart' ;
9
- import { useContractChange , useMarketChange } from '../../hooks/events' ;
10
- import Defaults , { PARAM_NAMES } from '../trade/defaults' ;
11
- import Language from '../../../_common/language' ;
12
- import Url from '../../../_common/url' ;
13
- import { localize } from '../../../_common/localize.js' ;
14
-
15
- const Explanation = ( ) => {
16
- const language = Language . get ( ) ;
17
-
18
- const [ formName , setFormName ] = useState ( '' ) ;
19
-
20
- const hasContractChanges = useContractChange ( ) ;
21
-
22
- useEffect ( ( ) => {
23
- const contractObject = {
24
- matchdiff : 'digits' ,
25
- callputequal : 'risefall' ,
26
- callput : 'higherlower' ,
27
- } ;
28
-
29
- const newFormName = Defaults . get ( PARAM_NAMES . FORM_NAME ) || 'risefall' ;
30
- const finalFormName = contractObject [ newFormName ] || newFormName ;
31
-
32
- setFormName ( finalFormName ) ;
33
-
34
- } , [ hasContractChanges ] ) ;
35
-
36
- const image_path = Url . urlForStatic (
37
- `images/pages/trade-explanation/${ language } /`
38
- ) ;
39
-
40
- const images = {
41
- risefall : {
42
- image1 : 'rises.svg' ,
43
- image2 : 'falls.svg' ,
44
- } ,
45
- higherlower : {
46
- image1 : 'higher.svg' ,
47
- image2 : 'lower.svg' ,
48
- } ,
49
- touchnotouch : {
50
- image1 : 'touch.svg' ,
51
- image2 : 'no-touch.svg' ,
52
- } ,
53
- endsinout : {
54
- image1 : 'ends-between.svg' ,
55
- image2 : 'ends-outside.svg' ,
56
- } ,
57
- staysinout : {
58
- image1 : 'stays-between.svg' ,
59
- image2 : 'goes-outside.svg' ,
60
- } ,
61
- digits : {
62
- image1 : 'matches.svg' ,
63
- image2 : 'differs.svg' ,
64
- } ,
65
- evenodd : {
66
- image1 : 'even.svg' ,
67
- image2 : 'odd.svg' ,
68
- } ,
69
- overunder : {
70
- image1 : 'over.svg' ,
71
- image2 : 'under.svg' ,
72
- } ,
73
- lookbackhigh : {
74
- image1 : 'high-close.svg' ,
75
- } ,
76
- lookbacklow : {
77
- image1 : 'close-low.svg' ,
78
- } ,
79
- lookbackhighlow : {
80
- image1 : 'high-low.svg' ,
81
- } ,
82
- reset : {
83
- image1 : 'reset-call.svg' ,
84
- image2 : 'reset-put.svg' ,
85
- } ,
86
- highlowticks : {
87
- image1 : 'high-tick.svg' ,
88
- image2 : 'low-tick.svg' ,
89
- } ,
90
- runs : {
91
- image1 : 'only-ups.svg' ,
92
- image2 : 'only-downs.svg' ,
93
- } ,
94
- } ;
95
-
96
- if ( formName ) {
97
- return (
98
- < div className = 'tab-explanation' >
99
- { /* ========== Winning ========== */ }
100
- < div id = 'explanation_winning' >
101
- < div id = { `winning_${ formName } ` } >
102
- < h3 > { localize ( 'Winning the contract' ) } </ h3 >
103
- { contractExplanationData . winning [ formName ] . content . map (
104
- ( data , idx ) => (
105
- < p key = { idx } > { parse ( data ) } </ p >
106
- )
107
- ) }
108
- </ div >
109
- </ div >
110
-
111
- { /* ========== Image ========== */ }
112
- { images [ formName ] && (
113
- < div id = 'explanation_image' >
114
- < div className = 'gr-row' >
115
- < div className = 'gr-2 hide-mobile' />
116
- < div
117
- className = 'gr-4 gr-12-m padding-right'
118
- style = { { margin : 'auto' } }
119
- >
120
- < img
121
- id = 'explanation_image_1'
122
- className = 'responsive'
123
- src = { `${ image_path } ${ images [ formName ] . image1 } ?${ process . env . BUILD_HASH } ` }
124
- />
125
- </ div >
126
- < div className = 'gr-4 gr-12-m padding-left' >
127
- < img
128
- id = 'explanation_image_2'
129
- className = 'responsive'
130
- src = { `${ image_path } ${ images [ formName ] . image2 } ?${ process . env . BUILD_HASH } ` }
131
- />
132
- </ div >
133
- < div className = 'gr-2 hide-mobile' />
134
- </ div >
135
- </ div >
136
- ) }
137
-
138
- { /* ========== Explain ========== */ }
139
- < div id = 'explanation_explain' className = 'gr-child' >
140
- < div id = { `explain_${ formName } ` } >
141
- < h3 > { contractExplanationData . explain [ formName ] . title } </ h3 >
142
- { contractExplanationData . explain [ formName ] . content . map (
143
- ( data , idx ) => (
144
- < p key = { idx } > { parse ( data ) } </ p >
145
- )
146
- ) }
147
- { contractExplanationData . explain [ formName ] . title_secondary && (
148
- < h3 className = 'secondary-title' >
149
- { contractExplanationData . explain [ formName ] . title_secondary }
150
- </ h3 >
151
- ) }
152
- { contractExplanationData . explain [ formName ] . content_secondary &&
153
- contractExplanationData . explain [ formName ] . content_secondary . map (
154
- ( data , idx ) => < p key = { idx } > { parse ( data ) } </ p >
155
- ) }
156
- </ div >
157
- </ div >
158
-
159
- { /* ========== Note ========== */ }
160
- { contractExplanationData . note [ formName ] && (
161
- < p className = 'hint' >
162
- < strong > { localize ( 'Note' ) } : </ strong >
163
- { contractExplanationData . note [ formName ] . content . map ( ( data , idx ) => (
164
- < span key = { idx } > { parse ( data ) } </ span >
165
- ) ) }
166
- </ p >
167
- ) }
168
- </ div >
169
- ) ;
170
- }
171
-
172
- return < > </ > ;
173
- } ;
8
+ import { useMarketChange } from '../../hooks/events' ;
174
9
175
10
const Graph = ( ) => (
176
- < div id = 'tab_graph' >
11
+ < div id = 'tab_graph' className = 'chart-section' >
177
12
< p className = 'error-msg' id = 'chart-error' />
178
13
< div id = 'trade_live_chart' >
179
14
< div id = 'webtrader_chart' />
@@ -186,6 +21,13 @@ const BottomTabs = () => {
186
21
const [ selectedTab , setSelectedTab ] = useState ( 1 ) ;
187
22
const [ showGraph , setShowGraph ] = useState ( true ) ;
188
23
24
+ useEffect ( ( ) => {
25
+ const savedTab = sessionStorage . getItem ( 'currentAnalysisTab' ) ;
26
+ if ( savedTab !== null ) {
27
+ setSelectedTab ( Number ( savedTab ) ) ;
28
+ }
29
+ } , [ ] ) ;
30
+
189
31
const renderGraph = ( callback ) => {
190
32
setTimeout ( ( ) => {
191
33
WebtraderChart . cleanupChart ( ) ;
@@ -210,6 +52,7 @@ const BottomTabs = () => {
210
52
} , [ hasMarketChange ] ) ;
211
53
212
54
useEffect ( ( ) => {
55
+ sessionStorage . setItem ( 'currentAnalysisTab' , selectedTab ) ;
213
56
if ( selectedTab === 0 ) {
214
57
renderGraph ( ) ;
215
58
}
0 commit comments