@jetthai/cuora 1.1.77-cash → 1.1.77-cash-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/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.1.77-cash-1](https://github.com/jetthai/cuora-module/compare/v1.1.77-cash...v1.1.77-cash-1) (2023-04-16)
6
+
5
7
  ### [1.1.77-cash](https://github.com/jetthai/cuora-module/compare/v1.1.66-1...v1.1.77-cash) (2023-04-14)
6
8
 
7
9
  ### [1.1.77](https://github.com/jetthai/cuora-module/compare/v1.1.76...v1.1.77) (2023-04-13)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.1.77-cash",
3
+ "version": "1.1.77-cash-1",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
@@ -31,13 +31,7 @@ export default function (request) {
31
31
  },
32
32
  },
33
33
  },
34
- idle: {
35
- on: {
36
- SET_ACTIVITY_NO: {
37
- // todo - deprecated
38
- },
39
- },
40
- },
34
+ idle: {},
41
35
  checking: {
42
36
  always: [{ target: 'loading', cond: 'hasActivityNo' }],
43
37
  },
@@ -58,6 +52,9 @@ export default function (request) {
58
52
  EXCHANGE: {
59
53
  target: 'exchanging',
60
54
  },
55
+ SELECT: {
56
+ actions: ['selectProduct', 'count'],
57
+ },
61
58
  ADD_TO_CART: {
62
59
  actions: ['addProduct', 'count'],
63
60
  },
@@ -145,6 +142,11 @@ export default function (request) {
145
142
  unclaimedRewardList: [],
146
143
  }
147
144
  }),
145
+ selectProduct: assign((context, event) => {
146
+ return {
147
+ exchangeList: [event.data],
148
+ }
149
+ }),
148
150
  addProduct: assign((context, event) => {
149
151
  return {
150
152
  exchangeList: [...context.exchangeList, event.data],
@@ -193,7 +193,13 @@ export default function (request) {
193
193
  after: {
194
194
  1000: {
195
195
  target: 'calculating',
196
- cond: (context, event) => context.selectedAmount >= context.selectedQrcode.minimum,
196
+ cond: (context, event) => {
197
+ if (context.selectedQrcode) {
198
+ return context.selectedQrcode.minimum <= context.selectedAmount && context.selectedAmount <= context.selectedQrcode.maximum
199
+ } else {
200
+ return false
201
+ }
202
+ },
197
203
  },
198
204
  },
199
205
  },
@@ -345,6 +351,7 @@ export default function (request) {
345
351
  setInitData: assign((context, event) => {
346
352
  const { siteConfig, paymentDetail } = event.data
347
353
  const qrcodes = paymentDetail.filter((element) => element.category === context.currentCategory)
354
+ console.log('qrcodes', qrcodes)
348
355
  let selectedQrcode = null
349
356
  if (siteConfig.walletMode === '4') {
350
357
  selectedQrcode = qrcodes.find((qrcode) => parseFloat(`${qrcode.charge || 0}`) === 0)
@@ -0,0 +1,433 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import payment from '../../api/payment.js'
3
+ import common from '../../api/common.js'
4
+
5
+ export default function (request) {
6
+ const { appSecret } = request.config
7
+ return createMachine(
8
+ {
9
+ id: 'qrcode',
10
+ initial: 'loading',
11
+ context: {
12
+ siteConfig: null,
13
+ qrcodes: null,
14
+ options: null,
15
+
16
+ selectedQrcode: null,
17
+ selectedAmount: null,
18
+
19
+ calculation: null,
20
+
21
+ paymentDetail: [],
22
+ currentCategory: 'qrcode',
23
+ currentMethod: null,
24
+
25
+ result: null,
26
+
27
+ grandTotalEnable: 1,
28
+
29
+ promotion: undefined,
30
+ bonusPreviewData: [],
31
+ },
32
+ states: {
33
+ loading: {
34
+ invoke: {
35
+ src: 'fetchInitData',
36
+ onDone: {
37
+ target: 'loaded',
38
+ actions: 'setInitData',
39
+ },
40
+ onError: {
41
+ target: 'fail',
42
+ },
43
+ },
44
+ },
45
+ fail: {},
46
+ loaded: {
47
+ entry: 'reset',
48
+ on: {
49
+ SELECT_QRCODE: [
50
+ {
51
+ target: 'fetching',
52
+ actions: 'setQrcode',
53
+ cond: (context, event) => {
54
+ const { siteConfig = {}, promotion = {} } = context
55
+ const { walletMode = '', bonusPreviewEnable = '0' } = siteConfig
56
+ return walletMode === '4' && bonusPreviewEnable === '1' && promotion.activityNo != 'none'
57
+ },
58
+ },
59
+ {
60
+ target: 'debouncing',
61
+ actions: ['setQrcode', 'setPromotionDefaultAmount'],
62
+ cond: (context, event) => context.siteConfig?.walletMode === '3' && context.promotion?.minimumAmount,
63
+ },
64
+ {
65
+ actions: 'setQrcode',
66
+ },
67
+ ],
68
+ SELECT_AMOUNT: [
69
+ {
70
+ target: 'pending',
71
+ actions: 'addAmount',
72
+ cond: (context, event) => context.siteConfig?.walletMode === '2' && context.grandTotalEnable === 1,
73
+ },
74
+ {
75
+ target: 'pending',
76
+ actions: 'setAmount',
77
+ cond: 'isFreeWalletMode',
78
+ },
79
+ {
80
+ target: 'debouncing',
81
+ actions: 'addAmount',
82
+ cond: 'isGrandTotalEnable',
83
+ },
84
+ {
85
+ target: 'debouncing',
86
+ actions: 'setAmount',
87
+ },
88
+ ],
89
+ KEY_IN: [
90
+ {
91
+ target: 'pending',
92
+ actions: 'setAmount',
93
+ cond: 'isFreeWalletMode',
94
+ },
95
+ {
96
+ target: 'calculating',
97
+ actions: 'setAmount',
98
+ },
99
+ ],
100
+ },
101
+ },
102
+ pending: {
103
+ on: {
104
+ SELECT_AMOUNT: [
105
+ {
106
+ actions: 'addAmount',
107
+ cond: 'isGrandTotalEnable',
108
+ },
109
+ {
110
+ actions: 'setAmount',
111
+ },
112
+ ],
113
+ KEY_IN: {
114
+ actions: 'setAmount',
115
+ },
116
+ CONFIRM: {
117
+ target: 'calculating',
118
+ },
119
+ BACK: {
120
+ target: 'loaded',
121
+ },
122
+ INPUT: {
123
+ target: 'debouncing',
124
+ actions: 'setAmount',
125
+ },
126
+ },
127
+ },
128
+ debouncing: {
129
+ on: {
130
+ SELECT_AMOUNT: [
131
+ {
132
+ target: 'debouncing',
133
+ actions: 'addAmount',
134
+ cond: (context, event) => context.siteConfig?.walletMode === '2' && context.grandTotalEnable === 1,
135
+ },
136
+ {
137
+ target: 'debouncing',
138
+ actions: 'setAmount',
139
+ cond: 'isFreeWalletMode',
140
+ },
141
+ {
142
+ target: 'debouncing',
143
+ actions: 'addAmount',
144
+ cond: 'isGrandTotalEnable',
145
+ },
146
+ {
147
+ target: 'debouncing',
148
+ actions: 'setAmount',
149
+ },
150
+ ],
151
+ INPUT: {
152
+ target: 'debouncing',
153
+ actions: 'setAmount',
154
+ },
155
+ BACK: {
156
+ target: 'loaded',
157
+ },
158
+ },
159
+ after: {
160
+ 1000: {
161
+ target: 'calculating',
162
+ cond: (context, event) => {
163
+ if (context.selectedQrcode) {
164
+ return context.selectedQrcode.minimum <= context.selectedAmount && context.selectedAmount <= context.selectedQrcode.maximum
165
+ } else {
166
+ return false
167
+ }
168
+ },
169
+ },
170
+ },
171
+ },
172
+ calculable: {
173
+ entry: 'clearCalculation',
174
+ on: {
175
+ SELECT_AMOUNT: [
176
+ {
177
+ target: 'pending',
178
+ actions: 'addAmount',
179
+ cond: (context, event) => context.siteConfig?.walletMode === '2' && context.grandTotalEnable === 1,
180
+ },
181
+ {
182
+ target: 'pending',
183
+ actions: 'setAmount',
184
+ cond: 'isFreeWalletMode',
185
+ },
186
+ {
187
+ target: 'debouncing',
188
+ actions: 'addAmount',
189
+ cond: 'isGrandTotalEnable',
190
+ },
191
+ {
192
+ target: 'debouncing',
193
+ actions: 'setAmount',
194
+ },
195
+ ],
196
+ KEY_IN: {
197
+ target: 'calculating',
198
+ actions: 'setAmount',
199
+ },
200
+ BACK: {
201
+ target: 'loaded',
202
+ },
203
+ },
204
+ },
205
+ calculating: {
206
+ invoke: {
207
+ src: 'fetchCalculation',
208
+ onDone: [
209
+ {
210
+ target: 'submitting',
211
+ actions: 'setCalculation',
212
+ cond: 'isFreeWalletMode',
213
+ },
214
+ {
215
+ target: 'calculated',
216
+ actions: 'setCalculation',
217
+ },
218
+ ],
219
+ onError: {
220
+ target: 'calculable',
221
+ },
222
+ },
223
+ },
224
+ calculated: {
225
+ on: {
226
+ SELECT_AMOUNT: [
227
+ {
228
+ target: 'pending',
229
+ actions: 'addAmount',
230
+ cond: (context, event) => context.siteConfig?.walletMode === '2' && context.grandTotalEnable === 1,
231
+ },
232
+ {
233
+ target: 'pending',
234
+ actions: 'setAmount',
235
+ cond: 'isFreeWalletMode',
236
+ },
237
+ {
238
+ target: 'debouncing',
239
+ actions: 'addAmount',
240
+ cond: 'isGrandTotalEnable',
241
+ },
242
+ {
243
+ target: 'debouncing',
244
+ actions: 'setAmount',
245
+ },
246
+ ],
247
+ KEY_IN: {
248
+ target: 'calculating',
249
+ actions: 'setAmount',
250
+ },
251
+ CONFIRM: {
252
+ target: 'submitting',
253
+ },
254
+ BACK: {
255
+ target: 'loaded',
256
+ },
257
+ CLEAR_CALCULATION: {
258
+ target: 'debouncing',
259
+ actions: 'clearCalculation',
260
+ },
261
+ INPUT: {
262
+ target: 'debouncing',
263
+ actions: 'setAmount',
264
+ },
265
+ SELECT_QRCODE: {
266
+ target: 'debouncing',
267
+ actions: 'setQrcode',
268
+ },
269
+ },
270
+ },
271
+ submitting: {
272
+ invoke: {
273
+ src: 'submitDeposit',
274
+ onDone: {
275
+ target: 'submitted',
276
+ actions: 'setResult',
277
+ },
278
+ onError: {
279
+ target: 'calculated',
280
+ },
281
+ },
282
+ },
283
+ submitted: {
284
+ on: {
285
+ SELECT_QRCODE: [
286
+ {
287
+ target: 'fetching',
288
+ actions: 'setQrcode',
289
+ cond: (context, event) => {
290
+ const { siteConfig = {}, promotion = {} } = context
291
+ const { walletMode = '', bonusPreviewEnable = '0' } = siteConfig
292
+ return walletMode === '4' && bonusPreviewEnable === '1' && promotion.activityNo != 'none'
293
+ },
294
+ },
295
+ {
296
+ target: 'loaded',
297
+ actions: 'setQrcode',
298
+ },
299
+ ],
300
+ },
301
+ },
302
+ },
303
+ on: {
304
+ SET_PROMOTION: {
305
+ actions: 'setPromotion',
306
+ },
307
+ },
308
+ },
309
+ {
310
+ actions: {
311
+ reset: assign((context, event) => {
312
+ return {
313
+ selectedAmount: null,
314
+ calculation: null,
315
+ }
316
+ }),
317
+ setInitData: assign((context, event) => {
318
+ const { siteConfig, paymentDetail } = event.data
319
+ const qrcodes = paymentDetail.filter((element) => element.category === context.currentCategory)
320
+ console.log('qrcodes', qrcodes)
321
+ let selectedQrcode = null
322
+ if (siteConfig.walletMode === '4') {
323
+ selectedQrcode = qrcodes.find((qrcode) => parseFloat(`${qrcode.charge || 0}`) === 0)
324
+ } else {
325
+ selectedQrcode = qrcodes[0]
326
+ }
327
+
328
+ return {
329
+ siteConfig,
330
+ paymentDetail,
331
+ qrcodes,
332
+ selectedQrcode,
333
+ currentMethod: selectedQrcode?.method,
334
+ options: selectedQrcode?.optional,
335
+ grandTotalEnable: selectedQrcode?.grandTotalEnable,
336
+ }
337
+ }),
338
+ setBonusPreview: assign((context, event) => {
339
+ return {
340
+ bonusPreviewData: event.data.bonus,
341
+ }
342
+ }),
343
+ setQrcode: assign((context, event) => {
344
+ return {
345
+ selectedQrcode: event.data,
346
+ currentMethod: event.data.method,
347
+ options: event.data.optional,
348
+ grandTotalEnable: event.data.grandTotalEnable,
349
+ }
350
+ }),
351
+ addAmount: assign((context, event) => {
352
+ return { selectedAmount: parseFloat(context.selectedAmount || 0) + parseFloat(event.data) }
353
+ }),
354
+ setAmount: assign((context, event) => {
355
+ return { selectedAmount: event.data }
356
+ }),
357
+ setCalculation: assign((context, event) => {
358
+ return {
359
+ calculation: event.data,
360
+ }
361
+ }),
362
+ clearCalculation: assign((context, event) => {
363
+ return {
364
+ calculation: null,
365
+ }
366
+ }),
367
+ setResult: assign((context, event) => {
368
+ return {
369
+ result: event.data,
370
+ }
371
+ }),
372
+ setPromotion: assign((context, event) => {
373
+ const promotion = event.data
374
+ return {
375
+ promotion,
376
+ }
377
+ }),
378
+ setPromotionDefaultAmount: assign((context, event) => {
379
+ return {
380
+ selectedAmount: context.promotion.minimumAmount,
381
+ }
382
+ }),
383
+ },
384
+ guards: {
385
+ isFreeWalletMode: (context, event) => {
386
+ return context.siteConfig?.walletMode === '2'
387
+ },
388
+ isGrandTotalEnable: (context, event) => {
389
+ return context.grandTotalEnable === 1
390
+ },
391
+ },
392
+ services: {
393
+ fetchInitData: async (context, event) => {
394
+ const [{ config }, paymentDetail = []] = await Promise.all([
395
+ request.send(common.getConfig({ appSecret })),
396
+ request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' })),
397
+ ])
398
+ const siteConfig = JSON.parse(window.atob(config))
399
+ return { siteConfig, paymentDetail }
400
+ },
401
+ fetchBonusPreview: async (context, event) => {
402
+ const { currentMethod, promotion } = context
403
+ return await request.send(
404
+ payment.getBonusPreview({
405
+ method: currentMethod,
406
+ promotionsNo: promotion?.activityNo,
407
+ })
408
+ )
409
+ },
410
+ fetchCalculation: async (context, event) => {
411
+ const { currentMethod, selectedAmount, promotion } = context
412
+ return await request.send(
413
+ payment.getDepositExpectedResult({
414
+ method: currentMethod,
415
+ amount: selectedAmount,
416
+ promotionsNo: promotion?.activityNo,
417
+ })
418
+ )
419
+ },
420
+ submitDeposit: async (context, event) => {
421
+ const { currentMethod, selectedAmount, promotion } = context
422
+ return await request.send(
423
+ payment.submitDepositTransaction({
424
+ method: currentMethod,
425
+ amount: selectedAmount,
426
+ promotionsNo: promotion?.activityNo,
427
+ })
428
+ )
429
+ },
430
+ },
431
+ }
432
+ )
433
+ }