@jetthai/cuora 1.0.129 → 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,8 @@
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
+
5
7
  ### [1.0.129](https://github.com/jetthai/cuora-module/compare/v1.0.128...v1.0.129) (2022-05-31)
6
8
 
7
9
  ### [1.0.128](https://github.com/jetthai/cuora-module/compare/v1.0.127...v1.0.128) (2022-05-27)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.0.129",
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`,
@@ -283,14 +283,14 @@ export default function (request) {
283
283
  const redirectURL = urljoin(
284
284
  request.config.fullURL,
285
285
  'login?' +
286
- qs.stringify({
287
- provider,
288
- redirectURI: `${window.location.protocol}//${window.location.host}`,
289
- channel: cookies.get('channel') || channel || 'official',
290
- subchannel: cookies.get('subchannel') || subchannel || 'pwa',
291
- // dt,
292
- platform: 'pwa',
293
- })
286
+ qs.stringify({
287
+ provider,
288
+ redirectURI: `${window.location.protocol}//${window.location.host}`,
289
+ channel: cookies.get('channel') || channel || 'official',
290
+ subchannel: cookies.get('subchannel') || subchannel || 'pwa',
291
+ // dt,
292
+ platform: 'pwa',
293
+ })
294
294
  )
295
295
  window.location.href = redirectURL
296
296
  },
@@ -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 }
@@ -46,8 +46,8 @@ export default function (request) {
46
46
  },
47
47
  KEY_IN: {
48
48
  target: 'calculable',
49
- actions: 'setAmount'
50
- }
49
+ actions: 'setAmount',
50
+ },
51
51
  },
52
52
  },
53
53
  fail: {},
@@ -59,7 +59,7 @@ export default function (request) {
59
59
  },
60
60
  KEY_IN: {
61
61
  target: 'calculable',
62
- actions: 'setAmount'
62
+ actions: 'setAmount',
63
63
  },
64
64
  CALCULATE: {
65
65
  target: 'calculating',
@@ -89,7 +89,7 @@ export default function (request) {
89
89
  },
90
90
  KEY_IN: {
91
91
  target: 'calculable',
92
- actions: 'setAmount'
92
+ actions: 'setAmount',
93
93
  },
94
94
  CONFIRM: {
95
95
  target: 'submitting',
@@ -46,8 +46,8 @@ export default function (request) {
46
46
  },
47
47
  KEY_IN: {
48
48
  target: 'calculable',
49
- actions: 'setAmount'
50
- }
49
+ actions: 'setAmount',
50
+ },
51
51
  },
52
52
  },
53
53
  fail: {},
@@ -58,7 +58,7 @@ export default function (request) {
58
58
  actions: 'addAmount',
59
59
  },
60
60
  KEY_IN: {
61
- actions: 'setAmount'
61
+ actions: 'setAmount',
62
62
  },
63
63
  CALCULATE: {
64
64
  target: 'calculating',
@@ -88,7 +88,7 @@ export default function (request) {
88
88
  },
89
89
  KEY_IN: {
90
90
  target: 'calculable',
91
- actions: 'setAmount'
91
+ actions: 'setAmount',
92
92
  },
93
93
  CONFIRM: {
94
94
  target: 'submitting',
@@ -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
+ }
@@ -9,7 +9,7 @@ export default function (request) {
9
9
  type: 'parallel',
10
10
  context: {
11
11
  rewardList: [],
12
- callback: () => { },
12
+ callback: () => {},
13
13
  },
14
14
  states: {
15
15
  timer: {
@@ -75,7 +75,7 @@ export default function (request) {
75
75
  }),
76
76
  setCallback: assign((context, event) => {
77
77
  return {
78
- callback: event.data?.callback || (() => { }),
78
+ callback: event.data?.callback || (() => {}),
79
79
  }
80
80
  }),
81
81
  doCallback: (context, event) => {