@jetthai/cuora 2.0.0-beta.1 → 2.0.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 (201) hide show
  1. package/.claude/commands/sync-ai-prompts.md +93 -0
  2. package/.claude/settings.local.json +23 -0
  3. package/.github/copilot-instructions.md +405 -0
  4. package/.husky/post-checkout +32 -0
  5. package/.husky/pre-commit +1 -3
  6. package/.husky/pre-push +36 -0
  7. package/AGENTS.md +405 -0
  8. package/AI_PROMPT_SOURCE.md +403 -0
  9. package/CHANGELOG.md +274 -3
  10. package/CLAUDE.md +405 -0
  11. package/GEMINI.md +405 -0
  12. package/README.md +299 -15
  13. package/docs/kibana/crypto-way-deposit-amount-bug-analysis.md +1003 -0
  14. package/docs/kibana/play-providerId-error.md +202 -0
  15. package/docs/kibana/play-selectedWalletType.md +1 -0
  16. package/docs/kibana/play-selectedWalletType_2.md +1 -0
  17. package/docs/kibana/play-selectedWalletType_analysis.md +565 -0
  18. package/package.json +3 -3
  19. package/scripts/auto-version.js +68 -0
  20. package/scripts/auto-version.sh +33 -0
  21. package/scripts/branch-auto-npm-publish.js +29 -0
  22. package/scripts/check-version.sh +36 -0
  23. package/scripts/clean-tags.sh +84 -0
  24. package/src/api/account.js +0 -1
  25. package/src/api/activity.js +22 -37
  26. package/src/api/auth.js +5 -36
  27. package/src/api/common.js +5 -3
  28. package/src/api/game.js +0 -10
  29. package/src/api/payment.js +17 -55
  30. package/src/api/user.js +10 -16
  31. package/src/index.js +2 -2
  32. package/src/machine/activity/activity_cash.js +84 -36
  33. package/src/machine/activity/cash_rain_activity.js +0 -1
  34. package/src/machine/activity/continue_deposit_activity.js +0 -1
  35. package/src/machine/activity/deposit_activity.js +0 -1
  36. package/src/machine/activity/diamond_shop_activity_cash.js +0 -8
  37. package/src/machine/activity/fafafa_activity.js +0 -11
  38. package/src/machine/activity/friend_invite_friends_activity.js +8 -7
  39. package/src/machine/activity/index.js +0 -12
  40. package/src/machine/activity/instant_rebate_activity.js +0 -1
  41. package/src/machine/activity/jackpot.js +0 -1
  42. package/src/machine/activity/otp_verified_activity.js +0 -1
  43. package/src/machine/activity/ranking_activity.js +0 -1
  44. package/src/machine/activity/roulette_activity_v2.js +0 -1
  45. package/src/machine/activity/sign_in_activity.js +0 -1
  46. package/src/machine/activity/sign_in_monthly_activity.js +1 -2
  47. package/src/machine/activity/specify_bets_activity.js +0 -1
  48. package/src/machine/activity/specify_turnover_activity.js +0 -1
  49. package/src/machine/activity/time_bomb_activity.js +0 -1
  50. package/src/machine/activity/vip_card_activity.js +0 -1
  51. package/src/machine/auth.js +112 -113
  52. package/src/machine/auth_otp_v3.js +11 -8
  53. package/src/machine/bank_binding.js +2 -3
  54. package/src/machine/common.js +14 -112
  55. package/src/machine/deposit/crypto_bank_cash.js +20 -35
  56. package/src/machine/deposit/crypto_qrcode_cash.js +26 -64
  57. package/src/machine/deposit/crypto_way_cash.js +48 -37
  58. package/src/machine/deposit/direct_cash.js +8 -10
  59. package/src/machine/deposit/index.js +0 -28
  60. package/src/machine/deposit/loadcard_cash.js +14 -32
  61. package/src/machine/deposit/manual_cash.js +18 -28
  62. package/src/machine/deposit/qrcode_cash.js +15 -32
  63. package/src/machine/deposit/usdt_cash.js +1 -15
  64. package/src/machine/deposit/virtual_bank_cash.js +13 -12
  65. package/src/machine/error.js +7 -1
  66. package/src/machine/game_betslip.js +0 -1
  67. package/src/machine/game_favorite_v2.js +0 -1
  68. package/src/machine/game_info.js +1 -13
  69. package/src/machine/game_search_cash.js +2 -13
  70. package/src/machine/game_v2_1.js +42 -166
  71. package/src/machine/honor_board_cash.js +8 -11
  72. package/src/machine/inbox.js +43 -105
  73. package/src/machine/index.js +0 -32
  74. package/src/machine/leaderboard.js +8 -12
  75. package/src/machine/navbar.js +1 -3
  76. package/src/machine/ranking.js +45 -30
  77. package/src/machine/reward_cash.js +0 -40
  78. package/src/machine/roulette_v2.js +14 -11
  79. package/src/machine/setting.js +0 -1
  80. package/src/machine/side_cash.js +3 -3
  81. package/src/machine/user_info.js +0 -1
  82. package/src/machine/user_photo.js +0 -1
  83. package/src/machine/user_reset_password.js +0 -14
  84. package/src/machine/user_sign_up.js +46 -61
  85. package/src/machine/websocket.js +18 -62
  86. package/src/machine/withdraw/index.js +0 -6
  87. package/src/machine/withdraw/withdraw_manual_cash.js +59 -39
  88. package/src/request/config.js +2 -0
  89. package/src/request/request.js +49 -60
  90. package/src/util/amount.js +8 -0
  91. package/src/util/constant.js +0 -1
  92. package/src/util/err998SentryExtra.js +26 -0
  93. package/src/util/index.js +2 -4
  94. package/src/util/paramStore.js +139 -0
  95. package/src/util/storage.js +3 -4
  96. package/BREAKING_CHANGES.md +0 -9
  97. package/resetGitBranch.sh +0 -101
  98. package/src/lib/fingerprint_v3_11_12.js +0 -11433
  99. package/src/machine/activity/activity.js +0 -213
  100. package/src/machine/activity/diamond_shop_activity_fc.js +0 -197
  101. package/src/machine/activity/diamond_shop_activity_vn.js +0 -179
  102. package/src/machine/activity/invite_friends_activity.js +0 -115
  103. package/src/machine/activity/mini_game_activity.js +0 -69
  104. package/src/machine/activity/return_bonus_activity.js +0 -155
  105. package/src/machine/auth_otp_v2.js +0 -178
  106. package/src/machine/bank_binding_amb.js +0 -146
  107. package/src/machine/bonus.js +0 -76
  108. package/src/machine/deposit/amb.js +0 -93
  109. package/src/machine/deposit/crypto_bank.js +0 -340
  110. package/src/machine/deposit/crypto_qrcode.js +0 -158
  111. package/src/machine/deposit/crypto_way.js +0 -253
  112. package/src/machine/deposit/deposit_fc.js +0 -272
  113. package/src/machine/deposit/direct.js +0 -311
  114. package/src/machine/deposit/float.js +0 -375
  115. package/src/machine/deposit/krway.js +0 -152
  116. package/src/machine/deposit/loadcard_vn.js +0 -352
  117. package/src/machine/deposit/manual_vn.js +0 -463
  118. package/src/machine/deposit/qrcode_v2.js +0 -339
  119. package/src/machine/deposit/usdt.js +0 -163
  120. package/src/machine/deposit/virtual_bank_vn.js +0 -270
  121. package/src/machine/deposit/vpay.js +0 -374
  122. package/src/machine/game_hot_new.js +0 -91
  123. package/src/machine/game_replay.js +0 -47
  124. package/src/machine/game_search_v2.js +0 -402
  125. package/src/machine/honor_board.js +0 -144
  126. package/src/machine/merge.js +0 -58
  127. package/src/machine/payment_data.js +0 -87
  128. package/src/machine/promotions.js +0 -163
  129. package/src/machine/reward.js +0 -256
  130. package/src/machine/reward_fc.js +0 -99
  131. package/src/machine/side.js +0 -160
  132. package/src/machine/side_v2.js +0 -223
  133. package/src/machine/vip_table.js +0 -58
  134. package/src/machine/welcome.js +0 -111
  135. package/src/machine/withdraw/withdraw_crypto_cash.js +0 -328
  136. package/src/machine/withdraw/withdraw_krway.js +0 -223
  137. package/src/machine/withdraw/withdraw_manual.js +0 -541
  138. package/src/util/deviceToken.js +0 -60
  139. package/src/util/math.js +0 -4
  140. package/test/api.behavior.test.js +0 -69
  141. package/test/api.contract.test.js +0 -18
  142. package/test/config.test.js +0 -27
  143. package/test/deviceToken.test.js +0 -139
  144. package/test/helpers.coverage.test.js +0 -11
  145. package/test/helpers.js +0 -91
  146. package/test/index.exports.test.js +0 -14
  147. package/test/machine.activity.core.coverage.test.js +0 -337
  148. package/test/machine.activity.gap.coverage.test.js +0 -252
  149. package/test/machine.activity.more.coverage.test.js +0 -180
  150. package/test/machine.activity_plus_and_binding_amb.coverage.test.js +0 -201
  151. package/test/machine.activity_timer_bonus.coverage.test.js +0 -136
  152. package/test/machine.activity_welcome.low.coverage.test.js +0 -211
  153. package/test/machine.amb_rewardfc_websocket.more.coverage.test.js +0 -201
  154. package/test/machine.auth.coverage.test.js +0 -215
  155. package/test/machine.bank_binding.test.js +0 -143
  156. package/test/machine.binding_otp_krway.coverage.test.js +0 -223
  157. package/test/machine.contract.test.js +0 -50
  158. package/test/machine.crypto_bank.coverage.test.js +0 -270
  159. package/test/machine.crypto_way.coverage.test.js +0 -108
  160. package/test/machine.crypto_way_cash.coverage.test.js +0 -114
  161. package/test/machine.definition.test.js +0 -137
  162. package/test/machine.deposit.manual.coverage.test.js +0 -365
  163. package/test/machine.deposit_fc.coverage.test.js +0 -126
  164. package/test/machine.direct.coverage.test.js +0 -96
  165. package/test/machine.direct_cash.coverage.test.js +0 -108
  166. package/test/machine.error.coverage.test.js +0 -37
  167. package/test/machine.events.test.js +0 -126
  168. package/test/machine.favorite_jackpot.coverage.test.js +0 -82
  169. package/test/machine.float.coverage.test.js +0 -136
  170. package/test/machine.flow.test.js +0 -226
  171. package/test/machine.game_hot_new_vip_table.coverage.test.js +0 -105
  172. package/test/machine.game_search_cash.coverage.test.js +0 -195
  173. package/test/machine.game_search_v2.test.js +0 -199
  174. package/test/machine.game_user_profile.coverage.test.js +0 -100
  175. package/test/machine.honor_board.test.js +0 -148
  176. package/test/machine.inbox.common.coverage.test.js +0 -304
  177. package/test/machine.loadcard_cash.coverage.test.js +0 -101
  178. package/test/machine.loadcard_vn.coverage.test.js +0 -122
  179. package/test/machine.misc.coverage.test.js +0 -361
  180. package/test/machine.more2.coverage.test.js +0 -261
  181. package/test/machine.options.execution.test.js +0 -272
  182. package/test/machine.priority.coverage.test.js +0 -629
  183. package/test/machine.qrcode_cash.coverage.test.js +0 -107
  184. package/test/machine.qrcode_v2.coverage.test.js +0 -121
  185. package/test/machine.regression.test.js +0 -82
  186. package/test/machine.roulette_v2.test.js +0 -142
  187. package/test/machine.side_reward_reset.coverage.test.js +0 -220
  188. package/test/machine.targeted.coverage.test.js +0 -313
  189. package/test/machine.usdt.coverage.test.js +0 -95
  190. package/test/machine.usdt_cash.coverage.test.js +0 -73
  191. package/test/machine.vip_card_activity.test.js +0 -114
  192. package/test/machine.virtual_bank_cash.coverage.test.js +0 -105
  193. package/test/machine.virtual_bank_vn.coverage.test.js +0 -105
  194. package/test/machine.vpay.coverage.test.js +0 -142
  195. package/test/machine.withdraw_crypto_cash.coverage.test.js +0 -166
  196. package/test/machine.withdraw_krway.coverage.test.js +0 -123
  197. package/test/machine.withdraw_manual.coverage.test.js +0 -185
  198. package/test/machine.withdraw_manual_cash.coverage.test.js +0 -123
  199. package/test/request.test.js +0 -325
  200. package/test/util.storage.errors.test.js +0 -47
  201. package/test/util.test.js +0 -41
@@ -1,19 +1,30 @@
1
1
  import { assign, createMachine } from 'xstate'
2
2
  import auth from '../api/auth.js'
3
- import { getDeviceTokenWithRetry } from '../util/deviceToken.js'
4
3
  import storage from '../util/storage.js'
4
+ import { readParamFromLocation, normalize, AC_KEYS, FC_KEYS } from '../util/paramStore.js'
5
+
6
+ // 註冊強制綁定多型出款:轉發各綁定型別欄位(BANK / CRYPTO / EWALLET),只帶有值的欄位
7
+ const BIND_FIELDS = [
8
+ 'bindingType',
9
+ 'cryptoCurrency',
10
+ 'cryptoNetwork',
11
+ 'cryptoAddress',
12
+ 'walletCode',
13
+ 'ifscCode',
14
+ 'pixType',
15
+ 'firstNameLocale',
16
+ 'lastNameLocale',
17
+ ]
18
+ const pickBindData = (data = {}) => BIND_FIELDS.reduce((acc, key) => (data[key] !== undefined ? { ...acc, [key]: data[key] } : acc), {})
5
19
 
6
20
  export default function (request) {
7
- const { fpToken, sentry, defaultChannel, defaultSubchannel } = request.config
21
+ const { sentry } = request.config
8
22
  return createMachine(
9
23
  {
10
24
  id: 'user_sign_up',
11
- predictableActionArguments: true,
12
25
  initial: 'idle',
13
26
  context: {
14
27
  provider: null,
15
- channel: null,
16
- subchannel: null,
17
28
  signUpData: {},
18
29
  fc: null,
19
30
  reCaptchaToken: null,
@@ -23,6 +34,7 @@ export default function (request) {
23
34
  site: null,
24
35
  strategy: null,
25
36
  uid: null,
37
+ agentId: null,
26
38
  },
27
39
  deviceTokenEnable: true,
28
40
  },
@@ -73,7 +85,8 @@ export default function (request) {
73
85
  }),
74
86
  setFriendCode: assign((context, event) => {
75
87
  const { fc } = event.data
76
- return { fc }
88
+ // api/auth.js 的 register 只濾 undefined/null,字面 'undefined' 會直送 query string
89
+ return { fc: normalize(fc) }
77
90
  }),
78
91
  setSignUpId: assign((context, event) => {
79
92
  const {
@@ -83,18 +96,19 @@ export default function (request) {
83
96
  password,
84
97
  countryCode,
85
98
  phone,
86
- channel,
87
- subchannel,
88
99
  bankCode,
89
100
  bankAccount,
90
101
  holderName,
91
102
  branch,
92
103
  branchCode,
93
104
  affiliateCode,
105
+ birthday,
94
106
  } = event.data
95
107
  return {
96
108
  signUpData: {
97
109
  provider: 'local',
110
+ ...pickBindData(event.data),
111
+ birthday,
98
112
  email,
99
113
  username,
100
114
  nick_name,
@@ -108,29 +122,16 @@ export default function (request) {
108
122
  branchCode,
109
123
  affiliateCode,
110
124
  },
111
- channel,
112
- subchannel,
113
125
  }
114
126
  }),
115
127
  setSignUpPhone: assign((context, event) => {
116
- const {
117
- email,
118
- countryCode,
119
- phone,
120
- nick_name,
121
- password,
122
- channel,
123
- subchannel,
124
- bankCode,
125
- bankAccount,
126
- holderName,
127
- branch,
128
- branchCode,
129
- affiliateCode,
130
- } = event.data
128
+ const { email, countryCode, phone, nick_name, password, bankCode, bankAccount, holderName, branch, branchCode, affiliateCode, birthday } =
129
+ event.data
131
130
  return {
132
131
  signUpData: {
133
132
  provider: 'phone',
133
+ ...pickBindData(event.data),
134
+ birthday,
134
135
  email,
135
136
  countryCode,
136
137
  phone,
@@ -143,29 +144,16 @@ export default function (request) {
143
144
  branchCode,
144
145
  affiliateCode,
145
146
  },
146
- channel,
147
- subchannel,
148
147
  }
149
148
  }),
150
149
  setSignUpEmail: assign((context, event) => {
151
- const {
152
- email,
153
- nick_name,
154
- password,
155
- channel,
156
- subchannel,
157
- bankCode,
158
- bankAccount,
159
- holderName,
160
- branch,
161
- branchCode,
162
- affiliateCode,
163
- countryCode,
164
- phone,
165
- } = event.data
150
+ const { email, nick_name, password, bankCode, bankAccount, holderName, branch, branchCode, affiliateCode, countryCode, phone, birthday } =
151
+ event.data
166
152
  return {
167
153
  signUpData: {
168
154
  provider: 'email',
155
+ ...pickBindData(event.data),
156
+ birthday,
169
157
  email,
170
158
  nick_name,
171
159
  password,
@@ -178,12 +166,10 @@ export default function (request) {
178
166
  countryCode,
179
167
  phone,
180
168
  },
181
- channel,
182
- subchannel,
183
169
  }
184
170
  }),
185
171
  setRegistrationData: assign((context, event) => {
186
- const { account, currency, site, strategy, uid, channel, sub_channel } = event.data
172
+ const { account, currency, site, strategy, uid, agentId } = event.data
187
173
  return {
188
174
  registrationData: {
189
175
  account,
@@ -191,8 +177,7 @@ export default function (request) {
191
177
  site,
192
178
  strategy,
193
179
  uid,
194
- channel,
195
- sub_channel,
180
+ agentId,
196
181
  },
197
182
  }
198
183
  }),
@@ -204,36 +189,36 @@ export default function (request) {
204
189
  },
205
190
  services: {
206
191
  authenticate: async (context, event) => {
207
- const { channel, subchannel, signUpData, deviceTokenEnable } = context
208
- const dt = await getDeviceTokenWithRetry({ fpToken, sentry, hosts: request.hosts, enable: deviceTokenEnable })
192
+ const { signUpData, deviceTokenEnable } = context
193
+ const dt = deviceTokenEnable ? await request.config.getDt?.() : undefined
209
194
 
210
- const affiliateCode = storage.get('ac') || signUpData?.affiliateCode
195
+ // 宿主明確帶入的 affiliateCode(註冊表單的代理碼欄位)優先於網址/儲存這類環境值。
196
+ // 判定用 `!== undefined` 而非 hasOwnProperty:上面的 setSignUpId/Phone/Email 是以解構寫入
197
+ // signUpData,宿主沒帶時 key 仍然存在(值為 undefined),hasOwnProperty 會恆為 true、
198
+ // 讓三層解析變成死碼。也不能用 `||`,否則使用者刻意清空送出的空字串會被吃掉、
199
+ // 退回三層解析把剛清掉的舊代理碼從網址撿回來。
200
+ const { affiliateCode: explicitAffiliateCode, ...signUpRest } = signUpData || {}
201
+ const hasExplicitAc = explicitAffiliateCode !== undefined
202
+ const acRead = readParamFromLocation(AC_KEYS)
203
+ const affiliateCode = hasExplicitAc ? normalize(explicitAffiliateCode) : acRead.value
211
204
  const messages = {
212
205
  url: window.location.href,
213
- channelOrders: [
214
- { channel: storage.get('channel'), subchannel: storage.get('subchannel') },
215
- { channel: defaultChannel, subchannel: defaultSubchannel },
216
- { channel: channel, subchannel: subchannel },
217
- ],
218
206
  affiliateCode,
207
+ acSource: hasExplicitAc ? 'signUpData' : acRead.from,
219
208
  }
220
- sentry.captureMessage(JSON.stringify(messages))
221
209
 
222
210
  const referralObj = {}
223
211
  if (![undefined, 'undefined', null, 'null'].includes(affiliateCode)) {
224
212
  referralObj.ac = affiliateCode
225
213
  }
226
214
 
227
- referralObj.channel = storage.get('channel') || defaultChannel || channel
228
- referralObj.subchannel = storage.get('subchannel') || defaultSubchannel || subchannel
229
-
230
215
  return await request.send(
231
216
  auth.register({
232
- ...signUpData,
217
+ ...signUpRest,
233
218
  ...referralObj,
234
219
  dt,
235
220
  reCaptchaToken: context.reCaptchaToken,
236
- fc: context.fc,
221
+ fc: context.fc || readParamFromLocation(FC_KEYS).value,
237
222
  })
238
223
  )
239
224
  },
@@ -3,12 +3,10 @@ import { io } from 'socket.io-client'
3
3
 
4
4
  export default function (request) {
5
5
  const { socketURL, bucketName, clientId, sentry } = request.config
6
- const socketIo = request.config.socketIo || io
7
6
  const maxReconnectCount = 3
8
7
  return createMachine(
9
8
  {
10
9
  id: 'socket',
11
- predictableActionArguments: true,
12
10
  initial: 'idle',
13
11
  context: {
14
12
  clientSocket: null,
@@ -75,10 +73,6 @@ export default function (request) {
75
73
  },
76
74
  },
77
75
  on: {
78
- CONNECT: {
79
- target: 'fetchSocket',
80
- cond: 'isNeedConnect',
81
- },
82
76
  SET_CONNECTED: {
83
77
  actions: 'setSocket',
84
78
  },
@@ -114,7 +108,6 @@ export default function (request) {
114
108
  actions: {
115
109
  saveSocketURL: assign((context, event) => {
116
110
  const { socketURL } = event.data
117
- // console.log('[socket][saveSocketURL] socketURL:', socketURL)
118
111
  return { socketURL }
119
112
  }),
120
113
  setSocket: assign((context, event) => {
@@ -126,14 +119,6 @@ export default function (request) {
126
119
  }),
127
120
  setConnectError: assign((context, event) => {
128
121
  const error = event.data
129
- const { analytics, connectError } = context
130
- if (connectError === null) {
131
- sentry?.captureException(`[socket] connectError ${error}`)
132
- analytics?.push({
133
- event: 'connect_error',
134
- message: error,
135
- })
136
- }
137
122
  return {
138
123
  connectError: error,
139
124
  connectStatus: 0, // 0: 未連線, 1: 連線中, 2: 連線成功
@@ -148,7 +133,7 @@ export default function (request) {
148
133
  // 主動觸發斷開socket連接
149
134
  let { clientSocket } = context
150
135
  console.log('[socket][disconnectSocket]')
151
- if (clientSocket && typeof clientSocket.disconnect === 'function') {
136
+ if (clientSocket) {
152
137
  clientSocket.disconnect()
153
138
  clientSocket = null
154
139
  }
@@ -219,10 +204,8 @@ export default function (request) {
219
204
  const { connectStatus, clientSocket } = context
220
205
  // 檢查 Socket 是否已連接
221
206
  if (connectStatus == 1 || (clientSocket && clientSocket?.connected)) {
222
- // console.log(`[socket] [isNeedConnect] 不做socket連線`)
223
207
  return false
224
208
  } else {
225
- // console.log(`[socket] [isNeedConnect] 重新socket連線`)
226
209
  return true
227
210
  }
228
211
  },
@@ -235,7 +218,7 @@ export default function (request) {
235
218
  fetchSocket: async (context, event) => {
236
219
  // 取得 Socket 連線資訊及選線
237
220
  const { url } = context
238
- const socketTester = new SocketTester(url)
221
+ const socketTester = new SocketTester(url, context.socketURL)
239
222
  const socketURL = await socketTester.test()
240
223
  console.log('[socket][fetchSocket] socketURL:', socketURL)
241
224
  return { socketURL }
@@ -245,7 +228,7 @@ export default function (request) {
245
228
  const { socketURL } = context
246
229
  const authToken = request.getToken()
247
230
  console.log('[socket][connectSocket] socketURL:', socketURL)
248
- const clientSocket = socketIo(`${socketURL}/frontend`, {
231
+ const clientSocket = io(`${socketURL}/frontend`, {
249
232
  withCredentials: true,
250
233
  forceNew: true,
251
234
  transports: ['websocket', 'polling'],
@@ -254,27 +237,15 @@ export default function (request) {
254
237
  },
255
238
  })
256
239
  return new Promise((resolve, reject) => {
257
- const onConnect = () => {
240
+ clientSocket.on('connect', () => {
258
241
  console.log('[socket][connect] success', clientSocket.id)
259
- cleanup()
260
242
  resolve(clientSocket) // 成功後返回 socket 實例
261
- }
243
+ })
262
244
 
263
- const onConnectError = (error) => {
245
+ clientSocket.on('connect_error', (error) => {
264
246
  console.log('[socket][connect_error] error', error.message)
265
- cleanup()
266
247
  reject(error.message) // 連接錯誤
267
- }
268
-
269
- const cleanup = () => {
270
- if (typeof clientSocket.off === 'function') {
271
- clientSocket.off('connect', onConnect)
272
- clientSocket.off('connect_error', onConnectError)
273
- }
274
- }
275
-
276
- clientSocket.on('connect', onConnect)
277
- clientSocket.on('connect_error', onConnectError)
248
+ })
278
249
  })
279
250
  },
280
251
  listenToSocketEvents: (context) => (callback) => {
@@ -283,36 +254,29 @@ export default function (request) {
283
254
 
284
255
  if (!clientSocket) {
285
256
  console.log('[socket][listenToSocketEvents] Socket is not connected')
286
- return
287
- }
288
-
289
- const listeners = []
290
- const on = (eventName, handler) => {
291
- listeners.push([eventName, handler])
292
- clientSocket.on(eventName, handler)
293
257
  }
294
258
 
295
259
  // 監聽 activity-info 事件
296
- on('activity-info', (data) => {
260
+ clientSocket.on('activity-info', (data) => {
297
261
  console.log('[socket][activity-info]:', data)
298
262
  callback({ type: 'ACTIVITY_INFO', data })
299
263
  callback({ type: 'PUSH_ANALYTICS', data })
300
264
  })
301
265
 
302
266
  // 監聽 activity-reward-info 事件
303
- on('activity-reward-info', (data) => {
267
+ clientSocket.on('activity-reward-info', (data) => {
304
268
  console.log('[socket][activity-reward-info]:', data)
305
269
  callback({ type: 'ACTIVITY_INFO', data })
306
270
  })
307
271
 
308
272
  // 監聽 message-notice-info 事件
309
- on('message-notice-info', (data) => {
273
+ clientSocket.on('message-notice-info', (data) => {
310
274
  console.log('[socket][message-notice-info]:', data)
311
275
  callback({ type: 'ACTIVITY_INFO', data })
312
276
  })
313
277
 
314
278
  // 監聽 payment-info 事件
315
- on('payment-info', (data) => {
279
+ clientSocket.on('payment-info', (data) => {
316
280
  console.log('[socket][payment-info]:', data)
317
281
  if (data.windowType === 'toast') {
318
282
  callback({ type: 'ACTIVITY_INFO', data })
@@ -322,29 +286,19 @@ export default function (request) {
322
286
  })
323
287
 
324
288
  // 監聽 'connect' 事件
325
- on('connect', () => {
326
- // console.log('[socket] [listenToSocketEvents] [connect] :', clientSocket.id)
289
+ clientSocket.on('connect', () => {
327
290
  callback({ type: 'SET_CONNECTED', data: clientSocket })
328
291
  })
329
292
 
330
293
  // 連線錯誤時觸發此事件'connect_error'
331
- on('connect_error', (error) => {
332
- // console.log('[socket] [listenToSocketEvents] [connect_error]:', error.message)
294
+ clientSocket.on('connect_error', (error) => {
333
295
  callback({ type: 'CONNECT_ERROR', data: error.message })
334
296
  })
335
297
 
336
298
  // 斷開連線時觸發此事件'disconnect'
337
- on('disconnect', (data) => {
338
- // console.log('[socket] [listenToSocketEvents] [disconnect] data:', data)
299
+ clientSocket.on('disconnect', (data) => {
339
300
  callback({ type: 'DISCONNECT', reason: data })
340
301
  })
341
-
342
- return () => {
343
- if (typeof clientSocket.off !== 'function') {
344
- return
345
- }
346
- listeners.forEach(([eventName, handler]) => clientSocket.off(eventName, handler))
347
- }
348
302
  },
349
303
  },
350
304
  }
@@ -352,9 +306,10 @@ export default function (request) {
352
306
  }
353
307
 
354
308
  class SocketTester {
355
- constructor(url) {
309
+ constructor(url, fallbackUrl) {
356
310
  this.url = url
357
311
  this.socket = []
312
+ this.fallbackUrl = fallbackUrl
358
313
  }
359
314
 
360
315
  async init() {
@@ -378,7 +333,7 @@ class SocketTester {
378
333
  return url
379
334
  } catch (error) {
380
335
  console.error('[Socket] Socket Test Fail.', error)
381
- return this.socket?.[0] || this.url
336
+ return this.fallbackUrl
382
337
  }
383
338
  }
384
339
 
@@ -387,6 +342,7 @@ class SocketTester {
387
342
  try {
388
343
  ts = new Date().getTime()
389
344
  response = await fetch(`${url}/ping/status`)
345
+ if (!response.ok) throw response
390
346
  return { url, index }
391
347
  } finally {
392
348
  const speed = new Date().getTime() - ts
@@ -1,11 +1,5 @@
1
- import withdraw_manual from './withdraw_manual.js'
2
- import withdraw_krway from './withdraw_krway.js'
3
- import withdraw_crypto_cash from './withdraw_crypto_cash.js'
4
1
  import withdraw_manual_cash from './withdraw_manual_cash.js'
5
2
 
6
3
  export default {
7
- withdraw_manual,
8
- withdraw_krway,
9
- withdraw_crypto_cash,
10
4
  withdraw_manual_cash,
11
5
  }
@@ -3,14 +3,14 @@ import payment from '../../api/payment.js'
3
3
  import user from '../../api/user.js'
4
4
 
5
5
  export default function (request, context) {
6
- const { paymentDetail = [] } = context || {}
6
+ const { paymentDetail = [], doubleWalletWithdrawLimitCheck = '0' } = context || {}
7
7
  return createMachine(
8
8
  {
9
9
  id: 'withdraw_manual_cash',
10
- predictableActionArguments: true,
11
10
  initial: 'loading',
12
11
  context: {
13
12
  paymentDetail,
13
+ doubleWalletWithdrawLimitCheck,
14
14
  currentPayment: null,
15
15
  banks: [],
16
16
  paymentInfo: null,
@@ -24,6 +24,8 @@ export default function (request, context) {
24
24
  requestId: null,
25
25
  status: null,
26
26
  target: null,
27
+ email: null,
28
+ number: null,
27
29
  ttl: null,
28
30
  },
29
31
  states: {
@@ -118,31 +120,20 @@ export default function (request, context) {
118
120
  RESET_OTP: {
119
121
  target: 'reset',
120
122
  },
121
- BACK: [
122
- // {
123
- // target: '#withdraw_vn2.activity.convertible',
124
- // cond: 'isActivity',
125
- // },
126
- // {
127
- // target: '#withdraw_vn2.cash.withdrawable',
128
- // },
129
- ],
123
+ BACK: {
124
+ target: '#withdraw_manual_cash.calculated',
125
+ },
130
126
  },
131
127
  },
132
128
  acknowledging: {
133
129
  invoke: {
134
130
  src: 'acknowledge',
135
- onDone: [
136
- // {
137
- // target: '#withdraw_vn2.activity.converted',
138
- // cond: 'isActivity',
139
- // },
140
- // {
141
- // target: '#withdraw_vn2.cash.submitted',
142
- // },
143
- ],
131
+ onDone: {
132
+ target: '#withdraw_manual_cash.submitted',
133
+ actions: 'setProcessing',
134
+ },
144
135
  onError: {
145
- target: 'idle',
136
+ target: '#withdraw_manual_cash.calculated',
146
137
  },
147
138
  },
148
139
  },
@@ -177,7 +168,7 @@ export default function (request, context) {
177
168
  actions: {
178
169
  setInitData: assign((context, event) => {
179
170
  const { currentPayment, paymentInfo, withdrawRule, processing } = event.data
180
- const userBanks = [...paymentInfo.bankList, ...paymentInfo.cryptoList, ...paymentInfo.ewalletList]
171
+ const userBanks = [...paymentInfo.bankList, ...paymentInfo.ewalletList, ...paymentInfo.cryptoList]
181
172
 
182
173
  return {
183
174
  currentPayment,
@@ -204,26 +195,27 @@ export default function (request, context) {
204
195
  }
205
196
  }),
206
197
  setOtp: assign((context, event) => {
207
- const { requestId, status, target, ttl } = event.data
198
+ const { request_id, email, number, ttl } = event.data
208
199
  return {
209
- requestId,
210
- status,
211
- target,
200
+ requestId: request_id,
201
+ email,
202
+ number,
212
203
  ttl,
213
204
  }
214
205
  }),
215
206
  decreaseTtl: assign((context, evnet) => {
216
207
  const second = context.ttl
217
208
  return {
218
- ttl: Math.max(second - 1, 0),
209
+ ttl: Math.max(second - 1000, 0),
219
210
  }
220
211
  }),
221
212
  setVerificationData: assign((context, event) => {
222
- const { requestId, ttl, target } = event.data
213
+ const { request_id, ttl, number, email } = event.data
223
214
  return {
224
- requestId,
215
+ requestId: request_id,
225
216
  ttl,
226
- target,
217
+ number,
218
+ email,
227
219
  }
228
220
  }),
229
221
  },
@@ -239,15 +231,43 @@ export default function (request, context) {
239
231
  return selectedUserBank && selectedAmount > 0 && currentPayment.minimum <= selectedAmount && selectedAmount <= currentPayment.maximum
240
232
  },
241
233
  isOtpRequired: (context, event) => {
242
- return event.data?.status === 'otp-verifying'
234
+ return event.data?.request_id !== undefined
243
235
  },
244
236
  },
245
237
  services: {
238
+ // 雙錢包出款規則閘門(對齊 client-pwa-ssr useWithdrawManual.initialize 流程):
239
+ // - '0':只抓 CASH withdrawRule
240
+ // - '1':只抓 ACTIVITY withdrawRule(不論達標與否,CASH 規則不參與閘門,省一次 API)
241
+ // - '2' + ACTIVITY 不可提:略過 CASH withdrawRule(少一次 API)
242
+ // - '2' + ACTIVITY 達標:續抓 CASH withdrawRule 作為最終出款依據
246
243
  fetchInitData: async (context, event) => {
247
- const { paymentDetail = [] } = context
244
+ const { paymentDetail = [], doubleWalletWithdrawLimitCheck = '0' } = context
248
245
  const currentPayment = paymentDetail.find((element) => element.category === 'manual' && element.transferType === 'withdraw')
249
246
 
250
- const [paymentInfo, withdrawRule, orders] = await Promise.all([
247
+ let prefetchedRule = null
248
+ if (doubleWalletWithdrawLimitCheck === '2' || doubleWalletWithdrawLimitCheck === '1') {
249
+ const activityRule = await request.send(payment.getDoubleWalletWithdrawRule({ walletType: 'ACTIVITY' }))
250
+ // '1' 模式僅看 ACTIVITY,'2' 模式 ACTIVITY 不可提則 CASH 不參與閘門 — 兩種情況都用 activityRule 為依據。
251
+ // enableWithdraw 用 truthy 比較對齊 client-pwa-ssr useWithdrawManual(!enableWithdraw.value),避免 backend 回傳非 boolean truthy 值(如 1)時誤判。
252
+ if (doubleWalletWithdrawLimitCheck === '1' || !activityRule?.enableWithdraw) {
253
+ prefetchedRule = activityRule
254
+ }
255
+ }
256
+
257
+ if (prefetchedRule) {
258
+ const [paymentInfo, orders] = await Promise.all([
259
+ request.send(payment.getBindingPaymentInfo()),
260
+ request.send(payment.getPendingOrder({ transferType: 'WITHDRAW' })),
261
+ ])
262
+ return {
263
+ currentPayment,
264
+ paymentInfo,
265
+ withdrawRule: prefetchedRule,
266
+ processing: orders[0],
267
+ }
268
+ }
269
+
270
+ const [paymentInfo, cashRule, orders] = await Promise.all([
251
271
  request.send(payment.getBindingPaymentInfo()),
252
272
  request.send(payment.getDoubleWalletWithdrawRule({ walletType: 'CASH' })),
253
273
  request.send(payment.getPendingOrder({ transferType: 'WITHDRAW' })),
@@ -256,7 +276,7 @@ export default function (request, context) {
256
276
  return {
257
277
  currentPayment,
258
278
  paymentInfo,
259
- withdrawRule,
279
+ withdrawRule: cashRule,
260
280
  processing: orders[0],
261
281
  }
262
282
  },
@@ -283,20 +303,20 @@ export default function (request, context) {
283
303
  method: currentPayment.method,
284
304
  amount: selectedAmount,
285
305
  cryptoCurrency: selectedUserBank.cryptoCurrency,
286
- cryptoNetwork: selectedUserBank.cryptoNetwork,
306
+ cryptoNetwork: selectedUserBank.networkCode,
287
307
  targetAddress: selectedUserBank.cryptoAddress,
288
308
  applyerHolderName: selectedUserBank.holderName,
289
309
  })
290
310
  )
291
311
  },
292
312
  resetOtp: async (context, event) => {
293
- const { requestId, target } = context
294
- return await request.send(user.otpReset({ requestId, target }))
313
+ const { currentPayment, requestId } = context
314
+ return await request.send(payment.otpReset({ method: currentPayment.method, requestId }))
295
315
  },
296
316
  acknowledge: async (context, event) => {
297
- const { requestId, target } = context
317
+ const { currentPayment, requestId } = context
298
318
  const code = event.data
299
- return await request.send(user.otpAcknowledge({ requestId, target, code }))
319
+ return await request.send(payment.otpAcknowledge({ method: currentPayment.method, requestId, code }))
300
320
  },
301
321
  },
302
322
  }
@@ -16,6 +16,7 @@ export default class Config {
16
16
  defaultSubchannel,
17
17
  socketURL,
18
18
  bucketName,
19
+ getDt,
19
20
  }) {
20
21
  this.apiURL = apiURL
21
22
  this.apiVersion = apiVersion
@@ -30,6 +31,7 @@ export default class Config {
30
31
  this.defaultSubchannel = defaultSubchannel
31
32
  this.socketURL = socketURL
32
33
  this.bucketName = bucketName
34
+ this.getDt = getDt
33
35
  }
34
36
 
35
37
  setApiURL(url) {