@jetthai/cuora 1.1.488 → 2.0.0-beta.0

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.
Files changed (212) hide show
  1. package/.husky/pre-commit +3 -1
  2. package/BREAKING_CHANGES.md +9 -0
  3. package/CHANGELOG.md +3 -316
  4. package/README.md +15 -299
  5. package/package.json +5 -5
  6. package/resetGitBranch.sh +101 -0
  7. package/src/api/account.js +1 -0
  8. package/src/api/activity.js +39 -24
  9. package/src/api/auth.js +36 -5
  10. package/src/api/common.js +3 -5
  11. package/src/api/game.js +10 -0
  12. package/src/api/payment.js +55 -17
  13. package/src/api/user.js +16 -10
  14. package/src/index.js +2 -2
  15. package/src/lib/fingerprint_v3_11_12.js +11433 -0
  16. package/src/machine/activity/activity.js +213 -0
  17. package/src/machine/activity/activity_cash.js +36 -84
  18. package/src/machine/activity/cash_rain_activity.js +1 -0
  19. package/src/machine/activity/continue_deposit_activity.js +1 -0
  20. package/src/machine/activity/deposit_activity.js +1 -0
  21. package/src/machine/activity/diamond_shop_activity_cash.js +8 -0
  22. package/src/machine/activity/diamond_shop_activity_fc.js +197 -0
  23. package/src/machine/activity/diamond_shop_activity_vn.js +179 -0
  24. package/src/machine/activity/fafafa_activity.js +11 -0
  25. package/src/machine/activity/friend_invite_friends_activity.js +7 -8
  26. package/src/machine/activity/index.js +12 -0
  27. package/src/machine/activity/instant_rebate_activity.js +1 -0
  28. package/src/machine/activity/invite_friends_activity.js +115 -0
  29. package/src/machine/activity/jackpot.js +1 -0
  30. package/src/machine/activity/mini_game_activity.js +69 -0
  31. package/src/machine/activity/otp_verified_activity.js +1 -0
  32. package/src/machine/activity/ranking_activity.js +1 -0
  33. package/src/machine/activity/return_bonus_activity.js +155 -0
  34. package/src/machine/activity/roulette_activity_v2.js +1 -0
  35. package/src/machine/activity/sign_in_activity.js +1 -0
  36. package/src/machine/activity/sign_in_monthly_activity.js +2 -1
  37. package/src/machine/activity/specify_bets_activity.js +1 -0
  38. package/src/machine/activity/specify_turnover_activity.js +1 -0
  39. package/src/machine/activity/time_bomb_activity.js +1 -0
  40. package/src/machine/activity/vip_card_activity.js +1 -0
  41. package/src/machine/auth.js +112 -149
  42. package/src/machine/auth_otp_v2.js +178 -0
  43. package/src/machine/auth_otp_v3.js +22 -64
  44. package/src/machine/bank_binding.js +3 -2
  45. package/src/machine/bank_binding_amb.js +146 -0
  46. package/src/machine/bonus.js +76 -0
  47. package/src/machine/common.js +98 -14
  48. package/src/machine/deposit/amb.js +93 -0
  49. package/src/machine/deposit/crypto_bank.js +340 -0
  50. package/src/machine/deposit/crypto_bank_cash.js +35 -20
  51. package/src/machine/deposit/crypto_qrcode.js +158 -0
  52. package/src/machine/deposit/crypto_qrcode_cash.js +64 -26
  53. package/src/machine/deposit/crypto_way.js +253 -0
  54. package/src/machine/deposit/crypto_way_cash.js +37 -48
  55. package/src/machine/deposit/deposit_fc.js +272 -0
  56. package/src/machine/deposit/direct.js +311 -0
  57. package/src/machine/deposit/direct_cash.js +10 -8
  58. package/src/machine/deposit/float.js +375 -0
  59. package/src/machine/deposit/index.js +28 -0
  60. package/src/machine/deposit/krway.js +152 -0
  61. package/src/machine/deposit/loadcard_cash.js +32 -14
  62. package/src/machine/deposit/loadcard_vn.js +352 -0
  63. package/src/machine/deposit/manual_cash.js +11 -8
  64. package/src/machine/deposit/manual_vn.js +459 -0
  65. package/src/machine/deposit/qrcode_cash.js +32 -15
  66. package/src/machine/deposit/qrcode_v2.js +339 -0
  67. package/src/machine/deposit/usdt.js +163 -0
  68. package/src/machine/deposit/usdt_cash.js +15 -1
  69. package/src/machine/deposit/virtual_bank_cash.js +12 -13
  70. package/src/machine/deposit/virtual_bank_vn.js +270 -0
  71. package/src/machine/deposit/vpay.js +374 -0
  72. package/src/machine/error.js +1 -7
  73. package/src/machine/game_betslip.js +1 -0
  74. package/src/machine/game_favorite_v2.js +1 -0
  75. package/src/machine/game_hot_new.js +80 -0
  76. package/src/machine/game_info.js +13 -1
  77. package/src/machine/game_replay.js +47 -0
  78. package/src/machine/game_search_cash.js +1 -0
  79. package/src/machine/game_search_v2.js +402 -0
  80. package/src/machine/game_v2_1.js +126 -39
  81. package/src/machine/honor_board.js +133 -0
  82. package/src/machine/honor_board_cash.js +28 -22
  83. package/src/machine/inbox.js +105 -43
  84. package/src/machine/index.js +32 -0
  85. package/src/machine/leaderboard.js +12 -8
  86. package/src/machine/merge.js +58 -0
  87. package/src/machine/navbar.js +3 -1
  88. package/src/machine/payment_data.js +87 -0
  89. package/src/machine/promotions.js +163 -0
  90. package/src/machine/ranking.js +30 -45
  91. package/src/machine/reward.js +256 -0
  92. package/src/machine/reward_cash.js +42 -2
  93. package/src/machine/reward_fc.js +99 -0
  94. package/src/machine/roulette_v2.js +11 -14
  95. package/src/machine/setting.js +1 -0
  96. package/src/machine/side.js +160 -0
  97. package/src/machine/side_cash.js +3 -3
  98. package/src/machine/side_v2.js +223 -0
  99. package/src/machine/user_info.js +1 -0
  100. package/src/machine/user_photo.js +1 -0
  101. package/src/machine/user_reset_password.js +14 -0
  102. package/src/machine/user_sign_up.js +61 -46
  103. package/src/machine/vip_table.js +58 -0
  104. package/src/machine/websocket.js +349 -374
  105. package/src/machine/welcome.js +111 -0
  106. package/src/machine/withdraw/index.js +6 -0
  107. package/src/machine/withdraw/withdraw_crypto_cash.js +328 -0
  108. package/src/machine/withdraw/withdraw_krway.js +223 -0
  109. package/src/machine/withdraw/withdraw_manual.js +541 -0
  110. package/src/machine/withdraw/withdraw_manual_cash.js +39 -59
  111. package/src/request/config.js +0 -2
  112. package/src/request/request.js +60 -124
  113. package/src/util/constant.js +2 -6
  114. package/src/util/deviceToken.js +60 -0
  115. package/src/util/index.js +4 -2
  116. package/src/util/math.js +4 -0
  117. package/src/util/storage.js +4 -3
  118. package/test/api.behavior.test.js +69 -0
  119. package/test/api.contract.test.js +18 -0
  120. package/test/config.test.js +27 -0
  121. package/test/deviceToken.test.js +139 -0
  122. package/test/helpers.coverage.test.js +11 -0
  123. package/test/helpers.js +91 -0
  124. package/test/index.exports.test.js +14 -0
  125. package/test/machine.activity.core.coverage.test.js +337 -0
  126. package/test/machine.activity.gap.coverage.test.js +252 -0
  127. package/test/machine.activity.more.coverage.test.js +180 -0
  128. package/test/machine.activity_plus_and_binding_amb.coverage.test.js +201 -0
  129. package/test/machine.activity_timer_bonus.coverage.test.js +136 -0
  130. package/test/machine.activity_welcome.low.coverage.test.js +211 -0
  131. package/test/machine.amb_rewardfc_websocket.more.coverage.test.js +201 -0
  132. package/test/machine.auth.coverage.test.js +215 -0
  133. package/test/machine.bank_binding.test.js +143 -0
  134. package/test/machine.binding_otp_krway.coverage.test.js +223 -0
  135. package/test/machine.contract.test.js +50 -0
  136. package/test/machine.crypto_bank.coverage.test.js +270 -0
  137. package/test/machine.crypto_way.coverage.test.js +108 -0
  138. package/test/machine.crypto_way_cash.coverage.test.js +114 -0
  139. package/test/machine.definition.test.js +137 -0
  140. package/test/machine.deposit.manual.coverage.test.js +365 -0
  141. package/test/machine.deposit_fc.coverage.test.js +126 -0
  142. package/test/machine.direct.coverage.test.js +96 -0
  143. package/test/machine.direct_cash.coverage.test.js +108 -0
  144. package/test/machine.error.coverage.test.js +37 -0
  145. package/test/machine.events.test.js +126 -0
  146. package/test/machine.favorite_jackpot.coverage.test.js +82 -0
  147. package/test/machine.float.coverage.test.js +136 -0
  148. package/test/machine.flow.test.js +226 -0
  149. package/test/machine.game_hot_new_vip_table.coverage.test.js +105 -0
  150. package/test/machine.game_search_cash.coverage.test.js +155 -0
  151. package/test/machine.game_search_v2.test.js +199 -0
  152. package/test/machine.game_user_profile.coverage.test.js +100 -0
  153. package/test/machine.honor_board.test.js +133 -0
  154. package/test/machine.inbox.common.coverage.test.js +304 -0
  155. package/test/machine.loadcard_cash.coverage.test.js +101 -0
  156. package/test/machine.loadcard_vn.coverage.test.js +122 -0
  157. package/test/machine.misc.coverage.test.js +361 -0
  158. package/test/machine.more2.coverage.test.js +261 -0
  159. package/test/machine.options.execution.test.js +272 -0
  160. package/test/machine.priority.coverage.test.js +603 -0
  161. package/test/machine.qrcode_cash.coverage.test.js +107 -0
  162. package/test/machine.qrcode_v2.coverage.test.js +121 -0
  163. package/test/machine.regression.test.js +82 -0
  164. package/test/machine.roulette_v2.test.js +142 -0
  165. package/test/machine.side_reward_reset.coverage.test.js +220 -0
  166. package/test/machine.targeted.coverage.test.js +313 -0
  167. package/test/machine.usdt.coverage.test.js +95 -0
  168. package/test/machine.usdt_cash.coverage.test.js +73 -0
  169. package/test/machine.vip_card_activity.test.js +114 -0
  170. package/test/machine.virtual_bank_cash.coverage.test.js +105 -0
  171. package/test/machine.virtual_bank_vn.coverage.test.js +105 -0
  172. package/test/machine.vpay.coverage.test.js +142 -0
  173. package/test/machine.withdraw_crypto_cash.coverage.test.js +166 -0
  174. package/test/machine.withdraw_krway.coverage.test.js +123 -0
  175. package/test/machine.withdraw_manual.coverage.test.js +185 -0
  176. package/test/machine.withdraw_manual_cash.coverage.test.js +123 -0
  177. package/test/request.test.js +325 -0
  178. package/test/util.storage.errors.test.js +47 -0
  179. package/test/util.test.js +41 -0
  180. package/.claude/commands/sync-ai-prompts.md +0 -93
  181. package/.claude/settings.local.json +0 -23
  182. package/.github/copilot-instructions.md +0 -448
  183. package/.husky/post-checkout +0 -32
  184. package/.husky/pre-push +0 -36
  185. package/AGENTS.md +0 -448
  186. package/AI_PROMPT_SOURCE.md +0 -446
  187. package/CLAUDE.md +0 -448
  188. package/GEMINI.md +0 -448
  189. package/docs/kibana/crypto-way-deposit-amount-bug-analysis.md +0 -1003
  190. package/docs/kibana/play-providerId-error.md +0 -202
  191. package/docs/kibana/play-selectedWalletType.md +0 -1
  192. package/docs/kibana/play-selectedWalletType_2.md +0 -1
  193. package/docs/kibana/play-selectedWalletType_analysis.md +0 -565
  194. package/docs/my-claude/feat-sharon-JT-1790247240-socket/branch-transfer.md +0 -14
  195. package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-preparation.json +0 -40
  196. package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-verification.md +0 -41
  197. package/docs/my-claude/feat-sharon-JT-1790247240-socket/implementation-ledger.md +0 -87
  198. package/docs/my-claude/feat-sharon-JT-1790247240-socket/module-report.md +0 -73
  199. package/docs/my-claude/feat-sharon-JT-1790247240-socket/plan.md +0 -309
  200. package/docs/my-claude/feat-sharon-JT-1790247240-socket/test-cases.md +0 -245
  201. package/docs/my-claude/feat-sharon-JT-1791180540-onesignal/transfer.md +0 -9
  202. package/scripts/auto-version.js +0 -68
  203. package/scripts/auto-version.sh +0 -33
  204. package/scripts/branch-auto-npm-publish.js +0 -29
  205. package/scripts/check-version.sh +0 -36
  206. package/scripts/clean-tags.sh +0 -84
  207. package/src/util/amount.js +0 -8
  208. package/src/util/err998SentryExtra.js +0 -26
  209. package/src/util/paramStore.js +0 -139
  210. package/src/util/socketPolicy.js +0 -57
  211. package/test/auth_otp_v3.test.js +0 -323
  212. package/tests/websocket.test.mjs +0 -779
@@ -0,0 +1,272 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import toNumber from 'lodash/toNumber.js'
3
+ import payment from '../../api/payment.js'
4
+
5
+ // const toNumber = require('lodash/toNumber')
6
+
7
+ export default function (request) {
8
+ return createMachine(
9
+ {
10
+ id: 'deposit',
11
+ predictableActionArguments: true,
12
+ initial: 'loading',
13
+ context: {
14
+ cryptos: [],
15
+ networks: [],
16
+ currentCrypto: null,
17
+ currentNetwork: null,
18
+ currentAmount: null,
19
+ calculatedResult: null,
20
+ submittedResult: null,
21
+ bonus: null,
22
+ },
23
+ states: {
24
+ loading: {
25
+ initial: 'bonusStatus',
26
+ states: {
27
+ bonusStatus: {
28
+ invoke: {
29
+ src: 'getPaymentInfo',
30
+ onDone: {
31
+ target: 'fetchingPayments',
32
+ actions: 'setBonus',
33
+ },
34
+ onError: {
35
+ target: '#deposit.loaded',
36
+ },
37
+ },
38
+ },
39
+ fetchingPayments: {
40
+ invoke: {
41
+ src: 'fetchPayments',
42
+ onDone: {
43
+ target: '#deposit.loaded',
44
+ actions: 'setCryptos',
45
+ },
46
+ onError: {
47
+ target: '#deposit.loaded',
48
+ },
49
+ },
50
+ },
51
+ },
52
+ },
53
+ loaded: {
54
+ on: {
55
+ SUBMIT: {
56
+ target: 'submitting',
57
+ cond: 'isSubmittable',
58
+ },
59
+ },
60
+ },
61
+ checking: {
62
+ entry: 'clearCalculatedResult',
63
+ always: [{ target: 'debouncing', cond: 'isCalculable' }, { target: 'loaded' }],
64
+ },
65
+ debouncing: {
66
+ after: {
67
+ 1000: {
68
+ target: 'calculating',
69
+ },
70
+ },
71
+ },
72
+ calculating: {
73
+ invoke: {
74
+ src: 'fetchCalculation',
75
+ onDone: {
76
+ target: 'loaded',
77
+ actions: 'setCalculatedResult',
78
+ },
79
+ onError: {
80
+ target: 'loaded',
81
+ },
82
+ },
83
+ },
84
+ submitting: {
85
+ invoke: {
86
+ src: 'submitDeposit',
87
+ onDone: {
88
+ target: '#deposit.submitted',
89
+ actions: 'setSubmittedResult',
90
+ },
91
+ onError: {
92
+ target: 'loaded',
93
+ },
94
+ },
95
+ },
96
+ switchingBonus: {
97
+ invoke: {
98
+ src: 'setBonusSetting',
99
+ onDone: {
100
+ target: 'checking',
101
+ },
102
+ onError: {
103
+ target: 'loaded',
104
+ },
105
+ },
106
+ },
107
+ submitted: {},
108
+ },
109
+ on: {
110
+ SET_CRYPTO: {
111
+ target: 'checking',
112
+ actions: 'setCrypto',
113
+ cond: 'hasCryptoOptions',
114
+ },
115
+ SET_NETWORK: {
116
+ target: 'checking',
117
+ actions: 'setNetwork',
118
+ cond: 'hasNetworkOptions',
119
+ },
120
+ SET_AMOUNT: {
121
+ target: 'checking',
122
+ actions: 'setAmount',
123
+ },
124
+ TOGGLE_BONUS: {
125
+ target: 'switchingBonus',
126
+ actions: 'toggleBonus',
127
+ },
128
+ },
129
+ },
130
+ {
131
+ actions: {
132
+ setCryptos: assign((context, event) => {
133
+ return {
134
+ cryptos: event.data.map((crypto) => ({
135
+ ...crypto,
136
+ label: crypto.channel,
137
+ value: crypto.method,
138
+ icon: crypto.channel,
139
+ })),
140
+ }
141
+ }),
142
+ setCrypto: assign((context, event) => {
143
+ const { cryptos, currentNetwork } = context
144
+ const method = cryptos.find((crypto) => crypto.method === event.data.value)
145
+ const networks =
146
+ method?.networkName.map((value, i) => {
147
+ return {
148
+ label: method?.networkOptional?.[i],
149
+ value,
150
+ icon: value,
151
+ }
152
+ }) || []
153
+
154
+ const properties = {
155
+ currentCrypto: event.data,
156
+ networks,
157
+ }
158
+
159
+ if (!networks.includes(currentNetwork)) {
160
+ properties.currentNetwork = null
161
+ properties.currentAmount = null
162
+ properties.calculatedResult = null
163
+ }
164
+
165
+ return properties
166
+ }),
167
+ setNetwork: assign((context, event) => {
168
+ return { currentNetwork: event.data }
169
+ }),
170
+ setAmount: assign((context, event) => {
171
+ const currentAmount = event.data
172
+
173
+ const properties = {
174
+ currentAmount,
175
+ }
176
+
177
+ if (!currentAmount) {
178
+ properties.calculatedResult = null
179
+ }
180
+
181
+ return properties
182
+ }),
183
+ setCalculatedResult: assign((context, event) => {
184
+ // V2接口轉換中回傳的資料結構不同
185
+ const { data } = event.data
186
+ if (data) {
187
+ return {
188
+ calculatedResult: data,
189
+ }
190
+ } else {
191
+ return {
192
+ calculatedResult: event.data,
193
+ }
194
+ }
195
+ }),
196
+ setSubmittedResult: assign((context, event) => {
197
+ return {
198
+ submittedResult: event.data,
199
+ }
200
+ }),
201
+ clearCalculatedResult: assign((context, event) => {
202
+ return {
203
+ calculatedResult: null,
204
+ }
205
+ }),
206
+ toggleBonus: assign((context, event) => {
207
+ const { bonus } = context
208
+ return {
209
+ bonus: bonus === 1 ? 0 : 1,
210
+ }
211
+ }),
212
+ setBonus: assign((context, event) => {
213
+ return {
214
+ bonus: event.data,
215
+ }
216
+ }),
217
+ },
218
+ guards: {
219
+ hasCryptoOptions: (context, evnet) => {
220
+ return context.cryptos.length > 0
221
+ },
222
+ hasNetworkOptions: (context, evnet) => {
223
+ return context.networks.length > 0
224
+ },
225
+ isCalculable: (context, event) => {
226
+ const { currentCrypto, currentNetwork, currentAmount } = context
227
+ return currentCrypto && currentNetwork && toNumber(currentAmount)
228
+ },
229
+ isSubmittable: (context, event) => {
230
+ return context.calculatedResult
231
+ },
232
+ isBonusOff: (context, event) => {
233
+ return context.bonus !== 1
234
+ },
235
+ },
236
+ services: {
237
+ fetchPayments: async (context, event) => {
238
+ return await request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' }))
239
+ },
240
+ fetchCalculation: async (context, event) => {
241
+ const { currentCrypto, currentAmount } = context
242
+ return await request.send(
243
+ payment.getDepositExpectedResult({
244
+ method: currentCrypto.method,
245
+ amount: Number(currentAmount),
246
+ cryptoCurrency: currentCrypto.channel,
247
+ })
248
+ )
249
+ },
250
+ submitDeposit: async (context, event) => {
251
+ const { currentCrypto, currentNetwork, calculatedResult } = context
252
+ return await request.send(
253
+ payment.submitDepositTransactionCrypto({
254
+ method: currentCrypto.method,
255
+ amount: calculatedResult.actualAmount,
256
+ cryptoCurrency: currentCrypto.channel,
257
+ cryptoNetwork: currentNetwork.value,
258
+ })
259
+ )
260
+ },
261
+ setBonusSetting: async (context, event) => {
262
+ const { bonus } = context
263
+ return await request.send(payment.setBonusSetting({ bonus }))
264
+ },
265
+ getPaymentInfo: async (context, event) => {
266
+ const { bonus } = await request.send(payment.getPaymentInfo())
267
+ return bonus
268
+ },
269
+ },
270
+ }
271
+ )
272
+ }
@@ -0,0 +1,311 @@
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: 'direct',
10
+ predictableActionArguments: true,
11
+ initial: 'loading',
12
+ context: {
13
+ siteConfig: null,
14
+ paymentDetail: [],
15
+ directs: [],
16
+ currentDirect: null,
17
+ banks: [],
18
+ selectedBank: null,
19
+ calculation: null,
20
+ currentCategory: 'direct',
21
+ currentMethod: null,
22
+ amount: null,
23
+ result: null,
24
+
25
+ // use for wallet mode 3
26
+ promotion: null,
27
+ },
28
+ states: {
29
+ loading: {
30
+ initial: 'init',
31
+ states: {
32
+ init: {
33
+ invoke: {
34
+ src: 'fetchInitData',
35
+ onDone: {
36
+ target: 'fetching',
37
+ actions: 'setInitData',
38
+ },
39
+ onError: {
40
+ target: '#direct.fail',
41
+ },
42
+ },
43
+ },
44
+ fetching: {
45
+ invoke: {
46
+ src: 'fetchBanksList',
47
+ onDone: {
48
+ target: '#direct.promotion',
49
+ actions: 'setBanks',
50
+ },
51
+ onError: {
52
+ target: '#direct.fail',
53
+ },
54
+ },
55
+ },
56
+ },
57
+ },
58
+ promotion: {
59
+ always: [
60
+ {
61
+ target: 'loaded',
62
+ },
63
+ {
64
+ target: 'calculating',
65
+ actions: 'setPromotionDefaultAmount',
66
+ cond: 'hasMinPromotionDeposit',
67
+ },
68
+ {
69
+ target: 'loaded',
70
+ },
71
+ ],
72
+ },
73
+ loaded: {
74
+ on: {
75
+ SELECT_DIRECT: {
76
+ actions: ['setDirect', 'reset'],
77
+ target: 'loading.fetching',
78
+ },
79
+ SELECT_BANK: {
80
+ actions: 'setSelectedBank',
81
+ },
82
+ SET_AMOUNT: {
83
+ actions: ['setAmount', 'clearCalculation'],
84
+ },
85
+ CLEAR_CALCULATION: {
86
+ actions: 'clearCalculation',
87
+ },
88
+ CALCULATE: {
89
+ target: 'debouncing',
90
+ },
91
+ SUBMIT: [
92
+ {
93
+ target: 'pending',
94
+ cond: (context, event) => !!context.calculation,
95
+ },
96
+ {
97
+ target: 'submitting',
98
+ cond: 'isSubmittable',
99
+ },
100
+ ],
101
+ },
102
+ },
103
+ pending: {
104
+ on: {
105
+ SUBMIT: {
106
+ target: 'submitting',
107
+ cond: 'isSubmittable',
108
+ },
109
+ },
110
+ },
111
+ debouncing: {
112
+ on: {
113
+ SELECT_DIRECT: {
114
+ actions: ['setDirect', 'reset'],
115
+ target: 'loading.fetching',
116
+ },
117
+ SELECT_BANK: {
118
+ actions: 'setSelectedBank',
119
+ },
120
+ SET_AMOUNT: {
121
+ actions: ['setAmount', 'clearCalculation'],
122
+ },
123
+ CLEAR_CALCULATION: {
124
+ actions: 'clearCalculation',
125
+ },
126
+ CALCULATE: {
127
+ target: 'debouncing',
128
+ },
129
+ SUBMIT: [
130
+ {
131
+ target: 'pending',
132
+ cond: (context, event) => !!context.calculation,
133
+ },
134
+ {
135
+ target: 'submitting',
136
+ cond: 'isSubmittable',
137
+ },
138
+ ],
139
+ },
140
+ after: {
141
+ 1000: [{ target: 'calculating', cond: 'isCalculable' }, { target: 'loaded' }],
142
+ },
143
+ },
144
+ calculating: {
145
+ invoke: {
146
+ src: 'fetchCalculation',
147
+ onDone: {
148
+ target: 'loaded',
149
+ actions: 'setCalculation',
150
+ },
151
+ onError: {
152
+ target: 'loaded',
153
+ },
154
+ },
155
+ },
156
+ submitting: {
157
+ invoke: {
158
+ src: 'submitDeposit',
159
+ onDone: {
160
+ target: 'submitted',
161
+ actions: 'setResult',
162
+ },
163
+ onError: {
164
+ target: 'loaded',
165
+ },
166
+ },
167
+ },
168
+ submitted: {},
169
+ fail: {},
170
+ },
171
+ on: {
172
+ SET_PROMOTION: {
173
+ actions: 'setPromotion',
174
+ },
175
+ },
176
+ },
177
+ {
178
+ actions: {
179
+ reset: assign((context, event) => {
180
+ const { banks } = context
181
+ return {
182
+ amount: null,
183
+ selectedBank: banks[0],
184
+ calculation: null,
185
+ result: null,
186
+ }
187
+ }),
188
+ setInitData: assign((context, event) => {
189
+ const { siteConfig, paymentDetail } = event.data
190
+ const directs = paymentDetail.filter((element) => element.category === context.currentCategory)
191
+ const currentDirect = directs[0]
192
+ return {
193
+ siteConfig,
194
+ paymentDetail,
195
+ directs,
196
+ currentDirect,
197
+ currentMethod: currentDirect?.method,
198
+ }
199
+ }),
200
+ setBanks: assign((context, event) => {
201
+ const banks = event.data?.data ? event.data.data : event.data
202
+ return {
203
+ banks,
204
+ selectedBank: banks[0],
205
+ }
206
+ }),
207
+ setDirect: assign((context, event) => {
208
+ return {
209
+ currentDirect: event.data,
210
+ currentMethod: event.data.method,
211
+ }
212
+ }),
213
+ setSelectedBank: assign((context, event) => {
214
+ return {
215
+ selectedBank: event.data,
216
+ }
217
+ }),
218
+ setAmount: assign((context, event) => {
219
+ return {
220
+ amount: event.data,
221
+ }
222
+ }),
223
+ setCalculation: assign((context, event) => {
224
+ // V2接口轉換中回傳的資料結構不同
225
+ const { data } = event.data
226
+ if (data) {
227
+ return {
228
+ calculation: data,
229
+ }
230
+ } else {
231
+ return {
232
+ calculation: event.data,
233
+ }
234
+ }
235
+ }),
236
+ clearCalculation: assign((context, event) => {
237
+ return {
238
+ calculation: null,
239
+ }
240
+ }),
241
+ setResult: assign((context, event) => {
242
+ return {
243
+ result: event.data,
244
+ }
245
+ }),
246
+ setPromotion: assign((context, event) => {
247
+ return {
248
+ promotion: event.data,
249
+ }
250
+ }),
251
+ setPromotionDefaultAmount: assign((context, event) => {
252
+ return {
253
+ amount: context.promotion.minimumAmount,
254
+ }
255
+ }),
256
+ },
257
+ guards: {
258
+ isCalculable: (context, event) => {
259
+ const {
260
+ amount,
261
+ currentDirect: { maximum, minimum },
262
+ } = context
263
+ return amount && minimum <= +amount && +amount <= maximum
264
+ },
265
+ isSubmittable: (context, event) => {
266
+ const { amount, currentMethod, selectedBank } = context
267
+ return amount && currentMethod && selectedBank?.bankCode
268
+ },
269
+ hasMinPromotionDeposit: (context, event) => {
270
+ return context.promotion?.minimumAmount
271
+ },
272
+ },
273
+ services: {
274
+ fetchInitData: async (context, event) => {
275
+ const [{ config }, paymentDetail = []] = await Promise.all([
276
+ request.send(common.getConfig({ appSecret })),
277
+ request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' })),
278
+ ])
279
+ const siteConfig = JSON.parse(window.atob(config))
280
+ return { siteConfig, paymentDetail }
281
+ },
282
+ fetchBanksList: async (context, event) => {
283
+ const { currentDirect } = context
284
+ const method = currentDirect.method
285
+ return await request.send(payment.getBankList(method))
286
+ },
287
+ fetchCalculation: async (context, event) => {
288
+ const { currentMethod, amount, promotion } = context
289
+ return await request.send(
290
+ payment.getDepositExpectedResult({
291
+ method: currentMethod,
292
+ amount: Number(amount),
293
+ promotionsNo: promotion?.activityNo,
294
+ })
295
+ )
296
+ },
297
+ submitDeposit: async (context, event) => {
298
+ const { currentMethod, amount, selectedBank, promotion } = context
299
+ return await request.send(
300
+ payment.submitDepositTransactionBank({
301
+ method: currentMethod,
302
+ amount,
303
+ applyerBankCode: selectedBank.bankCode,
304
+ promotionsNo: promotion?.activityNo,
305
+ })
306
+ )
307
+ },
308
+ },
309
+ }
310
+ )
311
+ }
@@ -1,6 +1,6 @@
1
1
  import { assign, createMachine } from 'xstate'
2
2
  import payment from '../../api/payment.js'
3
- import { isAmountInRange } from '../../util/amount.js'
3
+ import { max } from '../../util/index.js'
4
4
 
5
5
  export default function (request, context) {
6
6
  const { paymentDetail = [], promotion, selectedAmount } = context || {}
@@ -8,6 +8,7 @@ export default function (request, context) {
8
8
  return createMachine(
9
9
  {
10
10
  id: 'direct_cash',
11
+ predictableActionArguments: true,
11
12
  initial: 'loading',
12
13
  context: {
13
14
  paymentDetail,
@@ -88,7 +89,6 @@ export default function (request, context) {
88
89
  target: '.loading',
89
90
  actions: 'setPromotion',
90
91
  internal: false,
91
- cond: 'isPromotionChanged',
92
92
  },
93
93
  SELECT_DIRECT: {
94
94
  target: '.loading',
@@ -109,12 +109,13 @@ export default function (request, context) {
109
109
  {
110
110
  actions: {
111
111
  setInitData: assign((context, event) => {
112
- const { paymentDetail } = context
112
+ const { paymentDetail, selectedAmount, promotion } = context
113
113
  const directs = paymentDetail.filter((element) => element.category === context.currentCategory && element.transferType === 'deposit')
114
114
  const selectedDirect = context.selectedDirect || directs[0]
115
115
  return {
116
116
  directs,
117
117
  selectedDirect,
118
+ selectedAmount: max(promotion?.minimumAmount, selectedDirect?.minimum, selectedAmount, 0),
118
119
  }
119
120
  }),
120
121
  setBanks: assign((context, event) => {
@@ -131,7 +132,6 @@ export default function (request, context) {
131
132
  setDirect: assign((context, event) => {
132
133
  return {
133
134
  selectedDirect: event.data,
134
- calculation: null,
135
135
  }
136
136
  }),
137
137
  setUserBank: assign((context, event) => {
@@ -170,15 +170,17 @@ export default function (request, context) {
170
170
  setPromotion: assign((context, event) => {
171
171
  return {
172
172
  promotion: event.data,
173
- calculation: null,
174
173
  }
175
174
  }),
176
175
  },
177
176
  guards: {
178
- isPromotionChanged: (context, event) => {
179
- return event.data?.promotionsNo !== context.promotion?.promotionsNo
177
+ isCalculable: (context, event) => {
178
+ const {
179
+ selectedAmount,
180
+ selectedDirect: { maximum, minimum },
181
+ } = context
182
+ return selectedAmount && minimum <= +selectedAmount && +selectedAmount <= maximum
180
183
  },
181
- isCalculable: ({ selectedDirect, selectedAmount }) => isAmountInRange(selectedAmount, selectedDirect),
182
184
  isSubmittable: (context, event) => {
183
185
  const { selectedAmount, selectedDirect, selectedUserBank } = context
184
186
  return selectedAmount && selectedDirect && selectedUserBank