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