@jetthai/cuora 1.0.34 → 1.0.36

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.36](https://github.com/jetthai/cuora-module/compare/v1.0.35...v1.0.36) (2021-10-29)
6
+
7
+ ### [1.0.35](https://github.com/jetthai/cuora-module/compare/v1.0.34...v1.0.35) (2021-10-28)
8
+
5
9
  ### [1.0.34](https://github.com/jetthai/cuora-module/compare/v1.0.33...v1.0.34) (2021-10-26)
6
10
 
7
11
  ### [1.0.33](https://github.com/jetthai/cuora-module/compare/v1.0.32...v1.0.33) (2021-10-22)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.0.34",
3
+ "version": "1.0.36",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
package/src/api/user.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  getUserInfo: () => ({ url: 'self', method: 'get' }),
3
- modifyUserInfo: (data) => ({ url: 'self', method: 'post', params: data }),
3
+ updateUserInfo: (data) => ({ url: 'self', method: 'post', params: data }),
4
4
  changePassword: (data) => ({ url: 'settings/password', method: 'post', params: data }),
5
5
  setPreference: ({ defaultCategory }) => ({ url: 'settings/preference', method: 'post', params: { defaultCategory } }),
6
6
  resetOtp: ({ requestId, number }) => ({ url: 'reset', method: 'post', params: { requestId, number } }),
@@ -82,7 +82,7 @@ export default function (request) {
82
82
  src: 'fetchUserInfo',
83
83
  onDone: {
84
84
  target: 'pending',
85
- actions: ['setUserInfo', 'extendToken'],
85
+ actions: ['setUserInfo', 'extendToken', send({ type: 'CHECK' })],
86
86
  },
87
87
  onError: {
88
88
  target: '#auth.logout',
@@ -95,36 +95,18 @@ export default function (request) {
95
95
  target: 'running',
96
96
  },
97
97
  },
98
- on: {
99
- FETCH_USER_INFO: {
100
- target: 'running',
101
- },
102
- },
103
98
  },
104
99
  },
105
100
  },
106
101
  user: {
107
102
  initial: 'idle',
108
103
  states: {
109
- idle: {
110
- on: {
111
- MODIFY_USER_INFO: {
112
- target: 'modifyingUserInfo',
113
- },
114
- },
115
- },
116
- modifyingUserInfo: {
117
- invoke: {
118
- src: 'modifyUserInfo',
119
- onDone: {
120
- target: 'idle',
121
- actions: send({ type: 'FETCH_USER_INFO' }),
122
- },
123
- onError: {
124
- target: 'idle',
125
- },
126
- },
127
- },
104
+ idle: {},
105
+ normal: {},
106
+ inline: {},
107
+ },
108
+ on: {
109
+ CHECK: [{ target: '.inline', cond: 'isInline' }, { target: '.normal' }],
128
110
  },
129
111
  },
130
112
  },
@@ -160,9 +142,8 @@ export default function (request) {
160
142
  hasToken: (context, event) => {
161
143
  return context.token
162
144
  },
163
- isFirstLogin: (context, event) => {
164
- const { bank_account, bank_setting_status } = context.userInfo || {}
165
- return !!bank_account || bank_setting_status === 1
145
+ isInline: (context, event) => {
146
+ return context.userInfo?.rank >= 0
166
147
  },
167
148
  },
168
149
  actions: {
@@ -236,8 +217,8 @@ export default function (request) {
236
217
  fetchUserInfo: async (context, event) => {
237
218
  return await request.send(user.getUserInfo())
238
219
  },
239
- modifyUserInfo: async (context, event) => {
240
- return await request.send(user.modifyUserInfo(event.data))
220
+ updateUserInfo: async (context, event) => {
221
+ return await request.send(user.updateUserInfo(event.data))
241
222
  },
242
223
  },
243
224
  }
@@ -174,7 +174,7 @@ export default function (request) {
174
174
  },
175
175
  sendPhone: async (context, event) => {
176
176
  const { countryCode, phone } = context
177
- return await request.send(api.modifyUserInfo({ countryCode, phone }))
177
+ return await request.send(api.updateUserInfo({ countryCode, phone }))
178
178
  },
179
179
  resetOtp: async (context, event) => {
180
180
  const { requestId, number } = context
@@ -26,13 +26,13 @@ export default function () {
26
26
  { target: 'logout', cond: 'isLogout' },
27
27
  { target: 'deposit', cond: 'isNoBalance' },
28
28
  { target: 'unfinishedGame', cond: 'isUnfinishedGame', actions: 'setUnfinishedGame' },
29
- { target: 'hall' },
29
+ // { target: 'hall' },
30
30
  ],
31
31
  },
32
32
  logout: {},
33
33
  deposit: {},
34
34
  unfinishedGame: {},
35
- hall: {},
35
+ // hall: {},
36
36
  },
37
37
  },
38
38
  },
@@ -1,7 +1,7 @@
1
1
  import activity from './activity'
2
2
  import auth from './auth'
3
3
  import auth_otp from './auth_otp'
4
- import check from './check'
4
+ import welcome from './welcome'
5
5
  import common from './common'
6
6
  import deposit from './deposit'
7
7
  import error from './error'
@@ -15,12 +15,13 @@ import reward from './reward'
15
15
  import setting from './setting'
16
16
  import side from './side'
17
17
  import withdraw from './withdraw'
18
+ import user_info from './user_info'
18
19
 
19
20
  export default {
20
21
  ...activity,
21
22
  auth,
22
23
  auth_otp,
23
- check,
24
+ welcome,
24
25
  common,
25
26
  deposit,
26
27
  error,
@@ -34,4 +35,5 @@ export default {
34
35
  setting,
35
36
  side,
36
37
  withdraw,
38
+ user_info,
37
39
  }
@@ -0,0 +1,64 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import user from '../api/user'
3
+
4
+ export default function (request) {
5
+ return createMachine(
6
+ {
7
+ id: 'user_info',
8
+ initial: 'fetching',
9
+ context: {
10
+ userInfo: {},
11
+ },
12
+ states: {
13
+ fetching: {
14
+ invoke: {
15
+ src: 'fetchUserInfo',
16
+ onDone: {
17
+ target: 'idle',
18
+ actions: 'setUserInfo',
19
+ },
20
+ onError: {
21
+ target: 'idle',
22
+ },
23
+ },
24
+ },
25
+ idle: {
26
+ on: {
27
+ UPDATE_USER_INFO: {
28
+ target: 'updating',
29
+ },
30
+ },
31
+ },
32
+ updating: {
33
+ invoke: {
34
+ src: 'updateUserInfo',
35
+ onDone: {
36
+ target: 'idle',
37
+ // target: 'fetching', // 因為更新 userInfo 後 get self 還是拿到舊資料
38
+ },
39
+ onError: {
40
+ target: 'idle',
41
+ },
42
+ },
43
+ },
44
+ },
45
+ },
46
+ {
47
+ actions: {
48
+ setUserInfo: assign((context, event) => {
49
+ return {
50
+ userInfo: event.data,
51
+ }
52
+ }),
53
+ },
54
+ services: {
55
+ fetchUserInfo: async (context, event) => {
56
+ return await request.send(user.getUserInfo())
57
+ },
58
+ updateUserInfo: async (context, event) => {
59
+ return await request.send(user.updateUserInfo(event.data))
60
+ },
61
+ },
62
+ }
63
+ )
64
+ }
@@ -1,4 +1,4 @@
1
- import { assign, createMachine } from 'xstate'
1
+ import { assign, createMachine, send } from 'xstate'
2
2
  import Cookies from 'universal-cookie'
3
3
  import payment from '../api/payment'
4
4
  import user from '../api/user'
@@ -8,27 +8,33 @@ const cookies = new Cookies()
8
8
  export default function (request) {
9
9
  return createMachine(
10
10
  {
11
- id: 'check',
12
- initial: 'idle',
11
+ id: 'welcome',
12
+ initial: 'loading',
13
13
  context: {
14
14
  userInfo: null,
15
15
  bonus: null,
16
16
  gender: null,
17
17
  },
18
18
  states: {
19
- idle: {},
19
+ loading: {
20
+ invoke: {
21
+ src: 'fetchUserInfo',
22
+ onDone: {
23
+ target: 'checking',
24
+ actions: 'setUserInfo',
25
+ },
26
+ onError: {
27
+ target: 'checking',
28
+ },
29
+ },
30
+ },
20
31
  checking: {
21
- always: [
22
- { target: 'inline', cond: 'isInline' },
23
- { target: 'inquiry', cond: 'isInquiryIncomplete' },
24
- { target: 'completed' },
25
- ],
32
+ always: [{ target: 'firstLogin', cond: 'isFirstLogin' }, { target: 'completed' }],
26
33
  },
27
- inline: {},
28
- inquiry: {
29
- initial: 'inquiring',
34
+ firstLogin: {
35
+ initial: 'input',
30
36
  states: {
31
- inquiring: {
37
+ input: {
32
38
  on: {
33
39
  SET_BONUS: {
34
40
  actions: 'setBonus',
@@ -36,20 +42,20 @@ export default function (request) {
36
42
  SET_GENDER: {
37
43
  actions: 'setGender',
38
44
  },
39
- SEND_INQUIRY_RESULT: {
45
+ SEND_INFO: {
40
46
  target: 'submitting',
41
- cond: 'isInquiryFilled',
47
+ cond: 'isFilled',
42
48
  },
43
49
  },
44
50
  },
45
51
  submitting: {
46
52
  invoke: {
47
- src: 'sendInquiryResult',
53
+ src: 'updatingInfo',
48
54
  onDone: {
49
- target: '#check.completed',
55
+ target: '#welcome.completed',
50
56
  },
51
57
  onError: {
52
- target: '#check.completed',
58
+ target: '#welcome.completed',
53
59
  },
54
60
  },
55
61
  exit: 'setInfo',
@@ -58,24 +64,17 @@ export default function (request) {
58
64
  },
59
65
  completed: {},
60
66
  },
61
- on: {
62
- SET_USER_INFO: {
63
- target: 'checking',
64
- actions: 'setUserInfo',
65
- },
66
- },
67
67
  },
68
68
  {
69
69
  guards: {
70
- isInline: (context, event) => {
71
- return context.userInfo?.rank >= 0
70
+ isFirstLogin: (context, event) => {
71
+ const { bank_account, bank_setting_status, topup, verification_status, uid } = context.userInfo || {}
72
+ // const hasBankAccount = bank_account || bank_setting_status === 1 // sabai
73
+ const isComplete = topup === 1 || verification_status === 1
74
+ const isSent = cookies.get(`welcome_${uid}`)
75
+ return !(isSent || isComplete)
72
76
  },
73
- isInquiryIncomplete: (context, event) => {
74
- const { bank_account, bank_setting_status } = context.userInfo || {}
75
- const hasBankAccount = bank_account || bank_setting_status === 1
76
- return !hasBankAccount && !cookies.get('welcome')
77
- },
78
- isInquiryFilled: (context, event) => {
77
+ isFilled: (context, event) => {
79
78
  const { bonus, gender } = context
80
79
  return bonus !== null && gender !== null
81
80
  },
@@ -87,7 +86,7 @@ export default function (request) {
87
86
  }
88
87
  }),
89
88
  setInfo: (context, event) => {
90
- cookies.set('welcome', 'done', {
89
+ cookies.set(`welcome_${context.userInfo.uid}`, 'done', {
91
90
  path: '/',
92
91
  maxAge: 60 * 60 * 24 * 365,
93
92
  })
@@ -100,11 +99,14 @@ export default function (request) {
100
99
  }),
101
100
  },
102
101
  services: {
103
- sendInquiryResult: async (context, event) => {
102
+ fetchUserInfo: async (context, event) => {
103
+ return await request.send(user.getUserInfo())
104
+ },
105
+ updatingInfo: async (context, event) => {
104
106
  const { bonus, gender } = context
105
107
  await Promise.all([
106
108
  request.send(payment.setBonusSetting({ bonus })),
107
- request.send(user.modifyUserInfo({ gender })),
109
+ request.send(user.updateUserInfo({ gender })),
108
110
  ])
109
111
  },
110
112
  },