@jetthai/cuora 1.0.31 → 1.0.33

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.33](https://github.com/jetthai/cuora-module/compare/v1.0.32...v1.0.33) (2021-10-22)
6
+
7
+ ### [1.0.32](https://github.com/jetthai/cuora-module/compare/v1.0.31...v1.0.32) (2021-10-21)
8
+
5
9
  ### [1.0.31](https://github.com/jetthai/cuora-module/compare/v1.0.30...v1.0.31) (2021-10-21)
6
10
 
7
11
  ### [1.0.30](https://github.com/jetthai/cuora-module/compare/v1.0.29...v1.0.30) (2021-10-20)
package/README.md CHANGED
@@ -1,11 +1,19 @@
1
1
  # cuora
2
-
3
- > Intergrate API and Store for game.
2
+ Integrate API and logic by xstate.
4
3
 
5
4
  ## Installation
6
-
7
5
  Add @jetthai/cuora dependency to your project:
8
-
9
6
  ```bash
10
7
  npm install --save @jetthai/cuora
11
8
  ```
9
+
10
+ ## Setup
11
+ Add config in `nuxt.config.js` to support latest ECMAScript.
12
+ ```js
13
+ // nuxt.config.js
14
+ {
15
+ build: {
16
+ transpile: '@jetthai/cuora'
17
+ }
18
+ }
19
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.0.31",
3
+ "version": "1.0.33",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
package/src/api/common.js CHANGED
@@ -1,4 +1,6 @@
1
1
  export default {
2
2
  getConfig: ({ appSecret }) => ({ url: 'getConfig', method: 'get', params: { appSecret }, isPublic: true }),
3
3
  feeds: ({ appSecret }) => ({ url: 'feeds', method: 'get', params: { appSecret }, isPublic: true }),
4
+ broadcast: () => ({ url: 'broadcast', method: 'get', isPublic: true }),
5
+ getAnnouncements: () => ({ url: 'getAnnouncements', method: 'get', isPublic: true }),
4
6
  }
@@ -20,7 +20,7 @@ export default function (request) {
20
20
  withdrawRules: [],
21
21
  withdrawLimit: null,
22
22
  withdrawAmount: null,
23
- withdrawLeft: null,
23
+ withdrawDistance: null,
24
24
  tutorialUrls: [],
25
25
  balance: null,
26
26
  charge: null,
@@ -29,11 +29,24 @@ export default function (request) {
29
29
  idle: {
30
30
  on: {
31
31
  PRESET: {
32
- target: 'mode',
32
+ target: 'preparing',
33
33
  actions: ['setSiteConfig', 'setUserInfo', 'preset'],
34
34
  },
35
35
  },
36
36
  },
37
+ preparing: {
38
+ invoke: {
39
+ src: 'fetchPayments',
40
+ onDone: {
41
+ target: 'mode',
42
+ actions: 'setCrypto',
43
+ },
44
+ onError: {
45
+ target: 'fail',
46
+ },
47
+ },
48
+ },
49
+ fail: {},
37
50
  mode: {
38
51
  always: [{ target: 'free', cond: 'isFree' }, { target: 'cash' }],
39
52
  },
@@ -44,7 +57,7 @@ export default function (request) {
44
57
  invoke: {
45
58
  src: 'fetchWithdrawRules',
46
59
  onDone: {
47
- target: 'convertible',
60
+ target: 'checking',
48
61
  actions: 'updateWithdrawCondition',
49
62
  },
50
63
  onError: {
@@ -52,22 +65,14 @@ export default function (request) {
52
65
  },
53
66
  },
54
67
  },
68
+ checking: {
69
+ entry: 'recalculateDistance',
70
+ always: [{ target: 'convertible', cond: 'isConvertible' }, { target: 'notConvertible' }],
71
+ },
55
72
  notConvertible: {},
56
73
  convertible: {
57
- initial: 'preparing',
74
+ initial: 'operation',
58
75
  states: {
59
- preparing: {
60
- invoke: {
61
- src: 'fetchPayments',
62
- onDone: {
63
- target: 'operation',
64
- actions: 'setCrypto',
65
- },
66
- onError: {
67
- target: '#withdraw.free.notConvertible',
68
- },
69
- },
70
- },
71
76
  operation: {
72
77
  on: {
73
78
  SET_NETWORK: {
@@ -118,7 +123,7 @@ export default function (request) {
118
123
  initial: 'checking',
119
124
  states: {
120
125
  checking: {
121
- entry: 'calculateCashLeft',
126
+ entry: 'recalculateDistance',
122
127
  always: [
123
128
  { target: 'disable', cond: 'isWithdrawDisable' },
124
129
  { target: 'transferable', cond: 'isTransferable' },
@@ -129,20 +134,8 @@ export default function (request) {
129
134
  notTransferable: {},
130
135
  transferable: {
131
136
  entry: 'setBalanceToWithdrawAmount',
132
- initial: 'preparing',
137
+ initial: 'operation',
133
138
  states: {
134
- preparing: {
135
- invoke: {
136
- src: 'fetchPayments',
137
- onDone: {
138
- target: 'operation',
139
- actions: 'setCrypto',
140
- },
141
- onError: {
142
- target: '#withdraw.cash.checking',
143
- },
144
- },
145
- },
146
139
  operation: {
147
140
  on: {
148
141
  SET_NETWORK: {
@@ -227,7 +220,7 @@ export default function (request) {
227
220
  const { balance, withdrawLimit } = context
228
221
  const lastMatchedIndex = findLastIndex(rules, (rule) => balance >= rule.greaterEqualThen)
229
222
 
230
- let left = 0,
223
+ let distance = 0,
231
224
  limit,
232
225
  amount = 0
233
226
  if (lastMatchedIndex > -1) {
@@ -237,18 +230,17 @@ export default function (request) {
237
230
  } else if (withdrawLimit) {
238
231
  const diff = withdrawLimit - balance
239
232
  limit = withdrawLimit
240
- if (diff < 0) {
233
+ if (diff <= 0) {
241
234
  amount = balance
242
235
  } else {
243
- left = diff
236
+ distance = diff
244
237
  }
245
238
  } else {
246
- left = rules[0]?.greaterEqualThen - balance
247
- limit = rules[0]?.greaterEqualThen
239
+ limit = rules[0]?.greaterEqualThen || 0
240
+ distance = Math.max(limit - balance, 0)
248
241
  }
249
-
250
242
  return {
251
- withdrawLeft: left,
243
+ withdrawDistance: distance,
252
244
  withdrawAmount: amount,
253
245
  withdrawLimit: limit,
254
246
  withdrawRules: rules,
@@ -286,12 +278,13 @@ export default function (request) {
286
278
  charge: null,
287
279
  }
288
280
  }),
289
- calculateCashLeft: assign((context, event) => {
290
- const { balance, withdrawLimit } = context
291
- const diff = withdrawLimit - balance
292
- const left = Math.max(diff, 0)
281
+ recalculateDistance: assign((context, event) => {
282
+ const { balance, withdrawLimit, crypto } = context
283
+ const limit = Math.max(withdrawLimit, crypto?.minimum)
284
+ const distance = Math.max(limit - balance, 0)
293
285
  return {
294
- withdrawLeft: left,
286
+ withdrawDistance: distance,
287
+ withdrawLimit: limit,
295
288
  }
296
289
  }),
297
290
  },
@@ -304,15 +297,20 @@ export default function (request) {
304
297
  const methods = siteConfig?.paymentMethods?.withdraw || []
305
298
  return methods.length === 0
306
299
  },
300
+ isConvertible: (context, event) => {
301
+ const { balance, withdrawDistance } = context
302
+ return balance > 0 && withdrawDistance === 0
303
+ },
307
304
  isTransferable: (context, event) => {
308
- const { balance, withdrawLimit, isTurnoverMode } = context
305
+ const { balance, withdrawLimit, withdrawDistance, isTurnoverMode } = context
309
306
  if (balance === 0) {
310
307
  return false
311
308
  }
312
309
  if (isTurnoverMode) {
310
+ // not used in funnycash
313
311
  return withdrawLimit === 0
314
312
  } else {
315
- return balance - withdrawLimit >= 0
313
+ return withdrawDistance === 0
316
314
  }
317
315
  },
318
316
  isCalculable: (context, event) => {