@jetthai/cuora 1.1.343-dev-12 → 1.1.343-qa-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/CHANGELOG.md CHANGED
@@ -2,47 +2,7 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
- ### [1.1.343-dev-12](https://github.com/jetthai/cuora-module/compare/v1.1.343-dev-11...v1.1.343-dev-12) (2025-03-28)
6
-
7
- ### [1.1.346](https://github.com/jetthai/cuora-module/compare/v1.1.343-dev-10...v1.1.346) (2025-03-27)
8
-
9
- ### [1.1.345](https://github.com/jetthai/cuora-module/compare/v1.1.344-vipCardPro-2...v1.1.345) (2025-03-25)
10
-
11
- ### [1.1.343-dev-11](https://github.com/jetthai/cuora-module/compare/v1.1.343-dev-10...v1.1.343-dev-11) (2025-03-27)
12
-
13
- ### [1.1.343-dev-10](https://github.com/jetthai/cuora-module/compare/v1.1.344-vipCardPro-3...v1.1.343-dev-10) (2025-03-27)
14
-
15
- ### [1.1.343-dev-9](https://github.com/jetthai/cuora-module/compare/v1.1.344...v1.1.343-dev-9) (2025-03-18)
16
-
17
- ### [1.1.343-dev-8](https://github.com/jetthai/cuora-module/compare/v1.1.343-dev-7...v1.1.343-dev-8) (2025-03-18)
18
-
19
- ### [1.1.343-dev-7](https://github.com/jetthai/cuora-module/compare/v1.1.343-dev-6...v1.1.343-dev-7) (2025-03-17)
20
-
21
- ### [1.1.343-dev-6](https://github.com/jetthai/cuora-module/compare/v1.1.343-dev-5...v1.1.343-dev-6) (2025-03-17)
22
-
23
- ### [1.1.343-dev-5](https://github.com/jetthai/cuora-module/compare/v1.1.343-depositEvent-1...v1.1.343-dev-5) (2025-03-14)
24
-
25
- ### [1.1.343-dev-9](https://github.com/jetthai/cuora-module/compare/v1.1.343-dev-8...v1.1.343-dev-9) (2025-03-18)
26
-
27
- ### [1.1.343-dev-8](https://github.com/jetthai/cuora-module/compare/v1.1.343-dev-7...v1.1.343-dev-8) (2025-03-18)
28
-
29
- ### [1.1.343-dev-8](https://github.com/jetthai/cuora-module/compare/v1.1.343-dev-7...v1.1.343-dev-8) (2025-03-18)
30
-
31
- ### [1.1.343-dev-7](https://github.com/jetthai/cuora-module/compare/v1.1.343-dev-6...v1.1.343-dev-7) (2025-03-17)
32
-
33
- ### [1.1.343-dev-6](https://github.com/jetthai/cuora-module/compare/v1.1.343-dev-5...v1.1.343-dev-6) (2025-03-17)
34
-
35
- ### [1.1.343-depositEvent-1](https://github.com/jetthai/cuora-module/compare/v1.1.343...v1.1.343-depositEvent-1) (2025-03-14)
36
-
37
- ### [1.1.343-dev-5](https://github.com/jetthai/cuora-module/compare/v1.1.343-dev-4...v1.1.343-dev-5) (2025-03-14)
38
-
39
- ### [1.1.343-dev-4](https://github.com/jetthai/cuora-module/compare/v1.1.343-dev-3...v1.1.343-dev-4) (2025-03-14)
40
-
41
- ### [1.1.343-dev-3](https://github.com/jetthai/cuora-module/compare/v1.1.343-dev-2...v1.1.343-dev-3) (2025-03-14)
42
-
43
- ### [1.1.343-dev-2](https://github.com/jetthai/cuora-module/compare/v1.1.343-dev-1...v1.1.343-dev-2) (2025-03-14)
44
-
45
- ### [1.1.343-dev-1](https://github.com/jetthai/cuora-module/compare/v1.1.343...v1.1.343-dev-1) (2025-03-14)
5
+ ### [1.1.343-qa-1](https://github.com/jetthai/cuora-module/compare/v1.1.343...v1.1.343-qa-1) (2025-03-17)
46
6
 
47
7
  ### [1.1.343](https://github.com/jetthai/cuora-module/compare/v1.1.342...v1.1.343) (2025-03-11)
48
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.1.343-dev-12",
3
+ "version": "1.1.343-qa-1",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
@@ -107,9 +107,4 @@ export default {
107
107
  method: 'post',
108
108
  params: { startDate, endDate, appSecret },
109
109
  }),
110
- loseRebateHistory: ({ startDate, endDate, appSecret }) => ({
111
- url: 'activities/lose-rebate/history',
112
- method: 'post',
113
- params: { startDate, endDate, appSecret },
114
- }),
115
110
  }
package/src/api/index.js CHANGED
@@ -6,6 +6,5 @@ import mailbox from './mailbox.js'
6
6
  import payment from './payment.js'
7
7
  import user from './user.js'
8
8
  import form from './form.js'
9
- import ranking from './ranking.js'
10
9
 
11
- export default { activity, auth, common, game, mailbox, payment, user, form, ranking }
10
+ export default { activity, auth, common, game, mailbox, payment, user, form }
@@ -11,19 +11,17 @@ export default function (request) {
11
11
  activityDetail: null,
12
12
  conditions: null,
13
13
  rebateType: null,
14
- nextCycleCardCurrentReachLevel: null,
15
- nextCycleCardNextReachLevel: null,
16
- lastCycleCard: null,
14
+ currentReachLevel: null,
15
+ nextReachLevel: null,
16
+ lastPeriod: null,
17
17
  nextDepositLimit: null,
18
18
  nextTurnoverLimit: null,
19
- accumulateTotalDeposit: null,
20
- accumulateTotalValidTurnover: null,
19
+ currentTotalDeposit: null,
20
+ currentTotalTurnover: null,
21
21
  retainAmount: '0',
22
- yesterdayRewardsAmount: '0',
22
+ yesterdayReward: '0',
23
23
  calculateWalletMode: '1',
24
24
  duration: 0,
25
- isAccumulationPeriod: false, // 當前是否為累積期
26
- isAwardPeriod: false, // 當前是否為領獎期
27
25
  },
28
26
  initial: 'idle',
29
27
  states: {
@@ -47,17 +45,6 @@ export default function (request) {
47
45
  },
48
46
  },
49
47
  },
50
- sentAward: {
51
- invoke: {
52
- src: 'sentAward',
53
- onDone: {
54
- target: 'loading',
55
- },
56
- onError: {
57
- target: 'loaded',
58
- },
59
- },
60
- },
61
48
  loaded: {
62
49
  entry: 'setDuration',
63
50
  after: {
@@ -74,9 +61,6 @@ export default function (request) {
74
61
  STOP: {
75
62
  target: '.idle',
76
63
  },
77
- SENT_AWARD: {
78
- target: '.sentAward',
79
- },
80
64
  },
81
65
  },
82
66
  {
@@ -95,68 +79,50 @@ export default function (request) {
95
79
  const {
96
80
  rebateType,
97
81
  conditions = [],
98
- nextCycleCardCurrentReachLevel = {},
99
- nextCycleCardNextReachLevel = {},
100
- lastCycleCard = {},
101
- accumulateTotalDeposit = '0',
102
- accumulateTotalValidTurnover = '0',
82
+ currentReachLevel = {},
83
+ nextReachLevel = {},
84
+ lastPeriod = {},
85
+ currentTotalDeposit = '0',
86
+ currentTotalTurnover = '0',
103
87
  retainAmount = '0',
104
- yesterdayRewardsAmount = '0',
88
+ yesterdayReward = '0',
105
89
  calculateWalletMode = '0',
106
- accumulateStartTime,
107
- accumulateEndTime,
108
- lastCycleCardStartTime,
109
- lastCycleCardEndTime,
110
90
  } = context.activityDetail || {}
111
91
 
112
92
  let nextDepositLimit = '0'
113
93
  let nextTurnoverLimit = '0'
114
94
  let currentTurnover = '0'
115
95
  let currentDeposit = '0'
116
- const maxReachLevel = conditions?.[conditions?.length - 1]
117
96
  // 若已達到最高等級,所有數值皆以最高等級顯示
118
- if (maxReachLevel && nextCycleCardCurrentReachLevel?.title === maxReachLevel.title) {
119
- currentDeposit = maxReachLevel.depositLimit
120
- currentTurnover = maxReachLevel.turnoverLimit
121
- nextDepositLimit = maxReachLevel.depositLimit
122
- nextTurnoverLimit = maxReachLevel.turnoverLimit
97
+ if (currentReachLevel?.title === conditions?.[conditions?.length - 1]?.title) {
98
+ currentDeposit = conditions[conditions.length - 1].depositLimit
99
+ currentTurnover = conditions[conditions.length - 1].turnoverLimit
100
+ nextDepositLimit = conditions[conditions.length - 1].depositLimit
101
+ nextTurnoverLimit = conditions[conditions.length - 1].turnoverLimit
123
102
  } else {
124
- currentDeposit = accumulateTotalDeposit
125
- currentTurnover = accumulateTotalValidTurnover
126
- nextDepositLimit = nextCycleCardNextReachLevel?.depositLimit
127
- nextTurnoverLimit = nextCycleCardNextReachLevel?.turnoverLimit
103
+ currentDeposit = currentTotalDeposit
104
+ currentTurnover = currentTotalTurnover
105
+ nextDepositLimit = nextReachLevel?.depositLimit
106
+ nextTurnoverLimit = nextReachLevel?.turnoverLimit
128
107
  }
129
- // 計算當前是否為累積期及領獎期
130
- const currentTime = new Date().getTime() / 1000
131
- const isAccumulationPeriod = currentTime >= accumulateStartTime && currentTime <= accumulateEndTime
132
- const isAwardPeriod = currentTime >= lastCycleCardStartTime && currentTime <= lastCycleCardEndTime
133
108
 
134
109
  return {
135
110
  rebateType,
136
111
  conditions,
137
- nextCycleCardCurrentReachLevel,
138
- nextCycleCardNextReachLevel,
139
- lastCycleCard,
112
+ currentReachLevel,
113
+ nextReachLevel,
114
+ lastPeriod,
140
115
  nextDepositLimit,
141
116
  nextTurnoverLimit,
142
- accumulateTotalDeposit: currentDeposit,
143
- accumulateTotalValidTurnover: currentTurnover,
117
+ currentTotalDeposit: currentDeposit,
118
+ currentTotalTurnover: currentTurnover,
144
119
  retainAmount,
145
- yesterdayRewardsAmount,
120
+ yesterdayReward,
146
121
  calculateWalletMode,
147
- isAccumulationPeriod,
148
- isAwardPeriod,
149
122
  }
150
123
  }),
151
124
  setDuration: assign((context, event) => {
152
- const { rewardPeriodSameAsAccumulationPeriod, accumulateEndTime, lastCycleCardEndTime } = context?.activityDetail
153
- const { isAwardPeriod } = context
154
- // 若為累積期,則倒數時間以累積期結束時間計算
155
- let currentEndTime = accumulateEndTime
156
- // 若為領獎期,則倒數時間以領獎期結束時間計算
157
- if (!rewardPeriodSameAsAccumulationPeriod && isAwardPeriod) {
158
- currentEndTime = lastCycleCardEndTime
159
- }
125
+ const { currentEndTime } = context?.activityDetail
160
126
  return {
161
127
  duration: Math.max(parseInt(currentEndTime) - new Date().getTime() / 1000, 0),
162
128
  }
@@ -168,11 +134,6 @@ export default function (request) {
168
134
  const { data } = await request.send(api.getActivityDetail({ activityNo, appSecret }))
169
135
  return data
170
136
  },
171
- sentAward: async (context, event) => {
172
- const { activityNo } = context
173
- const { data } = await request.send(api.sentAward({ activityNo, appSecret }))
174
- return data
175
- },
176
137
  },
177
138
  }
178
139
  )
@@ -0,0 +1,288 @@
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',
11
+ initial: 'loading',
12
+ context: {
13
+ siteConfig: null,
14
+ paymentDetails: [],
15
+
16
+ channels: [],
17
+ cryptos: [],
18
+ networks: [],
19
+ sourceAddress: '',
20
+
21
+ amount: null,
22
+ selectedChannel: null,
23
+ selectedCrypto: null,
24
+ selectedNetwork: null,
25
+
26
+ currentCategory: 'crypto',
27
+ currentPayment: null,
28
+
29
+ calculation: null,
30
+ result: null,
31
+
32
+ // use for wallet mode 4
33
+ promotion: null,
34
+ },
35
+ states: {
36
+ loading: {
37
+ invoke: {
38
+ src: 'fetchInitData',
39
+ onDone: {
40
+ target: 'loaded',
41
+ actions: 'setInitData',
42
+ },
43
+ onError: {
44
+ target: '#crypto.fail',
45
+ },
46
+ },
47
+ },
48
+ loaded: {
49
+ always: [{ target: 'debouncing', cond: 'isCalculable' }],
50
+ },
51
+ debouncing: {
52
+ after: {
53
+ 1000: {
54
+ target: 'calculating',
55
+ },
56
+ },
57
+ },
58
+ calculating: {
59
+ invoke: {
60
+ src: 'fetchCalculation',
61
+ onDone: {
62
+ target: 'calculated',
63
+ actions: 'setCalculation',
64
+ },
65
+ onError: {
66
+ target: 'loaded',
67
+ },
68
+ },
69
+ },
70
+ calculated: {
71
+ on: {
72
+ SUBMIT: [
73
+ {
74
+ target: 'pending',
75
+ cond: 'isDoubleWalletMode',
76
+ },
77
+ {
78
+ target: 'submitting',
79
+ cond: 'isSubmittable',
80
+ },
81
+ ],
82
+ },
83
+ },
84
+ pending: {
85
+ on: {
86
+ SUBMIT: {
87
+ target: 'submitting',
88
+ cond: 'isSubmittable',
89
+ },
90
+ },
91
+ },
92
+ submitting: {
93
+ invoke: {
94
+ src: 'submitDeposit',
95
+ onDone: {
96
+ target: 'submitted',
97
+ actions: 'setResult',
98
+ },
99
+ onError: {
100
+ target: 'loaded',
101
+ },
102
+ },
103
+ },
104
+ submitted: {},
105
+ fail: {},
106
+ },
107
+ on: {
108
+ SET_CHANNEL: {
109
+ target: '.loaded',
110
+ actions: 'setChannel',
111
+ },
112
+ SET_CRYPTO: {
113
+ target: '.loaded',
114
+ actions: 'setCrypto',
115
+ },
116
+ SET_NETWORK: {
117
+ target: '.loaded',
118
+ actions: 'setNetwork',
119
+ },
120
+ SET_ADDRESS: {
121
+ actions: 'setAddress',
122
+ },
123
+ SET_AMOUNT: {
124
+ target: '.loaded',
125
+ actions: ['setAmount', 'clearCalculation'],
126
+ },
127
+ CALCULATE: {
128
+ target: '.debouncing',
129
+ actions: 'clearCalculation',
130
+ },
131
+ },
132
+ },
133
+ {
134
+ actions: {
135
+ setInitData: assign((context, event) => {
136
+ const { siteConfig, paymentDetail } = event.data
137
+ const cryptos =
138
+ paymentDetail
139
+ .filter((element) => element.category === context.currentCategory)
140
+ .map?.((crypto) => ({ ...crypto, label: crypto.channel, value: crypto.method, icon: crypto.channel })) || []
141
+ const currentPayment = cryptos[0]
142
+ const channels = cryptos.map((item, i) => ({ ...item, label: `Channel ${padStart(String(i + 1), 2, '0')}`, icon: 'channel' }))
143
+ const defaultNetworks =
144
+ cryptos[0].networkName.map((value, i) => {
145
+ return {
146
+ label: cryptos[0].networkOptional?.[i],
147
+ value,
148
+ icon: value,
149
+ }
150
+ }) || []
151
+ return {
152
+ siteConfig,
153
+ channels,
154
+ cryptos,
155
+ networks: defaultNetworks,
156
+ selectedChannel: channels[0],
157
+ selectedCrypto: cryptos[0],
158
+ selectedNetwork: defaultNetworks[0],
159
+ currentPayment,
160
+ }
161
+ }),
162
+ setChannel: assign((context, event) => {
163
+ const { cryptos } = context
164
+ const selectedCrypto = cryptos.find((crypto) => crypto.method === event.data.value)
165
+ const networks =
166
+ selectedCrypto?.networkName.map((value, i) => {
167
+ return {
168
+ label: selectedCrypto?.networkOptional?.[i],
169
+ value,
170
+ icon: value,
171
+ }
172
+ }) || []
173
+ return {
174
+ networks,
175
+ selectedChannel: event.data,
176
+ selectedCrypto: selectedCrypto,
177
+ selectedNetwork: networks[0],
178
+ amount: null,
179
+ calculation: null,
180
+ }
181
+ }),
182
+ setCrypto: assign((context, event) => {
183
+ const { cryptos, selectedNetwork } = context
184
+ const method = cryptos.find((crypto) => crypto.method === event.data.value)
185
+ const networks =
186
+ method?.networkName.map((value, i) => {
187
+ return {
188
+ label: method?.networkOptional?.[i],
189
+ value,
190
+ icon: value,
191
+ }
192
+ }) || []
193
+
194
+ const properties = {
195
+ selectedCrypto: event.data,
196
+ networks,
197
+ }
198
+
199
+ if (!networks.includes(selectedNetwork)) {
200
+ properties.selectedNetwork = null
201
+ properties.amount = null
202
+ properties.calculation = null
203
+ }
204
+
205
+ return properties
206
+ }),
207
+ setNetwork: assign((context, event) => {
208
+ return { selectedNetwork: event.data }
209
+ }),
210
+ setAmount: assign((context, event) => {
211
+ return {
212
+ amount: event.data,
213
+ }
214
+ }),
215
+ setAddress: assign((context, event) => {
216
+ return {
217
+ sourceAddress: event.data,
218
+ }
219
+ }),
220
+ setCalculation: assign((context, event) => {
221
+ return {
222
+ calculation: event.data,
223
+ }
224
+ }),
225
+ clearCalculation: assign((context, event) => {
226
+ return {
227
+ calculation: null,
228
+ }
229
+ }),
230
+ setResult: assign((context, event) => {
231
+ return {
232
+ result: event.data,
233
+ }
234
+ }),
235
+ },
236
+ guards: {
237
+ isDoubleWalletMode: (context, event) => {
238
+ return context.siteConfig?.walletMode === '4'
239
+ },
240
+ isCalculable: (context, event) => {
241
+ const {
242
+ selectedCrypto,
243
+ selectedNetwork,
244
+ amount,
245
+ currentPayment: { maximum, minimum },
246
+ } = context
247
+ return selectedCrypto && selectedNetwork && amount && minimum <= +amount && +amount <= maximum
248
+ },
249
+ isSubmittable: (context, event) => {
250
+ const { selectedCrypto, selectedNetwork, amount } = context
251
+ return selectedCrypto && selectedNetwork && amount
252
+ },
253
+ },
254
+ services: {
255
+ fetchInitData: async (context, event) => {
256
+ const [{ config }, paymentDetail = []] = await Promise.all([
257
+ request.send(common.getConfig({ appSecret })),
258
+ request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' })),
259
+ ])
260
+ const siteConfig = JSON.parse(window.atob(config))
261
+ return { siteConfig, paymentDetail }
262
+ },
263
+ fetchCalculation: async (context, event) => {
264
+ const { selectedCrypto, amount } = context
265
+ return await request.send(
266
+ payment.getDepositExpectedResult({
267
+ method: selectedCrypto.method,
268
+ amount,
269
+ cryptoCurrency: selectedCrypto.channel,
270
+ })
271
+ )
272
+ },
273
+ submitDeposit: async (context, event) => {
274
+ const { selectedCrypto, selectedNetwork, calculation, sourceAddress } = context
275
+ return await request.send(
276
+ payment.submitDepositTransactionCrypto({
277
+ method: selectedCrypto.method,
278
+ amount: calculation.actualAmount,
279
+ cryptoCurrency: selectedCrypto.channel,
280
+ cryptoNetwork: selectedNetwork.value,
281
+ sourceAddress: sourceAddress,
282
+ })
283
+ )
284
+ },
285
+ },
286
+ }
287
+ )
288
+ }