@jetthai/cuora 1.1.455-dev.8 → 1.1.455
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 +12 -5
- package/.claude/commands/commit-push.md +4 -15
- package/.claude/commands/sync-ai-prompts.md +1 -88
- package/.claude/settings.local.json +1 -3
- package/.github/copilot-instructions.md +394 -552
- package/.husky/post-checkout +3 -3
- package/.husky/pre-push +1 -1
- package/.prettierignore +1 -2
- package/AGENTS.md +394 -552
- package/AI_PROMPT_SOURCE.md +127 -663
- package/CHANGELOG.md +22 -325
- package/CLAUDE.md +394 -552
- package/GEMINI.md +394 -552
- package/README.md +137 -40
- package/package.json +1 -1
- package/scripts/auto-version.js +0 -1
- package/src/api/activity.js +2 -2
- package/src/api/user.js +0 -12
- package/src/index.js +2 -2
- package/src/machine/auth.js +2 -15
- package/src/machine/common.js +21 -11
- package/src/machine/deposit/crypto_bank_cash.js +5 -4
- package/src/machine/deposit/crypto_qrcode_cash.js +8 -16
- package/src/machine/deposit/crypto_way_cash.js +5 -4
- package/src/machine/deposit/direct_cash.js +3 -7
- package/src/machine/deposit/loadcard_cash.js +8 -7
- package/src/machine/deposit/manual_cash.js +2 -8
- package/src/machine/deposit/qrcode_cash.js +7 -5
- package/src/machine/deposit/virtual_bank_cash.js +2 -5
- package/src/machine/side_cash.js +2 -3
- package/src/machine/side_v2.js +4 -6
- package/src/machine/user_sign_up.js +3 -16
- package/src/util/index.js +1 -2
- package/src/util/paramStore.js +0 -139
package/README.md
CHANGED
|
@@ -1,8 +1,34 @@
|
|
|
1
1
|
# @jetthai/cuora
|
|
2
2
|
|
|
3
|
-
ESM JavaScript
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
`@jetthai/cuora` 是一個純 ESM JavaScript 函式庫,無建置步驟,原始 `.js` 檔案直接發佈至 npm。透過 XState v4 狀態機整合 API 呼叫與業務邏輯,服務於線上遊戲平台,處理認證、支付(存款/提款)、遊戲管理、活動及即時 WebSocket 通訊。設計用於 Nuxt.js 客戶端應用程式(`ssr: false`)。
|
|
4
|
+
|
|
5
|
+
- **模組格式**:`"type": "module"`
|
|
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)
|
|
6
32
|
|
|
7
33
|
## Installation
|
|
8
34
|
|
|
@@ -30,6 +56,18 @@ export default {
|
|
|
30
56
|
import { api, machine, Request, Config, util, constant, storage } from '@jetthai/cuora'
|
|
31
57
|
```
|
|
32
58
|
|
|
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
|
+
|
|
33
71
|
### Config
|
|
34
72
|
|
|
35
73
|
初始化 API 設定:
|
|
@@ -120,36 +158,35 @@ storage.set('key', value, ttl)
|
|
|
120
158
|
storage.get('key')
|
|
121
159
|
|
|
122
160
|
// 遊戲類型常數
|
|
123
|
-
constant.
|
|
124
|
-
constant.
|
|
125
|
-
constant.
|
|
126
|
-
constant.SPORT
|
|
161
|
+
constant.GAME_TYPE_LIST // 16 種遊戲類型陣列,每筆為 { typeId, name, gameTypeMappingId }
|
|
162
|
+
constant.MY_FAVORITE // 'MyFavorite'
|
|
163
|
+
constant.GAME_SEARCH // 'GameSearch'
|
|
127
164
|
```
|
|
128
165
|
|
|
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
|
+
|
|
129
177
|
## Architecture
|
|
130
178
|
|
|
131
179
|
```
|
|
132
180
|
src/
|
|
133
181
|
├── index.js # 進入點
|
|
134
182
|
├── 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
|
|
146
183
|
├── machine/ # XState v4 狀態機
|
|
147
184
|
│ ├── auth.js # 登入/註冊流程
|
|
148
185
|
│ ├── common.js # 網站設定、UA、聯盟行銷
|
|
149
186
|
│ ├── websocket.js # Socket.IO 即時通訊
|
|
150
|
-
│ ├── deposit/ # 存款狀態機
|
|
151
|
-
│ ├── withdraw/ # 提款狀態機
|
|
152
|
-
│ └── activity/ # 活動狀態機
|
|
187
|
+
│ ├── deposit/ # 存款狀態機
|
|
188
|
+
│ ├── withdraw/ # 提款狀態機
|
|
189
|
+
│ └── activity/ # 活動狀態機
|
|
153
190
|
├── request/
|
|
154
191
|
│ ├── config.js # Config 設定類別
|
|
155
192
|
│ └── request.js # Axios 封裝 + 攔截器
|
|
@@ -180,32 +217,92 @@ npm run release:qa
|
|
|
180
217
|
|
|
181
218
|
程式碼風格由 Prettier 管理(無分號、單引號、尾隨逗號 ES5、2 空格縮排、150 字元行寬),Husky pre-commit hook 會在每次提交時自動格式化。
|
|
182
219
|
|
|
183
|
-
|
|
220
|
+
## Git 分支版本發佈流程
|
|
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 |
|
|
184
239
|
|
|
185
|
-
|
|
240
|
+
### dev / qa 分支自動版本流程
|
|
241
|
+
|
|
242
|
+
當開發者在 `dev` 或 `qa` 分支執行 `git push` 時,Husky `pre-push` hook 觸發以下流程:
|
|
186
243
|
|
|
187
244
|
```
|
|
188
|
-
git push
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
245
|
+
git push origin dev
|
|
246
|
+
│
|
|
247
|
+
├─ .husky/pre-push
|
|
248
|
+
│ ├─ sh scripts/clean-tags.sh # 清理本地 tag
|
|
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 訊息為準)
|
|
192
272
|
```
|
|
193
273
|
|
|
194
|
-
|
|
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`、...
|
|
195
282
|
|
|
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}` |
|
|
283
|
+
**historyMax 防倒退機制**:
|
|
201
284
|
|
|
202
|
-
|
|
285
|
+
merge 其他分支後,`package.json` 的 version 可能被覆蓋為舊值(如從 `1.1.430-dev.4` 退回 `1.0.9-dev.20`)。此時腳本會掃描 git log 找出該 prefix 歷史上用過的最大編號,確保新版號不會倒退:
|
|
203
286
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
287
|
+
```
|
|
288
|
+
currentVersion = "1.0.9-dev.20" ← merge 後被覆蓋
|
|
289
|
+
git log 發現歷史有 "1.1.430-dev.4"
|
|
290
|
+
→ historyMax = 4, nextNum = 5
|
|
291
|
+
→ 新版號 = "1.1.430-dev.5"(而非從 0 重新開始)
|
|
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` | (保留,目前無額外操作) |
|
|
210
303
|
|
|
211
304
|
> **注意**:`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/activity.js
CHANGED
|
@@ -130,9 +130,9 @@ export default {
|
|
|
130
130
|
method: 'get',
|
|
131
131
|
params: { appSecret },
|
|
132
132
|
}),
|
|
133
|
-
getProgressDetail: ({ appSecret
|
|
133
|
+
getProgressDetail: ({ appSecret }) => ({
|
|
134
134
|
url: 'activities/progress-details',
|
|
135
135
|
method: 'get',
|
|
136
|
-
params: { appSecret
|
|
136
|
+
params: { appSecret },
|
|
137
137
|
}),
|
|
138
138
|
}
|
package/src/api/user.js
CHANGED
|
@@ -66,16 +66,4 @@ 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
|
-
}),
|
|
81
69
|
}
|
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
|
|
5
|
+
import util, { constant, storage } from './util/index.js'
|
|
6
6
|
|
|
7
|
-
export { api, machine, Request, Config, util, constant, storage
|
|
7
|
+
export { api, machine, Request, Config, util, constant, storage }
|
package/src/machine/auth.js
CHANGED
|
@@ -5,7 +5,6 @@ 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'
|
|
9
8
|
|
|
10
9
|
export default function (request) {
|
|
11
10
|
const { appSecret, clientId, sentry } = request.config
|
|
@@ -470,18 +469,7 @@ export default function (request) {
|
|
|
470
469
|
|
|
471
470
|
const dt = deviceTokenEnable ? await request.config.getDt?.() : undefined
|
|
472
471
|
|
|
473
|
-
|
|
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
|
-
|
|
472
|
+
const affiliateCode = storage.get('ac')
|
|
485
473
|
const nickname = storage.get('nk')
|
|
486
474
|
const phone = storage.get('tp_phone')
|
|
487
475
|
const countryCode = storage.get('tp_countryCode')
|
|
@@ -490,7 +478,6 @@ export default function (request) {
|
|
|
490
478
|
const messages = {
|
|
491
479
|
url: window.location.href,
|
|
492
480
|
affiliateCode,
|
|
493
|
-
acSource: hasExplicitAc ? 'event' : acRead.from,
|
|
494
481
|
nickname,
|
|
495
482
|
}
|
|
496
483
|
|
|
@@ -537,7 +524,7 @@ export default function (request) {
|
|
|
537
524
|
...referralObj,
|
|
538
525
|
dt,
|
|
539
526
|
platform: 'pwa',
|
|
540
|
-
fc
|
|
527
|
+
fc,
|
|
541
528
|
}).toString()
|
|
542
529
|
)
|
|
543
530
|
|
package/src/machine/common.js
CHANGED
|
@@ -3,10 +3,9 @@ import { assign, createMachine } from 'xstate'
|
|
|
3
3
|
import pickBy from 'lodash/pickBy.js'
|
|
4
4
|
import api from '../api/common.js'
|
|
5
5
|
import storage from '../util/storage.js'
|
|
6
|
-
import { readParam, writeParam, AC_KEYS, FC_KEYS } from '../util/paramStore.js'
|
|
7
6
|
|
|
8
7
|
export default function (request) {
|
|
9
|
-
const { appSecret
|
|
8
|
+
const { appSecret } = request.config
|
|
10
9
|
return createMachine(
|
|
11
10
|
{
|
|
12
11
|
id: 'common',
|
|
@@ -277,17 +276,28 @@ export default function (request) {
|
|
|
277
276
|
kpix,
|
|
278
277
|
}
|
|
279
278
|
}),
|
|
280
|
-
setAgent: assign(() => {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
279
|
+
setAgent: assign((context, event) => {
|
|
280
|
+
if (window.CC_JSB === true) {
|
|
281
|
+
// is cocos native app
|
|
282
|
+
return
|
|
283
|
+
} else {
|
|
284
|
+
let urlParams = new URLSearchParams(window.location.search)
|
|
285
|
+
const 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')
|
|
284
287
|
|
|
285
|
-
|
|
286
|
-
|
|
288
|
+
storage.set('ac', affiliateCode, {
|
|
289
|
+
path: '/',
|
|
290
|
+
maxAge: 60 * 60 * 24 * 7,
|
|
291
|
+
})
|
|
292
|
+
storage.set('fc', friendCode, {
|
|
293
|
+
path: '/',
|
|
294
|
+
maxAge: 60 * 60 * 24 * 7,
|
|
295
|
+
})
|
|
287
296
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
297
|
+
return {
|
|
298
|
+
affiliateCode,
|
|
299
|
+
friendCode,
|
|
300
|
+
}
|
|
291
301
|
}
|
|
292
302
|
}),
|
|
293
303
|
clearAnnouncements: assign((context, event) => {
|
|
@@ -1,5 +1,6 @@
|
|
|
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'
|
|
3
4
|
|
|
4
5
|
export default function (request, context) {
|
|
5
6
|
const { paymentDetail = [], promotion, selectedAmount, siteConfig } = context || {}
|
|
@@ -97,7 +98,6 @@ export default function (request, context) {
|
|
|
97
98
|
target: '.debouncing',
|
|
98
99
|
actions: 'setPromotion',
|
|
99
100
|
internal: false,
|
|
100
|
-
cond: 'isPromotionChanged',
|
|
101
101
|
},
|
|
102
102
|
SET_CRYPTO: {
|
|
103
103
|
target: '.debouncing',
|
|
@@ -164,6 +164,7 @@ 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),
|
|
167
168
|
}
|
|
168
169
|
}),
|
|
169
170
|
setCrypto: assign((context, event) => {
|
|
@@ -182,6 +183,7 @@ export default function (request, context) {
|
|
|
182
183
|
addresses,
|
|
183
184
|
selectedCrypto: selectedCrypto,
|
|
184
185
|
selectedAddress: addresses[0],
|
|
186
|
+
selectedAmount: max(context.promotion?.minimumAmount, selectedCrypto?.minimum || cryptoBank?.minimum, 0),
|
|
185
187
|
calculation: null,
|
|
186
188
|
options: cryptoBank.optional,
|
|
187
189
|
}
|
|
@@ -229,9 +231,11 @@ export default function (request, context) {
|
|
|
229
231
|
}
|
|
230
232
|
}),
|
|
231
233
|
setPromotion: assign((context, event) => {
|
|
234
|
+
const { cryptoBank, selectedAmount } = context
|
|
232
235
|
const promotion = event.data
|
|
233
236
|
return {
|
|
234
237
|
promotion,
|
|
238
|
+
selectedAmount: max(promotion.minimumAmount, cryptoBank.minimum, selectedAmount, 0),
|
|
235
239
|
calculation: null,
|
|
236
240
|
}
|
|
237
241
|
}),
|
|
@@ -247,9 +251,6 @@ export default function (request, context) {
|
|
|
247
251
|
}),
|
|
248
252
|
},
|
|
249
253
|
guards: {
|
|
250
|
-
isPromotionChanged: (context, event) => {
|
|
251
|
-
return event.data?.promotionsNo !== context.promotion?.promotionsNo
|
|
252
|
-
},
|
|
253
254
|
isCalculable: (context, event) => {
|
|
254
255
|
const { selectedCrypto, selectedAddress, selectedAmount } = context
|
|
255
256
|
return (
|
|
@@ -69,18 +69,13 @@ export default function (request) {
|
|
|
69
69
|
setInitData: assign((context, event) => {
|
|
70
70
|
const paymentDetail = event.data || []
|
|
71
71
|
const payments = paymentDetail.filter((item) => item.category === context.currentCategory)
|
|
72
|
-
const cryptos = payments.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
icon: payment.channel,
|
|
80
|
-
networkCode: networkItem?.networkCode ?? payment.networks?.[0]?.networkCode,
|
|
81
|
-
networkDisplayName: networkItem?.networkDisplayName ?? payment.networks?.[0]?.networkDisplayName,
|
|
82
|
-
}))
|
|
83
|
-
})
|
|
72
|
+
const cryptos = payments.map((payment) => ({
|
|
73
|
+
...payment,
|
|
74
|
+
label: payment.cryptoOptional?.[0],
|
|
75
|
+
network: payment.networkName?.[0],
|
|
76
|
+
value: payment.method,
|
|
77
|
+
icon: payment.channel,
|
|
78
|
+
}))
|
|
84
79
|
|
|
85
80
|
return {
|
|
86
81
|
cryptos,
|
|
@@ -89,10 +84,7 @@ export default function (request) {
|
|
|
89
84
|
}),
|
|
90
85
|
setCrypto: assign((context, event) => {
|
|
91
86
|
const { cryptos } = context
|
|
92
|
-
const
|
|
93
|
-
const selectedCrypto = data.networkCode
|
|
94
|
-
? cryptos.find((c) => c.channel === data.channel && c.networkCode === data.networkCode)
|
|
95
|
-
: cryptos.find((c) => c.label === data.label)
|
|
87
|
+
const selectedCrypto = cryptos.find((crypto) => crypto.label === event.data.label)
|
|
96
88
|
return { selectedCrypto }
|
|
97
89
|
}),
|
|
98
90
|
setResultFromLocal: assign((context, event) => {
|
|
@@ -1,5 +1,6 @@
|
|
|
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'
|
|
3
4
|
|
|
4
5
|
export default function (request, context) {
|
|
5
6
|
const { paymentDetail = [], promotion, selectedAmount } = context || {}
|
|
@@ -103,7 +104,6 @@ export default function (request, context) {
|
|
|
103
104
|
target: '.debouncing',
|
|
104
105
|
actions: 'setPromotion',
|
|
105
106
|
internal: false,
|
|
106
|
-
cond: 'isPromotionChanged',
|
|
107
107
|
},
|
|
108
108
|
SET_CRYPTO: {
|
|
109
109
|
target: '.debouncing',
|
|
@@ -153,6 +153,7 @@ 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),
|
|
156
157
|
}
|
|
157
158
|
}),
|
|
158
159
|
setCrypto: assign((context, event) => {
|
|
@@ -160,6 +161,7 @@ export default function (request, context) {
|
|
|
160
161
|
const selectedCrypto = cryptos.find((crypto) => crypto.label === event.data.label)
|
|
161
162
|
return {
|
|
162
163
|
selectedCrypto: selectedCrypto,
|
|
164
|
+
selectedAmount: max(context.promotion?.minimumAmount, selectedCrypto?.minimum, 0),
|
|
163
165
|
calculation: null,
|
|
164
166
|
options: selectedCrypto?.optional || [],
|
|
165
167
|
}
|
|
@@ -208,9 +210,11 @@ export default function (request, context) {
|
|
|
208
210
|
}
|
|
209
211
|
}),
|
|
210
212
|
setPromotion: assign((context, event) => {
|
|
213
|
+
const { selectedCrypto, selectedAmount } = context
|
|
211
214
|
const promotion = event.data
|
|
212
215
|
return {
|
|
213
216
|
promotion,
|
|
217
|
+
selectedAmount: max(promotion.minimumAmount, selectedCrypto.minimum, selectedAmount, 0),
|
|
214
218
|
calculation: null,
|
|
215
219
|
}
|
|
216
220
|
}),
|
|
@@ -227,9 +231,6 @@ export default function (request, context) {
|
|
|
227
231
|
}),
|
|
228
232
|
},
|
|
229
233
|
guards: {
|
|
230
|
-
isPromotionChanged: (context, event) => {
|
|
231
|
-
return event.data?.promotionsNo !== context.promotion?.promotionsNo
|
|
232
|
-
},
|
|
233
234
|
isCalculable: (context, event) => {
|
|
234
235
|
const { selectedCrypto, selectedAmount } = context
|
|
235
236
|
return selectedCrypto && selectedAmount && selectedCrypto.minimum <= +selectedAmount && +selectedAmount <= selectedCrypto.maximum
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assign, createMachine } from 'xstate'
|
|
2
2
|
import payment from '../../api/payment.js'
|
|
3
|
+
import { max } from '../../util/index.js'
|
|
3
4
|
|
|
4
5
|
export default function (request, context) {
|
|
5
6
|
const { paymentDetail = [], promotion, selectedAmount } = context || {}
|
|
@@ -87,7 +88,6 @@ export default function (request, context) {
|
|
|
87
88
|
target: '.loading',
|
|
88
89
|
actions: 'setPromotion',
|
|
89
90
|
internal: false,
|
|
90
|
-
cond: 'isPromotionChanged',
|
|
91
91
|
},
|
|
92
92
|
SELECT_DIRECT: {
|
|
93
93
|
target: '.loading',
|
|
@@ -108,12 +108,13 @@ export default function (request, context) {
|
|
|
108
108
|
{
|
|
109
109
|
actions: {
|
|
110
110
|
setInitData: assign((context, event) => {
|
|
111
|
-
const { paymentDetail } = context
|
|
111
|
+
const { paymentDetail, selectedAmount, promotion } = 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),
|
|
117
118
|
}
|
|
118
119
|
}),
|
|
119
120
|
setBanks: assign((context, event) => {
|
|
@@ -130,7 +131,6 @@ export default function (request, context) {
|
|
|
130
131
|
setDirect: assign((context, event) => {
|
|
131
132
|
return {
|
|
132
133
|
selectedDirect: event.data,
|
|
133
|
-
calculation: null,
|
|
134
134
|
}
|
|
135
135
|
}),
|
|
136
136
|
setUserBank: assign((context, event) => {
|
|
@@ -169,14 +169,10 @@ export default function (request, context) {
|
|
|
169
169
|
setPromotion: assign((context, event) => {
|
|
170
170
|
return {
|
|
171
171
|
promotion: event.data,
|
|
172
|
-
calculation: null,
|
|
173
172
|
}
|
|
174
173
|
}),
|
|
175
174
|
},
|
|
176
175
|
guards: {
|
|
177
|
-
isPromotionChanged: (context, event) => {
|
|
178
|
-
return event.data?.promotionsNo !== context.promotion?.promotionsNo
|
|
179
|
-
},
|
|
180
176
|
isCalculable: (context, event) => {
|
|
181
177
|
const {
|
|
182
178
|
selectedAmount,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assign, createMachine } from 'xstate'
|
|
2
2
|
import payment from '../../api/payment.js'
|
|
3
|
+
import { max } from '../../util'
|
|
3
4
|
|
|
4
5
|
export default function (request, context) {
|
|
5
6
|
const { paymentDetail = [], promotion, selectedAmount } = context || {}
|
|
@@ -95,7 +96,6 @@ export default function (request, context) {
|
|
|
95
96
|
target: '.debouncing',
|
|
96
97
|
actions: 'setPromotion',
|
|
97
98
|
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 } = context
|
|
115
|
+
const { paymentDetail, selectedAmount, promotion } = 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,9 +120,11 @@ 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),
|
|
123
124
|
}
|
|
124
125
|
}),
|
|
125
126
|
setPromotion: assign((context, event) => {
|
|
127
|
+
const { selectedAmount } = context
|
|
126
128
|
const promotion = event.data
|
|
127
129
|
const loadcards = context.loadcards
|
|
128
130
|
const selectedLoadcard = loadcards[0]
|
|
@@ -131,14 +133,17 @@ export default function (request, context) {
|
|
|
131
133
|
loadcards,
|
|
132
134
|
selectedLoadcard,
|
|
133
135
|
options: selectedLoadcard?.optional,
|
|
136
|
+
selectedAmount: max(promotion.minimumAmount, selectedLoadcard?.minimum, selectedAmount, 0),
|
|
134
137
|
calculation: null,
|
|
135
138
|
}
|
|
136
139
|
}),
|
|
137
140
|
setLoadcard: assign((context, event) => {
|
|
141
|
+
const { promotion, selectedAmount } = context
|
|
138
142
|
const selectedLoadcard = event.data
|
|
139
143
|
return {
|
|
140
144
|
selectedLoadcard,
|
|
141
145
|
options: selectedLoadcard.optional,
|
|
146
|
+
selectedAmount: max(promotion.minimumAmount, selectedAmount, 0),
|
|
142
147
|
calculation: null,
|
|
143
148
|
}
|
|
144
149
|
}),
|
|
@@ -179,11 +184,7 @@ export default function (request, context) {
|
|
|
179
184
|
}
|
|
180
185
|
}),
|
|
181
186
|
},
|
|
182
|
-
guards: {
|
|
183
|
-
isPromotionChanged: (context, event) => {
|
|
184
|
-
return event.data?.promotionsNo !== context.promotion?.promotionsNo
|
|
185
|
-
},
|
|
186
|
-
},
|
|
187
|
+
guards: {},
|
|
187
188
|
services: {
|
|
188
189
|
fetchCalculation: async (context, event) => {
|
|
189
190
|
const { selectedLoadcard, selectedAmount, promotion } = context
|