@jetthai/cuora 1.1.92-cash → 1.1.92

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.
@@ -1,258 +0,0 @@
1
- import { assign, createMachine } from 'xstate'
2
- import payment from '../../api/payment.js'
3
- import { max } from '../../util'
4
-
5
- export default function (request, context) {
6
- const { paymentDetail = [], promotion, selectedAmount } = context || {}
7
- return createMachine(
8
- {
9
- id: 'qrcode_cash',
10
- initial: 'loading',
11
- context: {
12
- paymentDetail,
13
- promotion,
14
- selectedAmount,
15
-
16
- qrcodes: null,
17
- options: null,
18
-
19
- selectedQrcode: null,
20
-
21
- calculation: null,
22
-
23
- currentCategory: 'qrcode',
24
-
25
- result: null,
26
-
27
- bonusPreviewData: [],
28
- },
29
- states: {
30
- loading: {
31
- always: [
32
- {
33
- target: 'loaded',
34
- actions: 'setInitData',
35
- cond: 'hasQrcodeMethods',
36
- },
37
- ],
38
- },
39
- loaded: {
40
- on: {
41
- SET_PROMOTION: {
42
- target: 'debouncing',
43
- actions: 'setPromotion',
44
- },
45
- SELECT_QRCODE: {
46
- target: 'debouncing',
47
- actions: 'setQrcode',
48
- },
49
- SELECT_AMOUNT: {
50
- target: 'debouncing',
51
- actions: 'setAmount',
52
- },
53
- INPUT_AMOUNT: {
54
- target: 'debouncing',
55
- actions: 'inputAmount',
56
- },
57
- },
58
- },
59
- debouncing: {
60
- after: {
61
- 1000: [
62
- {
63
- target: 'calculating',
64
- cond: (context, event) => {
65
- const { selectedQrcode, selectedAmount } = context
66
- if (selectedQrcode && selectedAmount) {
67
- return selectedQrcode.minimum <= selectedAmount && selectedAmount <= selectedQrcode.maximum
68
- } else {
69
- return false
70
- }
71
- },
72
- },
73
- {
74
- target: 'loaded',
75
- },
76
- ],
77
- },
78
- on: {
79
- SET_PROMOTION: {
80
- target: 'debouncing',
81
- actions: 'setPromotion',
82
- },
83
- SELECT_QRCODE: {
84
- target: 'debouncing',
85
- actions: 'setQrcode',
86
- },
87
- SELECT_AMOUNT: {
88
- target: 'debouncing',
89
- actions: 'setAmount',
90
- },
91
- INPUT_AMOUNT: {
92
- target: 'debouncing',
93
- actions: 'inputAmount',
94
- },
95
- },
96
- },
97
- calculating: {
98
- invoke: {
99
- src: 'fetchCalculation',
100
- onDone: {
101
- target: 'calculated',
102
- actions: 'setCalculation',
103
- },
104
- onError: {
105
- target: 'calculated',
106
- },
107
- },
108
- },
109
- calculated: {
110
- on: {
111
- SET_PROMOTION: {
112
- target: 'debouncing',
113
- actions: 'setPromotion',
114
- },
115
- SELECT_QRCODE: {
116
- target: 'debouncing',
117
- actions: 'setQrcode',
118
- },
119
- SELECT_AMOUNT: {
120
- target: 'debouncing',
121
- actions: 'setAmount',
122
- },
123
- INPUT_AMOUNT: {
124
- target: 'debouncing',
125
- actions: 'inputAmount',
126
- },
127
- SUBMIT: {
128
- target: 'submitting',
129
- },
130
- },
131
- },
132
- submitting: {
133
- invoke: {
134
- src: 'submitDeposit',
135
- onDone: {
136
- target: 'submitted',
137
- actions: 'setResult',
138
- },
139
- onError: {
140
- target: 'calculated',
141
- },
142
- },
143
- },
144
- submitted: {},
145
- },
146
- },
147
- {
148
- actions: {
149
- setInitData: assign((context, event) => {
150
- const { paymentDetail, selectedAmount, promotion } = context
151
- const qrcodes = paymentDetail
152
- .filter((element) => element.category === context.currentCategory)
153
- .map((qrcode) => {
154
- qrcode.disabled = promotion?.promotionsNo !== 'none' && qrcode.charge > 0
155
- return qrcode
156
- })
157
-
158
- const selectedQrcode = qrcodes.find((qrcode) => !qrcode.disabled)
159
-
160
- return {
161
- paymentDetail,
162
- qrcodes,
163
- selectedQrcode,
164
- options: selectedQrcode?.optional,
165
- selectedAmount: max(promotion?.minimumAmount, selectedQrcode?.minimum, selectedAmount, 0),
166
- }
167
- }),
168
- setBonusPreview: assign((context, event) => {
169
- return {
170
- bonusPreviewData: event.data.bonus,
171
- }
172
- }),
173
- setPromotion: assign((context, event) => {
174
- const { selectedAmount } = context
175
- const promotion = event.data
176
- const qrcodes = context.qrcodes.map((qrcode) => {
177
- qrcode.disabled = promotion.promotionsNo !== 'none' && qrcode.charge > 0
178
- return qrcode
179
- })
180
-
181
- const selectedQrcode = qrcodes.find((qrcode) => !qrcode.disabled)
182
-
183
- return {
184
- promotion,
185
- qrcodes,
186
- selectedQrcode,
187
- options: selectedQrcode?.optional,
188
- selectedAmount: max(promotion.minimumAmount, selectedQrcode?.minimum, selectedAmount, 0),
189
- calculation: null,
190
- }
191
- }),
192
- setQrcode: assign((context, event) => {
193
- const { promotion, selectedAmount } = context
194
- const selectedQrcode = event.data
195
- return {
196
- selectedQrcode,
197
- options: selectedQrcode.optional,
198
- selectedAmount: max(promotion.minimumAmount, selectedAmount, 0),
199
- calculation: null,
200
- }
201
- }),
202
- setAmount: assign((context, event) => {
203
- // 現金網可自由填額度,grandTotalEnable 欄位感覺不再需要?
204
- if (context.selectedQrcode?.grandTotalEnable === 1) {
205
- return { selectedAmount: parseFloat(context.selectedAmount || 0) + parseFloat(event.data) }
206
- } else {
207
- return { selectedAmount: event.data }
208
- }
209
- }),
210
- inputAmount: assign((context, event) => {
211
- return { selectedAmount: event.data }
212
- }),
213
- setCalculation: assign((context, event) => {
214
- return {
215
- calculation: event.data,
216
- }
217
- }),
218
- clearCalculation: assign((context, event) => {
219
- return {
220
- calculation: null,
221
- }
222
- }),
223
- setResult: assign((context, event) => {
224
- return {
225
- result: event.data,
226
- }
227
- }),
228
- },
229
- guards: {
230
- hasQrcodeMethods: (context, event) => {
231
- return context.paymentDetail?.filter((element) => element.category === context.currentCategory).length > 0
232
- },
233
- },
234
- services: {
235
- fetchCalculation: async (context, event) => {
236
- const { selectedQrcode, selectedAmount, promotion } = context
237
- return await request.send(
238
- payment.getDepositExpectedResult({
239
- method: selectedQrcode.method,
240
- amount: selectedAmount,
241
- promotionsNo: promotion?.promotionsNo,
242
- })
243
- )
244
- },
245
- submitDeposit: async (context, event) => {
246
- const { selectedQrcode, selectedAmount, promotion } = context
247
- return await request.send(
248
- payment.submitDepositTransaction({
249
- method: selectedQrcode.method,
250
- amount: selectedAmount,
251
- promotionsNo: promotion?.promotionsNo,
252
- })
253
- )
254
- },
255
- },
256
- }
257
- )
258
- }
@@ -1,220 +0,0 @@
1
- import { createMachine, assign, send } from 'xstate'
2
- import activity from '../api/activity.js'
3
- import payment from '../api/payment.js'
4
-
5
- export default function (request) {
6
- const { appSecret } = request.config
7
- return createMachine(
8
- {
9
- id: 'reward_cash',
10
- type: 'parallel',
11
- context: {
12
- hasAuth: false,
13
- otherRewardList: [],
14
- pointsRewardList: [],
15
- rewardList: [],
16
- activityNo: null,
17
- receiveNo: null,
18
- withdrawRule: {},
19
- callback: () => {},
20
- },
21
- states: {
22
- timer: {
23
- initial: 'checking',
24
- states: {
25
- checking: {
26
- always: [
27
- {
28
- target: 'loading',
29
- cond: (context, event) => {
30
- return context.hasAuth
31
- },
32
- },
33
- ],
34
- },
35
- loading: {
36
- invoke: {
37
- src: 'fetchRewardList',
38
- onDone: {
39
- target: 'pending',
40
- actions: 'setRewardList',
41
- },
42
- onError: {
43
- target: 'pending',
44
- },
45
- },
46
- },
47
- pending: {
48
- after: {
49
- 20000: { target: 'loading' },
50
- },
51
- },
52
- },
53
- on: {
54
- REFRESH: {
55
- target: '.loading',
56
- },
57
- },
58
- },
59
- reward: {
60
- initial: 'idle',
61
- states: {
62
- idle: {
63
- on: {
64
- FETCH_WITHDRAW_RULE: {
65
- target: 'fetching',
66
- actions: 'setRewardData',
67
- },
68
- RECEIVE_REWARD: {
69
- target: 'receiving',
70
- actions: 'setCallback',
71
- },
72
- RECEIVE_ALL_POINTS: {
73
- target: 'allPointsReceiving',
74
- actions: 'setCallback',
75
- },
76
- },
77
- },
78
- fetching: {
79
- invoke: {
80
- src: 'fetchWithdrawRulePreview',
81
- onDone: {
82
- target: 'pending',
83
- actions: 'setWithdrawRulePreview',
84
- },
85
- onError: {
86
- target: 'idle',
87
- },
88
- },
89
- },
90
- pending: {
91
- on: {
92
- RECEIVE_REWARD: {
93
- target: 'receiving',
94
- actions: 'setCallback',
95
- },
96
- BACK: {
97
- target: 'idle',
98
- },
99
- },
100
- },
101
- receiving: {
102
- invoke: {
103
- src: 'receiveReward',
104
- onDone: {
105
- target: 'received',
106
- actions: [send({ type: 'REFRESH' }), 'doCallback'],
107
- },
108
- onError: {
109
- target: 'idle',
110
- },
111
- },
112
- },
113
- received: {
114
- after: {
115
- 0: {
116
- target: 'idle',
117
- },
118
- },
119
- },
120
- allPointsReceiving: {
121
- invoke: {
122
- src: 'receiveAllPoints',
123
- onDone: {
124
- target: 'idle',
125
- actions: [send({ type: 'REFRESH' }), 'doCallback'],
126
- },
127
- onError: {
128
- target: 'idle',
129
- },
130
- },
131
- },
132
- },
133
- },
134
- },
135
- on: {
136
- SET_AUTH: {
137
- target: '.timer.checking',
138
- actions: 'setAuth',
139
- cond: (context, event) => {
140
- console.log(context.hasAuth, event.data)
141
- return context.hasAuth !== event.data
142
- },
143
- },
144
- },
145
- },
146
- {
147
- actions: {
148
- setAuth: assign((context, event) => {
149
- return { hasAuth: event.data }
150
- }),
151
- setRewardList: assign((context, event) => {
152
- return {
153
- otherRewardList: event.data[0]?.data || [],
154
- pointsRewardList: event.data[1]?.data || [],
155
- rewardList: event.data[2]?.data || [],
156
- }
157
- }),
158
- setRewardData: assign((context, event) => {
159
- const { activityNo, receiveNo } = event.data
160
- return {
161
- activityNo,
162
- receiveNo,
163
- }
164
- }),
165
- setCallback: assign((context, event) => {
166
- return {
167
- callback: event.data?.callback || (() => {}),
168
- }
169
- }),
170
- doCallback: (context, event) => {
171
- context.callback()
172
- },
173
- setWithdrawRulePreview: assign((context, event) => {
174
- return {
175
- withdrawRule: event.data,
176
- }
177
- }),
178
- },
179
- services: {
180
- fetchRewardList: async (context, event) => {
181
- const getRewardAPI = request.send(activity.getRewardList({ count: 30, appSecret }))
182
- const getPointsRewardAPI = request.send(
183
- activity.getRewardList({
184
- rewardType: 'POINTS',
185
- count: 30,
186
- appSecret,
187
- })
188
- )
189
- const getOtherRewardAPI = request.send(
190
- activity.getRewardList({
191
- rewardType: 'CASH,FREE',
192
- count: 30,
193
- appSecret,
194
- })
195
- )
196
- const [otherRewardList, pointsRewardList, rewardList] = await Promise.all([getOtherRewardAPI, getPointsRewardAPI, getRewardAPI])
197
- return [otherRewardList, pointsRewardList, rewardList]
198
- },
199
- fetchWithdrawRulePreview: async (context, event) => {
200
- const { receiveNo } = context
201
- const data = await request.send(
202
- payment.getWithdrawRulePreview({
203
- applyType: 'activity',
204
- applyNo: receiveNo,
205
- amount: null,
206
- })
207
- )
208
- return data
209
- },
210
- receiveReward: async (context, event) => {
211
- const { activityNo, receiveNo, attended } = event.data
212
- return await request.send(activity.getReward({ activityNo, receiveNo, appSecret, attended }))
213
- },
214
- receiveAllPoints: async (context, event) => {
215
- return await request.send(activity.collect({ collectType: 'collectPoints', appSecret }))
216
- },
217
- },
218
- }
219
- )
220
- }
@@ -1,198 +0,0 @@
1
- import { assign, createMachine } from 'xstate'
2
- import game from '../api/game.js'
3
-
4
- export default function (request) {
5
- return createMachine(
6
- {
7
- id: 'side',
8
- initial: 'inactive',
9
- context: {
10
- menu: null,
11
- // menuItemStack: [],
12
- // previousMenuItemStack: [],
13
- // historyStack: [],
14
- // defaultMenuItemStack: [],
15
- },
16
- states: {
17
- active: {
18
- initial: 'loading',
19
- states: {
20
- loading: {
21
- invoke: {
22
- src: 'getMenu',
23
- onDone: {
24
- target: 'idle',
25
- actions: ['setMenu', 'setDefaultMenuItemStack'],
26
- },
27
- },
28
- },
29
- idle: {
30
- initial: 'pending',
31
- states: {
32
- pending: {
33
- after: {
34
- 20000: [
35
- {
36
- target: 'updating',
37
- cond: 'isInMenu',
38
- },
39
- {
40
- target: 'pending',
41
- },
42
- ],
43
- },
44
- },
45
- updating: {
46
- invoke: {
47
- src: 'fetchUpdateMenu',
48
- onDone: {
49
- target: 'pending',
50
- actions: 'updateMenu',
51
- },
52
- },
53
- },
54
- },
55
- },
56
- },
57
- on: {
58
- STOP: {
59
- target: 'inactive',
60
- },
61
- },
62
- },
63
- inactive: {
64
- on: {
65
- START: {
66
- target: 'active',
67
- },
68
- },
69
- },
70
- },
71
- },
72
- {
73
- actions: {
74
- setMenu: assign((context, event) => {
75
- const menu = event.data
76
- addLevelProperty(menu.data, 0)
77
- return { menu }
78
- }),
79
- setDefaultMenuItemStack: assign((context, event) => {
80
- const menu = event.data
81
- if (menu.data.length > 0) {
82
- const menuItemStack = getDefaultItem(menu.data[0])
83
- return { menuItemStack, defaultMenuItemStack: menuItemStack }
84
- }
85
- }),
86
- setMenuItemStack: assign((context, event) => {
87
- const { menuItemStack } = context
88
- const inputItem = event.data
89
- const isTopItem = inputItem.level === 0
90
- const hasSubMenu = inputItem.sub.length
91
-
92
- if (isTopItem) {
93
- if (hasSubMenu) {
94
- return {
95
- previousMenuItemStack: menuItemStack,
96
- menuItemStack: [event.data],
97
- }
98
- } else {
99
- return {
100
- previousMenuItemStack: [],
101
- menuItemStack: [event.data],
102
- historyStack: [],
103
- }
104
- }
105
- } else {
106
- const slicedStack = menuItemStack.slice(0, inputItem.level)
107
- return {
108
- menuItemStack: [...slicedStack, event.data],
109
- historyStack: [],
110
- }
111
- }
112
- }),
113
- restoreMenuItemStack: assign((context, event) => {
114
- const { previousMenuItemStack } = context
115
- return {
116
- previousMenuItemStack: [],
117
- menuItemStack: previousMenuItemStack,
118
- }
119
- }),
120
- updateMenu: assign((context, event) => {
121
- const menu = event.data
122
- if (menu.data.length) {
123
- addLevelProperty(menu.data, 0)
124
- return { menu, defaultMenuItemStack: getDefaultItem(menu.data[0]) }
125
- }
126
- }),
127
- pushHistoryStack: assign((context, event) => {
128
- const { menuItemStack, historyStack } = context
129
- return {
130
- historyStack: historyStack.concat(menuItemStack.slice(-1)),
131
- }
132
- }),
133
- popHistoryStack: assign((context, event) => {
134
- const { historyStack } = context
135
- return {
136
- historyStack: historyStack.slice(0, -1),
137
- }
138
- }),
139
- resetMenuItemStack: assign((context, event) => {
140
- const { defaultMenuItemStack } = context
141
- return { menuItemStack: defaultMenuItemStack }
142
- }),
143
- },
144
- guards: {
145
- isInMenu: (context, event) => {
146
- const { menuItemStack, menu } = context
147
- const menuItem = menuItemStack.slice(-1)[0]
148
- return isItemInMenu(menuItem, menu.data)
149
- },
150
- },
151
- services: {
152
- getMenu: async (context, event) => {
153
- return await request.send(game.getListRoot())
154
- },
155
- fetchUpdateMenu: async (context, event) => {
156
- return await request.send(game.getListRoot({ timestamp: context.menu.timestamp }))
157
- },
158
- },
159
- }
160
- )
161
- }
162
-
163
- function isItemInMenu(targetItem, menuList) {
164
- return menuList.reduce((result, currentItem) => {
165
- if (result) {
166
- return true
167
- } else {
168
- if (currentItem.categoryId === targetItem.categoryId) {
169
- return true
170
- } else if (currentItem.sub?.length) {
171
- return isItemInMenu(targetItem, currentItem.sub)
172
- } else {
173
- return false
174
- }
175
- }
176
- }, false)
177
- }
178
-
179
- function getDefaultItem(node) {
180
- if (node.sub.length > 0) {
181
- const stack = getDefaultItem(node.sub[0])
182
- return [node, ...stack]
183
- } else {
184
- return [node]
185
- }
186
- }
187
-
188
- function addLevelProperty(list, level) {
189
- const nextLevel = level + 1
190
- for (let i = 0; i < list.length; i++) {
191
- list[i].level = level
192
-
193
- // avoid games in list
194
- if (!list[i].isGame) {
195
- addLevelProperty(list[i].sub, nextLevel)
196
- }
197
- }
198
- }