@jetthai/cuora 1.0.35 → 1.0.37

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.37](https://github.com/jetthai/cuora-module/compare/v1.0.36...v1.0.37) (2021-11-03)
6
+
7
+ ### [1.0.36](https://github.com/jetthai/cuora-module/compare/v1.0.35...v1.0.36) (2021-10-29)
8
+
5
9
  ### [1.0.35](https://github.com/jetthai/cuora-module/compare/v1.0.34...v1.0.35) (2021-10-28)
6
10
 
7
11
  ### [1.0.34](https://github.com/jetthai/cuora-module/compare/v1.0.33...v1.0.34) (2021-10-26)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.0.35",
3
+ "version": "1.0.37",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
@@ -10,7 +10,7 @@ export default function (request) {
10
10
  activityNo: null,
11
11
  activityDetail: null,
12
12
  awards: [],
13
- awardExchangeList: [],
13
+ exchangeList: [],
14
14
  exchangeAward: 0,
15
15
  exchangePoint: 0,
16
16
  },
@@ -40,6 +40,7 @@ export default function (request) {
40
40
  on: {
41
41
  EXCHANGE: {
42
42
  target: 'exchanging',
43
+ cond: 'isExchangeable'
43
44
  },
44
45
  ADD_TO_CART: {
45
46
  actions: ['addProduct', 'count'],
@@ -104,17 +105,17 @@ export default function (request) {
104
105
  }),
105
106
  addProduct: assign((context, event) => {
106
107
  return {
107
- awardExchangeList: [...context.awardExchangeList, event.data],
108
+ exchangeList: [...context.exchangeList, event.data],
108
109
  }
109
110
  }),
110
111
  clearCart: assign((context, event) => {
111
112
  return {
112
- awardExchangeList: [],
113
+ exchangeList: [],
113
114
  }
114
115
  }),
115
116
  count: assign((context, event) => {
116
- const { awardExchangeList } = context
117
- const { exchangeAward, exchangePoint } = awardExchangeList.reduce(
117
+ const { exchangeList } = context
118
+ const { exchangeAward, exchangePoint } = exchangeList.reduce(
118
119
  ({ exchangeAward, exchangePoint }, item) => {
119
120
  return {
120
121
  exchangeAward: exchangeAward + item.award,
@@ -133,6 +134,10 @@ export default function (request) {
133
134
  hasUnclaimedReward: (context, event) => {
134
135
  return context.activityDetail?.unclaimedReward?.length > 0
135
136
  },
137
+ isExchangeable: (context, event) => {
138
+ const { exchangeList } = context
139
+ return exchangeList.length > 0
140
+ }
136
141
  },
137
142
  services: {
138
143
  fetchActivityDetail: async (context, event) => {
@@ -141,9 +146,9 @@ export default function (request) {
141
146
  return data
142
147
  },
143
148
  exchange: async (context, event) => {
144
- const { activityNo, awardExchangeList } = context
149
+ const { activityNo, exchangeList } = context
145
150
  return await Promise.all(
146
- awardExchangeList.map((item) =>
151
+ exchangeList.map((item) =>
147
152
  request.send(
148
153
  api.exchange({
149
154
  exchangeType: 1,
@@ -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,57 +95,19 @@ 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
- id: 'user',
108
102
  initial: 'idle',
109
103
  states: {
110
- idle: {
111
- on: {
112
- CHECK: {
113
- target: 'checking',
114
- },
115
- },
116
- },
117
- checking: {
118
- always: [
119
- { target: 'inline', cond: 'isInline' },
120
- {
121
- target: 'normal',
122
- },
123
- ],
124
- },
125
- inline: {},
104
+ idle: {},
126
105
  normal: {},
106
+ inline: {},
107
+ },
108
+ on: {
109
+ CHECK: [{ target: '.inline', cond: 'isInline' }, { target: '.normal' }],
127
110
  },
128
- // states: {
129
- // idle: {
130
- // on: {
131
- // UPDATE_USER_INFO: {
132
- // target: 'updatingUserInfo',
133
- // },
134
- // },
135
- // },
136
- // updatingUserInfo: {
137
- // invoke: {
138
- // src: 'updateUserInfo',
139
- // onDone: {
140
- // target: 'idle',
141
- // actions: send({ type: 'FETCH_USER_INFO' }),
142
- // },
143
- // onError: {
144
- // target: 'idle',
145
- // },
146
- // },
147
- // },
148
- // },
149
111
  },
150
112
  },
151
113
  on: {
@@ -180,12 +142,7 @@ export default function (request) {
180
142
  hasToken: (context, event) => {
181
143
  return context.token
182
144
  },
183
- isFirstLogin: (context, event) => {
184
- const { bank_account, bank_setting_status } = context.userInfo || {}
185
- return !!bank_account || bank_setting_status === 1
186
- },
187
145
  isInline: (context, event) => {
188
- console.log(context.userInfo?.rank, context.userInfo?.rank >= 0)
189
146
  return context.userInfo?.rank >= 0
190
147
  },
191
148
  },
@@ -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'
@@ -21,7 +21,7 @@ export default {
21
21
  ...activity,
22
22
  auth,
23
23
  auth_otp,
24
- check,
24
+ welcome,
25
25
  common,
26
26
  deposit,
27
27
  error,
@@ -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, uid } = context.userInfo || {}
75
- const hasBankAccount = bank_account || bank_setting_status === 1
76
- return !hasBankAccount && !cookies.get(`welcome_${uid}`)
77
- },
78
- isInquiryFilled: (context, event) => {
77
+ isFilled: (context, event) => {
79
78
  const { bonus, gender } = context
80
79
  return bonus !== null && gender !== null
81
80
  },
@@ -100,7 +99,10 @@ 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 })),