@jetthai/cuora 1.0.302-sl-2 → 1.1.0
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 +3 -848
- package/README.md +0 -6
- package/dist/bundle.mjs +18461 -0
- package/package.json +9 -6
- package/rollup.config.js +16 -0
- package/src/api/activity.js +2 -43
- package/src/api/auth.js +7 -22
- package/src/api/common.js +1 -3
- package/src/api/game.js +7 -20
- package/src/api/mailbox.js +5 -9
- package/src/api/payment.js +19 -167
- package/src/api/user.js +0 -7
- package/src/machine/activity/activity.js +26 -111
- package/src/machine/activity/{friend_invite_friends_activity.js → affiliate_invite_friends_activity.js} +41 -70
- package/src/machine/activity/continue_deposit_activity.js +2 -11
- package/src/machine/activity/deposit_activity.js +4 -13
- package/src/machine/activity/diamond_shop_activity_vn.js +89 -54
- package/src/machine/activity/fafafa_activity.js +19 -34
- package/src/machine/activity/index.js +4 -22
- package/src/machine/activity/invite_friends_activity.js +14 -14
- package/src/machine/activity/ranking_activity.js +2 -11
- package/src/machine/activity/sign_in_activity.js +14 -21
- package/src/machine/activity/specify_bets_activity.js +3 -25
- package/src/machine/activity/specify_turnover_activity.js +3 -25
- package/src/machine/activity/time_bomb_activity.js +2 -11
- package/src/machine/auth.js +21 -134
- package/src/machine/auth_otp.js +201 -0
- package/src/machine/auth_otp_v2.js +4 -10
- package/src/machine/auth_otp_v3.js +3 -11
- package/src/machine/bank_binding.js +12 -112
- package/src/machine/common.js +25 -113
- package/src/machine/deposit/crypto.js +29 -50
- package/src/machine/deposit/crypto_button.js +39 -174
- package/src/machine/deposit/deposit_fc.js +5 -8
- package/src/machine/deposit/direct.js +16 -111
- package/src/machine/deposit/index.js +2 -43
- package/src/machine/deposit/loadcard_vn.js +43 -191
- package/src/machine/deposit/manual_vn.js +60 -182
- package/src/machine/deposit/qrcode_v2.js +52 -285
- package/src/machine/deposit/qrcode_vn.js +206 -0
- package/src/machine/game.js +285 -0
- package/src/machine/game_favorite.js +123 -0
- package/src/machine/game_favorite_v2.js +28 -74
- package/src/machine/game_search.js +244 -0
- package/src/machine/game_search_v2.js +24 -64
- package/src/machine/game_v2.js +356 -0
- package/src/machine/inbox.js +34 -259
- package/src/machine/index.js +17 -24
- package/src/machine/leaderboard.js +8 -31
- package/src/machine/reward.js +7 -74
- package/src/machine/setting.js +2 -5
- package/src/machine/side_v2.js +28 -33
- package/src/machine/user_sign_up.js +17 -117
- package/src/machine/{withdraw/withdraw_crypto.js → withdraw_crypto.js} +69 -220
- package/src/machine/{withdraw/withdraw_fc.js → withdraw_fc.js} +2 -2
- package/src/machine/{withdraw/withdraw_amb.js → withdraw_vn.js} +78 -146
- package/src/request/request.js +5 -10
- package/src/util/constant.js +1 -19
- package/src/util/deviceToken.js +8 -18
- package/src/util/index.js +1 -2
- package/src/util/storage.js +22 -22
- package/.husky/pre-commit +0 -4
- package/.prettierignore +0 -1
- package/src/lib/fingerprint.js +0 -9779
- package/src/machine/activity/activity_cash.js +0 -159
- package/src/machine/activity/cash_rain_activity.js +0 -153
- package/src/machine/activity/diamond_shop_activity_cash.js +0 -179
- package/src/machine/activity/instant_rebate_activity.js +0 -217
- package/src/machine/activity/jackpot.js +0 -74
- package/src/machine/activity/otp_verified_activity.js +0 -74
- package/src/machine/activity/roulette_activity_v2.js +0 -90
- package/src/machine/activity/sign_in_monthly_activity.js +0 -65
- package/src/machine/activity/vip_card_activity.js +0 -140
- package/src/machine/bank_binding_amb.js +0 -145
- package/src/machine/deposit/amb.js +0 -92
- package/src/machine/deposit/crypto_bank.js +0 -317
- package/src/machine/deposit/crypto_bank_cash.js +0 -287
- package/src/machine/deposit/crypto_cash.js +0 -255
- package/src/machine/deposit/crypto_qrcode.js +0 -148
- package/src/machine/deposit/crypto_qrcode_cash.js +0 -131
- package/src/machine/deposit/crypto_way.js +0 -239
- package/src/machine/deposit/crypto_way_cash.js +0 -256
- package/src/machine/deposit/direct_cash.js +0 -217
- package/src/machine/deposit/float.js +0 -366
- package/src/machine/deposit/krway.js +0 -151
- package/src/machine/deposit/loadcard_cash.js +0 -207
- package/src/machine/deposit/manual_cash.js +0 -356
- package/src/machine/deposit/qrcode_cash.js +0 -217
- package/src/machine/deposit/usdt.js +0 -144
- package/src/machine/deposit/usdt_cash.js +0 -138
- package/src/machine/deposit/vpay.js +0 -359
- package/src/machine/game_info.js +0 -57
- package/src/machine/game_search_cash.js +0 -390
- package/src/machine/game_v2_1.js +0 -662
- package/src/machine/honor_board_cash.js +0 -63
- package/src/machine/navbar.js +0 -57
- package/src/machine/promotions.js +0 -171
- package/src/machine/reward_cash.js +0 -219
- package/src/machine/roulette_v2.js +0 -276
- package/src/machine/side_cash.js +0 -110
- package/src/machine/user_photo.js +0 -65
- package/src/machine/withdraw/index.js +0 -23
- package/src/machine/withdraw/withdraw_crypto2.js +0 -540
- package/src/machine/withdraw/withdraw_crypto_cash.js +0 -319
- package/src/machine/withdraw/withdraw_krway.js +0 -207
- package/src/machine/withdraw/withdraw_manual.js +0 -595
- package/src/machine/withdraw/withdraw_manual_cash.js +0 -303
- package/src/machine/withdraw/withdraw_vn.js +0 -533
- package/src/machine/withdraw/withdraw_vn2.js +0 -548
- package/src/util/math.js +0 -4
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { assign, createMachine } from 'xstate'
|
|
2
2
|
import api from '../../api/activity.js'
|
|
3
3
|
|
|
4
|
-
export default function (request
|
|
4
|
+
export default function (request) {
|
|
5
5
|
const { appSecret } = request.config
|
|
6
|
-
const { activityNo } = context || {}
|
|
7
6
|
return createMachine(
|
|
8
7
|
{
|
|
9
8
|
id: 'specify_turnover_activity',
|
|
10
9
|
context: {
|
|
11
|
-
activityNo,
|
|
10
|
+
activityNo: null,
|
|
12
11
|
activityDetail: null,
|
|
13
12
|
callback: () => {},
|
|
14
|
-
duration: 0,
|
|
15
13
|
},
|
|
16
14
|
initial: 'idle',
|
|
17
15
|
states: {
|
|
@@ -42,14 +40,7 @@ export default function (request, context) {
|
|
|
42
40
|
{ target: 'receivable', cond: 'isReceivable' },
|
|
43
41
|
],
|
|
44
42
|
},
|
|
45
|
-
ongoing: {
|
|
46
|
-
entry: 'setDuration',
|
|
47
|
-
after: {
|
|
48
|
-
1000: {
|
|
49
|
-
target: 'ongoing',
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
},
|
|
43
|
+
ongoing: {},
|
|
53
44
|
received: {},
|
|
54
45
|
receivable: {
|
|
55
46
|
on: {
|
|
@@ -72,14 +63,6 @@ export default function (request, context) {
|
|
|
72
63
|
},
|
|
73
64
|
},
|
|
74
65
|
},
|
|
75
|
-
on: {
|
|
76
|
-
START: {
|
|
77
|
-
target: '.loading',
|
|
78
|
-
},
|
|
79
|
-
STOP: {
|
|
80
|
-
target: '.idle',
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
66
|
},
|
|
84
67
|
{
|
|
85
68
|
actions: {
|
|
@@ -101,11 +84,6 @@ export default function (request, context) {
|
|
|
101
84
|
doCallback: (context, event) => {
|
|
102
85
|
context.callback(event.data.type)
|
|
103
86
|
},
|
|
104
|
-
setDuration: assign((context, event) => {
|
|
105
|
-
return {
|
|
106
|
-
duration: Math.max(context?.activityDetail?.activityEndTime - new Date().getTime() / 1000, 0),
|
|
107
|
-
}
|
|
108
|
-
}),
|
|
109
87
|
},
|
|
110
88
|
guards: {
|
|
111
89
|
isReceivable: (context, event) => {
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { assign, createMachine } from 'xstate'
|
|
2
2
|
import api from '../../api/activity.js'
|
|
3
3
|
|
|
4
|
-
export default function (request
|
|
5
|
-
const { activityNo } = context || {}
|
|
4
|
+
export default function (request) {
|
|
6
5
|
const { appSecret } = request.config
|
|
7
6
|
return createMachine(
|
|
8
7
|
{
|
|
9
8
|
id: 'time_bomb_activity',
|
|
10
9
|
context: {
|
|
11
|
-
activityNo,
|
|
10
|
+
activityNo: null,
|
|
12
11
|
activityDetail: null,
|
|
13
12
|
duration: null,
|
|
14
13
|
},
|
|
@@ -45,14 +44,6 @@ export default function (request, context) {
|
|
|
45
44
|
},
|
|
46
45
|
expired: {},
|
|
47
46
|
},
|
|
48
|
-
on: {
|
|
49
|
-
START: {
|
|
50
|
-
target: '.loading',
|
|
51
|
-
},
|
|
52
|
-
STOP: {
|
|
53
|
-
target: '.idle',
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
47
|
},
|
|
57
48
|
{
|
|
58
49
|
actions: {
|
package/src/machine/auth.js
CHANGED
|
@@ -4,27 +4,25 @@ import auth from '../api/auth.js'
|
|
|
4
4
|
import user from '../api/user.js'
|
|
5
5
|
import storage from '../util/storage.js'
|
|
6
6
|
import { getDeviceToken } from '../util/deviceToken.js'
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
|
|
8
|
+
// const urljoin = require('url-join')
|
|
9
9
|
|
|
10
10
|
export default function (request) {
|
|
11
|
-
const {
|
|
11
|
+
const { clientId, fpToken, sentry, defaultChannel, defaultSubchannel } = request.config
|
|
12
12
|
const tokenKey = `cuora_${clientId}`
|
|
13
13
|
const userKey = `cuora_tempuser`
|
|
14
14
|
const phoneCountryCode = 'phone_countrycode'
|
|
15
15
|
const accountPhoneKey = 'account_phone'
|
|
16
16
|
const accountEmailKey = 'account_email'
|
|
17
|
-
const accountUsernameKey = 'account_username'
|
|
18
17
|
|
|
19
18
|
return createMachine(
|
|
20
19
|
{
|
|
21
20
|
id: 'auth',
|
|
22
|
-
initial: '
|
|
21
|
+
initial: 'idle',
|
|
23
22
|
context: {
|
|
24
23
|
base: '',
|
|
25
24
|
token: null,
|
|
26
25
|
tick: 2000,
|
|
27
|
-
siteConfig: {},
|
|
28
26
|
isPlaying: false,
|
|
29
27
|
loginData: {
|
|
30
28
|
provider: '',
|
|
@@ -38,24 +36,12 @@ export default function (request) {
|
|
|
38
36
|
userInfo: {},
|
|
39
37
|
redirectURL: null,
|
|
40
38
|
reCaptchaToken: null,
|
|
41
|
-
|
|
39
|
+
affiliate: null,
|
|
42
40
|
},
|
|
43
41
|
states: {
|
|
44
|
-
fetchingConfig: {
|
|
45
|
-
invoke: {
|
|
46
|
-
src: 'fetchSiteConfig',
|
|
47
|
-
onDone: {
|
|
48
|
-
target: 'idle',
|
|
49
|
-
actions: 'setSiteConfig',
|
|
50
|
-
},
|
|
51
|
-
onError: {
|
|
52
|
-
target: 'idle',
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
42
|
idle: {
|
|
57
43
|
entry: 'fetchToken',
|
|
58
|
-
always: [{ target: '
|
|
44
|
+
always: [{ target: 'authenticated', cond: 'hasToken' }],
|
|
59
45
|
},
|
|
60
46
|
authentication: {
|
|
61
47
|
invoke: {
|
|
@@ -97,25 +83,6 @@ export default function (request) {
|
|
|
97
83
|
},
|
|
98
84
|
},
|
|
99
85
|
authenticated: {
|
|
100
|
-
invoke: {
|
|
101
|
-
src: 'fetchUserInfo',
|
|
102
|
-
onDone: {
|
|
103
|
-
target: 'loginSuccess',
|
|
104
|
-
actions: ['setUserInfo', 'extendToken'],
|
|
105
|
-
},
|
|
106
|
-
onError: {
|
|
107
|
-
target: 'leaving',
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
loginSuccess: {
|
|
112
|
-
after: {
|
|
113
|
-
0: {
|
|
114
|
-
target: 'inline',
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
tokenAuthenticated: {
|
|
119
86
|
invoke: {
|
|
120
87
|
src: 'fetchUserInfo',
|
|
121
88
|
onDone: {
|
|
@@ -131,7 +98,7 @@ export default function (request) {
|
|
|
131
98
|
initial: 'pending',
|
|
132
99
|
states: {
|
|
133
100
|
pending: {
|
|
134
|
-
always: [{ target: '#auth.
|
|
101
|
+
always: [{ target: '#auth.login', cond: 'isNotInline' }],
|
|
135
102
|
after: {
|
|
136
103
|
TIMEOUT: {
|
|
137
104
|
target: 'fetching',
|
|
@@ -152,27 +119,9 @@ export default function (request) {
|
|
|
152
119
|
},
|
|
153
120
|
},
|
|
154
121
|
},
|
|
155
|
-
inlineFinish: {
|
|
156
|
-
after: {
|
|
157
|
-
0: {
|
|
158
|
-
target: 'login',
|
|
159
|
-
},
|
|
160
|
-
},
|
|
161
|
-
},
|
|
162
122
|
login: {
|
|
163
|
-
initial: '
|
|
123
|
+
initial: 'fetching',
|
|
164
124
|
states: {
|
|
165
|
-
deviceTokenChecking: {
|
|
166
|
-
invoke: {
|
|
167
|
-
src: 'checkDeviceToken',
|
|
168
|
-
onDone: {
|
|
169
|
-
target: 'fetching',
|
|
170
|
-
},
|
|
171
|
-
onError: {
|
|
172
|
-
target: 'fetching',
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
125
|
fetching: {
|
|
177
126
|
invoke: {
|
|
178
127
|
src: 'fetchUserInfo',
|
|
@@ -221,7 +170,7 @@ export default function (request) {
|
|
|
221
170
|
},
|
|
222
171
|
on: {
|
|
223
172
|
LOGIN_TOKEN: {
|
|
224
|
-
target: '
|
|
173
|
+
target: 'idle',
|
|
225
174
|
actions: 'setToken',
|
|
226
175
|
},
|
|
227
176
|
CLEAR: {
|
|
@@ -230,10 +179,6 @@ export default function (request) {
|
|
|
230
179
|
LOGIN_GUEST: {
|
|
231
180
|
target: '.authenticationGuest',
|
|
232
181
|
},
|
|
233
|
-
LOGIN_ID: {
|
|
234
|
-
target: '.authentication',
|
|
235
|
-
actions: ['setReCaptchaToken', 'setLoginId'],
|
|
236
|
-
},
|
|
237
182
|
LOGIN_PHONE: {
|
|
238
183
|
target: '.authentication',
|
|
239
184
|
actions: ['setReCaptchaToken', 'setLoginPhone'],
|
|
@@ -276,28 +221,12 @@ export default function (request) {
|
|
|
276
221
|
},
|
|
277
222
|
},
|
|
278
223
|
actions: {
|
|
279
|
-
setSiteConfig: assign((context, event) => {
|
|
280
|
-
const { loginMethods = {}, registerMethods = {} } = event.data
|
|
281
|
-
return {
|
|
282
|
-
siteConfig: { ...event.data, loginMethods: pickBy(loginMethods), registerMethods: pickBy(registerMethods) },
|
|
283
|
-
}
|
|
284
|
-
}),
|
|
285
224
|
setReCaptchaToken: assign((context, event) => {
|
|
286
225
|
const { reCaptchaToken } = event.data
|
|
287
226
|
return {
|
|
288
227
|
reCaptchaToken,
|
|
289
228
|
}
|
|
290
229
|
}),
|
|
291
|
-
setLoginId: assign((context, event) => {
|
|
292
|
-
const { username, password } = event.data
|
|
293
|
-
return {
|
|
294
|
-
loginData: {
|
|
295
|
-
provider: 'local',
|
|
296
|
-
username,
|
|
297
|
-
password,
|
|
298
|
-
},
|
|
299
|
-
}
|
|
300
|
-
}),
|
|
301
230
|
setLoginPhone: assign((context, event) => {
|
|
302
231
|
const { countryCode, countryAbbr, phone, password } = event.data
|
|
303
232
|
return {
|
|
@@ -350,31 +279,22 @@ export default function (request) {
|
|
|
350
279
|
}
|
|
351
280
|
}),
|
|
352
281
|
setAccount: assign((context, event) => {
|
|
353
|
-
if (context.loginData.
|
|
354
|
-
storage.remove(accountEmailKey)
|
|
355
|
-
storage.remove(accountPhoneKey)
|
|
356
|
-
storage.set(accountUsernameKey, `${context.loginData.username}`, {
|
|
357
|
-
path: '/',
|
|
358
|
-
maxAge: 60 * 60 * 24 * 31,
|
|
359
|
-
})
|
|
360
|
-
} else if (context.loginData.phone) {
|
|
282
|
+
if (context.loginData.phone) {
|
|
361
283
|
storage.remove(accountEmailKey)
|
|
362
|
-
storage.remove(accountUsernameKey)
|
|
363
284
|
storage.set(accountPhoneKey, `${context.loginData.phone}`, {
|
|
364
285
|
path: '/',
|
|
365
|
-
maxAge: 60 * 60 * 24 *
|
|
286
|
+
maxAge: 60 * 60 * 24 * 7,
|
|
366
287
|
})
|
|
367
288
|
storage.set(phoneCountryCode, `${context.countryAbbr}_${context.loginData.countryCode}`, {
|
|
368
289
|
path: '/',
|
|
369
|
-
maxAge: 60 * 60 * 24 *
|
|
290
|
+
maxAge: 60 * 60 * 24 * 7,
|
|
370
291
|
})
|
|
371
292
|
} else if (context.loginData.email) {
|
|
372
293
|
storage.remove(accountPhoneKey)
|
|
373
294
|
storage.remove(phoneCountryCode)
|
|
374
|
-
storage.remove(accountUsernameKey)
|
|
375
295
|
storage.set(accountEmailKey, context.loginData.email, {
|
|
376
296
|
path: '/',
|
|
377
|
-
maxAge: 60 * 60 * 24 *
|
|
297
|
+
maxAge: 60 * 60 * 24 * 7,
|
|
378
298
|
})
|
|
379
299
|
}
|
|
380
300
|
}),
|
|
@@ -394,51 +314,32 @@ export default function (request) {
|
|
|
394
314
|
return { token }
|
|
395
315
|
}),
|
|
396
316
|
redirectTo3Party: async (context, event) => {
|
|
397
|
-
const { provider, channel, subchannel,
|
|
398
|
-
const deviceTokenEnable = context.siteConfig?.dtVerify === '1'
|
|
317
|
+
const { provider, channel, subchannel, affiliate } = event.data
|
|
399
318
|
|
|
400
|
-
await getDeviceToken({
|
|
401
|
-
|
|
402
|
-
sentry,
|
|
403
|
-
hosts: request.hosts,
|
|
404
|
-
enable: deviceTokenEnable,
|
|
405
|
-
})
|
|
319
|
+
const dt = await getDeviceToken({ fpToken, sentry, apiURL: request.config.apiURL })
|
|
320
|
+
sentry.setTag('dt', dt)
|
|
406
321
|
|
|
407
|
-
const affiliateCode = storage.get('ac')
|
|
408
|
-
const nickname = storage.get('nk')
|
|
409
322
|
const messages = {
|
|
410
323
|
url: window.location.href,
|
|
411
|
-
|
|
324
|
+
list: [
|
|
412
325
|
{ channel: storage.get('channel'), subchannel: storage.get('subchannel') },
|
|
413
326
|
{ channel: defaultChannel, subchannel: defaultSubchannel },
|
|
414
327
|
{ channel: channel, subchannel: subchannel },
|
|
415
328
|
],
|
|
416
|
-
affiliateCode,
|
|
417
|
-
nickname,
|
|
418
329
|
}
|
|
419
330
|
sentry.captureMessage(JSON.stringify(messages))
|
|
420
331
|
|
|
421
|
-
const referralObj = {}
|
|
422
|
-
if (![undefined, 'undefined', null, 'null'].includes(affiliateCode)) {
|
|
423
|
-
referralObj.ac = affiliateCode
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
if (![undefined, 'undefined', null, 'null'].includes(nickname)) {
|
|
427
|
-
referralObj.nick_name = nickname
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
referralObj.channel = storage.get('channel') || defaultChannel || channel
|
|
431
|
-
referralObj.subchannel = storage.get('subchannel') || defaultSubchannel || subchannel
|
|
432
|
-
|
|
433
332
|
const redirectURL = urljoin(
|
|
434
333
|
request.config.fullURL,
|
|
435
334
|
'login?' +
|
|
436
335
|
new URLSearchParams({
|
|
437
336
|
provider,
|
|
438
337
|
redirectURI: `${window.location.protocol}//${window.location.host}${context.base}`,
|
|
439
|
-
|
|
338
|
+
channel: storage.get('channel') || channel || defaultChannel || 'official',
|
|
339
|
+
subchannel: storage.get('subchannel') || subchannel || defaultSubchannel || 'pwa',
|
|
340
|
+
// dt,
|
|
440
341
|
platform: 'pwa',
|
|
441
|
-
|
|
342
|
+
affiliate,
|
|
442
343
|
}).toString()
|
|
443
344
|
)
|
|
444
345
|
|
|
@@ -476,20 +377,6 @@ export default function (request) {
|
|
|
476
377
|
fetchUserInfo: async (context, event) => {
|
|
477
378
|
return await request.send(user.getUserInfo())
|
|
478
379
|
},
|
|
479
|
-
checkDeviceToken: async (context, event) => {
|
|
480
|
-
const deviceTokenEnable = context.siteConfig?.dtVerify === '1'
|
|
481
|
-
if (deviceTokenEnable) {
|
|
482
|
-
const { exist } = await request.send(user.checkDt())
|
|
483
|
-
if (!exist) {
|
|
484
|
-
const dt = await getDeviceToken({ fpToken, sentry, hosts: request.hosts, enable: deviceTokenEnable })
|
|
485
|
-
await request.send(user.updateDt({ dt }))
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
},
|
|
489
|
-
fetchSiteConfig: async (context, event) => {
|
|
490
|
-
const { config } = await request.send(common.getConfig({ appSecret }))
|
|
491
|
-
return JSON.parse(window.atob(config))
|
|
492
|
-
},
|
|
493
380
|
},
|
|
494
381
|
}
|
|
495
382
|
)
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { assign, createMachine } from 'xstate'
|
|
2
|
+
import api from '../api/user.js'
|
|
3
|
+
|
|
4
|
+
export default function (request) {
|
|
5
|
+
return createMachine(
|
|
6
|
+
{
|
|
7
|
+
id: 'auth_otp',
|
|
8
|
+
initial: 'fetching',
|
|
9
|
+
context: {
|
|
10
|
+
userInfo: null,
|
|
11
|
+
error: null,
|
|
12
|
+
countryCode: null,
|
|
13
|
+
phone: null,
|
|
14
|
+
number: null,
|
|
15
|
+
requestId: null,
|
|
16
|
+
ttl: 0,
|
|
17
|
+
},
|
|
18
|
+
states: {
|
|
19
|
+
fetching: {
|
|
20
|
+
invoke: {
|
|
21
|
+
src: 'fetchUserInfo',
|
|
22
|
+
onDone: {
|
|
23
|
+
target: 'checking',
|
|
24
|
+
actions: 'setUserInfo',
|
|
25
|
+
},
|
|
26
|
+
onError: {
|
|
27
|
+
target: 'fail',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
checking: {
|
|
32
|
+
always: [
|
|
33
|
+
{ target: 'verified', cond: 'isVerified' },
|
|
34
|
+
{ target: 'notVerified', cond: 'isNotVerified' },
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
notVerified: {
|
|
38
|
+
initial: 'checkingStatus',
|
|
39
|
+
states: {
|
|
40
|
+
checkingStatus: {
|
|
41
|
+
invoke: {
|
|
42
|
+
src: 'verify',
|
|
43
|
+
onDone: {
|
|
44
|
+
target: 'otp',
|
|
45
|
+
actions: 'setVerificationData',
|
|
46
|
+
},
|
|
47
|
+
onError: {
|
|
48
|
+
target: 'errorChecking',
|
|
49
|
+
actions: 'setError',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
errorChecking: {
|
|
54
|
+
always: [{ target: 'phone', cond: 'hasNoPhone' }, { target: '#auth_otp.fail' }],
|
|
55
|
+
},
|
|
56
|
+
phone: {
|
|
57
|
+
on: {
|
|
58
|
+
SEND_PHONE: {
|
|
59
|
+
target: 'sendingPhone',
|
|
60
|
+
actions: 'setPhone',
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
sendingPhone: {
|
|
65
|
+
invoke: {
|
|
66
|
+
src: 'sendPhone',
|
|
67
|
+
onDone: {
|
|
68
|
+
target: 'checkingStatus',
|
|
69
|
+
},
|
|
70
|
+
onError: { target: 'phone' },
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
otp: {
|
|
74
|
+
type: 'parallel',
|
|
75
|
+
states: {
|
|
76
|
+
countdown: {
|
|
77
|
+
after: {
|
|
78
|
+
1000: {
|
|
79
|
+
target: 'countdown',
|
|
80
|
+
actions: 'decreaseTtl',
|
|
81
|
+
cond: (context) => context.ttl > 0,
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
verification: {
|
|
86
|
+
initial: 'idle',
|
|
87
|
+
states: {
|
|
88
|
+
idle: {
|
|
89
|
+
on: {
|
|
90
|
+
SEND_OTP: {
|
|
91
|
+
target: 'acknowledging',
|
|
92
|
+
},
|
|
93
|
+
RESET_OTP: {
|
|
94
|
+
target: 'reset',
|
|
95
|
+
},
|
|
96
|
+
RESEND_PHONE: {
|
|
97
|
+
target: '#auth_otp.notVerified.phone',
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
acknowledging: {
|
|
102
|
+
invoke: {
|
|
103
|
+
src: 'acknowledge',
|
|
104
|
+
onDone: {
|
|
105
|
+
target: '#auth_otp.verified',
|
|
106
|
+
},
|
|
107
|
+
onError: {
|
|
108
|
+
target: 'idle',
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
reset: {
|
|
113
|
+
invoke: {
|
|
114
|
+
src: 'resetOtp',
|
|
115
|
+
onDone: {
|
|
116
|
+
target: 'idle',
|
|
117
|
+
actions: 'setVerificationData',
|
|
118
|
+
},
|
|
119
|
+
onError: { target: 'idle' },
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
verified: {},
|
|
129
|
+
fail: {},
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
actions: {
|
|
134
|
+
setUserInfo: assign((context, event) => {
|
|
135
|
+
return {
|
|
136
|
+
userInfo: event.data,
|
|
137
|
+
}
|
|
138
|
+
}),
|
|
139
|
+
setVerificationData: assign((context, event) => {
|
|
140
|
+
const { number, requestId, ttl } = event.data
|
|
141
|
+
return {
|
|
142
|
+
number,
|
|
143
|
+
requestId,
|
|
144
|
+
ttl,
|
|
145
|
+
}
|
|
146
|
+
}),
|
|
147
|
+
decreaseTtl: assign((context, evnet) => {
|
|
148
|
+
const ms = context.ttl
|
|
149
|
+
return {
|
|
150
|
+
ttl: Math.max(ms - 1000, 0),
|
|
151
|
+
}
|
|
152
|
+
}),
|
|
153
|
+
setError: assign((context, event) => {
|
|
154
|
+
return {
|
|
155
|
+
error: event.data,
|
|
156
|
+
}
|
|
157
|
+
}),
|
|
158
|
+
setPhone: assign((context, event) => {
|
|
159
|
+
const { countryCode, phone } = event.data
|
|
160
|
+
return {
|
|
161
|
+
countryCode,
|
|
162
|
+
phone,
|
|
163
|
+
}
|
|
164
|
+
}),
|
|
165
|
+
},
|
|
166
|
+
guards: {
|
|
167
|
+
isVerified: (context, event) => {
|
|
168
|
+
return context.userInfo?.verification_status === 1
|
|
169
|
+
},
|
|
170
|
+
isNotVerified: (context, event) => {
|
|
171
|
+
return context.userInfo && context.userInfo.verification_status !== 1
|
|
172
|
+
},
|
|
173
|
+
hasNoPhone: (context, event) => {
|
|
174
|
+
const { error } = context
|
|
175
|
+
return error.code === 'ERR_F106'
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
services: {
|
|
179
|
+
fetchUserInfo: async (context, event) => {
|
|
180
|
+
return await request.send(api.getUserInfo())
|
|
181
|
+
},
|
|
182
|
+
verify: async (context, event) => {
|
|
183
|
+
return await request.send(api.verify())
|
|
184
|
+
},
|
|
185
|
+
sendPhone: async (context, event) => {
|
|
186
|
+
const { countryCode, phone } = context
|
|
187
|
+
return await request.send(api.updateUserInfo({ countryCode, phone }))
|
|
188
|
+
},
|
|
189
|
+
resetOtp: async (context, event) => {
|
|
190
|
+
const { requestId, number } = context
|
|
191
|
+
return await request.send(api.resetOtp({ requestId, number }))
|
|
192
|
+
},
|
|
193
|
+
acknowledge: async (context, event) => {
|
|
194
|
+
const { requestId } = context
|
|
195
|
+
const code = event.data
|
|
196
|
+
return await request.send(api.acknowledge({ requestId, code }))
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
}
|
|
200
|
+
)
|
|
201
|
+
}
|
|
@@ -34,16 +34,10 @@ export default function (request) {
|
|
|
34
34
|
otpFetching: {
|
|
35
35
|
invoke: {
|
|
36
36
|
src: 'sendOtp',
|
|
37
|
-
onDone:
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
target: 'otp',
|
|
44
|
-
actions: 'setOtpResult',
|
|
45
|
-
},
|
|
46
|
-
],
|
|
37
|
+
onDone: {
|
|
38
|
+
target: 'otp',
|
|
39
|
+
actions: 'setOtpResult',
|
|
40
|
+
},
|
|
47
41
|
onError: {
|
|
48
42
|
target: 'idle',
|
|
49
43
|
},
|
|
@@ -16,7 +16,6 @@ export default function (request) {
|
|
|
16
16
|
email: null,
|
|
17
17
|
target: null,
|
|
18
18
|
requestId: null,
|
|
19
|
-
status: null,
|
|
20
19
|
ttl: 0,
|
|
21
20
|
},
|
|
22
21
|
states: {
|
|
@@ -116,14 +115,11 @@ export default function (request) {
|
|
|
116
115
|
},
|
|
117
116
|
},
|
|
118
117
|
verification: {
|
|
119
|
-
initial: '
|
|
118
|
+
initial: 'idle',
|
|
120
119
|
states: {
|
|
121
|
-
checking: {
|
|
122
|
-
always: [{ target: '#auth_otp.verified', cond: 'isAutoVerified' }, { target: 'idle' }],
|
|
123
|
-
},
|
|
124
120
|
idle: {
|
|
125
121
|
on: {
|
|
126
|
-
|
|
122
|
+
SEND_OTP: {
|
|
127
123
|
target: 'acknowledging',
|
|
128
124
|
},
|
|
129
125
|
RESET_OTP: {
|
|
@@ -178,12 +174,11 @@ export default function (request) {
|
|
|
178
174
|
}
|
|
179
175
|
}),
|
|
180
176
|
setVerificationData: assign((context, event) => {
|
|
181
|
-
const { requestId, ttl, target
|
|
177
|
+
const { requestId, ttl, target } = event.data
|
|
182
178
|
return {
|
|
183
179
|
requestId,
|
|
184
180
|
ttl: ttl * 1000,
|
|
185
181
|
target,
|
|
186
|
-
status,
|
|
187
182
|
}
|
|
188
183
|
}),
|
|
189
184
|
decreaseTtl: assign((context, evnet) => {
|
|
@@ -230,9 +225,6 @@ export default function (request) {
|
|
|
230
225
|
const { error } = context
|
|
231
226
|
return error.code === 'ERR_F106'
|
|
232
227
|
},
|
|
233
|
-
isAutoVerified: (context, event) => {
|
|
234
|
-
return context.status === 'success-verified'
|
|
235
|
-
},
|
|
236
228
|
},
|
|
237
229
|
services: {
|
|
238
230
|
fetchUserInfo: async (context, event) => {
|