@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
@@ -1,18 +1,12 @@
1
1
  import { assign, createMachine } from 'xstate'
2
2
  import user from '../api/user.js'
3
3
  import otp from '../api/otp.js'
4
- import { AUTO_VERIFY_MAX_USER_INFO_UPDATES, AUTO_VERIFY_WAIT_MS } from '../util/constant.js'
5
-
6
- function isStrategyVerified(strategy, userInfo) {
7
- if (strategy === 'phone') return !!(userInfo?.phone || userInfo?.tel) && !!userInfo?.phone_verification_status
8
- if (strategy === 'email') return !!userInfo?.email && !!userInfo?.email_verification_status
9
- return false
10
- }
11
4
 
12
5
  export default function (request) {
13
6
  return createMachine(
14
7
  {
15
8
  id: 'auth_otp',
9
+ predictableActionArguments: true,
16
10
  initial: 'idle',
17
11
  context: {
18
12
  strategy: null,
@@ -25,7 +19,6 @@ export default function (request) {
25
19
  requestId: null,
26
20
  status: null,
27
21
  ttl: 0,
28
- autoVerifyUpdates: 0,
29
22
  },
30
23
  states: {
31
24
  idle: {
@@ -56,44 +49,16 @@ export default function (request) {
56
49
  { target: 'notVerified', cond: 'isNotVerified' },
57
50
  ],
58
51
  },
59
- autoVerifying: {
60
- invoke: {
61
- src: 'fetchUserInfo',
62
- onDone: {
63
- target: 'checkingAutoVerification',
64
- actions: 'setUserInfo',
65
- },
66
- onError: { target: 'fail' },
67
- },
68
- },
69
- checkingAutoVerification: {
70
- always: [{ target: 'verified', cond: 'isVerified' }, { target: 'autoVerifyWaiting' }],
71
- },
72
- // 後端寫入驗證狀態到 /self 反映之間有延遲(主動打的那次可能還是舊值),
73
- // 改等下游轉送 auth 例行輪詢的 /self 結果,不另開輪詢以免重複打 /self
74
- autoVerifyWaiting: {
75
- entry: 'resetAutoVerifyUpdates',
76
- after: {
77
- AUTO_VERIFY_TIMEOUT: { target: 'fail' },
78
- },
79
- on: {
80
- USER_INFO_UPDATED: [
81
- { target: 'verified', cond: 'isUpdatedUserInfoVerified', actions: 'setUserInfo' },
82
- { target: 'fail', cond: 'isLastAutoVerifyUpdate', actions: 'setUserInfo' },
83
- { actions: ['setUserInfo', 'countAutoVerifyUpdate'] },
84
- ],
85
- },
86
- },
87
52
  notVerified: {
88
53
  initial: 'checkingStatus',
89
54
  states: {
90
55
  checkingStatus: {
91
56
  invoke: {
92
57
  src: 'verify',
93
- onDone: [
94
- { target: '#auth_otp.autoVerifying', cond: 'doesNotNeedAcknowledge' },
95
- { target: 'otp', actions: 'setVerificationData' },
96
- ],
58
+ onDone: {
59
+ target: 'otp',
60
+ actions: 'setVerificationData',
61
+ },
97
62
  onError: {
98
63
  target: 'errorChecking',
99
64
  actions: 'setError',
@@ -122,20 +87,20 @@ export default function (request) {
122
87
  sendingPhone: {
123
88
  invoke: {
124
89
  src: 'sendPhone',
125
- onDone: [
126
- { target: '#auth_otp.autoVerifying', cond: 'doesNotNeedAcknowledge' },
127
- { target: 'otp', actions: 'setVerificationData' },
128
- ],
90
+ onDone: {
91
+ target: 'otp',
92
+ actions: 'setVerificationData',
93
+ },
129
94
  onError: { target: 'phone' },
130
95
  },
131
96
  },
132
97
  sendingEmail: {
133
98
  invoke: {
134
99
  src: 'sendEmail',
135
- onDone: [
136
- { target: '#auth_otp.autoVerifying', cond: 'doesNotNeedAcknowledge' },
137
- { target: 'otp', actions: 'setVerificationData' },
138
- ],
100
+ onDone: {
101
+ target: 'otp',
102
+ actions: 'setVerificationData',
103
+ },
139
104
  onError: { target: 'email' },
140
105
  },
141
106
  },
@@ -165,6 +130,9 @@ export default function (request) {
165
130
  RESET_OTP: {
166
131
  target: 'reset',
167
132
  },
133
+ RESEND_PHONE: {
134
+ target: '#auth_otp.notVerified.phone',
135
+ },
168
136
  },
169
137
  },
170
138
  acknowledging: {
@@ -199,9 +167,6 @@ export default function (request) {
199
167
  },
200
168
  },
201
169
  {
202
- delays: {
203
- AUTO_VERIFY_TIMEOUT: AUTO_VERIFY_WAIT_MS,
204
- },
205
170
  actions: {
206
171
  setStrategy: assign((context, event) => {
207
172
  return {
@@ -232,8 +197,6 @@ export default function (request) {
232
197
  ttl: Math.max(ms - 1000, 0),
233
198
  }
234
199
  }),
235
- resetAutoVerifyUpdates: assign(() => ({ autoVerifyUpdates: 0 })),
236
- countAutoVerifyUpdate: assign((context) => ({ autoVerifyUpdates: context.autoVerifyUpdates + 1 })),
237
200
  setError: assign((context, event) => {
238
201
  return {
239
202
  error: event.data,
@@ -254,24 +217,19 @@ export default function (request) {
254
217
  }),
255
218
  },
256
219
  guards: {
257
- doesNotNeedAcknowledge: (context, event) => event.data?.needAcknowledge === false,
258
- isVerified: (context, event) => isStrategyVerified(context.strategy, context.userInfo),
259
- isUpdatedUserInfoVerified: (context, event) => isStrategyVerified(context.strategy, event.data),
260
- isLastAutoVerifyUpdate: (context, event) => context.autoVerifyUpdates + 1 >= AUTO_VERIFY_MAX_USER_INFO_UPDATES,
220
+ isVerified: (context, event) => {
221
+ return context.userInfo?.verification_status === 1
222
+ },
261
223
  isNotVerified: (context, event) => {
262
- const { strategy, userInfo } = context
263
- if (!userInfo) return false
264
- if (strategy === 'phone') return !userInfo.phone_verification_status
265
- if (strategy === 'email') return !userInfo.email_verification_status
266
- return false
224
+ return context.userInfo && context.userInfo.verification_status !== 1
267
225
  },
268
226
  isPhoneNotVerified: (context, event) => {
269
227
  const { strategy, userInfo } = context
270
- return strategy === 'phone' && !!userInfo && !(userInfo.phone || userInfo.tel)
228
+ return strategy === 'phone' && userInfo && userInfo.verification_status !== 1 && !userInfo.phone
271
229
  },
272
230
  isEmailNotVerified: (context, event) => {
273
231
  const { strategy, userInfo } = context
274
- return strategy === 'email' && !!userInfo && !userInfo.email
232
+ return strategy === 'email' && userInfo && userInfo.verification_status !== 1 && !userInfo.email
275
233
  },
276
234
  hasNoPhone: (context, event) => {
277
235
  const { error } = context
@@ -7,6 +7,7 @@ export default function (request) {
7
7
  return createMachine(
8
8
  {
9
9
  id: 'bank_binding',
10
+ predictableActionArguments: true,
10
11
  initial: 'fetching',
11
12
  context: {
12
13
  hasAnyAccount: false,
@@ -231,7 +232,7 @@ export default function (request) {
231
232
  fetchInitData: async (context, event) => {
232
233
  const [paymentList, paymentInfo] = await Promise.all([
233
234
  request.send(payment.getBindingPaymentList({ appSecret })),
234
- // request.send(payment.getPaymentInfo()),
235
+ request.send(payment.getPaymentInfo()),
235
236
  ])
236
237
  return { paymentList, paymentInfo }
237
238
  },
@@ -258,7 +259,7 @@ export default function (request) {
258
259
  ifscCode,
259
260
  bankCode: bank?.bankCode || '',
260
261
  cryptoCurrency: crypto?.symbol || '',
261
- cryptoNetwork: network?.networkCode,
262
+ cryptoNetwork: network?.label || '',
262
263
  cryptoAddress: cryptoAddress,
263
264
  walletCode: walletCode?.bankCode || '',
264
265
  branch: branch === 'BLANK' ? '' : branch, // 'BLANK'會置換成空值
@@ -0,0 +1,146 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import payment from '../api/payment.js'
3
+
4
+ export default function (request) {
5
+ const { appSecret } = request.config
6
+
7
+ return createMachine(
8
+ {
9
+ id: 'bank_binding_amb',
10
+ predictableActionArguments: true,
11
+ initial: 'fetching',
12
+ context: {
13
+ hasAnyAccount: false,
14
+ bankList: [],
15
+ bank: null,
16
+ // bonus: 0,
17
+ bankAccount: null,
18
+ firstNameTh: null,
19
+ lastNameTh: null,
20
+ firstNameEn: null,
21
+ lastNameEn: null,
22
+ },
23
+ states: {
24
+ fetching: {
25
+ invoke: {
26
+ src: 'fetchInitData',
27
+ onDone: {
28
+ target: 'idle',
29
+ actions: 'setBanks',
30
+ },
31
+ onError: {
32
+ target: 'idle',
33
+ },
34
+ },
35
+ },
36
+ idle: {
37
+ on: {
38
+ SET_BANK_CODE: {
39
+ actions: assign((context, event) => {
40
+ return {
41
+ bank: event.data,
42
+ }
43
+ }),
44
+ },
45
+ SET_BANK_ACCOUNT: {
46
+ actions: assign((context, event) => {
47
+ return {
48
+ bankAccount: event.data,
49
+ }
50
+ }),
51
+ },
52
+ SET_FIRST_NAME_TH: {
53
+ actions: assign((context, event) => {
54
+ return {
55
+ firstNameTh: event.data,
56
+ }
57
+ }),
58
+ },
59
+ SET_LAST_NAME_TH: {
60
+ actions: assign((context, event) => {
61
+ return {
62
+ lastNameTh: event.data,
63
+ }
64
+ }),
65
+ },
66
+ SET_FIRST_NAME_EN: {
67
+ actions: assign((context, event) => {
68
+ return {
69
+ firstNameEn: event.data,
70
+ }
71
+ }),
72
+ },
73
+ SET_LAST_NAME_EN: {
74
+ actions: assign((context, event) => {
75
+ return {
76
+ lastNameEn: event.data,
77
+ }
78
+ }),
79
+ },
80
+ BIND_BANK: {
81
+ target: 'binding',
82
+ cond: 'isBindable',
83
+ },
84
+ },
85
+ },
86
+ binding: {
87
+ invoke: {
88
+ src: 'updatePaymentInfo',
89
+ onDone: {
90
+ target: 'bound',
91
+ },
92
+ onError: {
93
+ target: 'idle',
94
+ },
95
+ },
96
+ },
97
+ bound: {},
98
+ },
99
+ },
100
+ {
101
+ actions: {
102
+ setBanks: assign((context, event) => {
103
+ const { bankList = [], paymentInfo = {} } = event.data
104
+ const { bankInfo = [] } = paymentInfo
105
+ return {
106
+ hasAnyAccount: bankInfo.length > 0,
107
+ holderName: bankInfo[0]?.holderName,
108
+ bankList,
109
+ bank: bankList[0],
110
+ }
111
+ }),
112
+ },
113
+ guards: {
114
+ isBindable: (context, event) => {
115
+ const { bank, bankAccount, firstNameTh, lastNameTh, firstNameEn, lastNameEn } = context
116
+
117
+ return bank.bankCode && bankAccount && firstNameTh && lastNameTh && firstNameEn && lastNameEn
118
+ },
119
+ },
120
+ services: {
121
+ fetchInitData: async (context, event) => {
122
+ const [bankList, paymentInfo] = await Promise.all([
123
+ request.send(payment.getBindingBankList({ appSecret })),
124
+ request.send(payment.getPaymentInfo()),
125
+ ])
126
+ return { bankList, paymentInfo }
127
+ },
128
+ updatePaymentInfo: async (context, event) => {
129
+ const { bonus, bank, bankAccount, firstNameTh, lastNameTh, firstNameEn, lastNameEn } = context
130
+ return await request.send(
131
+ payment.updatePaymentInfo({
132
+ paymentProvider: 'amb',
133
+ // bonus,
134
+ bankCode: bank.bankCode,
135
+ bankAccount,
136
+ firstNameTh,
137
+ lastNameTh,
138
+ firstNameEn,
139
+ lastNameEn,
140
+ })
141
+ )
142
+ },
143
+ },
144
+ }
145
+ )
146
+ }
@@ -0,0 +1,76 @@
1
+ import { assign, createMachine, send } from 'xstate'
2
+ import payment from '../api/payment.js'
3
+
4
+ export default function (request) {
5
+ return createMachine(
6
+ {
7
+ id: 'bonus',
8
+ predictableActionArguments: true,
9
+ initial: 'loading',
10
+ context: {
11
+ bonus: null,
12
+ },
13
+ states: {
14
+ loading: {
15
+ invoke: {
16
+ src: 'fetchInitData',
17
+ onDone: {
18
+ target: 'idle',
19
+ actions: 'setBonus',
20
+ },
21
+ onError: {
22
+ target: 'idle',
23
+ },
24
+ },
25
+ },
26
+ idle: {
27
+ on: {
28
+ TOGGLE: {
29
+ target: 'updating',
30
+ },
31
+ SWITCH_ON: {
32
+ actions: send((context, event) => ({ type: 'TOGGLE', data: 1 })),
33
+ cond: (context, event) => context.bonus !== 1,
34
+ },
35
+ SWITCH_OFF: {
36
+ actions: send((context, event) => ({ type: 'TOGGLE', data: 0 })),
37
+ cond: (context, event) => context.bonus !== 0,
38
+ },
39
+ },
40
+ },
41
+ updating: {
42
+ invoke: {
43
+ src: 'toggleBonus',
44
+ onDone: {
45
+ target: 'idle',
46
+ actions: 'setBonus',
47
+ },
48
+ onError: {
49
+ target: 'idle',
50
+ },
51
+ },
52
+ },
53
+ },
54
+ },
55
+ {
56
+ actions: {
57
+ setBonus: assign((context, event) => {
58
+ return {
59
+ bonus: event.data,
60
+ }
61
+ }),
62
+ },
63
+ services: {
64
+ fetchInitData: async (context, event) => {
65
+ const { bonus } = await request.send(payment.getPaymentInfo())
66
+ return bonus
67
+ },
68
+ toggleBonus: async (context, event) => {
69
+ const bonus = context.bonus ? 0 : 1
70
+ await request.send(payment.setBonusSetting({ bonus }))
71
+ return bonus
72
+ },
73
+ },
74
+ }
75
+ )
76
+ }
@@ -3,13 +3,13 @@ import { assign, createMachine } from 'xstate'
3
3
  import pickBy from 'lodash/pickBy.js'
4
4
  import api from '../api/common.js'
5
5
  import storage from '../util/storage.js'
6
- import { readParam, writeParam, AC_KEYS, FC_KEYS } from '../util/paramStore.js'
7
6
 
8
7
  export default function (request) {
9
- const { appSecret, sentry } = request.config
8
+ const { appSecret, defaultChannel, defaultSubchannel } = request.config
10
9
  return createMachine(
11
10
  {
12
11
  id: 'common',
12
+ predictableActionArguments: true,
13
13
  type: 'parallel',
14
14
  context: {
15
15
  tick: 2000,
@@ -34,6 +34,10 @@ export default function (request) {
34
34
  broadcastList: null,
35
35
  mailBoxInfo: null,
36
36
  promotions: [],
37
+ normalBroadcast: null,
38
+ sentNormalBroadcastList: [],
39
+ channel: null,
40
+ subchannel: null,
37
41
  affiliateCode: null,
38
42
  defaultAffiliateCode: null,
39
43
  friendCode: null,
@@ -119,9 +123,6 @@ export default function (request) {
119
123
  },
120
124
  },
121
125
  on: {
122
- REFRESH_FEEDS: {
123
- target: '.updating',
124
- },
125
126
  ENTER_GAME_PAUSE: {
126
127
  target: '.idle',
127
128
  actions: 'resetByEnterGame',
@@ -157,6 +158,39 @@ export default function (request) {
157
158
  },
158
159
  },
159
160
  },
161
+ broadcast: {
162
+ initial: 'idle',
163
+ states: {
164
+ idle: {
165
+ on: {
166
+ START_BROADCAST: {
167
+ target: 'picking',
168
+ },
169
+ },
170
+ },
171
+ picking: {
172
+ after: {
173
+ 5000: {
174
+ target: 'display',
175
+ actions: 'setBroadcast',
176
+ },
177
+ },
178
+ },
179
+ display: {
180
+ after: {
181
+ 5000: {
182
+ target: 'picking',
183
+ },
184
+ },
185
+ },
186
+ },
187
+ on: {
188
+ RESET_BROADCAST: {
189
+ target: '.idle',
190
+ actions: 'resetBroadcast',
191
+ },
192
+ },
193
+ },
160
194
  },
161
195
  },
162
196
  {
@@ -242,17 +276,40 @@ export default function (request) {
242
276
  kpix,
243
277
  }
244
278
  }),
245
- setAgent: assign(() => {
246
- const urlParams = new URLSearchParams(window.location.search)
247
- const ac = readParam(urlParams, AC_KEYS)
248
- const fc = readParam(urlParams, FC_KEYS)
279
+ setAgent: assign((context, event) => {
280
+ if (window.CC_JSB === true) {
281
+ // is cocos native app
282
+ return
283
+ } else {
284
+ let urlParams = new URLSearchParams(window.location.search)
285
+ const channel = urlParams.get('channel') || storage.get('channel') || defaultChannel || 'official'
286
+ const subchannel = urlParams.get('subchannel') || storage.get('subchannel') || defaultSubchannel || 'pwa'
287
+ const affiliateCode = urlParams.get('ac') || urlParams.get('referralCode') || storage.get('ac') || storage.get('referralCode')
288
+ const friendCode = urlParams.get('fc') || urlParams.get('affiliate') || storage.get('fc') || storage.get('affiliate')
249
289
 
250
- writeParam('ac', ac.value, { sentry })
251
- writeParam('fc', fc.value, { sentry })
290
+ storage.set('channel', channel, {
291
+ path: '/',
292
+ maxAge: 60 * 60 * 24 * 7,
293
+ })
294
+ storage.set('subchannel', subchannel, {
295
+ path: '/',
296
+ maxAge: 60 * 60 * 24 * 7,
297
+ })
298
+ storage.set('ac', affiliateCode, {
299
+ path: '/',
300
+ maxAge: 60 * 60 * 24 * 7,
301
+ })
302
+ storage.set('fc', friendCode, {
303
+ path: '/',
304
+ maxAge: 60 * 60 * 24 * 7,
305
+ })
252
306
 
253
- return {
254
- affiliateCode: ac.value,
255
- friendCode: fc.value,
307
+ return {
308
+ channel,
309
+ subchannel,
310
+ affiliateCode,
311
+ friendCode,
312
+ }
256
313
  }
257
314
  }),
258
315
  clearAnnouncements: assign((context, event) => {
@@ -271,6 +328,33 @@ export default function (request) {
271
328
  }
272
329
  return { broadcastList, mailBoxInfo }
273
330
  }),
331
+ setBroadcast: assign((context, event) => {
332
+ const { broadcastList, sentNormalBroadcastList, normalBroadcast } = context
333
+ let sentNormalList = sentNormalBroadcastList
334
+ if (normalBroadcast) {
335
+ sentNormalList = [...sentNormalBroadcastList, normalBroadcast]
336
+ }
337
+ const sentIds = new Set(sentNormalList.map((item) => item.broadcast_id))
338
+ const broadcastQueue = broadcastList?.broadcasts || []
339
+ let nextNormalBroadcast
340
+ for (let i = 0; i < broadcastQueue.length; i++) {
341
+ const broadcast = broadcastQueue[i]
342
+ if (broadcast.type === '0' && !sentIds.has(broadcast.broadcast_id)) {
343
+ nextNormalBroadcast = broadcast
344
+ break
345
+ }
346
+ }
347
+ return {
348
+ normalBroadcast: nextNormalBroadcast,
349
+ sentNormalBroadcastList: sentNormalList,
350
+ }
351
+ }),
352
+ resetBroadcast: assign((context, event) => {
353
+ return {
354
+ normalBroadcast: null,
355
+ sentNormalBroadcastList: [],
356
+ }
357
+ }),
274
358
  resetByEnterGame: assign((context, event) => {
275
359
  return {
276
360
  isPlaying: true,
@@ -0,0 +1,93 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import payment from '../../api/payment.js'
3
+
4
+ export default function (request) {
5
+ return createMachine(
6
+ {
7
+ id: 'amb',
8
+ predictableActionArguments: true,
9
+ initial: 'loading',
10
+ context: {
11
+ bankList: [],
12
+ userAccount: {},
13
+ houseAccountName: null,
14
+ houseAccountNumber: null,
15
+ houseBankName: null,
16
+ method: 'amb',
17
+ },
18
+ states: {
19
+ loading: {
20
+ initial: 'checkingUserAccount',
21
+ states: {
22
+ checkingUserAccount: {
23
+ invoke: {
24
+ src: 'fetchPaymentInfo',
25
+ onDone: [
26
+ {
27
+ target: 'initializing',
28
+ actions: 'setUserAccount',
29
+ cond: 'hasUserAccount',
30
+ },
31
+ { target: '#amb.accountUnbound' },
32
+ ],
33
+ onError: {
34
+ target: '#amb.unavailable',
35
+ },
36
+ },
37
+ },
38
+ initializing: {
39
+ invoke: {
40
+ src: 'initialize',
41
+ onDone: { target: '#amb.finish', actions: 'setInitialization' },
42
+ onError: {
43
+ target: '#amb.unavailable',
44
+ },
45
+ },
46
+ },
47
+ },
48
+ },
49
+ finish: {},
50
+ accountUnbound: {},
51
+ unavailable: {},
52
+ },
53
+ },
54
+ {
55
+ actions: {
56
+ setUserAccount: assign((context, event) => {
57
+ return {
58
+ userAccount: event.data?.[0],
59
+ }
60
+ }),
61
+ setInitialization: assign((context, event) => {
62
+ const { houseAccount, bankList } = event.data
63
+ return {
64
+ houseAccountName: houseAccount.accountName,
65
+ houseAccountNumber: houseAccount.accountNumber,
66
+ houseBankName: houseAccount.bankName,
67
+ bankList: bankList?.data ? bankList.data : bankList,
68
+ }
69
+ }),
70
+ },
71
+ guards: {
72
+ hasUserAccount: (context, event) => {
73
+ return event.data?.[0]
74
+ },
75
+ },
76
+ services: {
77
+ fetchPaymentInfo: async (context, event) => {
78
+ const { bankInfo } = await request.send(payment.getPaymentInfo())
79
+ const filterArray = bankInfo?.filter((item) => item.bindingType !== 'CRYPTO' && item.bindingType !== 'EWALLET')
80
+ return filterArray || []
81
+ },
82
+ initialize: async (context, event) => {
83
+ const { method } = context
84
+ const [houseAccount, bankList] = await Promise.all([
85
+ request.send(payment.submitDepositTransaction({ method })),
86
+ request.send(payment.getBankList(method)),
87
+ ])
88
+ return { houseAccount, bankList }
89
+ },
90
+ },
91
+ }
92
+ )
93
+ }