@jetthai/cuora 1.0.128 → 1.0.130

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.0.130](https://github.com/jetthai/cuora-module/compare/v1.0.129...v1.0.130) (2022-06-01)
6
+
7
+ ### [1.0.129](https://github.com/jetthai/cuora-module/compare/v1.0.128...v1.0.129) (2022-05-31)
8
+
5
9
  ### [1.0.128](https://github.com/jetthai/cuora-module/compare/v1.0.127...v1.0.128) (2022-05-27)
6
10
 
7
11
  ### [1.0.127](https://github.com/jetthai/cuora-module/compare/v1.0.125...v1.0.127) (2022-05-26)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.0.128",
3
+ "version": "1.0.130",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
@@ -42,10 +42,10 @@ export default {
42
42
  method: 'post',
43
43
  params: { transferType: 'WITHDRAW', amount, cryptoNetwork },
44
44
  }),
45
- submitDepositTransaction: ({ method, amount, cryptoCurrency, cryptoNetwork }) => ({
45
+ submitDepositTransaction: ({ method, amount, cryptoCurrency, cryptoNetwork, sourceAddress }) => ({
46
46
  url: `payment/v2/${method}/transaction`,
47
47
  method: 'post',
48
- params: { transferType: 'DEPOSIT', amount, cryptoCurrency, cryptoNetwork },
48
+ params: { transferType: 'DEPOSIT', amount, cryptoCurrency, cryptoNetwork, sourceAddress },
49
49
  }),
50
50
  submitDepositTransactionLoadcard: ({ method, amount, card_type, card_code, card_seri }) => ({
51
51
  url: `payment/v2/${method}/transaction`,
@@ -132,7 +132,6 @@ export default function (request) {
132
132
  actions: {
133
133
  setSiteConfig: assign((context, event) => {
134
134
  const { loginMethods = {}, registerMethods = {} } = event.data
135
- console.log(event.data)
136
135
  return {
137
136
  siteConfig: { ...event.data, loginMethods: pickBy(loginMethods), registerMethods: pickBy(registerMethods) },
138
137
  }
@@ -3,5 +3,6 @@ import loadcard_vn from './loadcard_vn'
3
3
  import qrcode_vn from './qrcode_vn'
4
4
  import qrcode_v2 from './qrcode_v2'
5
5
  import deposit_fc from './deposit_fc'
6
+ import web from './web'
6
7
 
7
- export default { manual_vn, loadcard_vn, qrcode_vn, qrcode_v2, deposit_fc }
8
+ export default { manual_vn, loadcard_vn, qrcode_vn, qrcode_v2, deposit_fc, web }
@@ -44,6 +44,10 @@ export default function (request) {
44
44
  target: 'calculable',
45
45
  actions: 'addAmount',
46
46
  },
47
+ KEY_IN: {
48
+ target: 'calculable',
49
+ actions: 'setAmount',
50
+ },
47
51
  },
48
52
  },
49
53
  fail: {},
@@ -53,6 +57,10 @@ export default function (request) {
53
57
  SELECT_AMOUNT: {
54
58
  actions: 'addAmount',
55
59
  },
60
+ KEY_IN: {
61
+ target: 'calculable',
62
+ actions: 'setAmount',
63
+ },
56
64
  CALCULATE: {
57
65
  target: 'calculating',
58
66
  },
@@ -79,6 +87,10 @@ export default function (request) {
79
87
  target: 'calculable',
80
88
  actions: 'addAmount',
81
89
  },
90
+ KEY_IN: {
91
+ target: 'calculable',
92
+ actions: 'setAmount',
93
+ },
82
94
  CONFIRM: {
83
95
  target: 'submitting',
84
96
  },
@@ -143,6 +155,9 @@ export default function (request) {
143
155
  addAmount: assign((context, event) => {
144
156
  return { selectedAmount: (context.selectedAmount || 0) + event.data }
145
157
  }),
158
+ setAmount: assign((context, event) => {
159
+ return { selectedAmount: event.data }
160
+ }),
146
161
  setCalculation: assign((context, event) => {
147
162
  return {
148
163
  calculation: event.data,
@@ -159,9 +174,6 @@ export default function (request) {
159
174
  }
160
175
  }),
161
176
  },
162
- guards: {
163
- isSubmittable: (context, event) => {},
164
- },
165
177
  services: {
166
178
  fetchInitData: async (context, event) => {
167
179
  return await request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' }))
@@ -173,9 +173,6 @@ export default function (request) {
173
173
  }
174
174
  }),
175
175
  },
176
- guards: {
177
- isSubmittable: (context, event) => {},
178
- },
179
176
  services: {
180
177
  fetchInitData: async (context, event) => {
181
178
  return await request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' }))
@@ -0,0 +1,217 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import payment from '../../api/payment'
3
+
4
+ export default function (request) {
5
+ return createMachine(
6
+ {
7
+ id: 'web',
8
+ initial: 'loading',
9
+ context: {
10
+ paymentDetails: [],
11
+
12
+ cryptos: [],
13
+ networks: [],
14
+ sourceAddress: null,
15
+
16
+ amount: null,
17
+ selectedCrypto: null,
18
+ selectedNetwork: null,
19
+
20
+ currentMethodType: 'web',
21
+ currentPayment: null,
22
+
23
+ calculation: null,
24
+ processing: null,
25
+ },
26
+ states: {
27
+ loading: {
28
+ invoke: {
29
+ src: 'fetchPayments',
30
+ onDone: {
31
+ target: 'idle',
32
+ actions: 'setCryptos',
33
+ },
34
+ onError: {
35
+ target: '#web.fail',
36
+ },
37
+ },
38
+ },
39
+ idle: {
40
+ on: {
41
+ SET_CRYPTO: {
42
+ actions: 'setCrypto',
43
+ },
44
+ SET_NETWORK: {
45
+ actions: 'setNetwork',
46
+ },
47
+ SET_AMOUNT: {
48
+ actions: ['setAmount', 'clearCalculation'],
49
+ },
50
+ CALCULATE: {
51
+ target: 'calculating',
52
+ cond: 'isCalculable',
53
+ },
54
+ CLEAR_CALCULATION: {
55
+ actions: 'clearCalculation',
56
+ },
57
+ SUBMIT: {
58
+ target: 'submitting',
59
+ cond: 'isSubmittable',
60
+ },
61
+ },
62
+ },
63
+ calculating: {
64
+ invoke: {
65
+ src: 'fetchCalculation',
66
+ onDone: {
67
+ target: 'idle',
68
+ actions: 'setCalculation',
69
+ },
70
+ onError: {
71
+ target: 'idle',
72
+ },
73
+ },
74
+ },
75
+ submitting: {
76
+ invoke: {
77
+ src: 'submitDeposit',
78
+ onDone: {
79
+ target: 'submitted',
80
+ actions: 'setProcessing',
81
+ },
82
+ onError: {
83
+ target: 'idle',
84
+ },
85
+ },
86
+ },
87
+ processing: {},
88
+ submitted: {},
89
+ fail: {},
90
+ },
91
+ },
92
+ {
93
+ actions: {
94
+ setCryptos: assign((context, event) => {
95
+ const cryptos = event.data?.map?.((crypto) => ({ ...crypto, label: crypto.channel, value: crypto.method, icon: crypto.channel })) || []
96
+ const currentPayment = cryptos.find((element) => element.methodType === context.currentMethodType)
97
+ const defaultNetworks =
98
+ cryptos[0].optional.map((value, i) => {
99
+ return {
100
+ label: cryptos[0].originalItem?.[i],
101
+ value,
102
+ icon: value,
103
+ }
104
+ }) || []
105
+ return {
106
+ cryptos,
107
+ selectedCrypto: cryptos[0],
108
+ selectedNetwork: defaultNetworks[0],
109
+ currentPayment,
110
+ }
111
+ }),
112
+ setCrypto: assign((context, event) => {
113
+ const { cryptos, selectedNetwork } = context
114
+ const method = cryptos.find((crypto) => crypto.method === event.data.value)
115
+ const networks =
116
+ method?.optional.map((value, i) => {
117
+ return {
118
+ label: method?.originalItem?.[i],
119
+ value,
120
+ icon: value,
121
+ }
122
+ }) || []
123
+
124
+ const properties = {
125
+ selectedCrypto: event.data,
126
+ networks,
127
+ }
128
+
129
+ if (!networks.includes(selectedNetwork)) {
130
+ properties.selectedNetwork = null
131
+ properties.amount = null
132
+ properties.calculation = null
133
+ }
134
+
135
+ return properties
136
+ }),
137
+ setNetwork: assign((context, event) => {
138
+ return { selectedNetwork: event.data }
139
+ }),
140
+ setAmount: assign((context, event) => {
141
+ return {
142
+ amount: event.data,
143
+ }
144
+ }),
145
+ setCalculation: assign((context, event) => {
146
+ return {
147
+ calculation: event.data,
148
+ }
149
+ }),
150
+ setProcessing: assign((context, event) => {
151
+ return {
152
+ processing: event.data,
153
+ }
154
+ }),
155
+ clearCalculation: assign((context, event) => {
156
+ return {
157
+ calculation: null,
158
+ }
159
+ }),
160
+ },
161
+ guards: {
162
+ isCalculable: (context, event) => {
163
+ const {
164
+ amount,
165
+ currentPayment: { maximum, minimum },
166
+ } = context
167
+ return amount && minimum <= +amount && +amount <= maximum
168
+ },
169
+ isCalculated: (context, event) => {
170
+ return context.calculation
171
+ },
172
+ isSubmittable: (context, event) => {
173
+ console.log(context)
174
+ const { amount } = context
175
+ return amount
176
+ },
177
+ isProcessing: (context, event) => {
178
+ return context.processing
179
+ },
180
+ },
181
+ services: {
182
+ fetchPayments: async (context, event) => {
183
+ return await request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' }))
184
+ },
185
+ fetchCalculation: async (context, event) => {
186
+ const { selectedCrypto, amount } = context
187
+ return await request.send(
188
+ payment.getDepositExpectedResult({
189
+ method: selectedCrypto.method,
190
+ amount,
191
+ cryptoCurrency: selectedCrypto.channel,
192
+ })
193
+ )
194
+ },
195
+ submitDeposit: async (context, event) => {
196
+ const { selectedCrypto, selectedNetwork, calculation, sourceAddress } = context
197
+ console.log({
198
+ method: selectedCrypto.method,
199
+ amount: calculation.actualAmount,
200
+ cryptoCurrency: selectedCrypto.channel,
201
+ cryptoNetwork: selectedNetwork.value,
202
+ sourceAddress: sourceAddress,
203
+ })
204
+ return await request.send(
205
+ payment.submitDepositTransaction({
206
+ method: selectedCrypto.method,
207
+ amount: calculation.actualAmount,
208
+ cryptoCurrency: selectedCrypto.channel,
209
+ cryptoNetwork: selectedNetwork.value,
210
+ sourceAddress: sourceAddress,
211
+ })
212
+ )
213
+ },
214
+ },
215
+ }
216
+ )
217
+ }