@jetthai/cuora 1.1.83-cash → 1.1.83

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.
@@ -22,8 +22,8 @@ export default class Request {
22
22
  this.axios.interceptors.request.use((axiosConfig) => {
23
23
  axiosConfig.headers['X-TH1GAMES-VERSION'] = this.config.version
24
24
  axiosConfig.headers['X-TH1GAMES-PLATFORM'] = this.config.platform
25
- if (this.getToken()) {
26
- axiosConfig.headers.Authorization = this.getToken()
25
+ if (storage.get(this.key)) {
26
+ axiosConfig.headers.Authorization = storage.get(this.key)
27
27
  }
28
28
  return axiosConfig
29
29
  })
@@ -51,7 +51,7 @@ export default class Request {
51
51
  async send(req, customToken) {
52
52
  try {
53
53
  const cancelToken = customToken || this.source.token
54
- this._checkToken(req)
54
+ this._checkToken(req, storage.get(this.key))
55
55
  const requestConfig = this._createConfig(req, cancelToken)
56
56
  const { data } = await this.axios.request(requestConfig)
57
57
  return data
@@ -97,14 +97,10 @@ export default class Request {
97
97
  }
98
98
  }
99
99
 
100
- _checkToken(req) {
101
- if (!req.isPublic && !this.getToken()) {
100
+ _checkToken(req, token) {
101
+ if (!req.isPublic && !token) {
102
102
  console.error(req)
103
103
  throw { code: 'ERR_A103', url: req.url }
104
104
  }
105
105
  }
106
-
107
- getToken() {
108
- return storage.get(this.key)
109
- }
110
106
  }
package/src/util/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { getDeviceToken } from './deviceToken.js'
2
2
  import storage from './storage.js'
3
3
  import * as constant from './constant.js'
4
- import { max } from './math.js'
5
4
 
6
5
  export default { getDeviceToken }
7
- export { constant, storage, max }
6
+ export { constant, storage }
@@ -1,215 +0,0 @@
1
- import { assign, createMachine } from 'xstate'
2
- import api from '../../api/activity.js'
3
-
4
- export default function (request) {
5
- const { appSecret } = request.config
6
- return createMachine(
7
- {
8
- id: 'diamond_shop_activity',
9
- context: {
10
- activityNo: null,
11
- activityDetail: null,
12
- awards: [],
13
- exchangeList: [],
14
- exchangeAward: 0,
15
- exchangePoint: 0,
16
- remainingPoints: 0,
17
- receiveRewards: [],
18
- unclaimedRewardList: [],
19
- },
20
- initial: 'fetching',
21
- states: {
22
- fetching: {
23
- invoke: {
24
- src: 'fetchActivityList',
25
- onDone: {
26
- target: 'checking',
27
- actions: 'setDiamondShopActivities',
28
- },
29
- onError: {
30
- target: 'idle',
31
- },
32
- },
33
- },
34
- idle: {},
35
- checking: {
36
- always: [{ target: 'loading', cond: 'hasActivityNo' }],
37
- },
38
- loading: {
39
- invoke: {
40
- src: 'fetchActivityDetail',
41
- onDone: {
42
- target: 'loaded',
43
- actions: ['setActivityDetail', 'setAwardList', 'setUnclaimedReward'],
44
- },
45
- onError: {
46
- target: 'idle',
47
- },
48
- },
49
- },
50
- loaded: {
51
- on: {
52
- EXCHANGE: {
53
- target: 'exchanging',
54
- },
55
- SELECT: {
56
- actions: ['selectProduct', 'count'],
57
- },
58
- // ADD_TO_CART: {
59
- // actions: ['addProduct', 'count'],
60
- // },
61
- // CLEAR_CART: {
62
- // actions: ['clearCart', 'count'],
63
- // },
64
- // COLLECT: {
65
- // target: 'collecting',
66
- // cond: 'hasUnclaimedReward',
67
- // },
68
- },
69
- },
70
- exchanging: {
71
- invoke: {
72
- src: 'exchange',
73
- onDone: {
74
- target: 'collecting',
75
- actions: ['setExchangedData', 'setUnclaimedReward'],
76
- },
77
- onError: {
78
- target: 'loaded',
79
- },
80
- },
81
- },
82
- collecting: {
83
- invoke: {
84
- src: 'collect',
85
- onDone: {
86
- target: 'collected',
87
- actions: 'clearExchangedData',
88
- },
89
- onError: {
90
- target: 'collected',
91
- },
92
- },
93
- },
94
- collected: {
95
- after: {
96
- 0: {
97
- target: 'loaded',
98
- },
99
- },
100
- },
101
- },
102
- },
103
- {
104
- actions: {
105
- setActivityNo: assign((context, event) => {
106
- return {
107
- activityNo: event.data,
108
- }
109
- }),
110
- setDiamondShopActivities: assign((context, event) => {
111
- const rankActivities = event.data.filter((item) => item.activityType === 91)
112
- return {
113
- rankActivities,
114
- activityNo: rankActivities?.[0]?.activityNo,
115
- }
116
- }),
117
- setActivityDetail: assign((context, event) => {
118
- return {
119
- activityDetail: event.data,
120
- }
121
- }),
122
- setAwardList: assign((context, event) => {
123
- return {
124
- awardList: event.data?.awards || [],
125
- }
126
- }),
127
- setExchangedData: assign((context, event) => {
128
- return {
129
- remainingPoints: event.data?.data?.points,
130
- receiveRewards: event.data?.date?.receiveRewards,
131
- }
132
- }),
133
- setUnclaimedReward: assign((context, event) => {
134
- return {
135
- unclaimedRewardList: event.data?.unclaimedReward || event.data?.data?.unclaimedReward || [],
136
- }
137
- }),
138
- clearExchangedData: assign((context, event) => {
139
- return {
140
- remainingPoints: null,
141
- receiveRewards: [],
142
- unclaimedRewardList: [],
143
- }
144
- }),
145
- selectProduct: assign((context, event) => {
146
- return {
147
- exchangeList: [event.data],
148
- }
149
- }),
150
- addProduct: assign((context, event) => {
151
- return {
152
- exchangeList: [...context.exchangeList, event.data],
153
- }
154
- }),
155
- clearCart: assign((context, event) => {
156
- return {
157
- exchangeList: [],
158
- }
159
- }),
160
- count: assign((context, event) => {
161
- const { exchangeList } = context
162
- const { exchangeAward, exchangePoint } = exchangeList.reduce(
163
- ({ exchangeAward, exchangePoint }, item) => {
164
- return {
165
- exchangeAward: exchangeAward + item.award,
166
- exchangePoint: exchangePoint + item.points,
167
- }
168
- },
169
- { exchangeAward: 0, exchangePoint: 0 }
170
- )
171
- return {
172
- exchangeAward,
173
- exchangePoint,
174
- }
175
- }),
176
- },
177
- guards: {
178
- hasUnclaimedReward: (context, event) => {
179
- return context.unclaimedRewardList.length > 0
180
- },
181
- isExchangeable: (context, event) => {
182
- const { exchangeList } = context
183
- return exchangeList.length > 0
184
- },
185
- hasActivityNo: (context, event) => {
186
- return !!context.activityNo
187
- },
188
- },
189
- services: {
190
- fetchActivityList: async (context, event) => {
191
- const { data } = await request.send(api.getActivityList({ appSecret }))
192
- return data
193
- },
194
- fetchActivityDetail: async (context, event) => {
195
- const { activityNo } = context
196
- const { data } = await request.send(api.getActivityDetail({ activityNo, appSecret }))
197
- return data
198
- },
199
- exchange: async (context, event) => {
200
- const { activityNo } = context
201
- return await request.send(
202
- api.exchange({
203
- exchangeType: 1,
204
- activityNo,
205
- exchangeAward: event.data,
206
- })
207
- )
208
- },
209
- collect: async (context, event) => {
210
- return await request.send(api.collect({ appSecret }))
211
- },
212
- },
213
- }
214
- )
215
- }
@@ -1,280 +0,0 @@
1
- import { assign, createMachine } from 'xstate'
2
- import payment from '../../api/payment.js'
3
- import common from '../../api/common.js'
4
- import { max } from '../../util'
5
-
6
- export default function (request, context) {
7
- const { appSecret } = request.config
8
- const { promotion, selectedAmount } = context || {}
9
- return createMachine(
10
- {
11
- id: 'qrcode_v_cash',
12
- initial: 'loading',
13
- context: {
14
- siteConfig: null,
15
- qrcodes: null,
16
- options: null,
17
-
18
- selectedQrcode: null,
19
- selectedAmount,
20
-
21
- calculation: null,
22
-
23
- paymentDetail: [],
24
- currentCategory: 'qrcode',
25
-
26
- result: null,
27
-
28
- promotion,
29
- bonusPreviewData: [],
30
- },
31
- states: {
32
- loading: {
33
- invoke: {
34
- src: 'fetchInitData',
35
- onDone: {
36
- target: 'loaded',
37
- actions: 'setInitData',
38
- },
39
- onError: {
40
- target: 'fail',
41
- },
42
- },
43
- },
44
- fail: {},
45
- loaded: {
46
- on: {
47
- SET_PROMOTION: {
48
- target: 'debouncing',
49
- actions: 'setPromotion',
50
- },
51
- SELECT_QRCODE: {
52
- target: 'debouncing',
53
- actions: 'setQrcode',
54
- },
55
- SELECT_AMOUNT: {
56
- target: 'debouncing',
57
- actions: 'setAmount',
58
- },
59
- INPUT_AMOUNT: {
60
- target: 'debouncing',
61
- actions: 'inputAmount',
62
- },
63
- },
64
- },
65
- debouncing: {
66
- on: {
67
- SET_PROMOTION: {
68
- target: 'debouncing',
69
- actions: 'setPromotion',
70
- },
71
- SELECT_QRCODE: {
72
- target: 'debouncing',
73
- actions: 'setQrcode',
74
- },
75
- SELECT_AMOUNT: {
76
- target: 'debouncing',
77
- actions: 'setAmount',
78
- },
79
- INPUT_AMOUNT: {
80
- target: 'debouncing',
81
- actions: 'inputAmount',
82
- },
83
- },
84
- after: {
85
- 1000: [
86
- {
87
- target: 'calculating',
88
- cond: (context, event) => {
89
- const { selectedQrcode, selectedAmount } = context
90
- if (selectedQrcode && selectedAmount) {
91
- return selectedQrcode.minimum <= selectedAmount && selectedAmount <= selectedQrcode.maximum
92
- } else {
93
- return false
94
- }
95
- },
96
- },
97
- {
98
- target: 'loaded',
99
- },
100
- ],
101
- },
102
- },
103
- calculating: {
104
- invoke: {
105
- src: 'fetchCalculation',
106
- onDone: {
107
- target: 'calculated',
108
- actions: 'setCalculation',
109
- },
110
- onError: {
111
- target: 'calculated',
112
- },
113
- },
114
- },
115
- calculated: {
116
- on: {
117
- SET_PROMOTION: {
118
- target: 'debouncing',
119
- actions: 'setPromotion',
120
- },
121
- SELECT_QRCODE: {
122
- target: 'debouncing',
123
- actions: 'setQrcode',
124
- },
125
- SELECT_AMOUNT: {
126
- target: 'debouncing',
127
- actions: 'setAmount',
128
- },
129
- INPUT_AMOUNT: {
130
- target: 'debouncing',
131
- actions: 'inputAmount',
132
- },
133
- CONFIRM: {
134
- target: 'submitting',
135
- },
136
- },
137
- },
138
- submitting: {
139
- invoke: {
140
- src: 'submitDeposit',
141
- onDone: {
142
- target: 'submitted',
143
- actions: 'setResult',
144
- },
145
- onError: {
146
- target: 'calculated',
147
- },
148
- },
149
- },
150
- submitted: {},
151
- },
152
- },
153
- {
154
- actions: {
155
- setInitData: assign((context, event) => {
156
- const { selectedAmount } = context
157
- const { siteConfig, paymentDetail } = event.data
158
- const qrcodes = paymentDetail
159
- .filter((element) => element.category === context.currentCategory)
160
- .map((qrcode) => {
161
- qrcode.disabled = promotion?.promotionsNo !== 'none' && qrcode.charge > 0
162
- return qrcode
163
- })
164
-
165
- const selectedQrcode = qrcodes.find((qrcode) => !qrcode.disabled)
166
-
167
- return {
168
- siteConfig,
169
- paymentDetail,
170
- promotion,
171
- qrcodes,
172
- selectedQrcode,
173
- options: selectedQrcode?.optional,
174
- selectedAmount: max(promotion?.minimumAmount, selectedQrcode?.minimum, selectedAmount, 0),
175
- }
176
- }),
177
- setBonusPreview: assign((context, event) => {
178
- return {
179
- bonusPreviewData: event.data.bonus,
180
- }
181
- }),
182
- setPromotion: assign((context, event) => {
183
- const { selectedAmount } = context
184
- const promotion = event.data
185
- const qrcodes = context.qrcodes.map((qrcode) => {
186
- qrcode.disabled = promotion.promotionsNo !== 'none' && qrcode.charge > 0
187
- return qrcode
188
- })
189
-
190
- const selectedQrcode = qrcodes.find((qrcode) => !qrcode.disabled)
191
-
192
- return {
193
- promotion,
194
- qrcodes,
195
- selectedQrcode,
196
- options: selectedQrcode?.optional,
197
- selectedAmount: max(promotion.minimumAmount, selectedQrcode?.minimum, selectedAmount, 0),
198
- calculation: null,
199
- }
200
- }),
201
- setQrcode: assign((context, event) => {
202
- const { promotion, selectedAmount } = context
203
- const selectedQrcode = event.data
204
- return {
205
- selectedQrcode,
206
- options: selectedQrcode.optional,
207
- selectedAmount: max(promotion.minimumAmount, selectedAmount, 0),
208
- calculation: null,
209
- }
210
- }),
211
- setAmount: assign((context, event) => {
212
- // 現金網可自由填額度,grandTotalEnable 欄位感覺不再需要?
213
- if (context.selectedQrcode?.grandTotalEnable === 1) {
214
- return { selectedAmount: parseFloat(context.selectedAmount || 0) + parseFloat(event.data) }
215
- } else {
216
- return { selectedAmount: event.data }
217
- }
218
- }),
219
- inputAmount: assign((context, event) => {
220
- return { selectedAmount: event.data }
221
- }),
222
- setCalculation: assign((context, event) => {
223
- return {
224
- calculation: event.data,
225
- }
226
- }),
227
- clearCalculation: assign((context, event) => {
228
- return {
229
- calculation: null,
230
- }
231
- }),
232
- setResult: assign((context, event) => {
233
- return {
234
- result: event.data,
235
- }
236
- }),
237
- },
238
- guards: {},
239
- services: {
240
- fetchInitData: async (context, event) => {
241
- const [{ config }, paymentDetail = [], promotions] = await Promise.all([
242
- request.send(common.getConfig({ appSecret })),
243
- request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' })),
244
- ])
245
- const siteConfig = JSON.parse(window.atob(config))
246
- return { siteConfig, paymentDetail }
247
- },
248
- fetchBonusPreview: async (context, event) => {
249
- const { selectedQrcode, promotion } = context
250
- return await request.send(
251
- payment.getBonusPreview({
252
- method: selectedQrcode.method,
253
- promotionsNo: promotion?.promotionsNo,
254
- })
255
- )
256
- },
257
- fetchCalculation: async (context, event) => {
258
- const { selectedQrcode, selectedAmount, promotion } = context
259
- return await request.send(
260
- payment.getDepositExpectedResult({
261
- method: selectedQrcode.method,
262
- amount: selectedAmount,
263
- promotionsNo: promotion?.promotionsNo,
264
- })
265
- )
266
- },
267
- submitDeposit: async (context, event) => {
268
- const { selectedQrcode, selectedAmount, promotion } = context
269
- return await request.send(
270
- payment.submitDepositTransaction({
271
- method: selectedQrcode.method,
272
- amount: selectedAmount,
273
- promotionsNo: promotion?.promotionsNo,
274
- })
275
- )
276
- },
277
- },
278
- }
279
- )
280
- }