@jetthai/cuora 1.1.441 → 1.1.442

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 (149) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/package.json +1 -1
  3. package/src/api/auth.js +2 -2
  4. package/src/machine/auth.js +2 -10
  5. package/src/machine/common.js +1 -15
  6. package/src/machine/user_sign_up.js +7 -67
  7. package/.claude/worktrees/geemee-sendpixel/.claude/commands/auto-git-flow.md +0 -52
  8. package/.claude/worktrees/geemee-sendpixel/.claude/commands/commit-push.md +0 -174
  9. package/.claude/worktrees/geemee-sendpixel/.claude/commands/create-branch.md +0 -142
  10. package/.claude/worktrees/geemee-sendpixel/.claude/commands/sync-ai-prompts.md +0 -93
  11. package/.claude/worktrees/geemee-sendpixel/.claude/settings.local.json +0 -23
  12. package/.claude/worktrees/geemee-sendpixel/.github/copilot-instructions.md +0 -696
  13. package/.claude/worktrees/geemee-sendpixel/.husky/post-checkout +0 -32
  14. package/.claude/worktrees/geemee-sendpixel/.husky/pre-commit +0 -2
  15. package/.claude/worktrees/geemee-sendpixel/.husky/pre-push +0 -36
  16. package/.claude/worktrees/geemee-sendpixel/.prettierignore +0 -1
  17. package/.claude/worktrees/geemee-sendpixel/.prettierrc +0 -7
  18. package/.claude/worktrees/geemee-sendpixel/AGENTS.md +0 -696
  19. package/.claude/worktrees/geemee-sendpixel/AI_PROMPT_SOURCE.md +0 -758
  20. package/.claude/worktrees/geemee-sendpixel/CHANGELOG.md +0 -1779
  21. package/.claude/worktrees/geemee-sendpixel/CLAUDE.md +0 -696
  22. package/.claude/worktrees/geemee-sendpixel/GEMINI.md +0 -696
  23. package/.claude/worktrees/geemee-sendpixel/README.md +0 -308
  24. package/.claude/worktrees/geemee-sendpixel/docs/kibana/crypto-way-deposit-amount-bug-analysis.md +0 -1003
  25. package/.claude/worktrees/geemee-sendpixel/docs/kibana/play-providerId-error.md +0 -202
  26. package/.claude/worktrees/geemee-sendpixel/docs/kibana/play-selectedWalletType.md +0 -1
  27. package/.claude/worktrees/geemee-sendpixel/docs/kibana/play-selectedWalletType_2.md +0 -1
  28. package/.claude/worktrees/geemee-sendpixel/docs/kibana/play-selectedWalletType_analysis.md +0 -565
  29. package/.claude/worktrees/geemee-sendpixel/package-lock.json +0 -2455
  30. package/.claude/worktrees/geemee-sendpixel/package.json +0 -34
  31. package/.claude/worktrees/geemee-sendpixel/scripts/auto-version.js +0 -68
  32. package/.claude/worktrees/geemee-sendpixel/scripts/auto-version.sh +0 -33
  33. package/.claude/worktrees/geemee-sendpixel/scripts/branch-auto-npm-publish.js +0 -29
  34. package/.claude/worktrees/geemee-sendpixel/scripts/check-version.sh +0 -36
  35. package/.claude/worktrees/geemee-sendpixel/scripts/clean-tags.sh +0 -59
  36. package/.claude/worktrees/geemee-sendpixel/src/api/account.js +0 -8
  37. package/.claude/worktrees/geemee-sendpixel/src/api/activity.js +0 -128
  38. package/.claude/worktrees/geemee-sendpixel/src/api/auth.js +0 -63
  39. package/.claude/worktrees/geemee-sendpixel/src/api/common.js +0 -17
  40. package/.claude/worktrees/geemee-sendpixel/src/api/form.js +0 -3
  41. package/.claude/worktrees/geemee-sendpixel/src/api/game.js +0 -114
  42. package/.claude/worktrees/geemee-sendpixel/src/api/index.js +0 -13
  43. package/.claude/worktrees/geemee-sendpixel/src/api/mailbox.js +0 -24
  44. package/.claude/worktrees/geemee-sendpixel/src/api/otp.js +0 -5
  45. package/.claude/worktrees/geemee-sendpixel/src/api/payment.js +0 -262
  46. package/.claude/worktrees/geemee-sendpixel/src/api/ranking.js +0 -27
  47. package/.claude/worktrees/geemee-sendpixel/src/api/user.js +0 -69
  48. package/.claude/worktrees/geemee-sendpixel/src/index.js +0 -7
  49. package/.claude/worktrees/geemee-sendpixel/src/machine/activity/activity.js +0 -209
  50. package/.claude/worktrees/geemee-sendpixel/src/machine/activity/activity_cash.js +0 -181
  51. package/.claude/worktrees/geemee-sendpixel/src/machine/activity/cash_rain_activity.js +0 -153
  52. package/.claude/worktrees/geemee-sendpixel/src/machine/activity/continue_deposit_activity.js +0 -146
  53. package/.claude/worktrees/geemee-sendpixel/src/machine/activity/deposit_activity.js +0 -95
  54. package/.claude/worktrees/geemee-sendpixel/src/machine/activity/diamond_shop_activity_cash.js +0 -179
  55. package/.claude/worktrees/geemee-sendpixel/src/machine/activity/diamond_shop_activity_fc.js +0 -196
  56. package/.claude/worktrees/geemee-sendpixel/src/machine/activity/diamond_shop_activity_vn.js +0 -178
  57. package/.claude/worktrees/geemee-sendpixel/src/machine/activity/fafafa_activity.js +0 -208
  58. package/.claude/worktrees/geemee-sendpixel/src/machine/activity/friend_invite_friends_activity.js +0 -287
  59. package/.claude/worktrees/geemee-sendpixel/src/machine/activity/index.js +0 -51
  60. package/.claude/worktrees/geemee-sendpixel/src/machine/activity/instant_rebate_activity.js +0 -209
  61. package/.claude/worktrees/geemee-sendpixel/src/machine/activity/invite_friends_activity.js +0 -114
  62. package/.claude/worktrees/geemee-sendpixel/src/machine/activity/jackpot.js +0 -74
  63. package/.claude/worktrees/geemee-sendpixel/src/machine/activity/mini_game_activity.js +0 -68
  64. package/.claude/worktrees/geemee-sendpixel/src/machine/activity/otp_verified_activity.js +0 -74
  65. package/.claude/worktrees/geemee-sendpixel/src/machine/activity/ranking_activity.js +0 -105
  66. package/.claude/worktrees/geemee-sendpixel/src/machine/activity/return_bonus_activity.js +0 -153
  67. package/.claude/worktrees/geemee-sendpixel/src/machine/activity/roulette_activity_v2.js +0 -95
  68. package/.claude/worktrees/geemee-sendpixel/src/machine/activity/sign_in_activity.js +0 -157
  69. package/.claude/worktrees/geemee-sendpixel/src/machine/activity/sign_in_monthly_activity.js +0 -65
  70. package/.claude/worktrees/geemee-sendpixel/src/machine/activity/specify_bets_activity.js +0 -157
  71. package/.claude/worktrees/geemee-sendpixel/src/machine/activity/specify_turnover_activity.js +0 -136
  72. package/.claude/worktrees/geemee-sendpixel/src/machine/activity/time_bomb_activity.js +0 -89
  73. package/.claude/worktrees/geemee-sendpixel/src/machine/activity/vip_card_activity.js +0 -187
  74. package/.claude/worktrees/geemee-sendpixel/src/machine/auth.js +0 -592
  75. package/.claude/worktrees/geemee-sendpixel/src/machine/auth_otp_v2.js +0 -177
  76. package/.claude/worktrees/geemee-sendpixel/src/machine/auth_otp_v3.js +0 -300
  77. package/.claude/worktrees/geemee-sendpixel/src/machine/bank_binding.js +0 -277
  78. package/.claude/worktrees/geemee-sendpixel/src/machine/bank_binding_amb.js +0 -146
  79. package/.claude/worktrees/geemee-sendpixel/src/machine/bonus.js +0 -76
  80. package/.claude/worktrees/geemee-sendpixel/src/machine/common.js +0 -418
  81. package/.claude/worktrees/geemee-sendpixel/src/machine/deposit/amb.js +0 -93
  82. package/.claude/worktrees/geemee-sendpixel/src/machine/deposit/crypto_bank.js +0 -330
  83. package/.claude/worktrees/geemee-sendpixel/src/machine/deposit/crypto_bank_cash.js +0 -307
  84. package/.claude/worktrees/geemee-sendpixel/src/machine/deposit/crypto_qrcode.js +0 -148
  85. package/.claude/worktrees/geemee-sendpixel/src/machine/deposit/crypto_qrcode_cash.js +0 -131
  86. package/.claude/worktrees/geemee-sendpixel/src/machine/deposit/crypto_way.js +0 -252
  87. package/.claude/worktrees/geemee-sendpixel/src/machine/deposit/crypto_way_cash.js +0 -296
  88. package/.claude/worktrees/geemee-sendpixel/src/machine/deposit/deposit_fc.js +0 -272
  89. package/.claude/worktrees/geemee-sendpixel/src/machine/deposit/direct.js +0 -310
  90. package/.claude/worktrees/geemee-sendpixel/src/machine/deposit/direct_cash.js +0 -225
  91. package/.claude/worktrees/geemee-sendpixel/src/machine/deposit/float.js +0 -375
  92. package/.claude/worktrees/geemee-sendpixel/src/machine/deposit/index.js +0 -49
  93. package/.claude/worktrees/geemee-sendpixel/src/machine/deposit/krway.js +0 -151
  94. package/.claude/worktrees/geemee-sendpixel/src/machine/deposit/loadcard_cash.js +0 -215
  95. package/.claude/worktrees/geemee-sendpixel/src/machine/deposit/loadcard_vn.js +0 -351
  96. package/.claude/worktrees/geemee-sendpixel/src/machine/deposit/manual_cash.js +0 -364
  97. package/.claude/worktrees/geemee-sendpixel/src/machine/deposit/manual_vn.js +0 -458
  98. package/.claude/worktrees/geemee-sendpixel/src/machine/deposit/qrcode_cash.js +0 -225
  99. package/.claude/worktrees/geemee-sendpixel/src/machine/deposit/qrcode_v2.js +0 -338
  100. package/.claude/worktrees/geemee-sendpixel/src/machine/deposit/usdt.js +0 -144
  101. package/.claude/worktrees/geemee-sendpixel/src/machine/deposit/usdt_cash.js +0 -138
  102. package/.claude/worktrees/geemee-sendpixel/src/machine/deposit/virtual_bank_cash.js +0 -209
  103. package/.claude/worktrees/geemee-sendpixel/src/machine/deposit/virtual_bank_vn.js +0 -269
  104. package/.claude/worktrees/geemee-sendpixel/src/machine/deposit/vpay.js +0 -368
  105. package/.claude/worktrees/geemee-sendpixel/src/machine/error.js +0 -112
  106. package/.claude/worktrees/geemee-sendpixel/src/machine/game_betslip.js +0 -46
  107. package/.claude/worktrees/geemee-sendpixel/src/machine/game_favorite_v2.js +0 -160
  108. package/.claude/worktrees/geemee-sendpixel/src/machine/game_hot_new.js +0 -79
  109. package/.claude/worktrees/geemee-sendpixel/src/machine/game_info.js +0 -61
  110. package/.claude/worktrees/geemee-sendpixel/src/machine/game_replay.js +0 -46
  111. package/.claude/worktrees/geemee-sendpixel/src/machine/game_search_cash.js +0 -401
  112. package/.claude/worktrees/geemee-sendpixel/src/machine/game_search_v2.js +0 -401
  113. package/.claude/worktrees/geemee-sendpixel/src/machine/game_v2_1.js +0 -699
  114. package/.claude/worktrees/geemee-sendpixel/src/machine/honor_board.js +0 -132
  115. package/.claude/worktrees/geemee-sendpixel/src/machine/honor_board_cash.js +0 -89
  116. package/.claude/worktrees/geemee-sendpixel/src/machine/inbox.js +0 -489
  117. package/.claude/worktrees/geemee-sendpixel/src/machine/index.js +0 -89
  118. package/.claude/worktrees/geemee-sendpixel/src/machine/leaderboard.js +0 -130
  119. package/.claude/worktrees/geemee-sendpixel/src/machine/merge.js +0 -57
  120. package/.claude/worktrees/geemee-sendpixel/src/machine/navbar.js +0 -126
  121. package/.claude/worktrees/geemee-sendpixel/src/machine/payment_data.js +0 -86
  122. package/.claude/worktrees/geemee-sendpixel/src/machine/promotions.js +0 -170
  123. package/.claude/worktrees/geemee-sendpixel/src/machine/ranking.js +0 -219
  124. package/.claude/worktrees/geemee-sendpixel/src/machine/reward.js +0 -255
  125. package/.claude/worktrees/geemee-sendpixel/src/machine/reward_cash.js +0 -276
  126. package/.claude/worktrees/geemee-sendpixel/src/machine/reward_fc.js +0 -98
  127. package/.claude/worktrees/geemee-sendpixel/src/machine/roulette_v2.js +0 -280
  128. package/.claude/worktrees/geemee-sendpixel/src/machine/setting.js +0 -47
  129. package/.claude/worktrees/geemee-sendpixel/src/machine/side.js +0 -154
  130. package/.claude/worktrees/geemee-sendpixel/src/machine/side_cash.js +0 -111
  131. package/.claude/worktrees/geemee-sendpixel/src/machine/side_v2.js +0 -209
  132. package/.claude/worktrees/geemee-sendpixel/src/machine/user_info.js +0 -64
  133. package/.claude/worktrees/geemee-sendpixel/src/machine/user_photo.js +0 -65
  134. package/.claude/worktrees/geemee-sendpixel/src/machine/user_reset_password.js +0 -231
  135. package/.claude/worktrees/geemee-sendpixel/src/machine/user_sign_up.js +0 -244
  136. package/.claude/worktrees/geemee-sendpixel/src/machine/vip_table.js +0 -57
  137. package/.claude/worktrees/geemee-sendpixel/src/machine/websocket.js +0 -361
  138. package/.claude/worktrees/geemee-sendpixel/src/machine/welcome.js +0 -110
  139. package/.claude/worktrees/geemee-sendpixel/src/machine/withdraw/index.js +0 -11
  140. package/.claude/worktrees/geemee-sendpixel/src/machine/withdraw/withdraw_crypto_cash.js +0 -327
  141. package/.claude/worktrees/geemee-sendpixel/src/machine/withdraw/withdraw_krway.js +0 -223
  142. package/.claude/worktrees/geemee-sendpixel/src/machine/withdraw/withdraw_manual.js +0 -536
  143. package/.claude/worktrees/geemee-sendpixel/src/machine/withdraw/withdraw_manual_cash.js +0 -324
  144. package/.claude/worktrees/geemee-sendpixel/src/request/config.js +0 -41
  145. package/.claude/worktrees/geemee-sendpixel/src/request/request.js +0 -365
  146. package/.claude/worktrees/geemee-sendpixel/src/util/constant.js +0 -20
  147. package/.claude/worktrees/geemee-sendpixel/src/util/index.js +0 -6
  148. package/.claude/worktrees/geemee-sendpixel/src/util/math.js +0 -4
  149. package/.claude/worktrees/geemee-sendpixel/src/util/storage.js +0 -42
@@ -1,1003 +0,0 @@
1
- # Crypto Way 存款 amount 異常分析報告
2
-
3
- > **Issue**: `/payment/v2/${method}/transaction` API 送出時 `amount` 缺失(undefined)或為負數(-5)
4
- > **影響範圍**: `crypto_way_cash` 存款流程(含所有 cryptoWay 類別的支付方式)
5
- > **發現日期**: 2026-04-13
6
- > **分支**: `fix/well/JT-1775988900-kibana-error`
7
-
8
- ---
9
-
10
- ## 一、Kibana 錯誤記錄
11
-
12
- ### 1.1 前端送出的 HTTP Request
13
-
14
- ```
15
- route: /v2/BTK/payment/v2/bitfunpay_usdt/transaction
16
- method: POST
17
- body: {
18
- transferType: "DEPOSIT",
19
- amount: -5, ← 負數
20
- cryptoCurrency: "USDT",
21
- cryptoNetwork: "TRX_TRC20",
22
- sourceAddress: "", ← 空字串
23
- promotionsNo: "none"
24
- }
25
- version: v1.2.10-1
26
- platform: pwa
27
- browser: Chrome/146 (Windows)
28
- ```
29
-
30
- ### 1.2 後端收到的資料
31
-
32
- ```
33
- TransactionApplyForm(
34
- transferType = DEPOSIT,
35
- amount = null, ← 後端將 -5 拒絕並轉為 null
36
- cryptoCurrency = USDT,
37
- cryptoNetwork = TRX_TRC20,
38
- sourceAddress = "",
39
- promotionsNo = none,
40
- paymentMethod = bitfunpayUsdt
41
- )
42
- ```
43
-
44
- ### 1.3 結論
45
-
46
- 前端確實送出了 `amount: -5`,後端驗證後將其轉為 `null`,導致交易建立失敗。問題出在前端的多層防線全部未擋住非法金額(負數或缺失)。
47
-
48
- ---
49
-
50
- ## 二、資料流與相關檔案索引
51
-
52
- ### 2.1 完整資料流
53
-
54
- ```
55
- 使用者操作(輸入框 / DepositOptions 按鈕)
56
- → Vue Component: CryptoWay.vue
57
- → inputAmount() / setAmount()
58
- → XState Event: INPUT_AMOUNT / SET_AMOUNT
59
- → XState Action: inputAmount / setAmount (assign to context)
60
- → debouncing (1000ms) → isCalculable guard
61
- → calculating → fetchCalculation API
62
- → calculated
63
- → SUBMIT → isSubmittable guard
64
- → submitting → submitDeposit service
65
- → payment.submitDepositTransactionCrypto()
66
- → Request._createConfig() → pickBy(params, isValid)
67
- → Axios POST 送出
68
- ```
69
-
70
- ### 2.2 關鍵檔案索引
71
-
72
- | 檔案 | 用途 |
73
- | -------------------------------------------------------------------- | ---------------------------------------- |
74
- | `components/deposit/CryptoWay.vue` | CryptoWay 存款 UI 元件 |
75
- | `components/deposit/Options.vue` | DepositOptions 快速金額按鈕元件 |
76
- | `components/deposit/Calculation.vue` | DepositCalculation 確認頁元件 |
77
- | `components/base/Input.vue` | BaseInput 通用輸入框元件 |
78
- | `components/modal/Wallet.vue` | 存款 Modal 容器(管理 promotionDeposit) |
79
- | `mixins/promotionMixin.js` | 存款 promotion 共用 mixin |
80
- | `node_modules/@jetthai/cuora/src/machine/deposit/crypto_way_cash.js` | CryptoWay 現金網狀態機 |
81
- | `node_modules/@jetthai/cuora/src/machine/deposit/crypto_way.js` | CryptoWay 平台版狀態機(有額外 bug) |
82
- | `node_modules/@jetthai/cuora/src/api/payment.js` | Payment API 定義 |
83
- | `node_modules/@jetthai/cuora/src/request/request.js` | HTTP 請求封裝層 |
84
- | `node_modules/@jetthai/cuora/src/util/math.js` | `max()` 工具函式 |
85
- | `store/index.js` | Vuex store(promotionDeposit 狀態) |
86
-
87
- ### 2.3 API 呼叫對應
88
-
89
- 前端 request body 格式對應 `payment.js:110-113` 的 `submitDepositTransactionCrypto`:
90
-
91
- ```js
92
- submitDepositTransactionCrypto: ({ method, amount, cryptoCurrency, cryptoNetwork, sourceAddress, promotionsNo, receipt }) => ({
93
- url: `payment/v2/${method}/transaction`,
94
- method: 'post',
95
- params: { transferType: 'DEPOSIT', amount, cryptoCurrency, cryptoNetwork, sourceAddress, promotionsNo, receipt },
96
- })
97
- ```
98
-
99
- 呼叫者為 `crypto_way_cash.js:251-262` 的 `submitDeposit` service:
100
-
101
- ```js
102
- submitDeposit: async (context, event) => {
103
- const { selectedCrypto, selectedAmount, sourceAddress, promotion } = context
104
- return await request.send(
105
- payment.submitDepositTransactionCrypto({
106
- method: selectedCrypto.method,
107
- amount: selectedAmount, // ← 此值為 -5 或 undefined
108
- cryptoCurrency: selectedCrypto.channel,
109
- cryptoNetwork: selectedCrypto.networkCode,
110
- sourceAddress: sourceAddress,
111
- promotionsNo: promotion?.promotionsNo,
112
- })
113
- )
114
- }
115
- ```
116
-
117
- `request.js:160-162, 317` 中的 `pickBy(params, isValid)` 會過濾 `undefined` 和 `null`,但不會過濾 `-5`、`""`、`0`、`NaN`:
118
-
119
- ```js
120
- function isValid(value) {
121
- return value !== undefined && value !== null
122
- }
123
- ```
124
-
125
- - `amount = undefined` → 被 `pickBy` 過濾 → request body 中無 `amount` 欄位
126
- - `amount = -5` → 通過 `pickBy` → request body 中 `amount: -5`
127
-
128
- ---
129
-
130
- ## 三、問題原因分析
131
-
132
- ### 3.1 根因總覽:七層防線全部失效
133
-
134
- ```
135
- Layer 1 - BaseInput UI → ❌ type="float" 非合法 HTML type,無原生驗證
136
- Layer 2 - XState action → ❌ inputAmount 無驗證,setAmount 累加無下界保護
137
- Layer 3 - isCalculable guard → ❓ 理論上擋住(min <= -5 通常 false),但非絕對
138
- Layer 4 - isSubmittable guard → ❌ 只查 truthy,-5 / "" 直接通過
139
- Layer 5 - submitDeposit service → ❌ 無防禦性檢查,直接傳入 API
140
- Layer 6 - API function → ❌ 無參數驗證
141
- Layer 7 - pickBy(params,isValid)→ ❌ -5 / "" / NaN 不是 null/undefined,不過濾
142
- ```
143
-
144
- ---
145
-
146
- ### 3.2 問題 A:amount 為負數(Kibana 實際案例 `amount: -5`)
147
-
148
- #### A1. `isSubmittable` guard 不驗證 amount 範圍(核心防線缺口)
149
-
150
- **檔案**: `cuora/src/machine/deposit/crypto_way_cash.js:234-237`
151
-
152
- ```js
153
- isSubmittable: (context, event) => {
154
- const { selectedCrypto, selectedAmount, calculation } = context
155
- return selectedCrypto && selectedAmount && calculation
156
- // ^^^^^^^^^^^^^^^^
157
- // -5 (number) 是 truthy → 通過
158
- // "-5" (string) 也是 truthy → 通過
159
- // 完全不檢查 amount > 0 或 min/max 範圍
160
- }
161
- ```
162
-
163
- **對比 `isCalculable` guard**(有做範圍檢查):
164
-
165
- ```js
166
- isCalculable: (context) => {
167
- const { selectedCrypto, selectedAmount } = context
168
- return (
169
- selectedCrypto &&
170
- selectedAmount &&
171
- selectedCrypto.minimum <= +selectedAmount && // ← 有檢查 min
172
- +selectedAmount <= selectedCrypto.maximum
173
- ) // ← 有檢查 max
174
- }
175
- ```
176
-
177
- `isCalculable` 在 `debouncing → calculating` 之間檢查,是進入 `calculated` 的門檻。但 `isSubmittable` 作為 `calculated → submitting` 的最後防線,**沒有重複檢查範圍**,形成防禦缺口。
178
-
179
- #### A2. `grandTotalEnable` 累加模式無下界保護
180
-
181
- **檔案**: `cuora/src/machine/deposit/crypto_way_cash.js:167-176`
182
-
183
- ```js
184
- setAmount: assign((context, event) => {
185
- if (context.selectedCrypto?.grandTotalEnable === 1) {
186
- return {
187
- selectedAmount: preciseAdd(
188
- `${parseFloat(context.selectedAmount || 0)}`,
189
- `${parseFloat(event.data)}`
190
- ),
191
- // ❌ 沒有 Math.max(result, 0) 下界保護
192
- }
193
- } else {
194
- return { selectedAmount: event.data }
195
- }
196
- }),
197
- ```
198
-
199
- `preciseAdd` 函式(同檔案 269-279 行)是純數學運算,不阻止負數結果。
200
-
201
- **觸發場景**:
202
-
203
- ```
204
- 1. 使用者手動輸入 "-20"(BaseInput 不阻止負數輸入)
205
- → INPUT_AMOUNT("-20") → selectedAmount = "-20"
206
- → debouncing → isCalculable: min <= -20 → false → loaded
207
-
208
- 2. 使用者點擊 DepositOptions 的 "+15" 按鈕
209
- → SET_AMOUNT(15)
210
- → grandTotalEnable === 1
211
- → preciseAdd("-20", "15") = -5
212
- → selectedAmount = -5
213
- → debouncing → isCalculable: min <= -5 → 通常 false → loaded
214
- ```
215
-
216
- 正常流程下 `isCalculable` 會擋住,但 `-5` 已存在於 context 中。配合下方 A4/A5 的狀態機缺陷,有機會在 `calculated` 狀態下保留舊的 `calculation`,使 `isSubmittable` 通過。
217
-
218
- #### A3. `type="float"` 非合法 HTML input type
219
-
220
- **檔案**: `components/deposit/CryptoWay.vue:8`
221
-
222
- ```pug
223
- BaseInput(:value="selectedAmount", type="float", @input="inputAmount", :focusOnLoad="true", :noParse="true")
224
- ```
225
-
226
- **檔案**: `components/base/Input.vue:111-128`
227
-
228
- ```js
229
- input(e) {
230
- if (e.target.value && this.type === 'number') {
231
- // type="float" ≠ "number",不走這個分支
232
- } else {
233
- // type="float" 走這裡 → 直接 emit 原始字串(含負號)
234
- this.$emit('input', e.target.value)
235
- }
236
- }
237
- ```
238
-
239
- **問題**:
240
-
241
- 1. `type="float"` 不是合法的 HTML input type,瀏覽器 fallback 為 `type="text"`
242
- 2. text input 不會阻擋負號 `-` 的輸入
243
- 3. 因為 `type !== 'number'`,走 `else` 分支,直接 emit 原始字串
244
- 4. 沒有設定 `:minValue="0"`,`filterInput`(阻擋 `e` 和 `.`)不會觸發
245
-
246
- #### A4. `calculating onError` 導向 `calculated` 狀態(不一致狀態)
247
-
248
- **檔案**: `cuora/src/machine/deposit/crypto_way_cash.js:53-62`
249
-
250
- ```js
251
- calculating: {
252
- invoke: {
253
- src: 'fetchCalculation',
254
- onDone: {
255
- target: 'calculated',
256
- actions: 'setCalculation',
257
- },
258
- onError: {
259
- target: 'calculated', // ❌ 計算失敗也進入 calculated
260
- // 沒有 setCalculation action → calculation 維持 debouncing entry 清除後的 null
261
- },
262
- },
263
- },
264
- ```
265
-
266
- **影響**:
267
-
268
- - 計算 API 失敗時,machine 仍進入 `calculated` 狀態
269
- - 此時 `calculation` 為 `null`(已在 `debouncing` entry 被 `clearCalculation` 清除)
270
- - `isSubmittable` 會檢查 `calculation` 是否 truthy → `null` 不通過 → SUBMIT 被擋
271
- - **但 UI 按鈕只看 `state.matches('calculated')`**(CryptoWay.vue:36),按鈕會變為可點擊,造成使用者困惑
272
- - 可能誘導使用者反覆操作,增加觸發其他 race condition 的機率
273
-
274
- #### A5. `fail` 狀態 0ms 立即回到 `calculated`(舊 calculation 殘留)
275
-
276
- **檔案**: `cuora/src/machine/deposit/crypto_way_cash.js:86-89`
277
-
278
- ```js
279
- fail: {
280
- after: {
281
- 0: { target: 'calculated' }, // 0ms 延遲立即回到 calculated
282
- },
283
- },
284
- ```
285
-
286
- **影響**:
287
-
288
- - 提交 API 失敗後,`fail → calculated` 立即轉換
289
- - `selectedAmount` 和 `calculation` 都**不會被清除**
290
- - 使用者可以用舊的 calculation(可能與當前 amount 不一致)再次 SUBMIT
291
- - Vue 的 UI 更新是異步的,`fail → calculated` 的瞬間轉換可能導致 UI 來不及顯示錯誤狀態
292
-
293
- #### A6. `crypto_way.js`(平台版)SUBMIT transition 設計錯誤
294
-
295
- **檔案**: `cuora/src/machine/deposit/crypto_way.js:67-74`
296
-
297
- ```js
298
- calculated: {
299
- on: {
300
- SUBMIT: [
301
- {
302
- target: 'pending',
303
- // ❌ 第一條沒有 cond guard → 永遠匹配
304
- },
305
- {
306
- target: 'submitting',
307
- cond: 'isSubmittable', // 永遠不會執行到這裡
308
- },
309
- ],
310
- },
311
- },
312
- ```
313
-
314
- XState v4 的 transition 陣列是**第一個匹配就執行**。第一條沒有 `cond`,永遠走 `pending`,`isSubmittable` guard 完全被跳過。
315
-
316
- > **注意**:目前 CryptoWay.vue 使用的是 `crypto_way_cash`(已修正此問題),但如果有其他入口使用 `crypto_way`,此 bug 仍然存在。
317
-
318
- #### A7. 可透過 DevTools 直接操作 XState service
319
-
320
- 使用者可透過瀏覽器 Console 直接操作:
321
-
322
- ```js
323
- // 透過 $nuxt 找到 component
324
- const vm = window.$nuxt.$children[0].$children[...]
325
-
326
- // 直接修改 context 並 submit
327
- vm.service.send({ type: 'INPUT_AMOUNT', data: '-5' })
328
- vm.service.send({ type: 'SUBMIT' })
329
- ```
330
-
331
- `isSubmittable` 不驗證 amount 範圍,程式性操作也不會被擋住。
332
-
333
- ---
334
-
335
- ### 3.3 問題 B:amount 缺失(undefined → API 不帶 amount 欄位)
336
-
337
- #### B1. `selectedAmount` 初始值可能為 undefined 或 0
338
-
339
- **檔案**: `components/deposit/CryptoWay.vue:145-151`
340
-
341
- ```js
342
- this.service = interpret(
343
- machine.crypto_way_cash(this.$request, {
344
- paymentDetail: this.paymentDetail,
345
- promotion: this.defaultPromotion,
346
- selectedAmount: this.getPromotionDeposit, // ← 來自 Vuex store
347
- })
348
- )
349
- ```
350
-
351
- **檔案**: `store/index.js:98`
352
-
353
- ```js
354
- promotionDeposit: 0, // 預設值
355
- ```
356
-
357
- **檔案**: `components/modal/Wallet.vue:213`
358
-
359
- ```js
360
- beforeDestroy() {
361
- this.setPromotionDeposit(null) // ← 關閉 modal 時設為 null
362
- }
363
- ```
364
-
365
- **檔案**: `cuora/src/machine/deposit/crypto_way_cash.js:5-14`
366
-
367
- ```js
368
- export default function (request, context) {
369
- const { paymentDetail = [], promotion, selectedAmount } = context || {}
370
- // ^^^^^^^^^^^^^^^
371
- // 如果 getPromotionDeposit 回傳 null(Wallet 關閉再開),selectedAmount = null
372
- // 如果未從 promotion 進入(一般入口),selectedAmount = 0
373
- return createMachine({
374
- context: {
375
- selectedAmount, // 可能是 null、0、或 undefined
376
- },
377
- })
378
- }
379
- ```
380
-
381
- **影響**:初始 `selectedAmount` 為 falsy(`null`/`0`/`undefined`)時,`isCalculable` 的第一關 `selectedAmount &&` 就會擋住,進入 `loaded`。**正常情況安全**。但 `undefined` 值若後續未被覆蓋就直接提交,會導致 API 不帶 amount。
382
-
383
- #### B2. `inputAmount` 傳入空字串或非預期值
384
-
385
- **觸發場景**:使用者清空輸入框
386
-
387
- ```
388
- 1. BaseInput type="float" → 瀏覽器 fallback 為 text → 清空輸入框
389
- 2. @input 觸發 → e.target.value = ""
390
- 3. Input.vue: type !== 'number' → 走 else → emit("")
391
- 4. CryptoWay.vue: inputAmount("") → service.send({ type: 'INPUT_AMOUNT', data: "" })
392
- 5. crypto_way_cash.js inputAmount action: selectedAmount = ""
393
- ```
394
-
395
- **檔案**: `cuora/src/machine/deposit/crypto_way_cash.js:177-179`
396
-
397
- ```js
398
- inputAmount: assign((context, event) => {
399
- return { selectedAmount: event.data } // event.data = "" → selectedAmount = ""
400
- }),
401
- ```
402
-
403
- **後續**:
404
-
405
- - `isCalculable`:`"" && ...` → `""` 是 falsy → `false` → 進入 `loaded` → **安全**
406
- - **但** `""` 已存在於 context。若配合其他 race condition 觸發 SUBMIT:
407
- - `isSubmittable`:`"" && ...` → `""` 是 falsy → `false` → **被擋住**
408
- - 空字串情境下 `isSubmittable` 恰好能擋住
409
-
410
- **真正危險的值**:如果瀏覽器因 IME 輸入法、自動填充、或其他原因傳入非預期的 truthy 字串(例如 `"-"`、`"e"`、`"."`),這些值:
411
-
412
- - 是 truthy → 通過 `isSubmittable` 的 `selectedAmount &&` 檢查
413
- - `+"-"` = `NaN` → `NaN <= maximum` = `false` → `isCalculable` 擋住
414
- - 但 `isSubmittable` 不做數值檢查 → 通過
415
-
416
- #### B3. `setCrypto` 重置 amount 為 null + debounce 時間窗
417
-
418
- **檔案**: `cuora/src/machine/deposit/crypto_way_cash.js:157-165`
419
-
420
- ```js
421
- setCrypto: assign((context, event) => {
422
- return {
423
- selectedCrypto: selectedCrypto,
424
- selectedAmount: null, // ← 切換幣種時清除金額
425
- calculation: null,
426
- }
427
- }),
428
- ```
429
-
430
- **時序場景**:
431
-
432
- ```
433
- 1. 使用者輸入 amount=100 → calculated → calculation 有效 → 按鈕可點
434
- 2. 使用者切換 crypto 幣種 → SET_CRYPTO
435
- 3. setCrypto: selectedAmount = null, calculation = null
436
- 4. 轉到 .debouncing → entry: clearCalculation(calculation 已是 null)
437
- 5. debouncing 的 1000ms 期間 selectedAmount = null
438
- 6. isCalculable: null → false → loaded
439
- ```
440
-
441
- **正常情況安全**。但如果裝置嚴重卡頓(見 3.4 節),Vue UI 更新可能延遲,按鈕在短暫時間內仍顯示為可點擊。
442
-
443
- #### B4. `setPromotion` 修改 amount 的邊界行為
444
-
445
- **檔案**: `cuora/src/machine/deposit/crypto_way_cash.js:208-216`
446
-
447
- ```js
448
- setPromotion: assign((context, event) => {
449
- const { selectedCrypto, selectedAmount } = context
450
- const promotion = event.data
451
- return {
452
- promotion,
453
- selectedAmount: max(promotion.minimumAmount, selectedCrypto.minimum, selectedAmount, 0),
454
- calculation: null,
455
- }
456
- }),
457
- ```
458
-
459
- **檔案**: `cuora/src/util/math.js:1-4`
460
-
461
- ```js
462
- export function max(...args) {
463
- const casted = args.map((arg) => arg || 0) // falsy 值轉為 0
464
- return Math.max(...casted)
465
- }
466
- ```
467
-
468
- **邊界情境**:
469
-
470
- - 若 `promotion.minimumAmount` 為 `undefined`/`null`/`0` → `max()` 將其轉為 0
471
- - 若 `selectedCrypto.minimum` 為 `undefined` → 轉為 0
472
- - 若 `selectedAmount` 為 `null` → 轉為 0
473
- - 最終結果至少為 0(因為最後一個參數是 `0`)
474
-
475
- `max()` 的 `arg || 0` 有一個隱藏問題:**負數是 truthy,不會被轉為 0**。
476
- `max(-5, 0)` → `Math.max(-5, 0)` → `0` → **安全**(因為最後有 `0` 兜底)。
477
-
478
- 但如果未來 `max()` 的呼叫者忘記加 `0` 作為最後參數,負數就可能穿透。
479
-
480
- ---
481
-
482
- ### 3.4 問題 C:時序問題、網路慢、裝置卡頓的 Race Condition
483
-
484
- #### C1. 全域 `on` 事件可在 `submitting` 狀態修改 context
485
-
486
- **檔案**: `cuora/src/machine/deposit/crypto_way_cash.js:101-126`
487
-
488
- ```js
489
- on: {
490
- SET_AMOUNT: {
491
- target: '.debouncing',
492
- actions: 'setAmount', // ← 修改 selectedAmount
493
- internal: false,
494
- },
495
- INPUT_AMOUNT: {
496
- target: '.debouncing',
497
- actions: 'inputAmount', // ← 修改 selectedAmount
498
- internal: false,
499
- },
500
- }
501
- ```
502
-
503
- XState v4 中,根層級的 `on` handler **可以在任何子狀態被觸發,包括 `submitting`**。
504
-
505
- **時序場景**:
506
-
507
- ```
508
- 1. [calculated] selectedAmount = 100, calculation = {有效}
509
- 2. 使用者點「確認」→ SUBMIT → isSubmittable ✅ → [submitting]
510
- 3. submitDeposit async 開始:
511
- const { selectedAmount } = context // 取到 100
512
- await request.send(...) // HTTP 請求發出中...
513
-
514
- 4. ⚡ HTTP in-flight 期間使用者在輸入框修改金額 ⚡
515
- → INPUT_AMOUNT("-5") 觸發
516
- → 全域 on handler 在 submitting 狀態執行
517
- → inputAmount action: selectedAmount = "-5"
518
- → target: .debouncing → 離開 submitting
519
-
520
- 5. XState 「取消」invoke,但 request.send() 是 pure Promise
521
- HTTP 請求已在步驟 3 取值並發出,帶的是 100(非 -5)
522
- 但 context 已被污染為 -5
523
- ```
524
-
525
- **在此場景中**,API 帶的是正確的 100(步驟 3 已取值),但 context 被修改為 -5。**如果 HTTP 請求失敗**:
526
-
527
- ```
528
- 6. onError → fail → (0ms) → calculated
529
- 7. 此時 selectedAmount = -5, calculation = {舊的有效值}(未清除)
530
- 8. isSubmittable: -5(truthy) && calculation(truthy) → ✅
531
- 9. 使用者再次 SUBMIT → 帶 amount: -5 發出 HTTP 請求
532
- ```
533
-
534
- **這是產出 `amount: -5` 的最完整路徑。**
535
-
536
- #### C2. Debounce 1000ms 期間的 SUBMIT 事件丟失
537
-
538
- **檔案**: `cuora/src/machine/deposit/crypto_way_cash.js:38-51`
539
-
540
- ```js
541
- debouncing: {
542
- entry: 'clearCalculation',
543
- after: {
544
- 1000: [
545
- { target: 'calculating', cond: 'isCalculable' },
546
- { target: 'loaded' },
547
- ],
548
- },
549
- // ❌ 沒有 SUBMIT handler → 事件被丟棄
550
- },
551
- ```
552
-
553
- **時序場景**:
554
-
555
- ```
556
- 1. [calculated] 使用者修改金額 → INPUT_AMOUNT → [debouncing]
557
- 2. debouncing 的 1000ms 期間,使用者點擊提交
558
- 3. SUBMIT 事件在 debouncing 沒有 handler → 被丟棄
559
- 4. 使用者以為提交失敗,但實際上是事件被忽略
560
- ```
561
-
562
- **影響**:不會造成錯誤金額提交,但使用者體驗差(按了沒反應)。
563
-
564
- #### C3. Vue UI 更新異步 vs XState 同步轉換的不一致
565
-
566
- **背景**:XState 狀態轉換是同步的,但 Vue 2 的 DOM 更新是異步的(透過 `nextTick`)。
567
-
568
- **時序場景**:
569
-
570
- ```
571
- 1. [calculated] 按鈕 enabled(state.matches('calculated') = true)
572
- 2. 使用者修改金額 → INPUT_AMOUNT → XState 同步轉到 [debouncing]
573
- 3. Vue 的 onTransition callback 觸發,設定 this.state = newState
574
- 4. 但 Vue DOM 更新是 nextTick → 按鈕仍顯示 enabled
575
- 5. 在 DOM 更新前(微秒級窗口),使用者快速點擊提交
576
- 6. @click 觸發 submit() → service.send({ type: 'SUBMIT' })
577
- 7. 此時 XState 已在 debouncing → SUBMIT 被丟棄 → 安全
578
- ```
579
-
580
- **結論**:XState 的狀態是 source of truth,即使 Vue UI 短暫不一致,SUBMIT 事件到達 XState 時已經是 debouncing 狀態,會被丟棄。**此場景安全**。
581
-
582
- 但如果結合 C1 的場景(submitting → fail → calculated 的快速迴圈),Vue UI 可能在 `fail` 到 `calculated` 的 0ms 轉換中完全看不到 fail 狀態,使用者不知道發生了錯誤。
583
-
584
- #### C4. `fail → calculated`(0ms)+ 網路超時的致命組合
585
-
586
- **檔案**: `cuora/src/machine/deposit/crypto_way_cash.js:74-89`
587
-
588
- ```js
589
- submitting: {
590
- invoke: {
591
- src: 'submitDeposit',
592
- onDone: { target: 'submitted', actions: ['setResult', 'setTtl'] },
593
- onError: { target: 'fail' },
594
- },
595
- },
596
- fail: {
597
- after: {
598
- 0: { target: 'calculated' },
599
- },
600
- },
601
- ```
602
-
603
- **時序場景(完整致命路徑)**:
604
-
605
- ```
606
- 時間軸
607
- ──────────────────────────────────────────────────────────────
608
- T0 使用者輸入 amount=100 → 計算成功 → [calculated]
609
- selectedAmount=100, calculation={有效}
610
-
611
- T1 使用者點「確認」→ SUBMIT → [submitting]
612
- HTTP 請求發出: amount=100
613
-
614
- T2 網路慢... 10 秒後 timeout → onError → [fail]
615
-
616
- T3 fail after:0 → 立即 [calculated]
617
- selectedAmount=100, calculation={有效}(都沒被清除)
618
-
619
- T4 ⚡ 在 T2-T3 之間,使用者已經修改金額為 -5 ⚡
620
- (submitting 期間全域 on: INPUT_AMOUNT 仍可觸發)
621
- selectedAmount 被改為 -5
622
-
623
- T5 回到 [calculated] 時:
624
- selectedAmount=-5, calculation={T0 時的有效計算結果}
625
- isSubmittable: -5(truthy) && calculation(truthy) → ✅
626
-
627
- T6 使用者再次點「確認」→ SUBMIT → [submitting]
628
- HTTP 請求發出: amount=-5 ← ❌ Kibana 記錄到的錯誤
629
- ──────────────────────────────────────────────────────────────
630
- ```
631
-
632
- #### C5. `calculating onError → calculated` + 網路錯誤
633
-
634
- **時序場景**:
635
-
636
- ```
637
- T0 使用者輸入 amount=50 → [calculated], calculation={有效}
638
- T1 使用者改金額為 100 → [debouncing] → clearCalculation
639
- T2 1000ms → [calculating] → fetchCalculation API 發出
640
- T3 網路錯誤 → onError → [calculated]
641
- 此時 calculation=null(在 T1 的 debouncing entry 已清除)
642
- T4 按鈕 enabled(state.matches('calculated')=true)
643
- 但 isSubmittable: calculation=null → false → SUBMIT 被擋
644
- ```
645
-
646
- **此場景不會造成錯誤提交**,但按鈕 enabled 卻無法提交,使用者體驗差。
647
-
648
- #### C6. 多次快速點擊 DepositOptions 按鈕的累加溢出
649
-
650
- **時序場景**(`grandTotalEnable === 1`):
651
-
652
- ```
653
- 1. selectedAmount = 5000(已計算成功,calculated 狀態)
654
- 2. 使用者快速連點「+1000」按鈕 100 次
655
- 3. 每次 SET_AMOUNT → setAmount → preciseAdd → selectedAmount += 1000
656
- 4. 每次都轉到 .debouncing → 1000ms 計時重置
657
- 5. 最終 selectedAmount = 105000
658
- 6. 1000ms 後 → isCalculable: selectedAmount <= maximum?
659
- 如果 maximum=100000 → false → loaded
660
- ```
661
-
662
- **影響**:金額超過 maximum 時被 `isCalculable` 擋住。**安全**,但累加過程中金額暫時超標。
663
-
664
- ---
665
-
666
- ## 四、XState 狀態機完整流程圖
667
-
668
- ```
669
- ┌──────────────────────────────────────────────────────────┐
670
- │ 全域 on handlers(任何子狀態都可觸發) │
671
- │ SET_PROMOTION → .debouncing + setPromotion │
672
- │ SET_CRYPTO → .debouncing + setCrypto │
673
- │ SET_ADDRESS → setAddress(不轉換狀態) │
674
- │ SET_AMOUNT → .debouncing + setAmount │
675
- │ INPUT_AMOUNT → .debouncing + inputAmount │
676
- └──────────────────────────────────────────────────────────┘
677
-
678
- ┌─────────┐ always ┌────────────┐ 1000ms ┌─────────────┐
679
- │ loading ├────────────►│ debouncing │──────────►│ calculating │
680
- │ │ setInitData│ │isCalculable│ │
681
- └─────────┘ │entry: │ ✅ │fetchCalc API│
682
- │clearCalc │ │ │
683
- │ │ 1000ms └──┬──────┬───┘
684
- │ │──────────► │ │
685
- │ │isCalculable │onDone│onError
686
- │ │ ❌ │ │ ❌應改為
687
- └──────┬─────┘ ┌───▼──────▼───┐ loaded
688
- │ │ calculated │
689
- ┌──────▼─────┐ │ │
690
- │ loaded │ │ SUBMIT │
691
- │ │ │ +isSubmittable│
692
- │(無 SUBMIT) │ └──────┬───────┘
693
- └────────────┘ │
694
- ┌──────▼───────┐
695
- │ submitting │
696
- │submitDeposit │
697
- │ API call │
698
- └──┬───────┬───┘
699
- │ │
700
- onDone│ │onError
701
- │ │
702
- ┌──────▼──┐ ┌──▼──────┐
703
- │submitted│ │ fail │
704
- │countdown│ │after:0ms│
705
- └─────────┘ └────┬────┘
706
- │❌應改為
707
- ┌──────▼──────┐ loaded
708
- │ calculated │
709
- │(舊 calc 殘留)│
710
- └─────────────┘
711
- ```
712
-
713
- ---
714
-
715
- ## 五、詳細調整方式
716
-
717
- ### 5.1 Layer 1 — BaseInput UI 層
718
-
719
- **目標**:在使用者輸入階段就阻止負數及非數字字元
720
-
721
- #### 5.1.1 CryptoWay.vue 修改 input type
722
-
723
- **檔案**: `components/deposit/CryptoWay.vue:8`
724
-
725
- ```diff
726
- - BaseInput.mb-2.h-16(:value="selectedAmount", type="float", @input="inputAmount", :focusOnLoad="true", :noParse="true")
727
- + BaseInput.mb-2.h-16(:value="selectedAmount", type="number", @input="inputAmount", :focusOnLoad="true", :noParse="true", :minValue="0")
728
- ```
729
-
730
- **說明**:
731
-
732
- - `type="number"`:啟用瀏覽器原生數字輸入驗證,移動端會顯示數字鍵盤
733
- - `:minValue="0"`:觸發 `Input.vue` 中的 `filterInput` 方法,同時作為語義標記
734
-
735
- #### 5.1.2 Input.vue filterInput 加入負號阻擋
736
-
737
- **檔案**: `components/base/Input.vue:183-188`
738
-
739
- ```diff
740
- filterInput(e) {
741
- - let prohibitInput = ['e', '.']
742
- + let prohibitInput = ['e', '.', '-', '+']
743
- if (prohibitInput.includes(e.key)) {
744
- e.preventDefault()
745
- }
746
- },
747
- ```
748
-
749
- **說明**:阻止鍵盤輸入負號 `-` 和正號 `+`,從 UI 層面杜絕負數輸入。
750
-
751
- ---
752
-
753
- ### 5.2 Layer 2 — XState action 資料驗證
754
-
755
- **目標**:在 XState action 層確保 amount 不為負數、不為 NaN
756
-
757
- #### 5.2.1 `inputAmount` action 拒絕非法值
758
-
759
- **檔案**: `cuora/src/machine/deposit/crypto_way_cash.js:177-179`
760
-
761
- ```diff
762
- inputAmount: assign((context, event) => {
763
- - return { selectedAmount: event.data }
764
- + const val = parseFloat(event.data)
765
- + if (isNaN(val) || val < 0) return {}
766
- + return { selectedAmount: event.data }
767
- }),
768
- ```
769
-
770
- **說明**:如果輸入值無法解析為數字或為負數,返回空物件(context 不變),等效於忽略此次輸入。
771
-
772
- #### 5.2.2 `setAmount` action 累加下界保護
773
-
774
- **檔案**: `cuora/src/machine/deposit/crypto_way_cash.js:167-176`
775
-
776
- ```diff
777
- setAmount: assign((context, event) => {
778
- if (context.selectedCrypto?.grandTotalEnable === 1) {
779
- + const result = preciseAdd(`${parseFloat(context.selectedAmount || 0)}`, `${parseFloat(event.data)}`)
780
- return {
781
- - selectedAmount: preciseAdd(`${parseFloat(context.selectedAmount || 0)}`, `${parseFloat(event.data)}`),
782
- + selectedAmount: Math.max(result, 0),
783
- }
784
- } else {
785
- - return { selectedAmount: event.data }
786
- + const val = parseFloat(event.data)
787
- + if (isNaN(val) || val < 0) return {}
788
- + return { selectedAmount: event.data }
789
- }
790
- }),
791
- ```
792
-
793
- **說明**:累加模式下用 `Math.max(result, 0)` 確保結果不低於 0;直接設定模式下拒絕負數和 NaN。
794
-
795
- ---
796
-
797
- ### 5.3 Layer 3 — `isSubmittable` guard 加入範圍驗證
798
-
799
- **目標**:作為提交前的最後 guard,重新驗證 amount 的合法性(與 `isCalculable` 同等嚴格)
800
-
801
- **檔案**: `cuora/src/machine/deposit/crypto_way_cash.js:234-237`
802
-
803
- ```diff
804
- isSubmittable: (context, event) => {
805
- const { selectedCrypto, selectedAmount, calculation } = context
806
- - return selectedCrypto && selectedAmount && calculation
807
- + return (
808
- + selectedCrypto &&
809
- + selectedAmount &&
810
- + +selectedAmount > 0 &&
811
- + selectedCrypto.minimum <= +selectedAmount &&
812
- + +selectedAmount <= selectedCrypto.maximum &&
813
- + calculation
814
- + )
815
- },
816
- ```
817
-
818
- **說明**:將 `isCalculable` 的 min/max 範圍檢查複製到 `isSubmittable`。即使有 race condition 導致 context 不一致,最後一道 guard 也能擋住。
819
-
820
- ---
821
-
822
- ### 5.4 Layer 4 — `submitDeposit` service 防禦性檢查
823
-
824
- **目標**:在 API 呼叫前做最後一次驗證,並確保 amount 為數字型別
825
-
826
- **檔案**: `cuora/src/machine/deposit/crypto_way_cash.js:251-262`
827
-
828
- ```diff
829
- submitDeposit: async (context, event) => {
830
- const { selectedCrypto, selectedAmount, sourceAddress, promotion } = context
831
- + const amount = +selectedAmount
832
- + if (!amount || amount <= 0 || amount < selectedCrypto.minimum || amount > selectedCrypto.maximum) {
833
- + throw new Error('INVALID_AMOUNT')
834
- + }
835
- return await request.send(
836
- payment.submitDepositTransactionCrypto({
837
- method: selectedCrypto.method,
838
- - amount: selectedAmount,
839
- + amount: amount,
840
- cryptoCurrency: selectedCrypto.channel,
841
- cryptoNetwork: selectedCrypto.networkCode,
842
- sourceAddress: sourceAddress,
843
- promotionsNo: promotion?.promotionsNo,
844
- })
845
- )
846
- },
847
- ```
848
-
849
- **說明**:
850
-
851
- - `+selectedAmount` 將字串轉為數字,避免送出字串型別的 amount
852
- - 驗證 amount > 0 且在 min/max 範圍內
853
- - 不合法時 throw → 進入 `fail` 狀態,HTTP 請求不會發出
854
-
855
- ---
856
-
857
- ### 5.5 Layer 5 — `calculating onError` 修正
858
-
859
- **目標**:計算失敗時回到 `loaded` 而非 `calculated`,避免 UI 與 state 不一致
860
-
861
- **檔案**: `cuora/src/machine/deposit/crypto_way_cash.js:53-62`
862
-
863
- ```diff
864
- calculating: {
865
- invoke: {
866
- src: 'fetchCalculation',
867
- onDone: {
868
- target: 'calculated',
869
- actions: 'setCalculation',
870
- },
871
- onError: {
872
- - target: 'calculated',
873
- + target: 'loaded',
874
- },
875
- },
876
- },
877
- ```
878
-
879
- **說明**:
880
-
881
- - 計算失敗不應進入 `calculated` 狀態(否則按鈕可點但無法提交,UX 差)
882
- - 回到 `loaded` 讓使用者重新操作,狀態清晰一致
883
- - 使用者修改金額後會重新走 debouncing → calculating 流程
884
-
885
- ---
886
-
887
- ### 5.6 Layer 6 — `fail` 狀態回到 `loaded`
888
-
889
- **目標**:提交失敗後強制重新走完整 debounce → calculate 流程,避免 calculation 與 amount 不一致
890
-
891
- **檔案**: `cuora/src/machine/deposit/crypto_way_cash.js:86-89`
892
-
893
- ```diff
894
- fail: {
895
- after: {
896
- - 0: { target: 'calculated' },
897
- + 0: { target: 'loaded' },
898
- },
899
- },
900
- ```
901
-
902
- **說明**:
903
-
904
- - 改為回到 `loaded` 而非 `calculated`
905
- - 使用者需要重新觸發 calculation(修改金額或切換 promotion),確保 calculation 與當前 amount 一致
906
- - 杜絕「fail → calculated → 用舊 calculation 重複提交」的 race condition
907
- - 消除 C4 場景中描述的致命路徑
908
-
909
- ---
910
-
911
- ### 5.7 Layer 7 — CryptoWay.vue 按鈕 disabled 條件強化
912
-
913
- **目標**:UI 層面做完整性檢查,確保按鈕 disabled 與實際可提交性一致
914
-
915
- **檔案**: `components/deposit/CryptoWay.vue:36`
916
-
917
- ```diff
918
- - BaseButton.self-center.flex.justify-center.items-center.gap-x-2.min-w-45(variant="primary", :disabled="!state.matches('calculated') || isEligible" @click="checkStep")
919
- + BaseButton.self-center.flex.justify-center.items-center.gap-x-2.min-w-45(variant="primary", :disabled="!state.matches('calculated') || !calculation || !selectedAmount || +selectedAmount <= 0 || isEligible" @click="checkStep")
920
- ```
921
-
922
- **說明**:除了檢查狀態機狀態,額外檢查:
923
-
924
- - `calculation` 存在(避免 `calculating onError → calculated` 但 calculation 為 null 的情境)
925
- - `selectedAmount` 存在且為正數(避免 UI 可點但 guard 擋住的不一致體驗)
926
-
927
- ---
928
-
929
- ### 5.8 修改總覽表
930
-
931
- | Layer | 檔案 | 行號 | 修改內容 | 防禦目標 |
932
- | ----- | ---------------------------------- | ------- | -------------------------------------------------- | ---------------- |
933
- | 1 | `components/deposit/CryptoWay.vue` | 8 | `type="float"` → `type="number"` + `:minValue="0"` | 阻止輸入負數 |
934
- | 1 | `components/base/Input.vue` | 184 | `filterInput` 加入 `'-'`, `'+'` | 阻止鍵盤輸入負號 |
935
- | 2 | `cuora/.../crypto_way_cash.js` | 177-179 | `inputAmount` 拒絕負數和 NaN | action 層驗證 |
936
- | 2 | `cuora/.../crypto_way_cash.js` | 167-176 | `setAmount` 累加結果 `Math.max(result, 0)` | 累加下界保護 |
937
- | 3 | `cuora/.../crypto_way_cash.js` | 234-237 | `isSubmittable` 加 min/max/正數檢查 | guard 範圍驗證 |
938
- | 4 | `cuora/.../crypto_way_cash.js` | 251-262 | `submitDeposit` 防禦性檢查 + 轉數字 | API 前最後防線 |
939
- | 5 | `cuora/.../crypto_way_cash.js` | 59-61 | `calculating onError → loaded` | 避免不一致狀態 |
940
- | 6 | `cuora/.../crypto_way_cash.js` | 86-89 | `fail → loaded` | 強制重新計算 |
941
- | 7 | `components/deposit/CryptoWay.vue` | 36 | 按鈕 disabled 加 calculation + amount 檢查 | UI 一致性 |
942
-
943
- ---
944
-
945
- ## 六、其他存款 Machine 同類問題檢查
946
-
947
- 以下 machine 存在相同或類似的防線缺口,建議一併排查:
948
-
949
- | Machine | 檔案 | isSubmittable 檢查範圍 | SUBMIT 有 guard | calculating onError | fail 回到 | 風險 |
950
- | ------------------- | ------------------------------ | ---------------------- | ------------------ | ------------------- | --------------- | ------ |
951
- | `crypto_way_cash` | `deposit/crypto_way_cash.js` | ❌ 只查 truthy | ✅ 有 cond | → calculated ❌ | → calculated ❌ | 高 |
952
- | `crypto_way` | `deposit/crypto_way.js` | ❌ 只查 truthy | ❌ 第一條無 cond | → loaded ✅ | → loaded ✅ | 高 |
953
- | `crypto_bank_cash` | `deposit/crypto_bank_cash.js` | 需排查 | 需排查 | 需排查 | 需排查 | 需排查 |
954
- | `manual_cash` | `deposit/manual_cash.js` | N/A | ❌ SUBMIT 無 guard | → loaded ✅ | N/A | 中 |
955
- | `direct_cash` | `deposit/direct_cash.js` | ✅ 有 isSubmittable | ✅ 有 cond | → loaded ✅ | N/A | 低 |
956
- | `loadcard_cash` | `deposit/loadcard_cash.js` | N/A | ❌ SUBMIT 無 guard | N/A | N/A | 中 |
957
- | `qrcode_cash` | `deposit/qrcode_cash.js` | 需排查 | 需排查 | 需排查 | 需排查 | 需排查 |
958
- | `virtual_bank_cash` | `deposit/virtual_bank_cash.js` | 需排查 | 需排查 | 需排查 | 需排查 | 需排查 |
959
-
960
- ---
961
-
962
- ## 七、驗證方式
963
-
964
- ### 7.1 手動測試
965
-
966
- 1. 開啟存款頁面,選擇 CryptoWay 類型的支付方式
967
- 2. 嘗試在金額輸入框輸入 `-5`、`-100` 等負數 → 應被阻止輸入
968
- 3. 嘗試貼上含負號的文字 → 應被忽略或不更新金額
969
- 4. 在瀏覽器 Console 嘗試 `vm.service.send({ type: 'INPUT_AMOUNT', data: '-5' })` → context 不應更新
970
- 5. 確認 `grandTotalEnable === 1` 時,累加結果不低於 0
971
- 6. 確認提交失敗後回到 `loaded`(按鈕 disabled),而非 `calculated`
972
- 7. 確認計算 API 失敗後回到 `loaded`,而非 `calculated`
973
- 8. 模擬網路慢(Chrome DevTools Throttling)→ 在 submitting 期間修改金額 → 確認不會產生非法提交
974
-
975
- ### 7.2 E2E 測試要點
976
-
977
- ```ts
978
- // 測試負數輸入被阻止
979
- test('should not allow negative amount input', async ({ page }) => {
980
- // ... 進入 CryptoWay 存款頁面
981
- const input = page.locator('input[type="number"]')
982
- await input.fill('-5')
983
- const value = await input.inputValue()
984
- expect(parseFloat(value) >= 0 || value === '').toBeTruthy()
985
- })
986
-
987
- // 測試提交失敗後狀態回到 loaded
988
- test('should return to loaded state after submit failure', async ({ page }) => {
989
- // ... 填入有效金額,模擬 API 失敗
990
- await page.route('**/transaction', (route) => route.abort())
991
- await page.click('button:has-text("Confirm")')
992
- // 驗證按鈕變為 disabled
993
- await expect(page.locator('button:has-text("Confirm")')).toBeDisabled()
994
- })
995
-
996
- // 測試計算 API 失敗後回到 loaded
997
- test('should return to loaded state after calculation failure', async ({ page }) => {
998
- await page.route('**/expected/result', (route) => route.abort())
999
- // ... 輸入金額觸發計算
1000
- // 驗證按鈕保持 disabled
1001
- await expect(page.locator('button:has-text("Confirm")')).toBeDisabled()
1002
- })
1003
- ```