@jetthai/cuora 1.1.344-vipCardPro-3 → 1.1.345

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,11 +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.344-vipCardPro-3](https://github.com/jetthai/cuora-module/compare/v1.1.344-vipCardPro-2...v1.1.344-vipCardPro-3) (2025-03-25)
6
-
7
- ### [1.1.344-vipCardPro-2](https://github.com/jetthai/cuora-module/compare/v1.1.344-vipCardPro-1...v1.1.344-vipCardPro-2) (2025-03-24)
8
-
9
- ### [1.1.344-vipCardPro-1](https://github.com/jetthai/cuora-module/compare/v1.1.344...v1.1.344-vipCardPro-1) (2025-03-21)
5
+ ### [1.1.345](https://github.com/jetthai/cuora-module/compare/v1.1.344...v1.1.345) (2025-03-25)
10
6
 
11
7
  ### [1.1.344](https://github.com/jetthai/cuora-module/compare/v1.1.343-depositEvent-1...v1.1.344) (2025-03-18)
12
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.1.344-vipCardPro-3",
3
+ "version": "1.1.345",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
@@ -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
  )
@@ -2,8 +2,6 @@ import manual_vn from './manual_vn.js'
2
2
  import loadcard_vn from './loadcard_vn.js'
3
3
  import qrcode_v2 from './qrcode_v2.js'
4
4
  import deposit_fc from './deposit_fc.js'
5
- import crypto from './crypto.js'
6
- import crypto_button from './crypto_button.js'
7
5
  import direct from './direct.js'
8
6
  import amb from './amb.js'
9
7
  import float from './float.js'
@@ -13,7 +11,6 @@ import usdt from './usdt.js'
13
11
  import manual_cash from './manual_cash.js'
14
12
  import qrcode_cash from './qrcode_cash.js'
15
13
  import usdt_cash from './usdt_cash.js'
16
- import crypto_cash from './crypto_cash.js'
17
14
  import direct_cash from './direct_cash.js'
18
15
  import loadcard_cash from './loadcard_cash.js'
19
16
  import crypto_bank from './crypto_bank.js'
@@ -30,8 +27,6 @@ export default {
30
27
  loadcard_vn,
31
28
  qrcode_v2,
32
29
  deposit_fc,
33
- crypto,
34
- crypto_button,
35
30
  direct,
36
31
  amb,
37
32
  float,
@@ -41,7 +36,6 @@ export default {
41
36
  manual_cash,
42
37
  qrcode_cash,
43
38
  usdt_cash,
44
- crypto_cash,
45
39
  direct_cash,
46
40
  loadcard_cash,
47
41
  crypto_bank,
@@ -1,288 +0,0 @@
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
- }
@@ -1,432 +0,0 @@
1
- import { assign, createMachine } from 'xstate'
2
- import padStart from 'lodash/padStart.js'
3
- import payment from '../../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: 'crypro_button',
11
- initial: 'loading',
12
- context: {
13
- siteConfig: null,
14
- paymentDetails: [],
15
-
16
- channels: [],
17
- cryptos: [],
18
- networks: [],
19
- options: [],
20
- sourceAddress: '',
21
-
22
- selectedChannel: null,
23
- selectedAmount: null,
24
- selectedCrypto: null,
25
- selectedNetwork: null,
26
-
27
- currentCategory: 'crypto',
28
- currentPayment: null,
29
-
30
- calculation: null,
31
- result: null,
32
-
33
- grandTotalEnable: 1,
34
-
35
- // use for wallet mode 4
36
- promotion: null,
37
- bonusPreviewData: [],
38
- },
39
- states: {
40
- loading: {
41
- invoke: {
42
- src: 'fetchInitData',
43
- onDone: {
44
- target: 'loaded',
45
- actions: 'setInitData',
46
- },
47
- onError: {
48
- target: 'fail',
49
- },
50
- },
51
- },
52
- checking: {
53
- always: [
54
- {
55
- target: 'fetching',
56
- cond: (context, event) => {
57
- const { siteConfig = {}, promotion = {}, selectedCrypto } = context
58
- const { walletMode = '', bonusPreviewEnable } = siteConfig
59
- return !!selectedCrypto && walletMode === '4' && bonusPreviewEnable && promotion.activityNo != 'none'
60
- },
61
- },
62
- { target: 'loaded' },
63
- ],
64
- },
65
- fetching: {
66
- invoke: {
67
- src: 'fetchBonusPreview',
68
- onDone: {
69
- target: 'loaded',
70
- actions: 'setBonusPreview',
71
- },
72
- onError: {
73
- target: 'loaded',
74
- },
75
- },
76
- },
77
- loaded: {
78
- on: {
79
- SET_CHANNEL: {
80
- actions: 'setChannel',
81
- },
82
- SET_CRYPTO: {
83
- actions: 'setCrypto',
84
- },
85
- SET_NETWORK: {
86
- actions: 'setNetwork',
87
- },
88
- SET_ADDRESS: {
89
- actions: 'setAddress',
90
- },
91
- CONFIRM: {
92
- target: 'selecting',
93
- cond: 'isConfirmable',
94
- },
95
- },
96
- },
97
- fail: {},
98
- selecting: {
99
- entry: 'reset',
100
- on: {
101
- SELECT_AMOUNT: [
102
- {
103
- target: 'debouncing',
104
- actions: 'setAmount',
105
- cond: 'isDoubleWalletMode',
106
- },
107
- {
108
- actions: 'addAmount',
109
- cond: (context, event) => context.siteConfig?.walletMode === '2' && context.grandTotalEnable === 1,
110
- },
111
- {
112
- actions: 'setAmount',
113
- cond: 'isFreeWalletMode',
114
- },
115
- {
116
- target: 'debouncing',
117
- actions: 'addAmount',
118
- cond: 'isGrandTotalEnable',
119
- },
120
- {
121
- target: 'debouncing',
122
- actions: 'setAmount',
123
- },
124
- ],
125
- KEY_IN: [
126
- {
127
- actions: 'setAmount',
128
- cond: 'isFreeWalletMode',
129
- },
130
- {
131
- target: 'debouncing',
132
- actions: 'setAmount',
133
- },
134
- ],
135
- SUBMIT: {
136
- target: 'debouncing',
137
- },
138
- BACK: {
139
- target: 'loaded',
140
- },
141
- CLEAR_ALL: {
142
- actions: 'reset',
143
- },
144
- },
145
- },
146
- debouncing: {
147
- on: {
148
- SELECT_AMOUNT: [
149
- {
150
- target: 'debouncing',
151
- actions: 'addAmount',
152
- cond: 'isGrandTotalEnable',
153
- },
154
- {
155
- target: 'debouncing',
156
- actions: 'setAmount',
157
- },
158
- ],
159
- KEY_IN: {
160
- target: 'debouncing',
161
- actions: 'setAmount',
162
- },
163
- },
164
- after: {
165
- 1000: {
166
- target: 'calculating',
167
- },
168
- },
169
- },
170
- calculating: {
171
- invoke: {
172
- src: 'fetchCalculation',
173
- onDone: [
174
- {
175
- target: 'submitting',
176
- actions: 'setCalculation',
177
- cond: 'isFreeWalletMode',
178
- },
179
- {
180
- target: 'calculated',
181
- actions: 'setCalculation',
182
- },
183
- ],
184
- onError: {
185
- target: 'selecting',
186
- actions: 'reset',
187
- },
188
- },
189
- },
190
- calculated: {
191
- on: {
192
- SELECT_AMOUNT: [
193
- {
194
- target: 'debouncing',
195
- actions: 'addAmount',
196
- cond: 'isGrandTotalEnable',
197
- },
198
- {
199
- target: 'debouncing',
200
- actions: 'setAmount',
201
- },
202
- ],
203
- KEY_IN: {
204
- target: 'debouncing',
205
- actions: 'setAmount',
206
- },
207
- SUBMIT: {
208
- target: 'submitting',
209
- cond: 'isSubmittable',
210
- },
211
- CLEAR_CALCULATION: {
212
- target: 'debouncing',
213
- actions: 'clearCalculation',
214
- },
215
- CLEAR_ALL: {
216
- target: 'selecting',
217
- actions: 'reset',
218
- },
219
- },
220
- },
221
- submitting: {
222
- invoke: {
223
- src: 'submitDeposit',
224
- onDone: {
225
- target: 'submitted',
226
- actions: 'setResult',
227
- },
228
- onError: {
229
- target: 'loaded',
230
- },
231
- },
232
- },
233
- submitted: {},
234
- },
235
- on: {
236
- SET_PROMOTION: {
237
- actions: 'setPromotion',
238
- },
239
- },
240
- },
241
- {
242
- actions: {
243
- reset: assign((context, event) => {
244
- return {
245
- selectedAmount: null,
246
- calculation: null,
247
- result: null,
248
- }
249
- }),
250
- setInitData: assign((context, event) => {
251
- const { siteConfig, paymentDetail } = event.data
252
- const cryptos =
253
- paymentDetail
254
- ?.filter((element) => element.category === context.currentCategory)
255
- ?.map((crypto) => ({ ...crypto, label: crypto.channel, value: crypto.method, icon: crypto.channel })) || []
256
- const currentPayment = cryptos[0]
257
- const channels = cryptos.map((item, i) => ({ ...item, label: `Channel ${padStart(String(i + 1), 2, '0')}`, icon: 'channel' }))
258
- const defaultNetworks =
259
- cryptos[0].networkName.map((value, i) => {
260
- return {
261
- label: cryptos[0].networkOptional?.[i],
262
- value,
263
- icon: value,
264
- }
265
- }) || []
266
- const options = cryptos[0].optional
267
- return {
268
- siteConfig,
269
- channels,
270
- cryptos,
271
- networks: defaultNetworks,
272
- selectedChannel: channels[0],
273
- selectedCrypto: cryptos[0],
274
- selectedNetwork: defaultNetworks[0],
275
- grandTotalEnable: cryptos[0].grandTotalEnable,
276
- currentPayment,
277
- options,
278
- }
279
- }),
280
- setChannel: assign((context, event) => {
281
- const { cryptos } = context
282
- const selectedCrypto = cryptos.find((crypto) => crypto.method === event.data.value)
283
- const networks =
284
- selectedCrypto?.networkName.map((value, i) => {
285
- return {
286
- label: selectedCrypto?.networkOptional?.[i],
287
- value,
288
- icon: value,
289
- }
290
- }) || []
291
- const options = selectedCrypto.optional
292
- return {
293
- networks,
294
- selectedChannel: event.data,
295
- selectedCrypto: selectedCrypto,
296
- selectedNetwork: networks[0],
297
- selectedAmount: null,
298
- calculation: null,
299
- grandTotalEnable: selectedCrypto.grandTotalEnable,
300
- options,
301
- }
302
- }),
303
- setCrypto: assign((context, event) => {
304
- const { cryptos, selectedNetwork } = context
305
- const method = cryptos.find((crypto) => crypto.method === event.data.value)
306
- const networks =
307
- method?.networkName.map((value, i) => {
308
- return {
309
- label: method?.networkOptional?.[i],
310
- value,
311
- icon: value,
312
- }
313
- }) || []
314
- const properties = {
315
- selectedCrypto: event.data,
316
- networks,
317
- }
318
-
319
- if (!networks.includes(selectedNetwork)) {
320
- properties.selectedNetwork = null
321
- properties.selectedAmount = null
322
- properties.calculation = null
323
- }
324
-
325
- return properties
326
- }),
327
- setNetwork: assign((context, event) => {
328
- return { selectedNetwork: event.data }
329
- }),
330
- setBonusPreview: assign((context, event) => {
331
- return {
332
- bonusPreviewData: event.data,
333
- }
334
- }),
335
- addAmount: assign((context, event) => {
336
- return { selectedAmount: (context.selectedAmount || 0) + event.data }
337
- }),
338
- setAmount: assign((context, event) => {
339
- return { selectedAmount: event.data }
340
- }),
341
- setAddress: assign((context, event) => {
342
- return {
343
- sourceAddress: event.data,
344
- }
345
- }),
346
- setCalculation: assign((context, event) => {
347
- return {
348
- calculation: event.data,
349
- }
350
- }),
351
- clearCalculation: assign((context, event) => {
352
- return {
353
- calculation: null,
354
- }
355
- }),
356
- setResult: assign((context, event) => {
357
- return {
358
- result: event.data,
359
- }
360
- }),
361
- setPromotion: assign((context, event) => {
362
- const promotion = event.data
363
- return {
364
- promotion,
365
- }
366
- }),
367
- },
368
- guards: {
369
- isFreeWalletMode: (context, event) => {
370
- return context.siteConfig?.walletMode === '2'
371
- },
372
- isDoubleWalletMode: (context, event) => {
373
- return context.siteConfig?.walletMode === '4'
374
- },
375
- isGrandTotalEnable: (context, event) => {
376
- return context.grandTotalEnable === 1
377
- },
378
- isConfirmable: (context, event) => {
379
- const { selectedCrypto, selectedNetwork } = context
380
- return selectedCrypto && selectedNetwork
381
- },
382
- isSubmittable: (context, event) => {
383
- const { selectedCrypto, selectedNetwork, selectedAmount } = context
384
- return selectedCrypto && selectedNetwork && selectedAmount
385
- },
386
- },
387
- services: {
388
- fetchInitData: async (context, event) => {
389
- const [{ config }, paymentDetail = []] = await Promise.all([
390
- request.send(common.getConfig({ appSecret })),
391
- request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' })),
392
- ])
393
- const siteConfig = JSON.parse(window.atob(config))
394
- return { siteConfig, paymentDetail }
395
- },
396
- fetchBonusPreview: async (context, event) => {
397
- const { selectedCrypto, promotion } = context
398
- return await request.send(
399
- payment.getBonusPreview({
400
- method: selectedCrypto.method,
401
- promotionsNo: promotion?.activityNo,
402
- })
403
- )
404
- },
405
- fetchCalculation: async (context, event) => {
406
- const { selectedCrypto, selectedAmount, promotion } = context
407
- return await request.send(
408
- payment.getDepositExpectedResult({
409
- method: selectedCrypto.method,
410
- amount: selectedAmount,
411
- cryptoCurrency: selectedCrypto.channel,
412
- promotionsNo: promotion?.activityNo,
413
- })
414
- )
415
- },
416
- submitDeposit: async (context, event) => {
417
- const { selectedCrypto, selectedNetwork, calculation, sourceAddress, promotion } = context
418
- return await request.send(
419
- payment.submitDepositTransactionCrypto({
420
- method: selectedCrypto.method,
421
- amount: calculation.actualAmount,
422
- cryptoCurrency: selectedCrypto.channel,
423
- cryptoNetwork: selectedNetwork.value,
424
- sourceAddress: sourceAddress,
425
- promotionsNo: promotion?.activityNo,
426
- })
427
- )
428
- },
429
- },
430
- }
431
- )
432
- }
@@ -1,255 +0,0 @@
1
- import { assign, createMachine } from 'xstate'
2
- import payment from '@jetthai/cuora/src/api/payment.js'
3
- import { max } from '../../util/index.js'
4
-
5
- export default function (request, context) {
6
- const { paymentDetail = [], promotion, selectedAmount } = context || {}
7
- return createMachine(
8
- {
9
- id: 'crypto_cash',
10
- initial: 'loading',
11
- context: {
12
- paymentDetail,
13
- promotion,
14
- selectedAmount,
15
-
16
- cryptos: [],
17
- networks: [],
18
- sourceAddress: '',
19
- options: [],
20
-
21
- selectedCrypto: null,
22
- selectedNetwork: null,
23
-
24
- currentCategory: 'crypto',
25
-
26
- calculation: null,
27
- result: null,
28
- },
29
- states: {
30
- loading: {
31
- always: [
32
- {
33
- target: 'debouncing',
34
- actions: 'setInitData',
35
- },
36
- ],
37
- },
38
- loaded: {},
39
- debouncing: {
40
- entry: 'clearCalculation',
41
- after: {
42
- 1000: [
43
- {
44
- target: 'calculating',
45
- cond: 'isCalculable',
46
- },
47
- {
48
- target: 'loaded',
49
- },
50
- ],
51
- },
52
- },
53
- calculating: {
54
- invoke: {
55
- src: 'fetchCalculation',
56
- onDone: {
57
- target: 'calculated',
58
- actions: 'setCalculation',
59
- },
60
- onError: {
61
- target: 'calculated',
62
- },
63
- },
64
- },
65
- calculated: {
66
- on: {
67
- SUBMIT: [
68
- {
69
- target: 'submitting',
70
- cond: 'isSubmittable',
71
- },
72
- ],
73
- },
74
- },
75
- submitting: {
76
- invoke: {
77
- src: 'submitDeposit',
78
- onDone: {
79
- target: 'submitted',
80
- actions: 'setResult',
81
- },
82
- onError: {
83
- target: 'loaded',
84
- },
85
- },
86
- },
87
- submitted: {},
88
- },
89
- on: {
90
- SET_PROMOTION: {
91
- target: '.debouncing',
92
- actions: 'setPromotion',
93
- internal: false,
94
- },
95
- SET_CRYPTO: {
96
- target: '.debouncing',
97
- actions: 'setCrypto',
98
- internal: false,
99
- },
100
- SET_NETWORK: {
101
- target: '.debouncing',
102
- actions: 'setNetwork',
103
- internal: false,
104
- },
105
- SET_ADDRESS: {
106
- actions: 'setAddress',
107
- internal: false,
108
- },
109
- SET_AMOUNT: {
110
- target: '.debouncing',
111
- actions: 'setAmount',
112
- internal: false,
113
- },
114
- INPUT_AMOUNT: {
115
- target: '.debouncing',
116
- actions: 'inputAmount',
117
- internal: false,
118
- },
119
- },
120
- },
121
- {
122
- actions: {
123
- setInitData: assign((context, event) => {
124
- const { paymentDetail } = context
125
- const cryptos = paymentDetail
126
- .filter((element) => element.transferType === 'deposit' && element.category === context.currentCategory)
127
- .map((crypto) => ({
128
- ...crypto,
129
- label: crypto.channel,
130
- value: crypto.method,
131
- icon: crypto.channel,
132
- }))
133
- const defaultNetworks = cryptos[0].networkName.map((value, i) => {
134
- return {
135
- label: cryptos[0].networkOptional?.[i],
136
- value,
137
- icon: value,
138
- }
139
- })
140
- return {
141
- cryptos,
142
- networks: defaultNetworks,
143
- selectedCrypto: cryptos[0],
144
- selectedNetwork: defaultNetworks[0],
145
- options: cryptos[0].optional,
146
- }
147
- }),
148
- setCrypto: assign((context, event) => {
149
- const { cryptos } = context
150
- const selectedCrypto = cryptos.find((crypto) => crypto.method === event.data.value)
151
- const networks = selectedCrypto?.networkName.map((value, i) => {
152
- return {
153
- label: selectedCrypto?.networkOptional?.[i],
154
- value,
155
- icon: value,
156
- }
157
- })
158
- return {
159
- networks,
160
- selectedCrypto: selectedCrypto,
161
- selectedNetwork: networks[0],
162
- selectedAmount: null,
163
- calculation: null,
164
- options: selectedCrypto.optional,
165
- }
166
- }),
167
- setNetwork: assign((context, event) => {
168
- return { selectedNetwork: event.data }
169
- }),
170
- setAmount: assign((context, event) => {
171
- // 現金網可自由填額度,grandTotalEnable 欄位感覺不再需要?
172
- if (context.selectedCrypto?.grandTotalEnable === 1) {
173
- return { selectedAmount: parseFloat(context.selectedAmount || 0) + parseFloat(event.data) }
174
- } else {
175
- return { selectedAmount: event.data }
176
- }
177
- }),
178
- inputAmount: assign((context, event) => {
179
- return { selectedAmount: event.data }
180
- }),
181
- setAddress: assign((context, event) => {
182
- return {
183
- sourceAddress: event.data,
184
- }
185
- }),
186
- setCalculation: assign((context, event) => {
187
- return {
188
- calculation: event.data,
189
- }
190
- }),
191
- clearCalculation: assign((context, event) => {
192
- return {
193
- calculation: null,
194
- }
195
- }),
196
- setResult: assign((context, event) => {
197
- return {
198
- result: event.data,
199
- }
200
- }),
201
- setPromotion: assign((context, event) => {
202
- const { selectedCrypto, selectedAmount } = context
203
- const promotion = event.data
204
- return {
205
- promotion,
206
- selectedAmount: max(promotion.minimumAmount, selectedCrypto.minimum, selectedAmount, 0),
207
- calculation: null,
208
- }
209
- }),
210
- },
211
- guards: {
212
- isCalculable: (context, event) => {
213
- const { selectedCrypto, selectedNetwork, selectedAmount } = context
214
- return (
215
- selectedCrypto &&
216
- selectedNetwork &&
217
- selectedAmount &&
218
- selectedCrypto.minimum <= +selectedAmount &&
219
- +selectedAmount <= selectedCrypto.maximum
220
- )
221
- },
222
- isSubmittable: (context, event) => {
223
- const { selectedCrypto, selectedNetwork, selectedAmount } = context
224
- return selectedCrypto && selectedNetwork && selectedAmount
225
- },
226
- },
227
- services: {
228
- fetchCalculation: async (context, event) => {
229
- const { selectedCrypto, selectedAmount, promotion } = context
230
- return await request.send(
231
- payment.getDepositExpectedResult({
232
- method: selectedCrypto.method,
233
- amount: selectedAmount,
234
- cryptoCurrency: selectedCrypto.channel,
235
- promotionsNo: promotion?.promotionsNo,
236
- })
237
- )
238
- },
239
- submitDeposit: async (context, event) => {
240
- const { selectedCrypto, selectedNetwork, calculation, sourceAddress, promotion } = context
241
- return await request.send(
242
- payment.submitDepositTransactionCrypto({
243
- method: selectedCrypto.method,
244
- amount: calculation.actualAmount,
245
- cryptoCurrency: selectedCrypto.channel,
246
- cryptoNetwork: selectedNetwork.value,
247
- sourceAddress: sourceAddress,
248
- promotionsNo: promotion?.promotionsNo,
249
- })
250
- )
251
- },
252
- },
253
- }
254
- )
255
- }