@jetthai/cuora 1.1.473-dev.0 → 1.1.474

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 (85) hide show
  1. package/.claude/commands/sync-ai-prompts.md +1 -88
  2. package/.claude/settings.local.json +1 -3
  3. package/.github/copilot-instructions.md +61 -66
  4. package/.husky/post-checkout +3 -3
  5. package/.husky/pre-push +1 -1
  6. package/.prettierignore +1 -2
  7. package/AGENTS.md +61 -66
  8. package/AI_PROMPT_SOURCE.md +61 -66
  9. package/CHANGELOG.md +6 -249
  10. package/CLAUDE.md +61 -66
  11. package/GEMINI.md +61 -66
  12. package/README.md +12 -11
  13. package/package.json +1 -1
  14. package/scripts/auto-version.js +0 -1
  15. package/scripts/branch-auto-npm-publish.js +2 -9
  16. package/src/api/account.js +1 -0
  17. package/src/api/activity.js +37 -0
  18. package/src/api/auth.js +31 -0
  19. package/src/api/game.js +10 -0
  20. package/src/api/payment.js +52 -1
  21. package/src/api/user.js +16 -0
  22. package/src/index.js +2 -2
  23. package/src/machine/activity/activity.js +209 -0
  24. package/src/machine/activity/activity_cash.js +1 -14
  25. package/src/machine/activity/diamond_shop_activity_cash.js +1 -0
  26. package/src/machine/activity/diamond_shop_activity_fc.js +196 -0
  27. package/src/machine/activity/diamond_shop_activity_vn.js +178 -0
  28. package/src/machine/activity/fafafa_activity.js +10 -0
  29. package/src/machine/activity/index.js +12 -0
  30. package/src/machine/activity/invite_friends_activity.js +114 -0
  31. package/src/machine/activity/mini_game_activity.js +68 -0
  32. package/src/machine/activity/return_bonus_activity.js +153 -0
  33. package/src/machine/auth.js +59 -0
  34. package/src/machine/auth_otp_v2.js +177 -0
  35. package/src/machine/auth_otp_v3.js +19 -30
  36. package/src/machine/bank_binding_amb.js +146 -0
  37. package/src/machine/bonus.js +76 -0
  38. package/src/machine/common.js +55 -0
  39. package/src/machine/deposit/amb.js +93 -0
  40. package/src/machine/deposit/crypto_bank.js +330 -0
  41. package/src/machine/deposit/crypto_qrcode.js +148 -0
  42. package/src/machine/deposit/crypto_way.js +252 -0
  43. package/src/machine/deposit/deposit_fc.js +272 -0
  44. package/src/machine/deposit/direct.js +310 -0
  45. package/src/machine/deposit/float.js +375 -0
  46. package/src/machine/deposit/index.js +28 -0
  47. package/src/machine/deposit/krway.js +151 -0
  48. package/src/machine/deposit/loadcard_vn.js +351 -0
  49. package/src/machine/deposit/manual_cash.js +8 -0
  50. package/src/machine/deposit/manual_vn.js +458 -0
  51. package/src/machine/deposit/qrcode_v2.js +338 -0
  52. package/src/machine/deposit/usdt.js +144 -0
  53. package/src/machine/deposit/virtual_bank_vn.js +269 -0
  54. package/src/machine/deposit/vpay.js +368 -0
  55. package/src/machine/game_hot_new.js +79 -0
  56. package/src/machine/game_info.js +12 -1
  57. package/src/machine/game_replay.js +46 -0
  58. package/src/machine/game_search_v2.js +401 -0
  59. package/src/machine/game_v2_1.js +89 -1
  60. package/src/machine/honor_board.js +132 -0
  61. package/src/machine/honor_board_cash.js +18 -15
  62. package/src/machine/inbox.js +12 -0
  63. package/src/machine/index.js +32 -0
  64. package/src/machine/merge.js +57 -0
  65. package/src/machine/payment_data.js +86 -0
  66. package/src/machine/promotions.js +170 -0
  67. package/src/machine/reward.js +255 -0
  68. package/src/machine/reward_cash.js +39 -0
  69. package/src/machine/reward_fc.js +98 -0
  70. package/src/machine/side.js +154 -0
  71. package/src/machine/side_v2.js +211 -0
  72. package/src/machine/user_reset_password.js +13 -0
  73. package/src/machine/user_sign_up.js +0 -3
  74. package/src/machine/vip_table.js +57 -0
  75. package/src/machine/websocket.js +4 -0
  76. package/src/machine/welcome.js +110 -0
  77. package/src/machine/withdraw/index.js +6 -0
  78. package/src/machine/withdraw/withdraw_crypto_cash.js +327 -0
  79. package/src/machine/withdraw/withdraw_krway.js +223 -0
  80. package/src/machine/withdraw/withdraw_manual.js +536 -0
  81. package/src/request/request.js +28 -0
  82. package/src/util/constant.js +1 -0
  83. package/src/util/index.js +4 -1
  84. package/src/util/math.js +4 -0
  85. package/test/auth_otp_v3.test.js +0 -192
@@ -0,0 +1,252 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import padStart from 'lodash/padStart.js'
3
+ import payment from '@jetthai/cuora/src/api/payment.js'
4
+ import common from '../../api/common.js'
5
+
6
+ export default function (request) {
7
+ const { appSecret } = request.config
8
+ return createMachine(
9
+ {
10
+ id: 'crypto_way',
11
+ initial: 'loading',
12
+ context: {
13
+ paymentDetails: [],
14
+
15
+ cryptos: [],
16
+ sourceAddress: '',
17
+
18
+ amount: null,
19
+ selectedCrypto: null,
20
+
21
+ currentCategory: 'cryptoWay',
22
+ currentPayment: null,
23
+
24
+ calculation: null,
25
+ result: null,
26
+
27
+ // use for wallet mode 4
28
+ promotion: null,
29
+ },
30
+ states: {
31
+ loading: {
32
+ invoke: {
33
+ src: 'fetchPayments',
34
+ onDone: {
35
+ target: 'loaded',
36
+ actions: 'setPayment',
37
+ },
38
+ onError: {
39
+ target: '#crypto_way.fail',
40
+ },
41
+ },
42
+ },
43
+ loaded: {
44
+ always: [{ target: 'debouncing', cond: 'isCalculable' }],
45
+ },
46
+ debouncing: {
47
+ after: {
48
+ 1000: {
49
+ target: 'calculating',
50
+ },
51
+ },
52
+ },
53
+ calculating: {
54
+ invoke: {
55
+ src: 'fetchCalculation',
56
+ onDone: {
57
+ target: 'calculated',
58
+ actions: 'setCalculation',
59
+ },
60
+ onError: {
61
+ target: 'loaded',
62
+ },
63
+ },
64
+ },
65
+ calculated: {
66
+ on: {
67
+ SUBMIT: [
68
+ {
69
+ target: 'pending',
70
+ },
71
+ {
72
+ target: 'submitting',
73
+ cond: 'isSubmittable',
74
+ },
75
+ ],
76
+ },
77
+ },
78
+ pending: {
79
+ on: {
80
+ SUBMIT: {
81
+ target: 'submitting',
82
+ cond: 'isSubmittable',
83
+ },
84
+ },
85
+ },
86
+ submitting: {
87
+ invoke: {
88
+ src: 'submitDeposit',
89
+ onDone: {
90
+ target: 'submitted',
91
+ actions: 'setResult',
92
+ },
93
+ onError: {
94
+ target: 'submitFail',
95
+ },
96
+ },
97
+ },
98
+ submitFail: {
99
+ after: {
100
+ 0: { target: 'loaded' },
101
+ },
102
+ },
103
+ submitted: {},
104
+ fail: {},
105
+ },
106
+ on: {
107
+ SET_CRYPTO: {
108
+ target: '.loaded',
109
+ actions: 'setCrypto',
110
+ },
111
+ SET_ADDRESS: {
112
+ actions: 'setAddress',
113
+ },
114
+ SET_AMOUNT: {
115
+ target: '.loaded',
116
+ actions: ['setAmount', 'clearCalculation'],
117
+ },
118
+ INPUT_AMOUNT: {
119
+ target: '.loaded',
120
+ actions: ['inputAmount', 'clearCalculation'],
121
+ },
122
+ CALCULATE: {
123
+ target: '.debouncing',
124
+ actions: 'clearCalculation',
125
+ },
126
+ SET_PROMOTION: {
127
+ actions: 'setPromotion',
128
+ },
129
+ },
130
+ },
131
+ {
132
+ actions: {
133
+ setPayment: assign((context, event) => {
134
+ const payments = event.data.filter((item) => item.category === context.currentCategory)
135
+ const cryptos = payments?.map((value, i) => {
136
+ return {
137
+ ...value,
138
+ label: value?.cryptoOptional[0],
139
+ network: value?.networkName[0],
140
+ icon: value?.channel,
141
+ }
142
+ })
143
+ return {
144
+ cryptos,
145
+ selectedCrypto: cryptos[0],
146
+ currentPayment: cryptos[0],
147
+ }
148
+ }),
149
+ setCrypto: assign((context, event) => {
150
+ const { cryptos } = context
151
+ const selectedCrypto = cryptos.find((crypto) => crypto.label === event.data.label)
152
+ return {
153
+ selectedCrypto: selectedCrypto,
154
+ amount: null,
155
+ calculation: null,
156
+ }
157
+ }),
158
+ setAmount: assign((context, event) => {
159
+ return {
160
+ amount: event.data,
161
+ }
162
+ }),
163
+ inputAmount: assign((context, event) => {
164
+ return { amount: preciseAdd(`${parseFloat(context.amount || 0)}`, `${parseFloat(event.data)}`) }
165
+ }),
166
+ setAddress: assign((context, event) => {
167
+ return {
168
+ sourceAddress: event.data,
169
+ }
170
+ }),
171
+ setCalculation: assign((context, event) => {
172
+ // V2接口轉換中回傳的資料結構不同
173
+ const { data } = event.data
174
+ if (data) {
175
+ return {
176
+ calculation: data,
177
+ }
178
+ } else {
179
+ return {
180
+ calculation: event.data,
181
+ }
182
+ }
183
+ }),
184
+ clearCalculation: assign((context, event) => {
185
+ return {
186
+ calculation: null,
187
+ }
188
+ }),
189
+ setResult: assign((context, event) => {
190
+ return {
191
+ result: event.data,
192
+ }
193
+ }),
194
+ setPromotion: assign((context, event) => {
195
+ const promotion = event.data
196
+ return {
197
+ promotion,
198
+ }
199
+ }),
200
+ },
201
+ guards: {
202
+ isCalculable: (context, event) => {
203
+ const { selectedCrypto, amount } = context
204
+ return selectedCrypto && amount && selectedCrypto?.minimum <= +amount && +amount <= selectedCrypto?.maximum
205
+ },
206
+ isSubmittable: (context, event) => {
207
+ const { selectedCrypto, amount } = context
208
+ return selectedCrypto && amount
209
+ },
210
+ },
211
+ services: {
212
+ fetchPayments: async (context, event) => {
213
+ return await request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' }))
214
+ },
215
+ fetchCalculation: async (context, event) => {
216
+ const { selectedCrypto, amount, promotion } = context
217
+ return await request.send(
218
+ payment.getCryptoDepositExpectedResult({
219
+ method: selectedCrypto.method,
220
+ amount,
221
+ cryptoCurrency: selectedCrypto.channel,
222
+ promotionsNo: promotion?.activityNo,
223
+ })
224
+ )
225
+ },
226
+ submitDeposit: async (context, event) => {
227
+ const { selectedCrypto, amount } = context
228
+ return await request.send(
229
+ payment.submitDepositTransactionCrypto({
230
+ method: selectedCrypto.method,
231
+ amount: amount,
232
+ cryptoCurrency: selectedCrypto.channel,
233
+ cryptoNetwork: selectedCrypto.network,
234
+ })
235
+ )
236
+ },
237
+ },
238
+ }
239
+ )
240
+ }
241
+
242
+ function preciseAdd(a, b) {
243
+ let aStr = a.toString()
244
+ let bStr = b.toString()
245
+
246
+ let aDecimalPlaces = aStr.split('.')[1] ? aStr.split('.')[1].length : 0
247
+ let bDecimalPlaces = bStr.split('.')[1] ? bStr.split('.')[1].length : 0
248
+
249
+ let factor = Math.pow(10, Math.max(aDecimalPlaces, bDecimalPlaces))
250
+
251
+ return (Math.round(a * factor) + Math.round(b * factor)) / factor
252
+ }
@@ -0,0 +1,272 @@
1
+ // 棄用
2
+ import { assign, createMachine } from 'xstate'
3
+ import toNumber from 'lodash/toNumber.js'
4
+ import payment from '../../api/payment.js'
5
+
6
+ // const toNumber = require('lodash/toNumber')
7
+
8
+ export default function (request) {
9
+ return createMachine(
10
+ {
11
+ id: 'deposit',
12
+ initial: 'loading',
13
+ context: {
14
+ cryptos: [],
15
+ networks: [],
16
+ currentCrypto: null,
17
+ currentNetwork: null,
18
+ currentAmount: null,
19
+ calculatedResult: null,
20
+ submittedResult: null,
21
+ bonus: null,
22
+ },
23
+ states: {
24
+ loading: {
25
+ initial: 'bonusStatus',
26
+ states: {
27
+ bonusStatus: {
28
+ invoke: {
29
+ src: 'getPaymentInfo',
30
+ onDone: {
31
+ target: 'fetchingPayments',
32
+ actions: 'setBonus',
33
+ },
34
+ onError: {
35
+ target: '#deposit.loaded',
36
+ },
37
+ },
38
+ },
39
+ fetchingPayments: {
40
+ invoke: {
41
+ src: 'fetchPayments',
42
+ onDone: {
43
+ target: '#deposit.loaded',
44
+ actions: 'setCryptos',
45
+ },
46
+ onError: {
47
+ target: '#deposit.loaded',
48
+ },
49
+ },
50
+ },
51
+ },
52
+ },
53
+ loaded: {
54
+ on: {
55
+ SUBMIT: {
56
+ target: 'submitting',
57
+ cond: 'isSubmittable',
58
+ },
59
+ },
60
+ },
61
+ checking: {
62
+ entry: 'clearCalculatedResult',
63
+ always: [{ target: 'debouncing', cond: 'isCalculable' }, { target: 'loaded' }],
64
+ },
65
+ debouncing: {
66
+ after: {
67
+ 1000: {
68
+ target: 'calculating',
69
+ },
70
+ },
71
+ },
72
+ calculating: {
73
+ invoke: {
74
+ src: 'fetchCalculation',
75
+ onDone: {
76
+ target: 'loaded',
77
+ actions: 'setCalculatedResult',
78
+ },
79
+ onError: {
80
+ target: 'loaded',
81
+ },
82
+ },
83
+ },
84
+ submitting: {
85
+ invoke: {
86
+ src: 'submitDeposit',
87
+ onDone: {
88
+ target: '#deposit.submitted',
89
+ actions: 'setSubmittedResult',
90
+ },
91
+ onError: {
92
+ target: 'loaded',
93
+ },
94
+ },
95
+ },
96
+ switchingBonus: {
97
+ invoke: {
98
+ src: 'setBonusSetting',
99
+ onDone: {
100
+ target: 'checking',
101
+ },
102
+ onError: {
103
+ target: 'loaded',
104
+ },
105
+ },
106
+ },
107
+ submitted: {},
108
+ },
109
+ on: {
110
+ SET_CRYPTO: {
111
+ target: 'checking',
112
+ actions: 'setCrypto',
113
+ cond: 'hasCryptoOptions',
114
+ },
115
+ SET_NETWORK: {
116
+ target: 'checking',
117
+ actions: 'setNetwork',
118
+ cond: 'hasNetworkOptions',
119
+ },
120
+ SET_AMOUNT: {
121
+ target: 'checking',
122
+ actions: 'setAmount',
123
+ },
124
+ TOGGLE_BONUS: {
125
+ target: 'switchingBonus',
126
+ actions: 'toggleBonus',
127
+ },
128
+ },
129
+ },
130
+ {
131
+ actions: {
132
+ setCryptos: assign((context, event) => {
133
+ return {
134
+ cryptos: event.data.map((crypto) => ({
135
+ ...crypto,
136
+ label: crypto.channel,
137
+ value: crypto.method,
138
+ icon: crypto.channel,
139
+ })),
140
+ }
141
+ }),
142
+ setCrypto: assign((context, event) => {
143
+ const { cryptos, currentNetwork } = context
144
+ const method = cryptos.find((crypto) => crypto.method === event.data.value)
145
+ const networks =
146
+ method?.networkName.map((value, i) => {
147
+ return {
148
+ label: method?.networkOptional?.[i],
149
+ value,
150
+ icon: value,
151
+ }
152
+ }) || []
153
+
154
+ const properties = {
155
+ currentCrypto: event.data,
156
+ networks,
157
+ }
158
+
159
+ if (!networks.includes(currentNetwork)) {
160
+ properties.currentNetwork = null
161
+ properties.currentAmount = null
162
+ properties.calculatedResult = null
163
+ }
164
+
165
+ return properties
166
+ }),
167
+ setNetwork: assign((context, event) => {
168
+ return { currentNetwork: event.data }
169
+ }),
170
+ setAmount: assign((context, event) => {
171
+ const currentAmount = event.data
172
+
173
+ const properties = {
174
+ currentAmount,
175
+ }
176
+
177
+ if (!currentAmount) {
178
+ properties.calculatedResult = null
179
+ }
180
+
181
+ return properties
182
+ }),
183
+ setCalculatedResult: assign((context, event) => {
184
+ // V2接口轉換中回傳的資料結構不同
185
+ const { data } = event.data
186
+ if (data) {
187
+ return {
188
+ calculatedResult: data,
189
+ }
190
+ } else {
191
+ return {
192
+ calculatedResult: event.data,
193
+ }
194
+ }
195
+ }),
196
+ setSubmittedResult: assign((context, event) => {
197
+ return {
198
+ submittedResult: event.data,
199
+ }
200
+ }),
201
+ clearCalculatedResult: assign((context, event) => {
202
+ return {
203
+ calculatedResult: null,
204
+ }
205
+ }),
206
+ toggleBonus: assign((context, event) => {
207
+ const { bonus } = context
208
+ return {
209
+ bonus: bonus === 1 ? 0 : 1,
210
+ }
211
+ }),
212
+ setBonus: assign((context, event) => {
213
+ return {
214
+ bonus: event.data,
215
+ }
216
+ }),
217
+ },
218
+ guards: {
219
+ hasCryptoOptions: (context, evnet) => {
220
+ return context.cryptos.length > 0
221
+ },
222
+ hasNetworkOptions: (context, evnet) => {
223
+ return context.networks.length > 0
224
+ },
225
+ isCalculable: (context, event) => {
226
+ const { currentCrypto, currentNetwork, currentAmount } = context
227
+ return currentCrypto && currentNetwork && toNumber(currentAmount)
228
+ },
229
+ isSubmittable: (context, event) => {
230
+ return context.calculatedResult
231
+ },
232
+ isBonusOff: (context, event) => {
233
+ return context.bonus !== 1
234
+ },
235
+ },
236
+ services: {
237
+ fetchPayments: async (context, event) => {
238
+ return await request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' }))
239
+ },
240
+ fetchCalculation: async (context, event) => {
241
+ const { currentCrypto, currentAmount } = context
242
+ return await request.send(
243
+ payment.getDepositExpectedResult({
244
+ method: currentCrypto.method,
245
+ amount: Number(currentAmount),
246
+ cryptoCurrency: currentCrypto.channel,
247
+ })
248
+ )
249
+ },
250
+ submitDeposit: async (context, event) => {
251
+ const { currentCrypto, currentNetwork, calculatedResult } = context
252
+ return await request.send(
253
+ payment.submitDepositTransactionCrypto({
254
+ method: currentCrypto.method,
255
+ amount: calculatedResult.actualAmount,
256
+ cryptoCurrency: currentCrypto.channel,
257
+ cryptoNetwork: currentNetwork.value,
258
+ })
259
+ )
260
+ },
261
+ setBonusSetting: async (context, event) => {
262
+ const { bonus } = context
263
+ return await request.send(payment.setBonusSetting({ bonus }))
264
+ },
265
+ getPaymentInfo: async (context, event) => {
266
+ const { bonus } = await request.send(payment.getPaymentInfo())
267
+ return bonus
268
+ },
269
+ },
270
+ }
271
+ )
272
+ }