@jetthai/cuora 1.1.454 → 1.1.455-dev.1
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/.claude/commands/auto-git-flow.md +5 -12
- package/.claude/commands/commit-push.md +15 -4
- package/.claude/commands/sync-ai-prompts.md +88 -1
- package/.claude/settings.local.json +3 -1
- package/.github/copilot-instructions.md +553 -395
- package/.husky/post-checkout +3 -3
- package/.husky/pre-push +1 -1
- package/.prettierignore +2 -1
- package/AGENTS.md +553 -395
- package/AI_PROMPT_SOURCE.md +664 -128
- package/CHANGELOG.md +317 -22
- package/CLAUDE.md +553 -395
- package/GEMINI.md +553 -395
- package/README.md +40 -137
- package/package.json +1 -1
- package/scripts/auto-version.js +1 -0
- package/src/api/user.js +12 -0
- package/src/index.js +2 -2
- package/src/machine/auth.js +15 -2
- package/src/machine/common.js +11 -21
- package/src/machine/deposit/crypto_bank_cash.js +4 -5
- package/src/machine/deposit/crypto_way_cash.js +4 -5
- package/src/machine/deposit/direct_cash.js +7 -3
- package/src/machine/deposit/loadcard_cash.js +7 -8
- package/src/machine/deposit/manual_cash.js +8 -2
- package/src/machine/deposit/qrcode_cash.js +5 -7
- package/src/machine/deposit/virtual_bank_cash.js +5 -2
- package/src/machine/user_sign_up.js +16 -3
- package/src/request/request.js +7 -3
- package/src/util/index.js +2 -1
- package/src/util/paramStore.js +139 -0
package/README.md
CHANGED
|
@@ -1,34 +1,8 @@
|
|
|
1
1
|
# @jetthai/cuora
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
- **進入點**:`./src/index.js`
|
|
7
|
-
- **無建置步驟**:無 Webpack/Rollup/TypeScript,無測試框架,無 Linter
|
|
8
|
-
- **程式碼格式化**:Prettier(不加分號、單引號、2 空格縮排、150 字元行寬、ES5 尾隨逗號)
|
|
9
|
-
- **Pre-commit Hook**:Husky 執行 `npm run format && git add .`
|
|
10
|
-
|
|
11
|
-
## 目錄
|
|
12
|
-
|
|
13
|
-
- [Installation](#installation)
|
|
14
|
-
- [Setup](#setup)
|
|
15
|
-
- [Usage](#usage)
|
|
16
|
-
- [模組匯出](#模組匯出)
|
|
17
|
-
- [Config](#config)
|
|
18
|
-
- [Request](#request)
|
|
19
|
-
- [API](#api)
|
|
20
|
-
- [Machine](#machine)
|
|
21
|
-
- [Utilities](#utilities)
|
|
22
|
-
- [Dependencies](#dependencies)
|
|
23
|
-
- [Architecture](#architecture)
|
|
24
|
-
- [Development](#development)
|
|
25
|
-
- [Git 分支版本發佈流程](#git-分支版本發佈流程)
|
|
26
|
-
- [分支策略](#分支策略)
|
|
27
|
-
- [腳本權責分離](#腳本權責分離)
|
|
28
|
-
- [dev / qa 分支自動版本流程](#dev--qa-分支自動版本流程)
|
|
29
|
-
- [版號計算規則](#版號計算規則)
|
|
30
|
-
- [Husky Hooks 總覽](#husky-hooks-總覽)
|
|
31
|
-
- [License](#license)
|
|
3
|
+
ESM JavaScript 函式庫,透過 XState v4 狀態機整合 API 呼叫與業務邏輯,服務於線上遊戲平台。處理認證、支付(存款/提款)、遊戲管理、活動及即時 WebSocket 通訊。
|
|
4
|
+
|
|
5
|
+
設計用於 Nuxt.js 客戶端應用程式(`ssr: false`)。
|
|
32
6
|
|
|
33
7
|
## Installation
|
|
34
8
|
|
|
@@ -56,18 +30,6 @@ export default {
|
|
|
56
30
|
import { api, machine, Request, Config, util, constant, storage } from '@jetthai/cuora'
|
|
57
31
|
```
|
|
58
32
|
|
|
59
|
-
### 模組匯出
|
|
60
|
-
|
|
61
|
-
| 匯出名稱 | 說明 |
|
|
62
|
-
| ---------- | ------------------------------------------------------- |
|
|
63
|
-
| `api` | 11 個 API 模組的聚合物件 |
|
|
64
|
-
| `machine` | 91 個 XState 狀態機工廠函式的聚合物件 |
|
|
65
|
-
| `Request` | Axios 封裝類別(攔截器、Token、版本控制) |
|
|
66
|
-
| `Config` | 設定類別(apiURL、clientId、appSecret 等) |
|
|
67
|
-
| `util` | 工具函式(`getDeviceToken`、`getDeviceTokenWithRetry`) |
|
|
68
|
-
| `constant` | 遊戲類型常數(16 種遊戲類型) |
|
|
69
|
-
| `storage` | localStorage 封裝(支援 TTL/過期) |
|
|
70
|
-
|
|
71
33
|
### Config
|
|
72
34
|
|
|
73
35
|
初始化 API 設定:
|
|
@@ -158,35 +120,36 @@ storage.set('key', value, ttl)
|
|
|
158
120
|
storage.get('key')
|
|
159
121
|
|
|
160
122
|
// 遊戲類型常數
|
|
161
|
-
constant.
|
|
162
|
-
constant.
|
|
163
|
-
constant.
|
|
123
|
+
constant.SLOT
|
|
124
|
+
constant.FISH
|
|
125
|
+
constant.LIVE
|
|
126
|
+
constant.SPORT
|
|
164
127
|
```
|
|
165
128
|
|
|
166
|
-
## Dependencies
|
|
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` |
|
|
176
|
-
|
|
177
129
|
## Architecture
|
|
178
130
|
|
|
179
131
|
```
|
|
180
132
|
src/
|
|
181
133
|
├── index.js # 進入點
|
|
182
134
|
├── api/ # API 請求描述物件
|
|
135
|
+
│ ├── auth.js
|
|
136
|
+
│ ├── account.js
|
|
137
|
+
│ ├── activity.js
|
|
138
|
+
│ ├── common.js
|
|
139
|
+
│ ├── form.js
|
|
140
|
+
│ ├── game.js
|
|
141
|
+
│ ├── mailbox.js
|
|
142
|
+
│ ├── otp.js
|
|
143
|
+
│ ├── payment.js
|
|
144
|
+
│ ├── ranking.js
|
|
145
|
+
│ └── user.js
|
|
183
146
|
├── machine/ # XState v4 狀態機
|
|
184
147
|
│ ├── auth.js # 登入/註冊流程
|
|
185
148
|
│ ├── common.js # 網站設定、UA、聯盟行銷
|
|
186
149
|
│ ├── websocket.js # Socket.IO 即時通訊
|
|
187
|
-
│ ├── deposit/ # 存款狀態機
|
|
188
|
-
│ ├── withdraw/ # 提款狀態機
|
|
189
|
-
│ └── activity/ # 活動狀態機
|
|
150
|
+
│ ├── deposit/ # 存款狀態機 (22+)
|
|
151
|
+
│ ├── withdraw/ # 提款狀態機 (4)
|
|
152
|
+
│ └── activity/ # 活動狀態機 (24+)
|
|
190
153
|
├── request/
|
|
191
154
|
│ ├── config.js # Config 設定類別
|
|
192
155
|
│ └── request.js # Axios 封裝 + 攔截器
|
|
@@ -217,92 +180,32 @@ npm run release:qa
|
|
|
217
180
|
|
|
218
181
|
程式碼風格由 Prettier 管理(無分號、單引號、尾隨逗號 ES5、2 空格縮排、150 字元行寬),Husky pre-commit hook 會在每次提交時自動格式化。
|
|
219
182
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
### 分支策略
|
|
223
|
-
|
|
224
|
-
| 分支 | 用途 | 版本格式 |
|
|
225
|
-
| -------- | -------- | -------------------------- |
|
|
226
|
-
| `master` | 正式發佈 | `x.y.z`(如 `1.1.430`) |
|
|
227
|
-
| `dev` | 開發測試 | `{master_version}-dev.{N}` |
|
|
228
|
-
| `qa` | QA 測試 | `{master_version}-qa.{N}` |
|
|
229
|
-
|
|
230
|
-
### 腳本權責分離
|
|
231
|
-
|
|
232
|
-
dev/qa 分支的自動版本發佈由三個腳本各司其職:
|
|
233
|
-
|
|
234
|
-
| 腳本 | 職責 | 說明 |
|
|
235
|
-
| ------------------------------------ | --------------------- | ----------------------------------------------------------------------------------------------------- |
|
|
236
|
-
| `scripts/auto-version.sh` | **流程控制**(Shell) | pre-push hook 入口。依序呼叫版號計算 → standard-version → push + publish,最後 `exit 1` 中止原始 push |
|
|
237
|
-
| `scripts/auto-version.js` | **版號計算**(ESM) | 純計算邏輯。讀取 master 版本、比對當前版本與 git log 歷史(historyMax 防倒退),stdout 輸出新版號 |
|
|
238
|
-
| `scripts/branch-auto-npm-publish.js` | **推送與發佈**(ESM) | 執行 `git push --follow-tags` 推送至遠端,再 `npm publish --tag {branch}` 發佈至 npm registry |
|
|
183
|
+
### dev / qa 分支版本發佈
|
|
239
184
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
當開發者在 `dev` 或 `qa` 分支執行 `git push` 時,Husky `pre-push` hook 觸發以下流程:
|
|
185
|
+
在 `dev` 或 `qa` 分支執行 `git push` 時,Husky `pre-push` hook 會自動觸發三階段流程:
|
|
243
186
|
|
|
244
187
|
```
|
|
245
|
-
git push
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
│ └─ sh scripts/auto-version.sh "$1" # 流程入口(傳入 remote name)
|
|
250
|
-
│
|
|
251
|
-
├─ auto-version.sh 流程控制
|
|
252
|
-
│ │
|
|
253
|
-
│ ├─ ① node scripts/auto-version.js ← 版號計算
|
|
254
|
-
│ │ ├─ git show origin/master:package.json → 取得 master version(如 1.1.430)
|
|
255
|
-
│ │ │ └─ fallback: git show master:package.json
|
|
256
|
-
│ │ ├─ 讀取當前 package.json version
|
|
257
|
-
│ │ ├─ 從 currentVersion 推算下一編號
|
|
258
|
-
│ │ ├─ 掃描 git log 最近 50 筆 commit(historyMax 防倒退)
|
|
259
|
-
│ │ └─ stdout 輸出新版號(如 1.1.430-dev.3)
|
|
260
|
-
│ │ └─ 若版號無變更 → 靜默退出,auto-version.sh 跳過後續步驟
|
|
261
|
-
│ │
|
|
262
|
-
│ ├─ ② npx standard-version --release-as {version}
|
|
263
|
-
│ │ └─ 更新 CHANGELOG.md + 建立 commit + 建立 git tag
|
|
264
|
-
│ │
|
|
265
|
-
│ ├─ ③ node scripts/branch-auto-npm-publish.js ← 推送與發佈
|
|
266
|
-
│ │ ├─ git push --follow-tags origin dev
|
|
267
|
-
│ │ └─ npm publish --tag dev
|
|
268
|
-
│ │
|
|
269
|
-
│ └─ exit 1(中止原始 push,因為 script 已完成推送)
|
|
270
|
-
│
|
|
271
|
-
└─ 終端顯示 push 失敗,但實際發佈已成功(以 Released x.x.x 訊息為準)
|
|
188
|
+
git push → auto-version.sh(流程控制)
|
|
189
|
+
├─ ① auto-version.js → 計算版號(含 historyMax 防倒退)
|
|
190
|
+
├─ ② standard-version → 更新 CHANGELOG + commit + tag
|
|
191
|
+
└─ ③ branch-auto-npm-publish.js → git push + npm publish
|
|
272
192
|
```
|
|
273
193
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
**基本遞增**:
|
|
277
|
-
|
|
278
|
-
- master 為 `1.1.430` → dev 第一次 push:`1.1.430-dev.0`
|
|
279
|
-
- 再次 push:`1.1.430-dev.1`、`1.1.430-dev.2`、...
|
|
280
|
-
- master 升版至 `1.1.431` → dev 重置為 `1.1.431-dev.0`
|
|
281
|
-
- qa 分支同理:`1.1.430-qa.0`、`1.1.430-qa.1`、...
|
|
194
|
+
**腳本權責:**
|
|
282
195
|
|
|
283
|
-
|
|
196
|
+
| 腳本 | 職責 | 說明 |
|
|
197
|
+
| ------------------------------------ | ---------- | --------------------------------------------------------- |
|
|
198
|
+
| `scripts/auto-version.sh` | 流程控制 | pre-push 入口,串接版號計算 → standard-version → 發佈 |
|
|
199
|
+
| `scripts/auto-version.js` | 版號計算 | 讀取 master 版本 + 掃描 git log 防倒退,stdout 輸出新版號 |
|
|
200
|
+
| `scripts/branch-auto-npm-publish.js` | 推送與發佈 | `git push --follow-tags` + `npm publish --tag {branch}` |
|
|
284
201
|
|
|
285
|
-
|
|
202
|
+
**版本號規則:**
|
|
286
203
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
### Husky Hooks 總覽
|
|
295
|
-
|
|
296
|
-
| Hook | 檔案 | 說明 |
|
|
297
|
-
| --------------- | ---------------------- | ---------------------------------------------------- |
|
|
298
|
-
| `pre-commit` | `.husky/pre-commit` | 執行 `npm run format && git add .`(Prettier) |
|
|
299
|
-
| `pre-push` | `.husky/pre-push` | dev/qa 分支自動版本發佈(`scripts/auto-version.sh`) |
|
|
300
|
-
| `post-checkout` | `.husky/post-checkout` | dev/qa/hotfix 分支自動 `git pull --rebase` |
|
|
301
|
-
| `post-commit` | `.husky/post-commit` | (保留,目前無額外操作) |
|
|
302
|
-
| `post-merge` | `.husky/post-merge` | (保留,目前無額外操作) |
|
|
204
|
+
| 情境 | 範例 |
|
|
205
|
+
| ------------------------------------ | ------------------------------------- |
|
|
206
|
+
| master 為 `1.1.425`,dev 第一次 push | `1.1.425-dev.0` |
|
|
207
|
+
| dev 再次 push | `1.1.425-dev.1`、`1.1.425-dev.2`、... |
|
|
208
|
+
| master 升版至 `1.1.426` 後 | dev 重置為 `1.1.426-dev.0` |
|
|
209
|
+
| qa 分支 | `1.1.425-qa.0`、`1.1.425-qa.1`、... |
|
|
303
210
|
|
|
304
211
|
> **注意**:`pre-push` hook 完成推送後會以 `exit 1` 中止原始 push(因為已推送完成),終端會顯示 push 失敗訊息,但實際發佈已成功。以 `Released x.x.x on {branch}` 訊息為準。
|
|
305
|
-
|
|
306
|
-
## License
|
|
307
|
-
|
|
308
|
-
ISC
|
package/package.json
CHANGED
package/scripts/auto-version.js
CHANGED
package/src/api/user.js
CHANGED
|
@@ -66,4 +66,16 @@ export default {
|
|
|
66
66
|
getUserPhotoList: () => ({ url: 'getAllAvatar', method: 'get' }),
|
|
67
67
|
updateUserPhoto: (data) => ({ url: 'updateUserAvatar', method: 'post', params: data }),
|
|
68
68
|
getUserProfile: () => ({ url: 'user-info/get-profile', method: 'get' }),
|
|
69
|
+
subscribeStatus: ({ fingerprintId, domain }) => ({
|
|
70
|
+
url: 'notification-subscription/status',
|
|
71
|
+
method: 'post',
|
|
72
|
+
params: { fingerprintId, domain },
|
|
73
|
+
isPublic: true,
|
|
74
|
+
}),
|
|
75
|
+
subscribeUpdate: ({ fingerprintId, domain, action = 'subscribe' }) => ({
|
|
76
|
+
url: 'notification-subscription/update',
|
|
77
|
+
method: 'post',
|
|
78
|
+
params: { fingerprintId, domain, action },
|
|
79
|
+
isPublic: true,
|
|
80
|
+
}),
|
|
69
81
|
}
|
package/src/index.js
CHANGED
|
@@ -2,6 +2,6 @@ import api from './api/index.js'
|
|
|
2
2
|
import machine from './machine/index.js'
|
|
3
3
|
import Request from './request/request.js'
|
|
4
4
|
import Config from './request/config.js'
|
|
5
|
-
import util, { constant, storage } from './util/index.js'
|
|
5
|
+
import util, { constant, storage, paramStore } from './util/index.js'
|
|
6
6
|
|
|
7
|
-
export { api, machine, Request, Config, util, constant, storage }
|
|
7
|
+
export { api, machine, Request, Config, util, constant, storage, paramStore }
|
package/src/machine/auth.js
CHANGED
|
@@ -5,6 +5,7 @@ import user from '../api/user.js'
|
|
|
5
5
|
import storage from '../util/storage.js'
|
|
6
6
|
import common from '../api/common.js'
|
|
7
7
|
import pickBy from 'lodash/pickBy.js'
|
|
8
|
+
import { readParamFromLocation, writeParam, normalize, AC_KEYS, FC_KEYS } from '../util/paramStore.js'
|
|
8
9
|
|
|
9
10
|
export default function (request) {
|
|
10
11
|
const { appSecret, clientId, sentry } = request.config
|
|
@@ -469,7 +470,18 @@ export default function (request) {
|
|
|
469
470
|
|
|
470
471
|
const dt = deviceTokenEnable ? await request.config.getDt?.() : undefined
|
|
471
472
|
|
|
472
|
-
|
|
473
|
+
// 宿主若明確帶了 ac(使用者在補資料頁/代理碼彈窗按下確認,含刻意留白)以它為準:
|
|
474
|
+
// 網址層仍留著進站時的 ?ac=,不讓步的話使用者剛清掉的值會被網址撿回來又寫回兩個媒介
|
|
475
|
+
const hasExplicitAc = !!event.data && Object.prototype.hasOwnProperty.call(event.data, 'ac')
|
|
476
|
+
const acRead = readParamFromLocation(AC_KEYS)
|
|
477
|
+
const affiliateCode = hasExplicitAc ? normalize(event.data.ac) : acRead.value
|
|
478
|
+
// 尾綴 undefined 是刻意的:全空時維持原本序列化成 fc=undefined 的行為,不改為 fc=null
|
|
479
|
+
const friendCode = fc || readParamFromLocation(FC_KEYS).value || undefined
|
|
480
|
+
|
|
481
|
+
// 本段結尾以 window.location.href 離站,離站後 SPA 記憶體全丟;導頁前先落地雙寫
|
|
482
|
+
writeParam('ac', affiliateCode, { sentry })
|
|
483
|
+
writeParam('fc', friendCode, { sentry })
|
|
484
|
+
|
|
473
485
|
const nickname = storage.get('nk')
|
|
474
486
|
const phone = storage.get('tp_phone')
|
|
475
487
|
const countryCode = storage.get('tp_countryCode')
|
|
@@ -478,6 +490,7 @@ export default function (request) {
|
|
|
478
490
|
const messages = {
|
|
479
491
|
url: window.location.href,
|
|
480
492
|
affiliateCode,
|
|
493
|
+
acSource: hasExplicitAc ? 'event' : acRead.from,
|
|
481
494
|
nickname,
|
|
482
495
|
}
|
|
483
496
|
|
|
@@ -524,7 +537,7 @@ export default function (request) {
|
|
|
524
537
|
...referralObj,
|
|
525
538
|
dt,
|
|
526
539
|
platform: 'pwa',
|
|
527
|
-
fc,
|
|
540
|
+
fc: friendCode,
|
|
528
541
|
}).toString()
|
|
529
542
|
)
|
|
530
543
|
|
package/src/machine/common.js
CHANGED
|
@@ -3,9 +3,10 @@ import { assign, createMachine } from 'xstate'
|
|
|
3
3
|
import pickBy from 'lodash/pickBy.js'
|
|
4
4
|
import api from '../api/common.js'
|
|
5
5
|
import storage from '../util/storage.js'
|
|
6
|
+
import { readParam, writeParam, AC_KEYS, FC_KEYS } from '../util/paramStore.js'
|
|
6
7
|
|
|
7
8
|
export default function (request) {
|
|
8
|
-
const { appSecret } = request.config
|
|
9
|
+
const { appSecret, sentry } = request.config
|
|
9
10
|
return createMachine(
|
|
10
11
|
{
|
|
11
12
|
id: 'common',
|
|
@@ -276,28 +277,17 @@ export default function (request) {
|
|
|
276
277
|
kpix,
|
|
277
278
|
}
|
|
278
279
|
}),
|
|
279
|
-
setAgent: assign((
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
} else {
|
|
284
|
-
let urlParams = new URLSearchParams(window.location.search)
|
|
285
|
-
const affiliateCode = urlParams.get('ac') || urlParams.get('referralCode') || storage.get('ac') || storage.get('referralCode')
|
|
286
|
-
const friendCode = urlParams.get('fc') || urlParams.get('affiliate') || storage.get('fc') || storage.get('affiliate')
|
|
280
|
+
setAgent: assign(() => {
|
|
281
|
+
const urlParams = new URLSearchParams(window.location.search)
|
|
282
|
+
const ac = readParam(urlParams, AC_KEYS)
|
|
283
|
+
const fc = readParam(urlParams, FC_KEYS)
|
|
287
284
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
maxAge: 60 * 60 * 24 * 7,
|
|
291
|
-
})
|
|
292
|
-
storage.set('fc', friendCode, {
|
|
293
|
-
path: '/',
|
|
294
|
-
maxAge: 60 * 60 * 24 * 7,
|
|
295
|
-
})
|
|
285
|
+
writeParam('ac', ac.value, { sentry })
|
|
286
|
+
writeParam('fc', fc.value, { sentry })
|
|
296
287
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
288
|
+
return {
|
|
289
|
+
affiliateCode: ac.value,
|
|
290
|
+
friendCode: fc.value,
|
|
301
291
|
}
|
|
302
292
|
}),
|
|
303
293
|
clearAnnouncements: assign((context, event) => {
|
|
@@ -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
|
|
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
|
|
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,
|