@jetthai/cuora 1.1.457 → 1.1.460

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.
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  - **模組格式**:`"type": "module"`
6
6
  - **進入點**:`./src/index.js`
7
7
  - **無建置步驟**:無 Webpack/Rollup/TypeScript,無測試框架,無 Linter
8
- - **程式碼格式化**:Prettier(不加分號、單引號、2 空格縮排、150 字元行寬、ES5 尾隨逗號)
8
+ - **程式碼格式化**:Prettier,設定以 [`.prettierrc`](./.prettierrc) 為準
9
9
  - **Pre-commit Hook**:Husky 執行 `npm run format && git add .`
10
10
 
11
11
  ## 目錄
@@ -60,12 +60,12 @@ import { api, machine, Request, Config, util, constant, storage } from '@jetthai
60
60
 
61
61
  | 匯出名稱 | 說明 |
62
62
  | ---------- | ------------------------------------------------------- |
63
- | `api` | 11 個 API 模組的聚合物件 |
64
- | `machine` | 91 個 XState 狀態機工廠函式的聚合物件 |
63
+ | `api` | 各領域 API 模組的聚合物件(見下方 API 章節) |
64
+ | `machine` | XState 狀態機工廠函式的聚合物件(見下方 Machine 章節) |
65
65
  | `Request` | Axios 封裝類別(攔截器、Token、版本控制) |
66
66
  | `Config` | 設定類別(apiURL、clientId、appSecret 等) |
67
67
  | `util` | 工具函式(`getDeviceToken`、`getDeviceTokenWithRetry`) |
68
- | `constant` | 遊戲類型常數(16 種遊戲類型) |
68
+ | `constant` | 遊戲類型常數 |
69
69
  | `storage` | localStorage 封裝(支援 TTL/過期) |
70
70
 
71
71
  ### Config
@@ -135,7 +135,7 @@ const authMachine = machine.auth(request)
135
135
  const service = interpret(authMachine).start()
136
136
  ```
137
137
 
138
- 可用的狀態機分類:
138
+ 可用的狀態機分類(**完整清單以 `machine` 匯出物件為準**,下表僅列代表項):
139
139
 
140
140
  | 分類 | 狀態機 |
141
141
  | ---------- | ------------------------------------------------------------------------------------------------------------------------------------- |
@@ -158,21 +158,23 @@ storage.set('key', value, ttl)
158
158
  storage.get('key')
159
159
 
160
160
  // 遊戲類型常數
161
- constant.GAME_TYPE_LIST // 16 種遊戲類型陣列,每筆為 { typeId, name, gameTypeMappingId }
161
+ constant.GAME_TYPE_LIST // 遊戲類型陣列,每筆為 { typeId, name, gameTypeMappingId }
162
162
  constant.MY_FAVORITE // 'MyFavorite'
163
163
  constant.GAME_SEARCH // 'GameSearch'
164
164
  ```
165
165
 
166
166
  ## Dependencies
167
167
 
168
- | 套件 | 版本 | 角色 | 使用位置 |
169
- | ------------------ | ---------- | ---------------------------------------------------------------------------------- | ---------------------- |
170
- | `xstate` | `^4.25.0` | 狀態機核心框架 | 所有 `machine/` 檔案 |
171
- | `socket.io-client` | `^4.8.3` | WebSocket 即時通訊 | `machine/websocket.js` |
172
- | `lodash` | `^4.17.21` | 工具函式(`pickBy`、`uniqBy`、`findLastIndex`、`padStart`、`toNumber`、`isEqual`) | 分散於 12 個檔案 |
173
- | `ua-parser-js` | `^0.7.34` | 使用者代理解析(行動裝置偵測) | `machine/common.js` |
174
- | `url-join` | `^4.0.1` | URL 路徑安全組合 | `request/config.js` |
175
- | `universal-cookie` | `^4.0.4` | Cookie 操作 | `machine/common.js` |
168
+ 版本以 [`package.json`](./package.json) 為準;下表說明各依賴的角色:
169
+
170
+ | 套件 | 角色 |
171
+ | ------------------ | ---------------------------------------------- |
172
+ | `xstate` | 狀態機核心框架(**v4**,非 v5) |
173
+ | `socket.io-client` | WebSocket 即時通訊 |
174
+ | `lodash` | 少數工具函式(多數已可用原生方法替代) |
175
+ | `ua-parser-js` | 使用者代理解析(行動裝置偵測) |
176
+ | `url-join` | URL 路徑安全組合(注意前導斜線會改變組合行為) |
177
+ | `universal-cookie` | Cookie 操作 |
176
178
 
177
179
  ## Architecture
178
180
 
@@ -215,7 +217,15 @@ npm run release:dev
215
217
  npm run release:qa
216
218
  ```
217
219
 
218
- 程式碼風格由 Prettier 管理(無分號、單引號、尾隨逗號 ES5、2 空格縮排、150 字元行寬),Husky pre-commit hook 會在每次提交時自動格式化。
220
+ 程式碼風格由 Prettier 管理(設定見 [`.prettierrc`](./.prettierrc)),Husky pre-commit hook 會在每次提交時自動格式化。
221
+
222
+ ### AI 工具指引
223
+
224
+ 本專案以 [`AI_PROMPT_SOURCE.md`](./AI_PROMPT_SOURCE.md) 作為 AI 編碼工具的統一指引來源,內容涵蓋**本 README 刻意不重複的部分**:反直覺 Gotcha(前導斜線、`isMobile` 是字串、CancelToken 預設不附加)、Token 生命週期、存提款 Canonical Pattern、錯誤路由、風格收斂目標與已知技術債。
225
+
226
+ 透過 [`.claude/commands/sync-ai-prompts.md`](.claude/commands/sync-ai-prompts.md) 同步至 `CLAUDE.md`、`AGENTS.md`、`GEMINI.md`、`.github/copilot-instructions.md`。
227
+
228
+ ⚠️ 只修改 `AI_PROMPT_SOURCE.md`,上述四檔為自動產生。(本 `README.md` 不在同步範圍,可直接編輯。)
219
229
 
220
230
  ## Git 分支版本發佈流程
221
231
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.1.457",
3
+ "version": "1.1.460",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
@@ -0,0 +1,85 @@
1
+ # JT-1776243420: Third-Party Register Carry Phone / Email Payload
2
+
3
+ ## Key Changes
4
+
5
+ 1. Extended third-party redirect payload assembly to read `tp_phone`, `tp_countryCode`, and `tp_email` from storage.
6
+ 2. Preserved existing affiliate code / nickname behavior and appended new fields only when values are valid.
7
+ 3. Cleans the temporary third-party storage keys after composing the redirect query.
8
+
9
+ ---
10
+
11
+ ## Key Findings
12
+
13
+ ### Strengths
14
+
15
+ 1. The change is tightly scoped to the third-party auth redirect builder in `src/machine/auth.js:477-520`.
16
+ 2. Existing affiliate code and nickname logic remains unchanged while phone / email are additive only.
17
+ 3. Temporary keys are removed after payload composition, reducing leakage into later unrelated auth flows.
18
+
19
+ ---
20
+
21
+ ### Behavior Observed
22
+
23
+ 1. Static review confirms `phone`, `countryCode`, and `email` are appended only when storage values are not `undefined` / `null`.
24
+ 2. Channel and subchannel fallback logic stays intact after the new fields are added.
25
+ 3. No unrelated file changes were present in this repo for the review scope.
26
+
27
+ ---
28
+
29
+ ## 🔧 Change Type
30
+
31
+ - [ ] 🐛 Bug fix
32
+ - [x] ✨ New feature
33
+ - [ ] 💄 Style
34
+ - [ ] ♻️ Refactor
35
+ - [ ] ⚡ Performance
36
+ - [ ] 🔧 Chore
37
+
38
+ ---
39
+
40
+ ## 📱 Impact Scope
41
+
42
+ - Third-party register / login redirect query assembly in cuora shared auth machine.
43
+ - Downstream PWA clients that store `tp_phone`, `tp_countryCode`, and `tp_email` before `LOGIN_3PARTY`.
44
+
45
+ ---
46
+
47
+ ## Test Completion Status
48
+
49
+ | Item | Validation Tested | Status |
50
+ | -------------------------- | --------------------------------------------------------------------- | ------- |
51
+ | Diff hygiene | `git diff --check` in `cuora-module` | PASS |
52
+ | Shared auth payload review | Reviewed `src/machine/auth.js:477-520` against ticket intent | PASS |
53
+ | Runtime redirect execution | Not run in this repo directly; validated through client repos instead | NOT RUN |
54
+
55
+ ---
56
+
57
+ ## 📋 Spec Validation (Aligned with review-playbook)
58
+
59
+ | Spec Item | Evidence (File/Line/Result) | Status |
60
+ | ------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | ------ |
61
+ | Third-party flow can carry phone when client stored it | `src/machine/auth.js:479-520` reads `tp_phone` / `tp_countryCode` and appends them to `referralObj` | PASS |
62
+ | Third-party flow can carry email when client stored it | `src/machine/auth.js:481-520` reads `tp_email` and appends it to `referralObj` | PASS |
63
+ | Affiliate code and nickname keep original logic | `src/machine/auth.js:477-500` keeps `ac` / `nick_name` handling unchanged | PASS |
64
+ | Temporary third-party data does not leak into later unrelated flows | `src/machine/auth.js:518-520` removes the temporary storage keys after composing the redirect URL | PASS |
65
+
66
+ ---
67
+
68
+ ## 📋 Standards Checklist (Summary)
69
+
70
+ | Category | Result | Notes |
71
+ | ---------------------- | ------- | --------------------------------------------------------------------------- |
72
+ | Memory Safety | PASS | Simple storage reads and object assembly only. |
73
+ | Rendering Performance | PASS | No rendering code touched. |
74
+ | Network Requests | PASS | Existing redirect flow only; no extra requests added. |
75
+ | Bundle Optimization | PASS | No new imports or heavy logic added. |
76
+ | Code Quality | PASS | Scope is narrow and branch contains only the required file change. |
77
+ | Vue / Nuxt Standards | NOT RUN | Shared module; not a Vue / Nuxt surface. |
78
+ | SSR Security Standards | PASS | Query parameters are assembled from existing client-side storage path only. |
79
+ | Project Conventions | PASS | Matches existing storage-guard pattern used for affiliate / nickname. |
80
+
81
+ ## Conclusion
82
+
83
+ This repo’s shared auth-machine change matches the ticket intent and is internally consistent. Runtime behavior was not executed in `cuora-module` directly, but both client repos now pass the new storage keys into this shared payload path.
84
+
85
+ **Overall Result:** PASS (PARTIAL)
@@ -1,6 +1,5 @@
1
1
  import { assign, createMachine } from 'xstate'
2
2
  import payment from '@jetthai/cuora/src/api/payment.js'
3
- import { max } from '../../util/index.js'
4
3
 
5
4
  export default function (request, context) {
6
5
  const { paymentDetail = [], promotion, selectedAmount, siteConfig } = context || {}
@@ -98,6 +97,7 @@ export default function (request, context) {
98
97
  target: '.debouncing',
99
98
  actions: 'setPromotion',
100
99
  internal: false,
100
+ cond: 'isPromotionChanged',
101
101
  },
102
102
  SET_CRYPTO: {
103
103
  target: '.debouncing',
@@ -164,7 +164,6 @@ export default function (request, context) {
164
164
  selectedCrypto: defaultCrypto[0],
165
165
  selectedAddress: defaultAddresses[0],
166
166
  options: cryptoBank.optional,
167
- selectedAmount: max(context.promotion?.minimumAmount, defaultCrypto[0]?.minimum || cryptoBank?.minimum, context.selectedAmount, 0),
168
167
  }
169
168
  }),
170
169
  setCrypto: assign((context, event) => {
@@ -183,7 +182,6 @@ export default function (request, context) {
183
182
  addresses,
184
183
  selectedCrypto: selectedCrypto,
185
184
  selectedAddress: addresses[0],
186
- selectedAmount: max(context.promotion?.minimumAmount, selectedCrypto?.minimum || cryptoBank?.minimum, 0),
187
185
  calculation: null,
188
186
  options: cryptoBank.optional,
189
187
  }
@@ -231,11 +229,9 @@ export default function (request, context) {
231
229
  }
232
230
  }),
233
231
  setPromotion: assign((context, event) => {
234
- const { cryptoBank, selectedAmount } = context
235
232
  const promotion = event.data
236
233
  return {
237
234
  promotion,
238
- selectedAmount: max(promotion.minimumAmount, cryptoBank.minimum, selectedAmount, 0),
239
235
  calculation: null,
240
236
  }
241
237
  }),
@@ -251,6 +247,9 @@ export default function (request, context) {
251
247
  }),
252
248
  },
253
249
  guards: {
250
+ isPromotionChanged: (context, event) => {
251
+ return event.data?.promotionsNo !== context.promotion?.promotionsNo
252
+ },
254
253
  isCalculable: (context, event) => {
255
254
  const { selectedCrypto, selectedAddress, selectedAmount } = context
256
255
  return (
@@ -1,6 +1,5 @@
1
1
  import { assign, createMachine } from 'xstate'
2
2
  import payment from '@jetthai/cuora/src/api/payment.js'
3
- import { max } from '../../util/index.js'
4
3
 
5
4
  export default function (request, context) {
6
5
  const { paymentDetail = [], promotion, selectedAmount } = context || {}
@@ -104,6 +103,7 @@ export default function (request, context) {
104
103
  target: '.debouncing',
105
104
  actions: 'setPromotion',
106
105
  internal: false,
106
+ cond: 'isPromotionChanged',
107
107
  },
108
108
  SET_CRYPTO: {
109
109
  target: '.debouncing',
@@ -153,7 +153,6 @@ export default function (request, context) {
153
153
  cryptos,
154
154
  selectedCrypto: defaultCrypto,
155
155
  options: defaultCrypto?.optional || [],
156
- selectedAmount: max(context.promotion?.minimumAmount, defaultCrypto?.minimum, context.selectedAmount, 0),
157
156
  }
158
157
  }),
159
158
  setCrypto: assign((context, event) => {
@@ -161,7 +160,6 @@ export default function (request, context) {
161
160
  const selectedCrypto = cryptos.find((crypto) => crypto.label === event.data.label)
162
161
  return {
163
162
  selectedCrypto: selectedCrypto,
164
- selectedAmount: max(context.promotion?.minimumAmount, selectedCrypto?.minimum, 0),
165
163
  calculation: null,
166
164
  options: selectedCrypto?.optional || [],
167
165
  }
@@ -210,11 +208,9 @@ export default function (request, context) {
210
208
  }
211
209
  }),
212
210
  setPromotion: assign((context, event) => {
213
- const { selectedCrypto, selectedAmount } = context
214
211
  const promotion = event.data
215
212
  return {
216
213
  promotion,
217
- selectedAmount: max(promotion.minimumAmount, selectedCrypto.minimum, selectedAmount, 0),
218
214
  calculation: null,
219
215
  }
220
216
  }),
@@ -231,6 +227,9 @@ export default function (request, context) {
231
227
  }),
232
228
  },
233
229
  guards: {
230
+ isPromotionChanged: (context, event) => {
231
+ return event.data?.promotionsNo !== context.promotion?.promotionsNo
232
+ },
234
233
  isCalculable: (context, event) => {
235
234
  const { selectedCrypto, selectedAmount } = context
236
235
  return selectedCrypto && selectedAmount && selectedCrypto.minimum <= +selectedAmount && +selectedAmount <= selectedCrypto.maximum
@@ -1,6 +1,5 @@
1
1
  import { assign, createMachine } from 'xstate'
2
2
  import payment from '../../api/payment.js'
3
- import { max } from '../../util/index.js'
4
3
 
5
4
  export default function (request, context) {
6
5
  const { paymentDetail = [], promotion, selectedAmount } = context || {}
@@ -88,6 +87,7 @@ export default function (request, context) {
88
87
  target: '.loading',
89
88
  actions: 'setPromotion',
90
89
  internal: false,
90
+ cond: 'isPromotionChanged',
91
91
  },
92
92
  SELECT_DIRECT: {
93
93
  target: '.loading',
@@ -108,13 +108,12 @@ export default function (request, context) {
108
108
  {
109
109
  actions: {
110
110
  setInitData: assign((context, event) => {
111
- const { paymentDetail, selectedAmount, promotion } = context
111
+ const { paymentDetail } = context
112
112
  const directs = paymentDetail.filter((element) => element.category === context.currentCategory && element.transferType === 'deposit')
113
113
  const selectedDirect = context.selectedDirect || directs[0]
114
114
  return {
115
115
  directs,
116
116
  selectedDirect,
117
- selectedAmount: max(promotion?.minimumAmount, selectedDirect?.minimum, selectedAmount, 0),
118
117
  }
119
118
  }),
120
119
  setBanks: assign((context, event) => {
@@ -131,6 +130,7 @@ export default function (request, context) {
131
130
  setDirect: assign((context, event) => {
132
131
  return {
133
132
  selectedDirect: event.data,
133
+ calculation: null,
134
134
  }
135
135
  }),
136
136
  setUserBank: assign((context, event) => {
@@ -169,10 +169,14 @@ export default function (request, context) {
169
169
  setPromotion: assign((context, event) => {
170
170
  return {
171
171
  promotion: event.data,
172
+ calculation: null,
172
173
  }
173
174
  }),
174
175
  },
175
176
  guards: {
177
+ isPromotionChanged: (context, event) => {
178
+ return event.data?.promotionsNo !== context.promotion?.promotionsNo
179
+ },
176
180
  isCalculable: (context, event) => {
177
181
  const {
178
182
  selectedAmount,
@@ -1,6 +1,5 @@
1
1
  import { assign, createMachine } from 'xstate'
2
2
  import payment from '../../api/payment.js'
3
- import { max } from '../../util'
4
3
 
5
4
  export default function (request, context) {
6
5
  const { paymentDetail = [], promotion, selectedAmount } = context || {}
@@ -96,6 +95,7 @@ export default function (request, context) {
96
95
  target: '.debouncing',
97
96
  actions: 'setPromotion',
98
97
  internal: false,
98
+ cond: 'isPromotionChanged',
99
99
  },
100
100
  SELECT_LOADCARD: {
101
101
  target: '.debouncing',
@@ -112,7 +112,7 @@ export default function (request, context) {
112
112
  {
113
113
  actions: {
114
114
  setInitData: assign((context, event) => {
115
- const { paymentDetail, selectedAmount, promotion } = context
115
+ const { paymentDetail } = context
116
116
  const loadcards = paymentDetail.filter((element) => element.category === context.currentCategory && element.transferType === 'deposit')
117
117
  const selectedLoadcard = loadcards[0]
118
118
  return {
@@ -120,11 +120,9 @@ export default function (request, context) {
120
120
  loadcards,
121
121
  selectedLoadcard,
122
122
  options: selectedLoadcard?.optional,
123
- selectedAmount: max(promotion?.minimumAmount, selectedLoadcard?.minimum, selectedAmount, 0),
124
123
  }
125
124
  }),
126
125
  setPromotion: assign((context, event) => {
127
- const { selectedAmount } = context
128
126
  const promotion = event.data
129
127
  const loadcards = context.loadcards
130
128
  const selectedLoadcard = loadcards[0]
@@ -133,17 +131,14 @@ export default function (request, context) {
133
131
  loadcards,
134
132
  selectedLoadcard,
135
133
  options: selectedLoadcard?.optional,
136
- selectedAmount: max(promotion.minimumAmount, selectedLoadcard?.minimum, selectedAmount, 0),
137
134
  calculation: null,
138
135
  }
139
136
  }),
140
137
  setLoadcard: assign((context, event) => {
141
- const { promotion, selectedAmount } = context
142
138
  const selectedLoadcard = event.data
143
139
  return {
144
140
  selectedLoadcard,
145
141
  options: selectedLoadcard.optional,
146
- selectedAmount: max(promotion.minimumAmount, selectedAmount, 0),
147
142
  calculation: null,
148
143
  }
149
144
  }),
@@ -184,7 +179,11 @@ export default function (request, context) {
184
179
  }
185
180
  }),
186
181
  },
187
- guards: {},
182
+ guards: {
183
+ isPromotionChanged: (context, event) => {
184
+ return event.data?.promotionsNo !== context.promotion?.promotionsNo
185
+ },
186
+ },
188
187
  services: {
189
188
  fetchCalculation: async (context, event) => {
190
189
  const { selectedLoadcard, selectedAmount, promotion } = context
@@ -1,6 +1,5 @@
1
1
  import { assign, createMachine } from 'xstate'
2
2
  import payment from '../../api/payment.js'
3
- import { max } from '../../util/index.js'
4
3
 
5
4
  export default function (request, context) {
6
5
  const { appSecret } = request.config
@@ -134,6 +133,7 @@ export default function (request, context) {
134
133
  target: 'debouncing',
135
134
  actions: 'setPromotion',
136
135
  internal: false,
136
+ cond: 'isPromotionChanged',
137
137
  },
138
138
  INPUT_AMOUNT: {
139
139
  target: 'debouncing',
@@ -141,7 +141,9 @@ export default function (request, context) {
141
141
  internal: false,
142
142
  },
143
143
  SELECT_HOUSE_BANK: {
144
+ target: 'debouncing',
144
145
  actions: 'setHouseBank',
146
+ internal: false,
145
147
  },
146
148
  },
147
149
  },
@@ -180,7 +182,6 @@ export default function (request, context) {
180
182
  method: currentPayment.method,
181
183
  processing,
182
184
  houseBanks,
183
- selectedAmount: max(promotion?.minimumAmount, currentPayment?.minimum, selectedAmount, 0),
184
185
  selectedHouseBank: houseBanks[0],
185
186
  userBanks,
186
187
  selectedUserBank: userBanks[0],
@@ -194,6 +195,7 @@ export default function (request, context) {
194
195
  setHouseBank: assign((context, event) => {
195
196
  return {
196
197
  selectedHouseBank: event.data,
198
+ calculation: null,
197
199
  }
198
200
  }),
199
201
  inputAmount: assign((context, event) => {
@@ -276,10 +278,14 @@ export default function (request, context) {
276
278
  setPromotion: assign((context, event) => {
277
279
  return {
278
280
  promotion: event.data,
281
+ calculation: null,
279
282
  }
280
283
  }),
281
284
  },
282
285
  guards: {
286
+ isPromotionChanged: (context, event) => {
287
+ return event.data?.promotionsNo !== context.promotion?.promotionsNo
288
+ },
283
289
  isCalculable: (context, event) => {
284
290
  const {
285
291
  selectedAmount,
@@ -1,6 +1,5 @@
1
1
  import { assign, createMachine } from 'xstate'
2
2
  import payment from '../../api/payment.js'
3
- import { max } from '../../util'
4
3
 
5
4
  export default function (request, context) {
6
5
  const { paymentDetail = [], promotion, selectedAmount } = context || {}
@@ -102,6 +101,7 @@ export default function (request, context) {
102
101
  target: '.debouncing',
103
102
  actions: 'setPromotion',
104
103
  internal: false,
104
+ cond: 'isPromotionChanged',
105
105
  },
106
106
  SELECT_QRCODE: {
107
107
  target: '.debouncing',
@@ -123,7 +123,7 @@ export default function (request, context) {
123
123
  {
124
124
  actions: {
125
125
  setInitData: assign((context, event) => {
126
- const { paymentDetail, selectedAmount, promotion } = context
126
+ const { paymentDetail } = context
127
127
  const qrcodes = paymentDetail.filter((element) => element.category === context.currentCategory && element.transferType === 'deposit')
128
128
  const selectedQrcode = qrcodes[0]
129
129
  return {
@@ -131,11 +131,9 @@ export default function (request, context) {
131
131
  qrcodes,
132
132
  selectedQrcode,
133
133
  options: selectedQrcode?.optional,
134
- selectedAmount: max(promotion?.minimumAmount, selectedQrcode?.minimum, selectedAmount, 0),
135
134
  }
136
135
  }),
137
136
  setPromotion: assign((context, event) => {
138
- const { selectedAmount } = context
139
137
  const promotion = event.data
140
138
  const qrcodes = context.qrcodes
141
139
  const selectedQrcode = qrcodes[0]
@@ -144,17 +142,14 @@ export default function (request, context) {
144
142
  qrcodes,
145
143
  selectedQrcode,
146
144
  options: selectedQrcode?.optional,
147
- selectedAmount: max(promotion.minimumAmount, selectedQrcode?.minimum, selectedAmount, 0),
148
145
  calculation: null,
149
146
  }
150
147
  }),
151
148
  setQrcode: assign((context, event) => {
152
- const { promotion, selectedAmount } = context
153
149
  const selectedQrcode = event.data
154
150
  return {
155
151
  selectedQrcode,
156
152
  options: selectedQrcode.optional,
157
- selectedAmount: max(promotion.minimumAmount, selectedAmount, 0),
158
153
  calculation: null,
159
154
  }
160
155
  }),
@@ -194,6 +189,9 @@ export default function (request, context) {
194
189
  }),
195
190
  },
196
191
  guards: {
192
+ isPromotionChanged: (context, event) => {
193
+ return event.data?.promotionsNo !== context.promotion?.promotionsNo
194
+ },
197
195
  hasQrcodeMethods: (context, event) => {
198
196
  return context.paymentDetail?.filter((element) => element.category === context.currentCategory).length > 0
199
197
  },
@@ -1,6 +1,5 @@
1
1
  import { assign, createMachine } from 'xstate'
2
2
  import payment from '@jetthai/cuora/src/api/payment.js'
3
- import { max } from '@jetthai/cuora/src/util/index.js'
4
3
 
5
4
  export default function (request, context) {
6
5
  const { appSecret } = request.config
@@ -99,6 +98,7 @@ export default function (request, context) {
99
98
  target: 'debouncing',
100
99
  actions: 'setPromotion',
101
100
  internal: false,
101
+ cond: 'isPromotionChanged',
102
102
  },
103
103
  INPUT_AMOUNT: {
104
104
  target: 'debouncing',
@@ -120,7 +120,6 @@ export default function (request, context) {
120
120
  currentPayment,
121
121
  method: currentPayment.method,
122
122
  processing,
123
- selectedAmount: max(promotion?.minimumAmount, currentPayment?.minimum, selectedAmount, 0),
124
123
  virtualBanks,
125
124
  }
126
125
  }),
@@ -158,10 +157,14 @@ export default function (request, context) {
158
157
  setPromotion: assign((context, event) => {
159
158
  return {
160
159
  promotion: event.data,
160
+ calculation: null,
161
161
  }
162
162
  }),
163
163
  },
164
164
  guards: {
165
+ isPromotionChanged: (context, event) => {
166
+ return event.data?.promotionsNo !== context.promotion?.promotionsNo
167
+ },
165
168
  isCalculable: (context, event) => {
166
169
  const {
167
170
  selectedAmount,