react-native-seel-widget 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/assets/images/accredited.png +0 -0
- package/src/assets/images/background_image.jpg +0 -0
- package/src/assets/images/button_close.png +0 -0
- package/src/assets/images/button_close_background.png +0 -0
- package/src/assets/images/checkbox_normal.png +0 -0
- package/src/assets/images/checkbox_selected.png +0 -0
- package/src/assets/images/close_white.png +0 -0
- package/src/assets/images/ic_launcher.png +0 -0
- package/src/assets/images/icon_arrow_left.png +0 -0
- package/src/assets/images/icon_bg_select.png +0 -0
- package/src/assets/images/icon_check_selected_black.png +0 -0
- package/src/assets/images/icon_select.png +0 -0
- package/src/assets/images/info_black.png +0 -0
- package/src/assets/images/seel_icon.png +0 -0
- package/src/assets/images/seel_logo.png +0 -0
- package/src/assets/images/seel_word.png +0 -0
- package/src/assets/images/tick_small_minor.png +0 -0
- package/src/constants/key_value.ts +48 -0
- package/src/constants/network_request_statue_enum.ts +13 -0
- package/src/core/SeelWidgetSDK.ts +103 -0
- package/src/dto/EventsRequest.ts +71 -0
- package/src/dto/EventsResponse.ts +13 -0
- package/src/dto/IEvents.ts +51 -0
- package/src/dto/IQuotes.ts +36 -0
- package/src/dto/IQuotesRequest.ts +220 -0
- package/src/dto/IQuotesResponse.ts +111 -0
- package/src/network/request.ts +214 -0
- package/src/ui/coverage-info-footer.tsx +186 -0
- package/src/ui/gradient-animation-text.tsx +185 -0
- package/src/ui/gradient-animation-view.tsx +150 -0
- package/src/ui/index.ts +4 -0
- package/src/ui/seel-wfp-info-view.tsx +351 -0
- package/src/ui/seel-wfp-title-view.tsx +388 -0
- package/src/ui/seel-wfp-widget.tsx +270 -0
- package/src/utils/format_util.ts +117 -0
- package/src/utils/http_util.ts +30 -0
- package/src/utils/storage_util.ts +42 -0
- package/src/utils/uuid.ts +18 -0
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Image,
|
|
3
|
+
Platform,
|
|
4
|
+
StyleSheet,
|
|
5
|
+
Text,
|
|
6
|
+
TouchableOpacity,
|
|
7
|
+
View,
|
|
8
|
+
useColorScheme,
|
|
9
|
+
} from 'react-native';
|
|
10
|
+
import type { TextStyle, ViewStyle } from 'react-native';
|
|
11
|
+
import KeyValue from '../constants/key_value';
|
|
12
|
+
import GradientAnimationText, {
|
|
13
|
+
type GradientAnimationTextRef,
|
|
14
|
+
} from './gradient-animation-text';
|
|
15
|
+
import { useRef } from 'react';
|
|
16
|
+
import { NetworkRequestStatueEnum } from '../constants/network_request_statue_enum';
|
|
17
|
+
|
|
18
|
+
export interface SeelWFPTitleViewProps {
|
|
19
|
+
status: string;
|
|
20
|
+
/**
|
|
21
|
+
* Title text to display
|
|
22
|
+
*/
|
|
23
|
+
title?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Price text to display
|
|
26
|
+
*/
|
|
27
|
+
price?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Custom container style
|
|
30
|
+
*/
|
|
31
|
+
containerStyle?: ViewStyle;
|
|
32
|
+
/**
|
|
33
|
+
* Custom container style for dark mode
|
|
34
|
+
*/
|
|
35
|
+
darkContainerStyle?: ViewStyle;
|
|
36
|
+
/**
|
|
37
|
+
* Custom container style for light mode
|
|
38
|
+
*/
|
|
39
|
+
lightContainerStyle?: ViewStyle;
|
|
40
|
+
/**
|
|
41
|
+
* Custom title text style
|
|
42
|
+
*/
|
|
43
|
+
titleStyle?: TextStyle;
|
|
44
|
+
/**
|
|
45
|
+
* Custom title text style for dark mode
|
|
46
|
+
*/
|
|
47
|
+
darkTitleStyle?: TextStyle;
|
|
48
|
+
/**
|
|
49
|
+
* Custom title text style for light mode
|
|
50
|
+
*/
|
|
51
|
+
lightTitleStyle?: TextStyle;
|
|
52
|
+
/**
|
|
53
|
+
* Custom price text style
|
|
54
|
+
*/
|
|
55
|
+
priceStyle?: TextStyle;
|
|
56
|
+
/**
|
|
57
|
+
* Custom price text style for dark mode
|
|
58
|
+
*/
|
|
59
|
+
darkPriceStyle?: TextStyle;
|
|
60
|
+
/**
|
|
61
|
+
* Custom price text style for light mode
|
|
62
|
+
*/
|
|
63
|
+
lightPriceStyle?: TextStyle;
|
|
64
|
+
/**
|
|
65
|
+
* Callback function when title is pressed
|
|
66
|
+
* @param route - Route name or path to navigate to
|
|
67
|
+
*/
|
|
68
|
+
onClickInfoIcon?: (route?: string) => void;
|
|
69
|
+
/**
|
|
70
|
+
* Route name or path for navigation (optional, can be used with onClickInfoIcon)
|
|
71
|
+
*/
|
|
72
|
+
route?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Whether the title is pressable (default: true if onClickInfoIcon is provided)
|
|
75
|
+
*/
|
|
76
|
+
pressable?: boolean;
|
|
77
|
+
optedIn: boolean;
|
|
78
|
+
dictionary: any;
|
|
79
|
+
loadingStatue: NetworkRequestStatueEnum;
|
|
80
|
+
onChangeOptedInValue: (optedIn: boolean) => void;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export default function SeelWFPTitleView({
|
|
84
|
+
status,
|
|
85
|
+
title,
|
|
86
|
+
price,
|
|
87
|
+
containerStyle,
|
|
88
|
+
lightContainerStyle,
|
|
89
|
+
darkContainerStyle,
|
|
90
|
+
titleStyle,
|
|
91
|
+
lightTitleStyle,
|
|
92
|
+
darkTitleStyle,
|
|
93
|
+
priceStyle,
|
|
94
|
+
lightPriceStyle,
|
|
95
|
+
darkPriceStyle,
|
|
96
|
+
optedIn = false,
|
|
97
|
+
dictionary = {},
|
|
98
|
+
loadingStatue = NetworkRequestStatueEnum.Idle,
|
|
99
|
+
onClickInfoIcon,
|
|
100
|
+
onChangeOptedInValue = (_: boolean) => {},
|
|
101
|
+
}: SeelWFPTitleViewProps) {
|
|
102
|
+
const gradientViewRef = useRef<GradientAnimationTextRef>(null);
|
|
103
|
+
|
|
104
|
+
const colorScheme = useColorScheme();
|
|
105
|
+
const isDark = false && colorScheme === 'dark';
|
|
106
|
+
|
|
107
|
+
const _constainerStyle = [
|
|
108
|
+
defaultStyles.container,
|
|
109
|
+
containerStyle,
|
|
110
|
+
isDark
|
|
111
|
+
? defaultStyles.darkContainerStyle
|
|
112
|
+
: defaultStyles.lightContainerStyle,
|
|
113
|
+
isDark ? darkContainerStyle : lightContainerStyle,
|
|
114
|
+
];
|
|
115
|
+
|
|
116
|
+
const _titleStyle = [
|
|
117
|
+
defaultStyles.title,
|
|
118
|
+
titleStyle,
|
|
119
|
+
isDark ? defaultStyles.darkTitleStyle : defaultStyles.lightTitleStyle,
|
|
120
|
+
isDark ? darkTitleStyle : lightTitleStyle,
|
|
121
|
+
];
|
|
122
|
+
|
|
123
|
+
const _priceStyle = [
|
|
124
|
+
defaultStyles.price,
|
|
125
|
+
priceStyle,
|
|
126
|
+
isDark ? defaultStyles.darkPriceStyle : defaultStyles.lightPriceStyle,
|
|
127
|
+
isDark ? darkPriceStyle : lightPriceStyle,
|
|
128
|
+
];
|
|
129
|
+
|
|
130
|
+
const _poweredByText = [
|
|
131
|
+
defaultStyles.poweredByText,
|
|
132
|
+
isDark ? defaultStyles.dartPoweredByText : defaultStyles.lightPoweredByText,
|
|
133
|
+
];
|
|
134
|
+
|
|
135
|
+
const renderInfoButton = () => {
|
|
136
|
+
return (
|
|
137
|
+
<TouchableOpacity
|
|
138
|
+
style={defaultStyles.infoIconButton}
|
|
139
|
+
hitSlop={{ top: 12, right: 12, bottom: 12, left: 12 }}
|
|
140
|
+
onPress={() => {
|
|
141
|
+
console.log('Push To Info Page');
|
|
142
|
+
if (!!onClickInfoIcon && typeof onClickInfoIcon === 'function') {
|
|
143
|
+
onClickInfoIcon();
|
|
144
|
+
}
|
|
145
|
+
}}
|
|
146
|
+
>
|
|
147
|
+
<Image
|
|
148
|
+
style={defaultStyles.infoIcon}
|
|
149
|
+
source={require('../assets/images/info_black.png')}
|
|
150
|
+
/>
|
|
151
|
+
</TouchableOpacity>
|
|
152
|
+
);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const paddingTop = 4;
|
|
156
|
+
const paddingBottom = 4;
|
|
157
|
+
const paddingLeft = 22 + 6;
|
|
158
|
+
const alignItems = 'flex-start';
|
|
159
|
+
const renderTickView = (value: string) => {
|
|
160
|
+
return (
|
|
161
|
+
<View
|
|
162
|
+
style={[
|
|
163
|
+
defaultStyles.rowContainer,
|
|
164
|
+
{ paddingTop, paddingBottom, paddingLeft, alignItems },
|
|
165
|
+
]}
|
|
166
|
+
>
|
|
167
|
+
<View style={defaultStyles.tickIconContainer}>
|
|
168
|
+
<Image
|
|
169
|
+
style={defaultStyles.tickIcon}
|
|
170
|
+
source={require('../assets/images/tick_small_minor.png')}
|
|
171
|
+
/>
|
|
172
|
+
</View>
|
|
173
|
+
<Text style={defaultStyles.tickText}>{value}</Text>
|
|
174
|
+
</View>
|
|
175
|
+
);
|
|
176
|
+
};
|
|
177
|
+
const gradientContainerStyle = {
|
|
178
|
+
marginLeft: 4,
|
|
179
|
+
width: 60,
|
|
180
|
+
height: 18,
|
|
181
|
+
borderRadius: 4,
|
|
182
|
+
backgroundColor: '#e3e3e3',
|
|
183
|
+
};
|
|
184
|
+
return (
|
|
185
|
+
<View style={_constainerStyle}>
|
|
186
|
+
<View style={defaultStyles.rowContainer}>
|
|
187
|
+
<TouchableOpacity
|
|
188
|
+
hitSlop={{ top: 8, right: 8, bottom: 8, left: 8 }}
|
|
189
|
+
onPress={() => {
|
|
190
|
+
onChangeOptedInValue(!optedIn);
|
|
191
|
+
}}
|
|
192
|
+
>
|
|
193
|
+
<Image
|
|
194
|
+
source={
|
|
195
|
+
optedIn
|
|
196
|
+
? require('../assets/images/checkbox_selected.png')
|
|
197
|
+
: require('../assets/images/checkbox_normal.png')
|
|
198
|
+
}
|
|
199
|
+
style={defaultStyles.checkboxIcon}
|
|
200
|
+
/>
|
|
201
|
+
</TouchableOpacity>
|
|
202
|
+
<View style={defaultStyles.middleContainer}>
|
|
203
|
+
<View style={defaultStyles.titleContainer}>
|
|
204
|
+
<Text style={[_titleStyle]} adjustsFontSizeToFit>
|
|
205
|
+
{title}
|
|
206
|
+
</Text>
|
|
207
|
+
<Text style={_priceStyle} adjustsFontSizeToFit>
|
|
208
|
+
for
|
|
209
|
+
</Text>
|
|
210
|
+
{/* eslint-disable-next-line no-bitwise */}
|
|
211
|
+
{(loadingStatue & NetworkRequestStatueEnum.Loading) === 0 ? (
|
|
212
|
+
<Text style={_priceStyle} adjustsFontSizeToFit>
|
|
213
|
+
{price}
|
|
214
|
+
</Text>
|
|
215
|
+
) : (
|
|
216
|
+
<View>
|
|
217
|
+
<GradientAnimationText
|
|
218
|
+
ref={gradientViewRef}
|
|
219
|
+
containerStyle={gradientContainerStyle}
|
|
220
|
+
animationDuration={5000}
|
|
221
|
+
/>
|
|
222
|
+
</View>
|
|
223
|
+
)}
|
|
224
|
+
{renderInfoButton()}
|
|
225
|
+
</View>
|
|
226
|
+
</View>
|
|
227
|
+
</View>
|
|
228
|
+
<View style={[defaultStyles.columnContainer]}>
|
|
229
|
+
{status === 'accepted' &&
|
|
230
|
+
renderTickView(dictionary[KeyValue.wfp_subtitle] ?? '')}
|
|
231
|
+
{status === 'accepted' &&
|
|
232
|
+
renderTickView(dictionary[KeyValue.wfp_description] ?? '')}
|
|
233
|
+
{status === 'rejected' && (
|
|
234
|
+
<View
|
|
235
|
+
style={[
|
|
236
|
+
defaultStyles.rowContainer,
|
|
237
|
+
{ paddingTop, paddingBottom, paddingLeft, alignItems },
|
|
238
|
+
]}
|
|
239
|
+
>
|
|
240
|
+
<Text style={defaultStyles.tickText}>
|
|
241
|
+
{dictionary[KeyValue.ineligible_title] ?? ''}
|
|
242
|
+
</Text>
|
|
243
|
+
</View>
|
|
244
|
+
)}
|
|
245
|
+
</View>
|
|
246
|
+
<View
|
|
247
|
+
style={[
|
|
248
|
+
defaultStyles.rowContainer,
|
|
249
|
+
{ paddingTop, paddingLeft, alignItems },
|
|
250
|
+
]}
|
|
251
|
+
>
|
|
252
|
+
<View style={defaultStyles.poweredByContainer}>
|
|
253
|
+
<Text style={[_poweredByText]}>
|
|
254
|
+
{dictionary[KeyValue.powered_by] ?? 'Powered by'}
|
|
255
|
+
</Text>
|
|
256
|
+
<Image
|
|
257
|
+
style={defaultStyles.seelWordIcon}
|
|
258
|
+
source={require('../assets/images/seel_word.png')}
|
|
259
|
+
/>
|
|
260
|
+
</View>
|
|
261
|
+
</View>
|
|
262
|
+
</View>
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const defaultStyles = StyleSheet.create({
|
|
267
|
+
container: {
|
|
268
|
+
width: '100%',
|
|
269
|
+
flexDirection: 'column',
|
|
270
|
+
alignItems: 'center',
|
|
271
|
+
padding: 24,
|
|
272
|
+
},
|
|
273
|
+
lightContainerStyle: {
|
|
274
|
+
backgroundColor: 'white',
|
|
275
|
+
},
|
|
276
|
+
darkContainerStyle: {
|
|
277
|
+
backgroundColor: '#121212',
|
|
278
|
+
},
|
|
279
|
+
columnContainer: {
|
|
280
|
+
width: '100%',
|
|
281
|
+
flexDirection: 'column',
|
|
282
|
+
},
|
|
283
|
+
rowContainer: {
|
|
284
|
+
width: '100%',
|
|
285
|
+
flexDirection: 'row',
|
|
286
|
+
alignItems: 'center',
|
|
287
|
+
padding: 4,
|
|
288
|
+
},
|
|
289
|
+
checkboxContainer: {
|
|
290
|
+
width: 20,
|
|
291
|
+
height: 20,
|
|
292
|
+
justifyContent: 'center',
|
|
293
|
+
alignItems: 'center',
|
|
294
|
+
},
|
|
295
|
+
checkboxIcon: {
|
|
296
|
+
width: 16.5,
|
|
297
|
+
height: 16.5,
|
|
298
|
+
},
|
|
299
|
+
seelIcon: {
|
|
300
|
+
width: 20,
|
|
301
|
+
height: 20,
|
|
302
|
+
},
|
|
303
|
+
middleContainer: {
|
|
304
|
+
flex: 1,
|
|
305
|
+
flexDirection: 'column',
|
|
306
|
+
paddingLeft: 6,
|
|
307
|
+
paddingRight: 6,
|
|
308
|
+
},
|
|
309
|
+
titleContainer: {
|
|
310
|
+
flexDirection: 'row',
|
|
311
|
+
alignItems: 'center',
|
|
312
|
+
},
|
|
313
|
+
title: {
|
|
314
|
+
color: '#000000',
|
|
315
|
+
fontFamily: Platform.select({
|
|
316
|
+
ios: 'Open Sans',
|
|
317
|
+
}),
|
|
318
|
+
fontSize: 15,
|
|
319
|
+
fontWeight: 700,
|
|
320
|
+
lineHeight: 20,
|
|
321
|
+
},
|
|
322
|
+
lightTitleStyle: {
|
|
323
|
+
color: '#000000',
|
|
324
|
+
},
|
|
325
|
+
darkTitleStyle: {
|
|
326
|
+
color: '#ffffff',
|
|
327
|
+
},
|
|
328
|
+
price: {
|
|
329
|
+
marginLeft: 4,
|
|
330
|
+
fontSize: 14,
|
|
331
|
+
lineHeight: 20,
|
|
332
|
+
fontWeight: 'regular',
|
|
333
|
+
},
|
|
334
|
+
lightPriceStyle: {
|
|
335
|
+
color: '#000000',
|
|
336
|
+
},
|
|
337
|
+
darkPriceStyle: {
|
|
338
|
+
color: '#ffffff',
|
|
339
|
+
},
|
|
340
|
+
infoIconButton: {
|
|
341
|
+
marginLeft: 4,
|
|
342
|
+
justifyContent: 'center',
|
|
343
|
+
alignItems: 'center',
|
|
344
|
+
},
|
|
345
|
+
infoIcon: {
|
|
346
|
+
width: 12,
|
|
347
|
+
height: 12,
|
|
348
|
+
},
|
|
349
|
+
poweredByContainer: {
|
|
350
|
+
flexDirection: 'row',
|
|
351
|
+
alignItems: 'center',
|
|
352
|
+
},
|
|
353
|
+
poweredByText: {
|
|
354
|
+
color: '#565656',
|
|
355
|
+
fontSize: 10,
|
|
356
|
+
fontWeight: '600',
|
|
357
|
+
lineHeight: 16,
|
|
358
|
+
},
|
|
359
|
+
lightPoweredByText: {
|
|
360
|
+
color: '#565656',
|
|
361
|
+
},
|
|
362
|
+
dartPoweredByText: {
|
|
363
|
+
color: 'white',
|
|
364
|
+
},
|
|
365
|
+
tickIconContainer: {
|
|
366
|
+
width: 18,
|
|
367
|
+
height: 18,
|
|
368
|
+
justifyContent: 'center',
|
|
369
|
+
alignItems: 'center',
|
|
370
|
+
},
|
|
371
|
+
tickIcon: {
|
|
372
|
+
width: 15,
|
|
373
|
+
height: 15,
|
|
374
|
+
},
|
|
375
|
+
tickText: {
|
|
376
|
+
color: '#191919',
|
|
377
|
+
fontFamily: Platform.select({
|
|
378
|
+
ios: 'Inter',
|
|
379
|
+
}),
|
|
380
|
+
fontSize: 11,
|
|
381
|
+
fontWeight: 300,
|
|
382
|
+
lineHeight: 18,
|
|
383
|
+
},
|
|
384
|
+
seelWordIcon: {
|
|
385
|
+
width: 32,
|
|
386
|
+
height: 16,
|
|
387
|
+
},
|
|
388
|
+
});
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { forwardRef, useEffect, useImperativeHandle, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Modal,
|
|
4
|
+
Platform,
|
|
5
|
+
StyleSheet,
|
|
6
|
+
Text,
|
|
7
|
+
TouchableOpacity,
|
|
8
|
+
View,
|
|
9
|
+
} from 'react-native';
|
|
10
|
+
import SeelWFPTitleView from './seel-wfp-title-view';
|
|
11
|
+
import SeelWFPInfoView, { type Domain } from './seel-wfp-info-view';
|
|
12
|
+
import { createQuote } from '../utils/http_util';
|
|
13
|
+
import { writeOptedIn } from '../utils/storage_util';
|
|
14
|
+
import type { IQuotesRequest } from '../dto/IQuotesRequest';
|
|
15
|
+
import KeyValue from '../constants/key_value';
|
|
16
|
+
import type IQuotesResponse from '../dto/IQuotesResponse';
|
|
17
|
+
import { moneyFormat } from '../utils/format_util';
|
|
18
|
+
import { NetworkRequestStatueEnum } from '../constants/network_request_statue_enum';
|
|
19
|
+
|
|
20
|
+
export interface SeelWFPWidgetRef {
|
|
21
|
+
setup(quote: IQuotesRequest): void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface SeelWFPWidgetProps {
|
|
25
|
+
domain: Domain;
|
|
26
|
+
onChangeValue: ({
|
|
27
|
+
optedIn,
|
|
28
|
+
quotesResponse,
|
|
29
|
+
}: {
|
|
30
|
+
optedIn: boolean;
|
|
31
|
+
quotesResponse?: IQuotesResponse;
|
|
32
|
+
}) => void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const SeelWFPWidget = (
|
|
36
|
+
{
|
|
37
|
+
domain = '',
|
|
38
|
+
onChangeValue = ({ optedIn, quotesResponse }) => {
|
|
39
|
+
console.log(optedIn, quotesResponse);
|
|
40
|
+
},
|
|
41
|
+
}: SeelWFPWidgetProps,
|
|
42
|
+
ref: any
|
|
43
|
+
) => {
|
|
44
|
+
const [quotesResponse, setQuotesResponse] = useState<IQuotesResponse>();
|
|
45
|
+
const [termsUrl, setTermsUrl] = useState('');
|
|
46
|
+
const [privacyPolicyUrl, setPrivacyPolicyUrl] = useState('');
|
|
47
|
+
const [optedIn, setOptedIn] = useState(false);
|
|
48
|
+
const [visible, setVisible] = useState(false);
|
|
49
|
+
const [modalVisible, setModalVisible] = useState(false);
|
|
50
|
+
const [widgetTitle, setWidgetTitle] = useState('');
|
|
51
|
+
const [dictionary, setDictionary] = useState<any>({});
|
|
52
|
+
const [price, setPrice] = useState('');
|
|
53
|
+
const [status, setStatus] = useState('');
|
|
54
|
+
const [loadingStatue, setLoadingStatus] = useState<NetworkRequestStatueEnum>(
|
|
55
|
+
NetworkRequestStatueEnum.Idle
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
useImperativeHandle(
|
|
59
|
+
ref,
|
|
60
|
+
() => ({
|
|
61
|
+
setup(quote: IQuotesRequest) {
|
|
62
|
+
fetchNetworkData(quote);
|
|
63
|
+
},
|
|
64
|
+
}),
|
|
65
|
+
[]
|
|
66
|
+
);
|
|
67
|
+
async function fetchNetworkData(quote: IQuotesRequest) {
|
|
68
|
+
try {
|
|
69
|
+
setLoadingStatus(NetworkRequestStatueEnum.Loading);
|
|
70
|
+
const response = await createQuote(quote);
|
|
71
|
+
setLoadingStatus(NetworkRequestStatueEnum.Success);
|
|
72
|
+
setQuotesResponse(response);
|
|
73
|
+
let _status = response.status ?? '';
|
|
74
|
+
// _status = 'rejected';
|
|
75
|
+
setStatus(_status);
|
|
76
|
+
|
|
77
|
+
setOptedIn(_status === 'accepted' && response.is_default_on);
|
|
78
|
+
|
|
79
|
+
if (response.status === 'accepted') {
|
|
80
|
+
const extraInfo = response.extra_info ?? {};
|
|
81
|
+
const currency: string = response.currency;
|
|
82
|
+
const _title: string = extraInfo?.widget_title ?? '';
|
|
83
|
+
const _price: string = moneyFormat(
|
|
84
|
+
response.price?.toString(),
|
|
85
|
+
currency,
|
|
86
|
+
{}
|
|
87
|
+
);
|
|
88
|
+
const dict: any = {};
|
|
89
|
+
try {
|
|
90
|
+
(response.extra_info?.i18n?.texts ?? []).forEach((kv: any) => {
|
|
91
|
+
if (kv.key === KeyValue.wfp_title) {
|
|
92
|
+
dict[kv.key] = kv.value
|
|
93
|
+
.toString()
|
|
94
|
+
.replace('{{title}}', _title)
|
|
95
|
+
.replace('{{price}}', _price);
|
|
96
|
+
} else if (kv.key === KeyValue.powered_by) {
|
|
97
|
+
dict[kv.key] = kv.value.toString().replace('{{seel}}', '');
|
|
98
|
+
} else if (kv.key === KeyValue.pricing_message) {
|
|
99
|
+
dict[kv.key] = kv.value.toString().replace('{{price}}', _price);
|
|
100
|
+
} else {
|
|
101
|
+
dict[kv.key] = kv.value;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
} catch (error) {
|
|
105
|
+
console.warn('error:', error);
|
|
106
|
+
}
|
|
107
|
+
setDictionary(dict);
|
|
108
|
+
setPrice(_price);
|
|
109
|
+
setTermsUrl(response.extra_info?.terms_url ?? '');
|
|
110
|
+
setPrivacyPolicyUrl(response.extra_info?.privacy_policy_url ?? '');
|
|
111
|
+
setWidgetTitle(
|
|
112
|
+
(extraInfo.widget_title && extraInfo.widget_title) || ''
|
|
113
|
+
);
|
|
114
|
+
setVisible(true);
|
|
115
|
+
} else {
|
|
116
|
+
setModalVisible(false);
|
|
117
|
+
setVisible(false);
|
|
118
|
+
}
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.warn(error);
|
|
121
|
+
setLoadingStatus(NetworkRequestStatueEnum.Failed);
|
|
122
|
+
setModalVisible(false);
|
|
123
|
+
setVisible(false);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// useEffect(() => {
|
|
128
|
+
// fetchNetworkData();
|
|
129
|
+
// }, [optedIn]);
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
onChangeValue({ optedIn, quotesResponse });
|
|
132
|
+
}, [onChangeValue, optedIn, quotesResponse]);
|
|
133
|
+
|
|
134
|
+
const renderIneligibleModalView = () => {
|
|
135
|
+
const margin = 12;
|
|
136
|
+
return (
|
|
137
|
+
<TouchableOpacity
|
|
138
|
+
style={[defaultStyles.ineligibleModalViewContainer]}
|
|
139
|
+
onPress={() => {
|
|
140
|
+
setModalVisible(false);
|
|
141
|
+
}}
|
|
142
|
+
>
|
|
143
|
+
<View style={[defaultStyles.ineligibleModalView]}>
|
|
144
|
+
<Text
|
|
145
|
+
style={[defaultStyles.ineligibleText, { marginBottom: margin }]}
|
|
146
|
+
>
|
|
147
|
+
{dictionary[KeyValue.ineligible_main_message] || ''}
|
|
148
|
+
</Text>
|
|
149
|
+
<Text style={[defaultStyles.ineligibleText]}>
|
|
150
|
+
{dictionary[KeyValue.ineligible_reason_shipping] && ' • '}
|
|
151
|
+
{dictionary[KeyValue.ineligible_reason_shipping] || ''}
|
|
152
|
+
</Text>
|
|
153
|
+
<Text style={[defaultStyles.ineligibleText]}>
|
|
154
|
+
{dictionary[KeyValue.ineligible_reason_currency] && ' • '}
|
|
155
|
+
{dictionary[KeyValue.ineligible_reason_currency] || ''}
|
|
156
|
+
</Text>
|
|
157
|
+
<Text style={[defaultStyles.ineligibleText]}>
|
|
158
|
+
{dictionary[KeyValue.ineligible_reason_value] && ' • '}
|
|
159
|
+
{dictionary[KeyValue.ineligible_reason_value] || ''}
|
|
160
|
+
</Text>
|
|
161
|
+
<Text style={[defaultStyles.ineligibleText]}>
|
|
162
|
+
{dictionary[KeyValue.ineligible_reason_items] && ' • '}
|
|
163
|
+
{dictionary[KeyValue.ineligible_reason_items] || ''}
|
|
164
|
+
</Text>
|
|
165
|
+
<Text style={[defaultStyles.ineligibleText]}>
|
|
166
|
+
{dictionary[KeyValue.ineligible_reason_system] && ' • '}
|
|
167
|
+
{dictionary[KeyValue.ineligible_reason_system] || ''}
|
|
168
|
+
</Text>
|
|
169
|
+
<Text style={[defaultStyles.ineligibleText, { marginTop: margin }]}>
|
|
170
|
+
{dictionary[KeyValue.ineligible_support_message] || ''}
|
|
171
|
+
</Text>
|
|
172
|
+
</View>
|
|
173
|
+
</TouchableOpacity>
|
|
174
|
+
);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
return (
|
|
178
|
+
<View style={[defaultStyles.container]}>
|
|
179
|
+
{visible ? (
|
|
180
|
+
<View>
|
|
181
|
+
<SeelWFPTitleView
|
|
182
|
+
status={status}
|
|
183
|
+
title={widgetTitle}
|
|
184
|
+
price={price}
|
|
185
|
+
optedIn={optedIn}
|
|
186
|
+
dictionary={dictionary}
|
|
187
|
+
loadingStatue={loadingStatue}
|
|
188
|
+
onClickInfoIcon={() => {
|
|
189
|
+
setModalVisible(true);
|
|
190
|
+
}}
|
|
191
|
+
onChangeOptedInValue={async (value: boolean) => {
|
|
192
|
+
if (status === 'accepted') {
|
|
193
|
+
writeOptedIn(value);
|
|
194
|
+
setOptedIn(value);
|
|
195
|
+
onChangeValue({ optedIn, quotesResponse });
|
|
196
|
+
} else {
|
|
197
|
+
setModalVisible(true);
|
|
198
|
+
}
|
|
199
|
+
}}
|
|
200
|
+
/>
|
|
201
|
+
<Modal
|
|
202
|
+
animationType={status === 'accepted' ? 'slide' : 'fade'}
|
|
203
|
+
transparent={status === 'accepted' ? false : true}
|
|
204
|
+
visible={visible && modalVisible}
|
|
205
|
+
onRequestClose={() => {
|
|
206
|
+
setModalVisible(false);
|
|
207
|
+
}}
|
|
208
|
+
>
|
|
209
|
+
{status === 'accepted' ? (
|
|
210
|
+
<SeelWFPInfoView
|
|
211
|
+
widgetTitle={widgetTitle}
|
|
212
|
+
dictionary={dictionary}
|
|
213
|
+
domain={domain}
|
|
214
|
+
termsUrl={termsUrl}
|
|
215
|
+
privacyPolicyUrl={privacyPolicyUrl}
|
|
216
|
+
onClickClose={() => {
|
|
217
|
+
setModalVisible(false);
|
|
218
|
+
}}
|
|
219
|
+
onChangeOptedInValue={(value: boolean) => {
|
|
220
|
+
setModalVisible(false);
|
|
221
|
+
if (status === 'accepted') {
|
|
222
|
+
setOptedIn(value);
|
|
223
|
+
onChangeValue({ optedIn, quotesResponse });
|
|
224
|
+
} else {
|
|
225
|
+
setOptedIn(false);
|
|
226
|
+
onChangeValue({ optedIn, quotesResponse });
|
|
227
|
+
}
|
|
228
|
+
}}
|
|
229
|
+
/>
|
|
230
|
+
) : null}
|
|
231
|
+
{status === 'rejected' ? renderIneligibleModalView() : null}
|
|
232
|
+
</Modal>
|
|
233
|
+
</View>
|
|
234
|
+
) : (
|
|
235
|
+
<View />
|
|
236
|
+
)}
|
|
237
|
+
</View>
|
|
238
|
+
);
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
const defaultStyles = StyleSheet.create({
|
|
242
|
+
container: {
|
|
243
|
+
width: '100%',
|
|
244
|
+
},
|
|
245
|
+
ineligibleModalViewContainer: {
|
|
246
|
+
// width: '100%',
|
|
247
|
+
height: '100%',
|
|
248
|
+
// flex: 1,
|
|
249
|
+
justifyContent: 'center',
|
|
250
|
+
// alignItems: 'center',
|
|
251
|
+
backgroundColor: 'rgba(0, 0, 0, 0.4)',
|
|
252
|
+
// backgroundColor: 'white',
|
|
253
|
+
},
|
|
254
|
+
ineligibleModalView: {
|
|
255
|
+
padding: 12,
|
|
256
|
+
backgroundColor: 'white',
|
|
257
|
+
},
|
|
258
|
+
ineligibleText: {
|
|
259
|
+
color: '#202223',
|
|
260
|
+
fontFamily: Platform.select({
|
|
261
|
+
ios: 'Inter',
|
|
262
|
+
}),
|
|
263
|
+
fontSize: 12,
|
|
264
|
+
fontStyle: 'normal',
|
|
265
|
+
fontWeight: 400,
|
|
266
|
+
lineHeight: 16,
|
|
267
|
+
},
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
export default forwardRef<SeelWFPWidgetRef, SeelWFPWidgetProps>(SeelWFPWidget);
|