@jetthai/cuora 1.1.15-1 → 1.1.16

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.1.15-1",
3
+ "version": "1.1.16",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
@@ -114,4 +114,13 @@ export default {
114
114
  method: 'post',
115
115
  params: { transferType: 'WITHDRAW', amount },
116
116
  }),
117
+ getPromotionsList: () => ({ url: `payment/v2/bankWallet/promotions`, method: 'get' }),
118
+ applyPromotions: ({ promotionsNo, amount }) => ({
119
+ url: `payment/v2/bankWallet/promotion/apply`,
120
+ method: 'post',
121
+ params: {
122
+ promotionsNo,
123
+ amount,
124
+ },
125
+ }),
117
126
  }
@@ -1,13 +1,16 @@
1
1
  import { assign, createMachine } from 'xstate'
2
2
  import padStart from 'lodash/padStart.js'
3
3
  import payment from '../../api/payment.js'
4
+ import common from '../../api/common.js'
4
5
 
5
6
  export default function (request) {
7
+ const { appSecret } = request.config
6
8
  return createMachine(
7
9
  {
8
10
  id: 'crypro_button',
9
11
  initial: 'loading',
10
12
  context: {
13
+ siteConfig: null,
11
14
  paymentDetails: [],
12
15
 
13
16
  channels: [],
@@ -31,17 +34,127 @@ export default function (request) {
31
34
  states: {
32
35
  loading: {
33
36
  invoke: {
34
- src: 'fetchPayments',
37
+ src: 'fetchInitData',
35
38
  onDone: {
36
- target: 'loaded',
37
- actions: 'setCryptos',
39
+ target: 'checking',
40
+ actions: ['setInitData', 'preset'],
38
41
  },
39
42
  onError: {
40
43
  target: 'fail',
41
44
  },
42
45
  },
43
46
  },
44
- loaded: {
47
+ checking: {
48
+ always: [{ target: 'promotionApplyMode', cond: 'isPromotionApplyMode' }, { target: 'defaultMode' }],
49
+ },
50
+ promotionApplyMode: {
51
+ initial: 'loaded',
52
+ states: {
53
+ loaded: {
54
+ entry: 'reset',
55
+ on: {
56
+ SET_CHANNEL: {
57
+ actions: 'setChannel',
58
+ },
59
+ SET_CRYPTO: {
60
+ actions: 'setCrypto',
61
+ },
62
+ SET_NETWORK: {
63
+ actions: 'setNetwork',
64
+ },
65
+ SET_ADDRESS: {
66
+ actions: 'setAddress',
67
+ },
68
+ CONFIRM: {
69
+ target: 'selecting',
70
+ cond: 'isConfirmable',
71
+ },
72
+ },
73
+ },
74
+ selecting: {
75
+ entry: 'reset',
76
+ on: {
77
+ SELECT_AMOUNT: [
78
+ {
79
+ actions: 'addAmount',
80
+ cond: (context, event) => context.grandTotalEnable === 1,
81
+ },
82
+ {
83
+ actions: 'setAmount',
84
+ },
85
+ ],
86
+ KEY_IN: {
87
+ actions: 'setAmount',
88
+ },
89
+ SUBMIT: {
90
+ target: 'debouncing',
91
+ },
92
+ BACK: {
93
+ target: 'loaded',
94
+ },
95
+ CLEAR_ALL: {
96
+ actions: 'reset',
97
+ },
98
+ },
99
+ },
100
+ debouncing: {
101
+ on: {
102
+ SELECT_AMOUNT: [
103
+ {
104
+ target: 'debouncing',
105
+ actions: 'addAmount',
106
+ cond: (context, event) => context.grandTotalEnable === 1,
107
+ },
108
+ {
109
+ target: 'debouncing',
110
+ actions: 'setAmount',
111
+ },
112
+ ],
113
+ KEY_IN: {
114
+ target: 'debouncing',
115
+ actions: 'setAmount',
116
+ },
117
+ BACK: {
118
+ target: 'loaded',
119
+ },
120
+ CLEAR_ALL: {
121
+ actions: 'reset',
122
+ },
123
+ },
124
+ after: {
125
+ 1000: {
126
+ target: 'calculating',
127
+ },
128
+ },
129
+ },
130
+ calculating: {
131
+ invoke: {
132
+ src: 'fetchCalculation',
133
+ onDone: {
134
+ target: 'submitting',
135
+ actions: 'setCalculation',
136
+ },
137
+ onError: {
138
+ target: 'selecting',
139
+ actions: 'reset',
140
+ },
141
+ },
142
+ },
143
+ submitting: {
144
+ invoke: {
145
+ src: 'submitDeposit',
146
+ onDone: {
147
+ target: '#crypro_button.submitted',
148
+ actions: 'setResult',
149
+ },
150
+ onError: {
151
+ target: 'selecting',
152
+ },
153
+ },
154
+ },
155
+ },
156
+ },
157
+ defaultMode: {
45
158
  on: {
46
159
  SET_CHANNEL: {
47
160
  actions: 'setChannel',
@@ -81,7 +194,7 @@ export default function (request) {
81
194
  actions: 'setAmount',
82
195
  },
83
196
  BACK: {
84
- target: 'loaded',
197
+ target: 'defaultMode',
85
198
  },
86
199
  },
87
200
  },
@@ -176,8 +289,9 @@ export default function (request) {
176
289
  calculation: null,
177
290
  }
178
291
  }),
179
- setCryptos: assign((context, event) => {
180
- const cryptos = event.data?.map?.((crypto) => ({ ...crypto, label: crypto.channel, value: crypto.method, icon: crypto.channel })) || []
292
+ setInitData: assign((context, event) => {
293
+ const { paymentDetail } = event.data
294
+ const cryptos = paymentDetail?.map?.((crypto) => ({ ...crypto, label: crypto.channel, value: crypto.method, icon: crypto.channel })) || []
181
295
  const currentPayment = cryptos.find((element) => element.category === context.currentCategory)
182
296
  const channels = cryptos.map((item, i) => ({ ...item, label: `Channel ${padStart(String(i + 1), 2, '0')}`, icon: 'channel' }))
183
297
  const defaultNetworks =
@@ -201,6 +315,12 @@ export default function (request) {
201
315
  options,
202
316
  }
203
317
  }),
318
+ preset: assign((context, event) => {
319
+ const { siteConfig } = event.data
320
+ return {
321
+ siteConfig,
322
+ }
323
+ }),
204
324
  setChannel: assign((context, event) => {
205
325
  const { cryptos } = context
206
326
  const selectedCrypto = cryptos.find((crypto) => crypto.method === event.data.value)
@@ -280,6 +400,9 @@ export default function (request) {
280
400
  }),
281
401
  },
282
402
  guards: {
403
+ isPromotionApplyMode: (context, event) => {
404
+ return context.siteConfig?.promotionApplyMode === '1'
405
+ },
283
406
  isConfirmable: (context, event) => {
284
407
  const { selectedCrypto, selectedNetwork } = context
285
408
  return selectedCrypto && selectedNetwork
@@ -290,8 +413,13 @@ export default function (request) {
290
413
  },
291
414
  },
292
415
  services: {
293
- fetchPayments: async (context, event) => {
294
- return await request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' }))
416
+ fetchInitData: async (context, event) => {
417
+ const [{ config }, paymentDetail = []] = await Promise.all([
418
+ request.send(common.getConfig({ appSecret })),
419
+ request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' })),
420
+ ])
421
+ const siteConfig = JSON.parse(window.atob(config))
422
+ return { siteConfig, paymentDetail }
295
423
  },
296
424
  fetchCalculation: async (context, event) => {
297
425
  const { selectedCrypto, selectedAmount } = context
@@ -1,12 +1,15 @@
1
1
  import { assign, createMachine } from 'xstate'
2
2
  import payment from '../../api/payment.js'
3
+ import common from '../../api/common.js'
3
4
 
4
5
  export default function (request) {
6
+ const { appSecret } = request.config
5
7
  return createMachine(
6
8
  {
7
9
  id: 'loadcard',
8
10
  initial: 'loading',
9
11
  context: {
12
+ siteConfig: null,
10
13
  cards: [],
11
14
  options: [],
12
15
 
@@ -17,26 +20,137 @@ export default function (request) {
17
20
 
18
21
  calculation: null,
19
22
 
20
- paymentDetails: [],
23
+ paymentDetail: [],
21
24
  currentCategory: 'loadcard',
22
25
  currentMethod: null,
23
26
  currentPayment: null,
24
- result: null,
25
27
  },
26
28
  states: {
27
29
  loading: {
28
30
  invoke: {
29
31
  src: 'fetchInitData',
30
32
  onDone: {
31
- target: 'loaded',
32
- actions: 'setInitData',
33
+ target: 'checking',
34
+ actions: ['setInitData', 'preset'],
33
35
  },
34
36
  onError: {
35
37
  target: 'fail',
36
38
  },
37
39
  },
38
40
  },
39
- loaded: {
41
+ checking: {
42
+ always: [{ target: 'promotionApplyMode', cond: 'isPromotionApplyMode' }, { target: 'defaultMode' }],
43
+ },
44
+ promotionApplyMode: {
45
+ initial: 'loaded',
46
+ states: {
47
+ loaded: {
48
+ entry: 'reset',
49
+ on: {
50
+ SELECT_CARD: {
51
+ actions: 'setCard',
52
+ },
53
+ SELECT_AMOUNT: {
54
+ target: 'submittable',
55
+ actions: 'setAmount',
56
+ },
57
+ },
58
+ },
59
+ submittable: {
60
+ on: {
61
+ SELECT_AMOUNT: {
62
+ actions: 'setAmount',
63
+ },
64
+ CONFIRM: {
65
+ target: 'debouncing',
66
+ },
67
+ BACK: {
68
+ target: 'loaded',
69
+ },
70
+ },
71
+ },
72
+ debouncing: {
73
+ on: {
74
+ SELECT_AMOUNT: {
75
+ target: 'debouncing',
76
+ actions: 'setAmount',
77
+ },
78
+ BACK: {
79
+ target: 'loaded',
80
+ },
81
+ },
82
+ after: {
83
+ 1000: {
84
+ target: 'calculating',
85
+ },
86
+ },
87
+ },
88
+ calculable: {
89
+ entry: 'clearCalculation',
90
+ on: {
91
+ SELECT_AMOUNT: {
92
+ target: 'debouncing',
93
+ actions: 'setAmount',
94
+ },
95
+ CALCULATE: {
96
+ target: 'debouncing',
97
+ },
98
+ BACK: {
99
+ target: 'loaded',
100
+ },
101
+ },
102
+ },
103
+ calculating: {
104
+ invoke: {
105
+ src: 'fetchCalculation',
106
+ onDone: {
107
+ target: 'cardInfo',
108
+ actions: 'setCalculation',
109
+ },
110
+ onError: {
111
+ target: 'calculable',
112
+ },
113
+ },
114
+ },
115
+ cardInfo: {
116
+ on: {
117
+ INPUT_CARD_NUMBER: {
118
+ actions: 'setCardNumber',
119
+ },
120
+ INPUT_SERIAL_NUMBER: {
121
+ actions: 'setSerialNumber',
122
+ },
123
+ SUBMIT: {
124
+ target: 'submitting',
125
+ cond: 'isSubmittable',
126
+ },
127
+ SELECT_CARD: {
128
+ target: 'loaded',
129
+ actions: 'setCard',
130
+ },
131
+ },
132
+ },
133
+ submitting: {
134
+ invoke: {
135
+ src: 'submitDeposit',
136
+ onDone: {
137
+ target: 'submitted',
138
+ },
139
+ onError: {
140
+ target: 'cardInfo',
141
+ },
142
+ },
143
+ },
144
+ submitted: {
145
+ on: {
146
+ BACK: {
147
+ target: 'loaded',
148
+ },
149
+ },
150
+ },
151
+ },
152
+ },
153
+ defaultMode: {
40
154
  entry: 'reset',
41
155
  on: {
42
156
  SELECT_CARD: {
@@ -55,7 +169,7 @@ export default function (request) {
55
169
  actions: 'setAmount',
56
170
  },
57
171
  BACK: {
58
- target: 'loaded',
172
+ target: 'defaultMode',
59
173
  },
60
174
  },
61
175
  after: {
@@ -76,7 +190,7 @@ export default function (request) {
76
190
  target: 'debouncing',
77
191
  },
78
192
  BACK: {
79
- target: 'loaded',
193
+ target: 'defaultMode',
80
194
  },
81
195
  },
82
196
  },
@@ -98,17 +212,11 @@ export default function (request) {
98
212
  target: 'debouncing',
99
213
  actions: 'setAmount',
100
214
  },
101
- CONFIRM: [
102
- {
103
- target: 'submitting',
104
- cond: 'jumpLinkEnable',
105
- },
106
- {
107
- target: 'cardInfo',
108
- },
109
- ],
215
+ CONFIRM: {
216
+ target: 'cardInfo',
217
+ },
110
218
  BACK: {
111
- target: 'loaded',
219
+ target: 'defaultMode',
112
220
  },
113
221
  CLEAR_CALCULATION: {
114
222
  target: 'debouncing',
@@ -129,7 +237,7 @@ export default function (request) {
129
237
  cond: 'isSubmittable',
130
238
  },
131
239
  SELECT_CARD: {
132
- target: 'loaded',
240
+ target: 'defaultMode',
133
241
  actions: 'setCard',
134
242
  },
135
243
  },
@@ -139,7 +247,6 @@ export default function (request) {
139
247
  src: 'submitDeposit',
140
248
  onDone: {
141
249
  target: 'submitted',
142
- actions: 'setResult',
143
250
  },
144
251
  onError: {
145
252
  target: 'cardInfo',
@@ -149,7 +256,7 @@ export default function (request) {
149
256
  submitted: {
150
257
  on: {
151
258
  BACK: {
152
- target: 'loaded',
259
+ target: 'defaultMode',
153
260
  },
154
261
  },
155
262
  },
@@ -166,16 +273,22 @@ export default function (request) {
166
273
  }
167
274
  }),
168
275
  setInitData: assign((context, event) => {
169
- const paymentDetails = event.data
170
- const cards = paymentDetails.filter((element) => element.category === context.currentCategory)
276
+ const { paymentDetail } = event.data
277
+ const cards = paymentDetail.filter((element) => element.category === context.currentCategory)
171
278
  return {
172
- paymentDetails,
279
+ paymentDetail,
173
280
  cards,
174
281
  selectedCard: cards[0],
175
282
  currentMethod: cards[0].method,
176
283
  options: cards[0].optional,
177
284
  }
178
285
  }),
286
+ preset: assign((context, event) => {
287
+ const { siteConfig } = event.data
288
+ return {
289
+ siteConfig,
290
+ }
291
+ }),
179
292
  setCard: assign((context, event) => {
180
293
  return {
181
294
  selectedCard: event.data,
@@ -206,25 +319,24 @@ export default function (request) {
206
319
  calculation: null,
207
320
  }
208
321
  }),
209
- setResult: assign((context, event) => {
210
- return {
211
- result: event.data,
212
- }
213
- }),
214
322
  },
215
323
  guards: {
324
+ isPromotionApplyMode: (context, event) => {
325
+ return context.siteConfig?.promotionApplyMode === '1'
326
+ },
216
327
  isSubmittable: (context, event) => {
217
328
  const { cardNumber, serialNumber } = context
218
329
  return cardNumber && serialNumber
219
330
  },
220
- jumpLinkEnable: (context, event) => {
221
- const { selectedCard } = context
222
- return selectedCard.jumpLinkEnable === 1
223
- },
224
331
  },
225
332
  services: {
226
333
  fetchInitData: async (context, event) => {
227
- return await request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' }))
334
+ const [{ config }, paymentDetail = []] = await Promise.all([
335
+ request.send(common.getConfig({ appSecret })),
336
+ request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' })),
337
+ ])
338
+ const siteConfig = JSON.parse(window.atob(config))
339
+ return { siteConfig, paymentDetail }
228
340
  },
229
341
  fetchCalculation: async (context, event) => {
230
342
  const { currentMethod, selectedAmount } = context