@jetthai/cuora 1.1.15 → 1.1.17

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",
3
+ "version": "1.1.17",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
@@ -114,4 +114,15 @@ export default {
114
114
  method: 'post',
115
115
  params: { transferType: 'WITHDRAW', amount },
116
116
  }),
117
+ getPromotionsList: () => ({ url: `payment/v2/bankWallet/promotions`, method: 'get' }),
118
+ getWithdrawRulePreview: ({ applyType, applyNo, amount }) => ({
119
+ url: `payment/v2/bankWallet/promotion/preview`,
120
+ method: 'post',
121
+ params: { applyType, applyNo, amount },
122
+ }),
123
+ applyPromotions: ({ promotionsNo, amount }) => ({
124
+ url: `payment/v2/bankWallet/promotion/apply`,
125
+ method: 'post',
126
+ params: { promotionsNo, amount },
127
+ }),
117
128
  }
@@ -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,7 +20,7 @@ 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,
@@ -27,15 +30,127 @@ export default function (request) {
27
30
  invoke: {
28
31
  src: 'fetchInitData',
29
32
  onDone: {
30
- target: 'loaded',
31
- actions: 'setInitData',
33
+ target: 'checking',
34
+ actions: ['setInitData', 'preset'],
32
35
  },
33
36
  onError: {
34
37
  target: 'fail',
35
38
  },
36
39
  },
37
40
  },
38
- 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: {
39
154
  entry: 'reset',
40
155
  on: {
41
156
  SELECT_CARD: {
@@ -54,7 +169,7 @@ export default function (request) {
54
169
  actions: 'setAmount',
55
170
  },
56
171
  BACK: {
57
- target: 'loaded',
172
+ target: 'defaultMode',
58
173
  },
59
174
  },
60
175
  after: {
@@ -75,7 +190,7 @@ export default function (request) {
75
190
  target: 'debouncing',
76
191
  },
77
192
  BACK: {
78
- target: 'loaded',
193
+ target: 'defaultMode',
79
194
  },
80
195
  },
81
196
  },
@@ -101,7 +216,7 @@ export default function (request) {
101
216
  target: 'cardInfo',
102
217
  },
103
218
  BACK: {
104
- target: 'loaded',
219
+ target: 'defaultMode',
105
220
  },
106
221
  CLEAR_CALCULATION: {
107
222
  target: 'debouncing',
@@ -122,7 +237,7 @@ export default function (request) {
122
237
  cond: 'isSubmittable',
123
238
  },
124
239
  SELECT_CARD: {
125
- target: 'loaded',
240
+ target: 'defaultMode',
126
241
  actions: 'setCard',
127
242
  },
128
243
  },
@@ -141,7 +256,7 @@ export default function (request) {
141
256
  submitted: {
142
257
  on: {
143
258
  BACK: {
144
- target: 'loaded',
259
+ target: 'defaultMode',
145
260
  },
146
261
  },
147
262
  },
@@ -158,16 +273,22 @@ export default function (request) {
158
273
  }
159
274
  }),
160
275
  setInitData: assign((context, event) => {
161
- const paymentDetails = event.data
162
- const cards = paymentDetails.filter((element) => element.category === context.currentCategory)
276
+ const { paymentDetail } = event.data
277
+ const cards = paymentDetail.filter((element) => element.category === context.currentCategory)
163
278
  return {
164
- paymentDetails,
279
+ paymentDetail,
165
280
  cards,
166
281
  selectedCard: cards[0],
167
282
  currentMethod: cards[0].method,
168
283
  options: cards[0].optional,
169
284
  }
170
285
  }),
286
+ preset: assign((context, event) => {
287
+ const { siteConfig } = event.data
288
+ return {
289
+ siteConfig,
290
+ }
291
+ }),
171
292
  setCard: assign((context, event) => {
172
293
  return {
173
294
  selectedCard: event.data,
@@ -200,6 +321,9 @@ export default function (request) {
200
321
  }),
201
322
  },
202
323
  guards: {
324
+ isPromotionApplyMode: (context, event) => {
325
+ return context.siteConfig?.promotionApplyMode === '1'
326
+ },
203
327
  isSubmittable: (context, event) => {
204
328
  const { cardNumber, serialNumber } = context
205
329
  return cardNumber && serialNumber
@@ -207,7 +331,12 @@ export default function (request) {
207
331
  },
208
332
  services: {
209
333
  fetchInitData: async (context, event) => {
210
- 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 }
211
340
  },
212
341
  fetchCalculation: async (context, event) => {
213
342
  const { currentMethod, selectedAmount } = context