@jetthai/cuora 1.0.68 → 1.0.69

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.69](https://github.com/jetthai/cuora-module/compare/v1.0.68...v1.0.69) (2021-12-29)
6
+
5
7
  ### [1.0.68](https://github.com/jetthai/cuora-module/compare/v1.0.67...v1.0.68) (2021-12-28)
6
8
 
7
9
  ### [1.0.67](https://github.com/jetthai/cuora-module/compare/v1.0.66...v1.0.67) (2021-12-24)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.0.68",
3
+ "version": "1.0.69",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
@@ -0,0 +1,75 @@
1
+ import { assign, createMachine, send } from 'xstate'
2
+ import payment from '../api/payment'
3
+
4
+ export default function (request) {
5
+ return createMachine(
6
+ {
7
+ id: 'bonus',
8
+ initial: 'loading',
9
+ context: {
10
+ bonus: null,
11
+ },
12
+ states: {
13
+ loading: {
14
+ invoke: {
15
+ src: 'fetchInitData',
16
+ onDone: {
17
+ target: 'idle',
18
+ actions: 'setBonus',
19
+ },
20
+ onError: {
21
+ target: 'idle',
22
+ },
23
+ },
24
+ },
25
+ idle: {
26
+ on: {
27
+ TOGGLE: {
28
+ target: 'updating',
29
+ },
30
+ SWITCH_ON: {
31
+ actions: send((context, event) => ({ type: 'TOGGLE', data: 1 })),
32
+ cond: (context, event) => context.bonus !== 1,
33
+ },
34
+ SWITCH_OFF: {
35
+ actions: send((context, event) => ({ type: 'TOGGLE', data: 0 })),
36
+ cond: (context, event) => context.bonus !== 0,
37
+ },
38
+ },
39
+ },
40
+ updating: {
41
+ invoke: {
42
+ src: 'toggleBonus',
43
+ onDone: {
44
+ target: 'idle',
45
+ actions: 'setBonus',
46
+ },
47
+ onError: {
48
+ target: 'idle',
49
+ },
50
+ },
51
+ },
52
+ },
53
+ },
54
+ {
55
+ actions: {
56
+ setBonus: assign((context, event) => {
57
+ return {
58
+ bonus: event.data,
59
+ }
60
+ }),
61
+ },
62
+ services: {
63
+ fetchInitData: async (context, event) => {
64
+ const { bonus } = await request.send(payment.getPaymentInfo())
65
+ return bonus
66
+ },
67
+ toggleBonus: async (context, event) => {
68
+ const bonus = context.bonus ? 0 : 1
69
+ await request.send(payment.setBonusSetting({ bonus }))
70
+ return bonus
71
+ },
72
+ },
73
+ }
74
+ )
75
+ }
@@ -1,6 +1,6 @@
1
1
  import { assign, createMachine } from 'xstate'
2
2
  import toNumber from 'lodash/toNumber'
3
- import payment from '../api/payment'
3
+ import payment from '../../api/payment'
4
4
 
5
5
  export default function (request) {
6
6
  return createMachine(
@@ -0,0 +1,5 @@
1
+ import loadcard_vn from './loadcard_vn'
2
+ import qrcode_vn from './qrcode_vn'
3
+ import deposit_fc from './deposit_fc'
4
+
5
+ export default { loadcard_vn, qrcode_vn, deposit_fc }
@@ -0,0 +1,230 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import payment from '../../api/payment'
3
+
4
+ export default function (request) {
5
+ return createMachine(
6
+ {
7
+ id: 'loadcard',
8
+ initial: 'loading',
9
+ context: {
10
+ cards: [
11
+ { name: 'mobifone', code: 'VMS' },
12
+ { name: 'viettel', code: 'VTT' },
13
+ { name: 'vinaphone', code: 'VNP' },
14
+ // { name: 'vietnam mobile', code: 'VNM' },
15
+ // { name: 'thẻ zing', code: 'ZING' },
16
+ // { name: 'thẻ gate', code: 'GATE' },
17
+ // { name: 'thẻ garena', code: 'GARENA' },
18
+ ],
19
+ options: [],
20
+
21
+ selectedCard: null,
22
+ selectedAmount: null,
23
+ cardNumber: null,
24
+ serialNumber: null,
25
+
26
+ calculation: null,
27
+
28
+ paymentDetails: [],
29
+ currentMethodType: 'loadcard',
30
+ currentMethod: null,
31
+ currentPayment: null,
32
+ },
33
+ states: {
34
+ loading: {
35
+ invoke: {
36
+ src: 'fetchInitData',
37
+ onDone: {
38
+ target: 'loaded',
39
+ actions: 'setInitData',
40
+ },
41
+ onError: {
42
+ target: 'fail',
43
+ },
44
+ },
45
+ },
46
+ loaded: {
47
+ entry: 'reset',
48
+ on: {
49
+ SELECT_CARD: {
50
+ actions: 'setCard',
51
+ },
52
+ SELECT_AMOUNT: {
53
+ target: 'calculable',
54
+ actions: 'setAmount',
55
+ },
56
+ },
57
+ },
58
+ fail: {},
59
+ calculable: {
60
+ entry: 'clearCalculation',
61
+ on: {
62
+ SELECT_AMOUNT: {
63
+ actions: 'setAmount',
64
+ },
65
+ CALCULATE: {
66
+ target: 'calculating',
67
+ },
68
+ BACK: {
69
+ target: 'loaded',
70
+ },
71
+ },
72
+ },
73
+ calculating: {
74
+ invoke: {
75
+ src: 'fetchCalculation',
76
+ onDone: {
77
+ target: 'calculated',
78
+ actions: 'setCalculation',
79
+ },
80
+ onError: {
81
+ target: 'calculable',
82
+ },
83
+ },
84
+ },
85
+ calculated: {
86
+ on: {
87
+ SELECT_AMOUNT: {
88
+ target: 'calculable',
89
+ actions: 'setAmount',
90
+ },
91
+ CONFIRM: {
92
+ target: 'cardInfo',
93
+ },
94
+ BACK: {
95
+ target: 'loaded',
96
+ },
97
+ CLEAR_CALCULATION: {
98
+ target: 'calculable',
99
+ actions: 'clearCalculation',
100
+ },
101
+ },
102
+ },
103
+ cardInfo: {
104
+ on: {
105
+ INPUT_CARD_NUMBER: {
106
+ actions: 'setCardNumber',
107
+ },
108
+ INPUT_SERIAL_NUMBER: {
109
+ actions: 'setSerialNumber',
110
+ },
111
+ SUBMIT: {
112
+ target: 'submitting',
113
+ cond: 'isSubmittable',
114
+ },
115
+ SELECT_CARD: {
116
+ target: 'loaded',
117
+ actions: 'setCard',
118
+ },
119
+ },
120
+ },
121
+ submitting: {
122
+ invoke: {
123
+ src: 'submitDeposit',
124
+ onDone: {
125
+ target: 'submitted',
126
+ },
127
+ onError: {
128
+ target: 'cardInfo',
129
+ },
130
+ },
131
+ },
132
+ submitted: {
133
+ on: {
134
+ BACK: {
135
+ target: 'loaded',
136
+ },
137
+ },
138
+ },
139
+ },
140
+ },
141
+ {
142
+ actions: {
143
+ reset: assign((context, event) => {
144
+ return {
145
+ selectedAmount: null,
146
+ cardNumber: null,
147
+ serialNumber: null,
148
+ calculation: null,
149
+ }
150
+ }),
151
+ setInitData: assign((context, event) => {
152
+ const paymentDetails = event.data
153
+ const currentPayment = paymentDetails.find((element) => element.methodType === context.currentMethodType)
154
+ return {
155
+ paymentDetails,
156
+ currentPayment,
157
+ currentMethod: currentPayment.method,
158
+ options: currentPayment.optional,
159
+ selectedCard: context.cards[0],
160
+ }
161
+ }),
162
+ setCard: assign((context, event) => {
163
+ return {
164
+ selectedCard: event.data,
165
+ }
166
+ }),
167
+ setCardNumber: assign((context, event) => {
168
+ return {
169
+ cardNumber: event.data,
170
+ }
171
+ }),
172
+ setSerialNumber: assign((context, event) => {
173
+ return {
174
+ serialNumber: event.data,
175
+ }
176
+ }),
177
+ setAmount: assign((context, event) => {
178
+ return { selectedAmount: event.data }
179
+ }),
180
+ setCalculation: assign((context, event) => {
181
+ return {
182
+ calculation: event.data,
183
+ }
184
+ }),
185
+ clearCalculation: assign((context, event) => {
186
+ return {
187
+ calculation: null,
188
+ }
189
+ }),
190
+ },
191
+ guards: {
192
+ isSubmittable: (context, event) => {
193
+ const { cardNumber, serialNumber } = context
194
+ return cardNumber && serialNumber
195
+ },
196
+ },
197
+ services: {
198
+ fetchInitData: async (context, event) => {
199
+ return await request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' }))
200
+ },
201
+ fetchBanksList: async (context, event) => {
202
+ const { paymentDetails, currentMethodType } = context
203
+ const method = paymentDetails.find((item) => item.methodType === currentMethodType)?.method
204
+ return await request.send(payment.getBankList(method))
205
+ },
206
+ fetchCalculation: async (context, event) => {
207
+ const { currentMethod, selectedAmount } = context
208
+ return await request.send(
209
+ payment.getDepositExpectedResult({
210
+ method: currentMethod,
211
+ amount: selectedAmount,
212
+ })
213
+ )
214
+ },
215
+ submitDeposit: async (context, event) => {
216
+ const { currentMethod, selectedCard, selectedAmount, cardNumber, serialNumber } = context
217
+ return await request.send(
218
+ payment.submitDepositTransactionLoadcard({
219
+ method: currentMethod,
220
+ amount: selectedAmount,
221
+ card_type: selectedCard.code,
222
+ card_code: cardNumber,
223
+ card_seri: serialNumber,
224
+ })
225
+ )
226
+ },
227
+ },
228
+ }
229
+ )
230
+ }
@@ -0,0 +1,195 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import payment from '../../api/payment'
3
+
4
+ export default function (request) {
5
+ return createMachine(
6
+ {
7
+ id: 'qrcode',
8
+ initial: 'loading',
9
+ context: {
10
+ qrcodes: [],
11
+ options: [],
12
+
13
+ selectedQrcode: null,
14
+ selectedAmount: null,
15
+
16
+ calculation: null,
17
+
18
+ paymentDetails: [],
19
+ currentMethodType: 'qrcode',
20
+ currentMethod: null,
21
+
22
+ result: null,
23
+ },
24
+ states: {
25
+ loading: {
26
+ invoke: {
27
+ src: 'fetchInitData',
28
+ onDone: {
29
+ target: 'loaded',
30
+ actions: 'setInitData',
31
+ },
32
+ onError: {
33
+ target: 'fail',
34
+ },
35
+ },
36
+ },
37
+ loaded: {
38
+ entry: 'reset',
39
+ on: {
40
+ SELECT_QRCODE: {
41
+ actions: 'setQrcode',
42
+ },
43
+ SELECT_AMOUNT: {
44
+ target: 'calculable',
45
+ actions: 'addAmount',
46
+ },
47
+ },
48
+ },
49
+ fail: {},
50
+ calculable: {
51
+ entry: 'clearCalculation',
52
+ on: {
53
+ SELECT_AMOUNT: {
54
+ actions: 'addAmount',
55
+ },
56
+ CALCULATE: {
57
+ target: 'calculating',
58
+ },
59
+ BACK: {
60
+ target: 'loaded',
61
+ },
62
+ },
63
+ },
64
+ calculating: {
65
+ invoke: {
66
+ src: 'fetchCalculation',
67
+ onDone: {
68
+ target: 'calculated',
69
+ actions: 'setCalculation',
70
+ },
71
+ onError: {
72
+ target: 'calculable',
73
+ },
74
+ },
75
+ },
76
+ calculated: {
77
+ on: {
78
+ SELECT_AMOUNT: {
79
+ target: 'calculable',
80
+ actions: 'addAmount',
81
+ },
82
+ CONFIRM: {
83
+ target: 'submitting',
84
+ },
85
+ BACK: {
86
+ target: 'loaded',
87
+ },
88
+ CLEAR_CALCULATION: {
89
+ target: 'calculable',
90
+ actions: 'clearCalculation',
91
+ },
92
+ },
93
+ },
94
+ submitting: {
95
+ invoke: {
96
+ src: 'submitDeposit',
97
+ onDone: {
98
+ target: 'submitted',
99
+ actions: 'setResult',
100
+ },
101
+ onError: {
102
+ target: 'calculated',
103
+ },
104
+ },
105
+ },
106
+ submitted: {
107
+ on: {
108
+ SELECT_QRCODE: {
109
+ target: 'loaded',
110
+ actions: 'setQrcode',
111
+ },
112
+ },
113
+ },
114
+ },
115
+ },
116
+ {
117
+ actions: {
118
+ reset: assign((context, event) => {
119
+ return {
120
+ selectedAmount: null,
121
+ calculation: null,
122
+ }
123
+ }),
124
+ setInitData: assign((context, event) => {
125
+ const paymentDetails = event.data
126
+ const qrcodes = paymentDetails.filter((element) => element.methodType === context.currentMethodType)
127
+
128
+ return {
129
+ paymentDetails,
130
+ qrcodes,
131
+ selectedQrcode: qrcodes[0],
132
+ currentMethod: qrcodes[0].method,
133
+ options: qrcodes[0].optional,
134
+ }
135
+ }),
136
+ setQrcode: assign((context, event) => {
137
+ return {
138
+ selectedQrcode: event.data,
139
+ currentMethod: event.data.method,
140
+ options: event.data.optional,
141
+ }
142
+ }),
143
+ addAmount: assign((context, event) => {
144
+ return { selectedAmount: (context.selectedAmount || 0) + event.data }
145
+ }),
146
+ setCalculation: assign((context, event) => {
147
+ return {
148
+ calculation: event.data,
149
+ }
150
+ }),
151
+ clearCalculation: assign((context, event) => {
152
+ return {
153
+ calculation: null,
154
+ }
155
+ }),
156
+ setResult: assign((context, event) => {
157
+ return {
158
+ result: event.data,
159
+ }
160
+ }),
161
+ },
162
+ guards: {
163
+ isSubmittable: (context, event) => {},
164
+ },
165
+ services: {
166
+ fetchInitData: async (context, event) => {
167
+ return await request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' }))
168
+ },
169
+ fetchBanksList: async (context, event) => {
170
+ const { paymentDetails, currentMethodType } = context
171
+ const method = paymentDetails.find((item) => item.methodType === currentMethodType)?.method
172
+ return await request.send(payment.getBankList(method))
173
+ },
174
+ fetchCalculation: async (context, event) => {
175
+ const { currentMethod, selectedAmount } = context
176
+ return await request.send(
177
+ payment.getDepositExpectedResult({
178
+ method: currentMethod,
179
+ amount: selectedAmount,
180
+ })
181
+ )
182
+ },
183
+ submitDeposit: async (context, event) => {
184
+ const { currentMethod, selectedAmount } = context
185
+ return await request.send(
186
+ payment.submitDepositTransaction({
187
+ method: currentMethod,
188
+ amount: selectedAmount,
189
+ })
190
+ )
191
+ },
192
+ },
193
+ }
194
+ )
195
+ }
@@ -3,7 +3,6 @@ import auth from './auth'
3
3
  import auth_otp from './auth_otp'
4
4
  import welcome from './welcome'
5
5
  import common from './common'
6
- import deposit from './deposit'
7
6
  import error from './error'
8
7
  import game from './game'
9
8
  import game_favorite from './game_favorite'
@@ -21,6 +20,8 @@ import user_sign_up from './user_sign_up'
21
20
  import user_reset_password from './user_reset_password'
22
21
  import bank_binding from './bank_binding'
23
22
  import withdraw_vn from './withdraw_vn'
23
+ import deposit from './deposit'
24
+ import bonus from './bonus'
24
25
 
25
26
  export default {
26
27
  ...activity,
@@ -46,4 +47,6 @@ export default {
46
47
  user_reset_password,
47
48
  bank_binding,
48
49
  withdraw_vn,
50
+ ...deposit,
51
+ bonus,
49
52
  }