@jetthai/cuora 1.1.174 → 1.1.176

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,6 +2,10 @@
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.176](https://github.com/jetthai/cuora-module/compare/v1.1.175...v1.1.176) (2023-09-19)
6
+
7
+ ### [1.1.175](https://github.com/jetthai/cuora-module/compare/v1.1.174...v1.1.175) (2023-09-18)
8
+
5
9
  ### [1.1.174](https://github.com/jetthai/cuora-module/compare/v1.1.173...v1.1.174) (2023-09-08)
6
10
 
7
11
  ### [1.1.173](https://github.com/jetthai/cuora-module/compare/v1.1.172...v1.1.173) (2023-09-07)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.1.174",
3
+ "version": "1.1.176",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
@@ -0,0 +1,154 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import payment from '@jetthai/cuora/src/api/payment.js'
3
+
4
+ export default function (request) {
5
+ return createMachine(
6
+ {
7
+ id: 'crypto_qrcode',
8
+ initial: 'loading',
9
+ context: {
10
+ currentCategory: 'cryptoQrcode',
11
+ currentPayment: null,
12
+ cryptos: [],
13
+ networks: [],
14
+ selectedCrypto: null,
15
+ selectedNetwork: null,
16
+ resultMap: {},
17
+ result: {},
18
+ },
19
+ states: {
20
+ loading: {
21
+ invoke: {
22
+ src: 'fetchPaymentDetail',
23
+ onDone: {
24
+ target: 'submitting',
25
+ actions: 'setInitData',
26
+ },
27
+ onError: {
28
+ target: 'fail',
29
+ },
30
+ },
31
+ },
32
+ finding: {
33
+ always: [
34
+ {
35
+ target: 'idle',
36
+ actions: 'setResultFromLocal',
37
+ cond: 'isFound',
38
+ },
39
+ {
40
+ target: 'submitting',
41
+ },
42
+ ],
43
+ },
44
+ submitting: {
45
+ invoke: {
46
+ src: 'submitDeposit',
47
+ onDone: {
48
+ target: 'idle',
49
+ actions: 'setResult',
50
+ },
51
+ onError: {
52
+ target: 'idle',
53
+ },
54
+ },
55
+ },
56
+ idle: {},
57
+ fail: {},
58
+ },
59
+ on: {
60
+ SET_CRYPTO: {
61
+ target: '.finding',
62
+ actions: 'setCrypto',
63
+ },
64
+ SET_NETWORK: {
65
+ target: '.finding',
66
+ actions: 'setNetwork',
67
+ },
68
+ },
69
+ },
70
+ {
71
+ actions: {
72
+ setInitData: assign((context, event) => {
73
+ const paymentDetail = event.data || []
74
+ const payments = paymentDetail.filter((item) => item.category === context.currentCategory)
75
+ const currentPayment = payments[0]
76
+ const cryptos = payments.map((payment) => ({ ...payment, label: payment.channel, value: payment.method, icon: payment.channel }))
77
+ const networks = currentPayment?.networkName.map((value, i) => {
78
+ return {
79
+ label: currentPayment.networkOptional?.[i],
80
+ value,
81
+ icon: value,
82
+ }
83
+ })
84
+
85
+ return {
86
+ cryptos,
87
+ networks,
88
+ selectedCrypto: cryptos[0],
89
+ selectedNetwork: networks[0],
90
+ currentPayment,
91
+ }
92
+ }),
93
+ setCrypto: assign((context, event) => {
94
+ const { cryptos } = context
95
+ const selectedCrypto = cryptos.find((crypto) => crypto.channel === event.data.channel)
96
+ const networks =
97
+ selectedCrypto?.networkName.map((value, i) => {
98
+ return {
99
+ label: selectedCrypto?.networkOptional?.[i],
100
+ value,
101
+ icon: value,
102
+ }
103
+ }) || []
104
+ return {
105
+ networks,
106
+ selectedCrypto,
107
+ selectedNetwork: networks[0],
108
+ }
109
+ }),
110
+ setNetwork: assign((context, event) => {
111
+ return { selectedNetwork: event.data }
112
+ }),
113
+ setResultFromLocal: assign((context, event) => {
114
+ const { resultMap, selectedCrypto, selectedNetwork } = context
115
+ return { result: resultMap[`${selectedCrypto.value}_${selectedNetwork.value}`] }
116
+ }),
117
+ setResult: assign((context, event) => {
118
+ const { resultMap, selectedCrypto, selectedNetwork } = context
119
+ const { accountNumber, currency, network, qrcode, forexRate } = event.data
120
+ const result = { accountNumber, currency, network, qrcode, forexRate }
121
+
122
+ return {
123
+ result,
124
+ resultMap: {
125
+ ...resultMap,
126
+ [`${selectedCrypto.value}_${selectedNetwork.value}`]: result,
127
+ },
128
+ }
129
+ }),
130
+ },
131
+ guards: {
132
+ isFound: (context, event) => {
133
+ const { resultMap, selectedCrypto, selectedNetwork } = context
134
+ return resultMap[`${selectedCrypto.value}_${selectedNetwork.value}`]
135
+ },
136
+ },
137
+ services: {
138
+ fetchPaymentDetail: async (context, event) => {
139
+ return await request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' }))
140
+ },
141
+ submitDeposit: async (context, event) => {
142
+ const { currentPayment, selectedNetwork } = context
143
+ return await request.send(
144
+ payment.submitDepositTransactionCrypto({
145
+ method: currentPayment.method,
146
+ cryptoCurrency: currentPayment.channel,
147
+ cryptoNetwork: selectedNetwork.value,
148
+ })
149
+ )
150
+ },
151
+ },
152
+ }
153
+ )
154
+ }
@@ -0,0 +1,275 @@
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_way_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: 'cryptoWay',
25
+
26
+ calculation: null,
27
+ result: null,
28
+ ttl: 0,
29
+ },
30
+ states: {
31
+ loading: {
32
+ always: [
33
+ {
34
+ target: 'debouncing',
35
+ actions: 'setInitData',
36
+ },
37
+ ],
38
+ },
39
+ loaded: {},
40
+ debouncing: {
41
+ entry: 'clearCalculation',
42
+ after: {
43
+ 1000: [
44
+ {
45
+ target: 'calculating',
46
+ cond: 'isCalculable',
47
+ },
48
+ {
49
+ target: 'loaded',
50
+ },
51
+ ],
52
+ },
53
+ },
54
+ calculating: {
55
+ invoke: {
56
+ src: 'fetchCalculation',
57
+ onDone: {
58
+ target: 'calculated',
59
+ actions: 'setCalculation',
60
+ },
61
+ onError: {
62
+ target: 'calculated',
63
+ },
64
+ },
65
+ },
66
+ calculated: {
67
+ on: {
68
+ SUBMIT: [
69
+ {
70
+ target: 'submitting',
71
+ cond: 'isSubmittable',
72
+ },
73
+ ],
74
+ },
75
+ },
76
+ submitting: {
77
+ invoke: {
78
+ src: 'submitDeposit',
79
+ onDone: {
80
+ target: 'submitted',
81
+ actions: ['setResult', 'setTtl'],
82
+ },
83
+ onError: {
84
+ target: 'loaded',
85
+ },
86
+ },
87
+ },
88
+ submitted: {
89
+ after: {
90
+ 1000: {
91
+ target: 'submitted',
92
+ actions: 'decreaseTtl',
93
+ cond: (context) => context.ttl > 0,
94
+ },
95
+ },
96
+ },
97
+ },
98
+ on: {
99
+ SET_PROMOTION: {
100
+ target: '.debouncing',
101
+ actions: 'setPromotion',
102
+ internal: false,
103
+ },
104
+ SET_CRYPTO: {
105
+ target: '.debouncing',
106
+ actions: 'setCrypto',
107
+ internal: false,
108
+ },
109
+ SET_NETWORK: {
110
+ target: '.debouncing',
111
+ actions: 'setNetwork',
112
+ internal: false,
113
+ },
114
+ SET_ADDRESS: {
115
+ actions: 'setAddress',
116
+ internal: false,
117
+ },
118
+ SET_AMOUNT: {
119
+ target: '.debouncing',
120
+ actions: 'setAmount',
121
+ internal: false,
122
+ },
123
+ INPUT_AMOUNT: {
124
+ target: '.debouncing',
125
+ actions: 'inputAmount',
126
+ internal: false,
127
+ },
128
+ },
129
+ },
130
+ {
131
+ actions: {
132
+ setInitData: assign((context, event) => {
133
+ const { paymentDetail } = context
134
+ const cryptos = paymentDetail
135
+ .filter((element) => element.transferType === 'deposit' && element.category === context.currentCategory)
136
+ .map((crypto) => ({
137
+ ...crypto,
138
+ label: crypto.channel,
139
+ value: crypto.method,
140
+ icon: crypto.channel,
141
+ }))
142
+ const defaultNetworks = cryptos[0].networkName.map((value, i) => {
143
+ return {
144
+ label: cryptos[0].networkOptional?.[i],
145
+ value,
146
+ icon: value,
147
+ }
148
+ })
149
+ return {
150
+ cryptos,
151
+ networks: defaultNetworks,
152
+ selectedCrypto: cryptos[0],
153
+ selectedNetwork: defaultNetworks[0],
154
+ options: cryptos[0].optional,
155
+ }
156
+ }),
157
+ setCrypto: assign((context, event) => {
158
+ const { cryptos } = context
159
+ const selectedCrypto = cryptos.find((crypto) => crypto.method === event.data.value)
160
+ const networks = selectedCrypto?.networkName.map((value, i) => {
161
+ return {
162
+ label: selectedCrypto?.networkOptional?.[i],
163
+ value,
164
+ icon: value,
165
+ }
166
+ })
167
+ return {
168
+ networks,
169
+ selectedCrypto: selectedCrypto,
170
+ selectedNetwork: networks[0],
171
+ selectedAmount: null,
172
+ calculation: null,
173
+ options: selectedCrypto.optional,
174
+ }
175
+ }),
176
+ setNetwork: assign((context, event) => {
177
+ return { selectedNetwork: event.data }
178
+ }),
179
+ setAmount: assign((context, event) => {
180
+ // 現金網可自由填額度,grandTotalEnable 欄位感覺不再需要?
181
+ if (context.selectedCrypto?.grandTotalEnable === 1) {
182
+ return { selectedAmount: parseFloat(context.selectedAmount || 0) + parseFloat(event.data) }
183
+ } else {
184
+ return { selectedAmount: event.data }
185
+ }
186
+ }),
187
+ inputAmount: assign((context, event) => {
188
+ return { selectedAmount: event.data }
189
+ }),
190
+ setAddress: assign((context, event) => {
191
+ return {
192
+ sourceAddress: event.data,
193
+ }
194
+ }),
195
+ setCalculation: assign((context, event) => {
196
+ return {
197
+ calculation: event.data,
198
+ }
199
+ }),
200
+ clearCalculation: assign((context, event) => {
201
+ return {
202
+ calculation: null,
203
+ }
204
+ }),
205
+ setResult: assign((context, event) => {
206
+ return {
207
+ result: event.data,
208
+ }
209
+ }),
210
+ setPromotion: assign((context, event) => {
211
+ const { selectedCrypto, selectedAmount } = context
212
+ const promotion = event.data
213
+ return {
214
+ promotion,
215
+ selectedAmount: max(promotion.minimumAmount, selectedCrypto.minimum, selectedAmount, 0),
216
+ calculation: null,
217
+ }
218
+ }),
219
+ setTtl: assign((context, event) => {
220
+ const { cdtime } = event.data
221
+ return {
222
+ ttl: cdtime,
223
+ }
224
+ }),
225
+ decreaseTtl: assign((context, evnet) => {
226
+ return {
227
+ ttl: Math.max(context.ttl - 1000, 0),
228
+ }
229
+ }),
230
+ },
231
+ guards: {
232
+ isCalculable: (context, event) => {
233
+ const { selectedCrypto, selectedNetwork, selectedAmount } = context
234
+ return (
235
+ selectedCrypto &&
236
+ selectedNetwork &&
237
+ selectedAmount &&
238
+ selectedCrypto.minimum <= +selectedAmount &&
239
+ +selectedAmount <= selectedCrypto.maximum
240
+ )
241
+ },
242
+ isSubmittable: (context, event) => {
243
+ const { selectedCrypto, selectedNetwork, selectedAmount } = context
244
+ return selectedCrypto && selectedNetwork && selectedAmount
245
+ },
246
+ },
247
+ services: {
248
+ fetchCalculation: async (context, event) => {
249
+ const { selectedCrypto, selectedAmount, promotion } = context
250
+ return await request.send(
251
+ payment.getDepositExpectedResult({
252
+ method: selectedCrypto.method,
253
+ amount: selectedAmount,
254
+ cryptoCurrency: selectedCrypto.channel,
255
+ promotionsNo: promotion?.promotionsNo,
256
+ })
257
+ )
258
+ },
259
+ submitDeposit: async (context, event) => {
260
+ const { selectedCrypto, selectedNetwork, calculation, sourceAddress, promotion } = context
261
+ return await request.send(
262
+ payment.submitDepositTransactionCrypto({
263
+ method: selectedCrypto.method,
264
+ amount: calculation.actualAmount,
265
+ cryptoCurrency: selectedCrypto.channel,
266
+ cryptoNetwork: selectedNetwork.value,
267
+ sourceAddress: sourceAddress,
268
+ promotionsNo: promotion?.promotionsNo,
269
+ })
270
+ )
271
+ },
272
+ },
273
+ }
274
+ )
275
+ }
@@ -4,6 +4,8 @@ import qrcode_v2 from './qrcode_v2.js'
4
4
  import deposit_fc from './deposit_fc.js'
5
5
  import crypto from './crypto.js'
6
6
  import crypto_button from './crypto_button.js'
7
+ import crypto_qrcode from './crypto_qrcode.js'
8
+ import crypto_way_cash from './crypto_way_cash.js'
7
9
  import direct from './direct.js'
8
10
  import amb from './amb.js'
9
11
  import float from './float.js'
@@ -23,6 +25,8 @@ export default {
23
25
  deposit_fc,
24
26
  crypto,
25
27
  crypto_button,
28
+ crypto_qrcode,
29
+ crypto_way_cash,
26
30
  direct,
27
31
  amb,
28
32
  float,
@@ -127,7 +127,7 @@ export default function (request) {
127
127
  pushHistoryStack: assign((context, event) => {
128
128
  const { menuItemStack, historyStack } = context
129
129
  return {
130
- historyStack: historyStack.concat(menuItemStack.slice(-1)),
130
+ historyStack: [...historyStack, event.data],
131
131
  }
132
132
  }),
133
133
  popHistoryStack: assign((context, event) => {