@jetthai/cuora 1.1.9 → 1.1.11
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/.husky/pre-commit +4 -0
- package/.prettierignore +1 -0
- package/CHANGELOG.md +9 -2
- package/README.md +6 -0
- package/dist/bundle.mjs +2355 -3495
- package/package.json +6 -3
- package/rollup.config.js +3 -7
- package/src/api/activity.js +1 -1
- package/src/api/auth.js +4 -2
- package/src/api/game.js +14 -2
- package/src/api/payment.js +25 -5
- package/src/machine/activity/activity.js +7 -7
- package/src/machine/activity/affiliate_invite_friends_activity.js +16 -19
- package/src/machine/activity/invite_friends_activity.js +1 -1
- package/src/machine/activity/sign_in_activity.js +1 -1
- package/src/machine/auth.js +11 -4
- package/src/machine/bank_binding_amb.js +141 -0
- package/src/machine/common.js +3 -4
- package/src/machine/deposit/amb.js +90 -0
- package/src/machine/deposit/crypto.js +1 -1
- package/src/machine/deposit/crypto_button.js +24 -22
- package/src/machine/deposit/deposit_fc.js +8 -5
- package/src/machine/deposit/float.js +295 -0
- package/src/machine/deposit/index.js +16 -1
- package/src/machine/deposit/loadcard_vn.js +1 -1
- package/src/machine/deposit/manual_vn.js +5 -11
- package/src/machine/deposit/qrcode_v2.js +18 -14
- package/src/machine/deposit/qrcode_vn.js +1 -1
- package/src/machine/deposit/vpay.js +292 -0
- package/src/machine/game_favorite_v2.js +1 -1
- package/src/machine/game_search_v2.js +40 -14
- package/src/machine/game_v2.js +6 -9
- package/src/machine/index.js +4 -0
- package/src/machine/reward.js +2 -2
- package/src/machine/side_v2.js +12 -12
- package/src/machine/user_sign_up.js +4 -5
- package/src/machine/withdraw_amb.js +373 -0
- package/src/machine/withdraw_crypto.js +37 -25
- package/src/machine/withdraw_fc.js +1 -1
- package/src/util/constant.js +1 -1
- package/src/util/storage.js +22 -22
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
import { assign, createMachine } from 'xstate'
|
|
2
|
+
import findLastIndex from 'lodash/findLastIndex.js'
|
|
3
|
+
import payment from '../api/payment.js'
|
|
4
|
+
import common from '../api/common.js'
|
|
5
|
+
import user from '../api/user.js'
|
|
6
|
+
|
|
7
|
+
export default function (request) {
|
|
8
|
+
const { appSecret } = request.config
|
|
9
|
+
return createMachine(
|
|
10
|
+
{
|
|
11
|
+
id: 'withdraw_amb',
|
|
12
|
+
initial: 'loading',
|
|
13
|
+
context: {
|
|
14
|
+
siteConfig: null,
|
|
15
|
+
userInfo: null,
|
|
16
|
+
balance: null,
|
|
17
|
+
charge: null,
|
|
18
|
+
realAmount: null,
|
|
19
|
+
applyId: null,
|
|
20
|
+
methods: [],
|
|
21
|
+
paymentDetail: [],
|
|
22
|
+
bankInfo: [],
|
|
23
|
+
bankList: [],
|
|
24
|
+
withdrawLimit: null,
|
|
25
|
+
targetWithdrawLimit: null,
|
|
26
|
+
|
|
27
|
+
amount: null,
|
|
28
|
+
|
|
29
|
+
// otp
|
|
30
|
+
requestId: null,
|
|
31
|
+
status: null,
|
|
32
|
+
target: null,
|
|
33
|
+
ttl: null,
|
|
34
|
+
},
|
|
35
|
+
states: {
|
|
36
|
+
loading: {
|
|
37
|
+
invoke: {
|
|
38
|
+
src: 'fetchInitData',
|
|
39
|
+
onDone: {
|
|
40
|
+
target: 'mode',
|
|
41
|
+
actions: ['setInitData', 'preset'],
|
|
42
|
+
},
|
|
43
|
+
onError: {
|
|
44
|
+
target: 'fail',
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
mode: {
|
|
49
|
+
always: [{ target: 'free', cond: 'isFree' }, { target: 'cash' }],
|
|
50
|
+
},
|
|
51
|
+
free: {
|
|
52
|
+
initial: 'loading',
|
|
53
|
+
states: {
|
|
54
|
+
loading: {
|
|
55
|
+
invoke: {
|
|
56
|
+
src: 'fetchWithdrawRules',
|
|
57
|
+
onDone: {
|
|
58
|
+
target: 'checking',
|
|
59
|
+
actions: 'updateWithdrawCondition',
|
|
60
|
+
},
|
|
61
|
+
onError: {
|
|
62
|
+
target: 'notConvertible',
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
checking: {
|
|
67
|
+
always: [{ target: 'convertible', cond: 'isConvertible' }, { target: 'notConvertible' }],
|
|
68
|
+
},
|
|
69
|
+
notConvertible: {},
|
|
70
|
+
convertible: {
|
|
71
|
+
on: {
|
|
72
|
+
SUBMIT: {
|
|
73
|
+
target: 'converting',
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
converting: {
|
|
78
|
+
invoke: {
|
|
79
|
+
src: 'submitWithdrawFree',
|
|
80
|
+
onDone: [
|
|
81
|
+
{
|
|
82
|
+
target: '#withdraw_amb.otp',
|
|
83
|
+
actions: 'setOtp',
|
|
84
|
+
cond: 'isOtpRequired',
|
|
85
|
+
},
|
|
86
|
+
{ target: 'converted' },
|
|
87
|
+
],
|
|
88
|
+
onError: {
|
|
89
|
+
target: 'convertible',
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
converted: {},
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
cash: {
|
|
97
|
+
initial: 'checking',
|
|
98
|
+
states: {
|
|
99
|
+
checking: {
|
|
100
|
+
always: [
|
|
101
|
+
{ target: 'notWithdrawable', cond: 'isNotWithdrawable' },
|
|
102
|
+
{ target: 'unbound', cond: 'isBankNotBound' },
|
|
103
|
+
{ target: 'withdrawable' },
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
notWithdrawable: {},
|
|
107
|
+
unbound: {
|
|
108
|
+
// to bank_binding.js
|
|
109
|
+
},
|
|
110
|
+
withdrawable: {
|
|
111
|
+
entry: 'setMaximumWithdrawAmount',
|
|
112
|
+
on: {
|
|
113
|
+
SUBMIT: {
|
|
114
|
+
target: 'submitting',
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
submitting: {
|
|
119
|
+
invoke: {
|
|
120
|
+
src: 'submitWithdraw',
|
|
121
|
+
onDone: [
|
|
122
|
+
{
|
|
123
|
+
target: '#withdraw_amb.otp',
|
|
124
|
+
actions: 'setOtp',
|
|
125
|
+
cond: 'isOtpRequired',
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
target: 'submitted',
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
onError: {
|
|
132
|
+
target: 'withdrawable',
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
submitted: {
|
|
137
|
+
entry: assign((context, event) => {
|
|
138
|
+
const { applyId, balance, realAmount, charge } = event.data
|
|
139
|
+
return { applyId, balance, realAmount, charge }
|
|
140
|
+
}),
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
otp: {
|
|
145
|
+
type: 'parallel',
|
|
146
|
+
states: {
|
|
147
|
+
countdown: {
|
|
148
|
+
after: {
|
|
149
|
+
1000: {
|
|
150
|
+
target: 'countdown',
|
|
151
|
+
actions: 'decreaseTtl',
|
|
152
|
+
cond: (context) => context.ttl > 0,
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
verification: {
|
|
157
|
+
initial: 'idle',
|
|
158
|
+
states: {
|
|
159
|
+
idle: {
|
|
160
|
+
on: {
|
|
161
|
+
ACKNOWLEDGE: {
|
|
162
|
+
target: 'acknowledging',
|
|
163
|
+
},
|
|
164
|
+
RESET_OTP: {
|
|
165
|
+
target: 'reset',
|
|
166
|
+
},
|
|
167
|
+
BACK: [
|
|
168
|
+
{
|
|
169
|
+
target: '#withdraw_amb.free.convertible',
|
|
170
|
+
cond: 'isFree',
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
target: '#withdraw_amb.cash.withdrawable',
|
|
174
|
+
},
|
|
175
|
+
],
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
acknowledging: {
|
|
179
|
+
invoke: {
|
|
180
|
+
src: 'acknowledge',
|
|
181
|
+
onDone: [
|
|
182
|
+
{
|
|
183
|
+
target: '#withdraw_amb.free.converted',
|
|
184
|
+
cond: 'isFree',
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
target: '#withdraw_amb.cash.submitted',
|
|
188
|
+
},
|
|
189
|
+
],
|
|
190
|
+
onError: {
|
|
191
|
+
target: 'idle',
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
reset: {
|
|
196
|
+
invoke: {
|
|
197
|
+
src: 'resetOtp',
|
|
198
|
+
onDone: {
|
|
199
|
+
target: 'idle',
|
|
200
|
+
actions: 'setVerificationData',
|
|
201
|
+
},
|
|
202
|
+
onError: { target: 'idle' },
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
fail: {},
|
|
210
|
+
},
|
|
211
|
+
on: {
|
|
212
|
+
REFRESH: {
|
|
213
|
+
target: 'loading',
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
actions: {
|
|
219
|
+
setInitData: assign((context, event) => {
|
|
220
|
+
return {
|
|
221
|
+
paymentDetail: event.data.paymentDetail,
|
|
222
|
+
bankInfo: event.data.bankInfo,
|
|
223
|
+
bonus: event.data.bonus,
|
|
224
|
+
bankList: event.data.bankList,
|
|
225
|
+
}
|
|
226
|
+
}),
|
|
227
|
+
setPaymentData: assign((context, event) => {
|
|
228
|
+
return {
|
|
229
|
+
bankInfo: event.data.bankInfo,
|
|
230
|
+
bonus: event.data.bonus,
|
|
231
|
+
paymentDetail: event.data.paymentDetail,
|
|
232
|
+
}
|
|
233
|
+
}),
|
|
234
|
+
preset: assign((context, event) => {
|
|
235
|
+
const { userInfo, siteConfig } = event.data
|
|
236
|
+
const { withdraw_limit, target_withdraw_limit } = userInfo || {}
|
|
237
|
+
const balance = parseFloat(userInfo?.balance)
|
|
238
|
+
const methods = siteConfig?.paymentMethods?.withdraw || []
|
|
239
|
+
return {
|
|
240
|
+
withdrawLimit: Math.abs(withdraw_limit),
|
|
241
|
+
targetWithdrawLimit: Math.abs(target_withdraw_limit),
|
|
242
|
+
methods,
|
|
243
|
+
balance,
|
|
244
|
+
siteConfig,
|
|
245
|
+
userInfo,
|
|
246
|
+
}
|
|
247
|
+
}),
|
|
248
|
+
updateWithdrawCondition: assign((context, event) => {
|
|
249
|
+
const rules = event.data.rules.filter((rule) => rule.maxWithdrawAmount > 0)
|
|
250
|
+
|
|
251
|
+
const { balance, withdrawLimit } = context
|
|
252
|
+
const lastMatchedIndex = findLastIndex(rules, (rule) => balance >= rule.greaterEqualThen)
|
|
253
|
+
|
|
254
|
+
let maxWithdrawAmount = 0,
|
|
255
|
+
availableWithdrawAmount = 0
|
|
256
|
+
|
|
257
|
+
if (lastMatchedIndex > -1) {
|
|
258
|
+
rules[lastMatchedIndex].match = true
|
|
259
|
+
maxWithdrawAmount = rules[lastMatchedIndex].maxWithdrawAmount
|
|
260
|
+
|
|
261
|
+
if (withdrawLimit === 0) {
|
|
262
|
+
availableWithdrawAmount = Math.min(balance, maxWithdrawAmount)
|
|
263
|
+
}
|
|
264
|
+
} else if (rules.length > 0) {
|
|
265
|
+
maxWithdrawAmount = rules[0].maxWithdrawAmount
|
|
266
|
+
} else {
|
|
267
|
+
maxWithdrawAmount = balance
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return {
|
|
271
|
+
maxWithdrawAmount,
|
|
272
|
+
availableWithdrawAmount,
|
|
273
|
+
}
|
|
274
|
+
}),
|
|
275
|
+
setOtp: assign((context, event) => {
|
|
276
|
+
const { requestId, status, target, ttl } = event.data
|
|
277
|
+
return {
|
|
278
|
+
requestId,
|
|
279
|
+
status,
|
|
280
|
+
target,
|
|
281
|
+
ttl,
|
|
282
|
+
}
|
|
283
|
+
}),
|
|
284
|
+
decreaseTtl: assign((context, evnet) => {
|
|
285
|
+
const second = context.ttl
|
|
286
|
+
return {
|
|
287
|
+
ttl: Math.max(second - 1, 0),
|
|
288
|
+
}
|
|
289
|
+
}),
|
|
290
|
+
setVerificationData: assign((context, event) => {
|
|
291
|
+
const { requestId, ttl, target } = event.data
|
|
292
|
+
return {
|
|
293
|
+
requestId,
|
|
294
|
+
ttl,
|
|
295
|
+
target,
|
|
296
|
+
}
|
|
297
|
+
}),
|
|
298
|
+
setMaximumWithdrawAmount: assign((context, event) => {
|
|
299
|
+
const { balance, paymentDetail } = context
|
|
300
|
+
return {
|
|
301
|
+
amount: Math.min(balance, paymentDetail[0]?.maximum || 0),
|
|
302
|
+
}
|
|
303
|
+
}),
|
|
304
|
+
},
|
|
305
|
+
guards: {
|
|
306
|
+
isFree: (context, event) => {
|
|
307
|
+
return context.userInfo?.withdraw_rule !== 'DEFAULT'
|
|
308
|
+
},
|
|
309
|
+
isWithdrawDisable: (context, event) => {
|
|
310
|
+
const { siteConfig } = context
|
|
311
|
+
const methods = siteConfig?.paymentMethods?.withdraw || []
|
|
312
|
+
return methods.length === 0
|
|
313
|
+
},
|
|
314
|
+
isBankNotBound: (context, event) => {
|
|
315
|
+
return !context.bankInfo?.length
|
|
316
|
+
},
|
|
317
|
+
isConvertible: (context, event) => {
|
|
318
|
+
const { balance, withdrawLimit } = context
|
|
319
|
+
return balance > 0 && withdrawLimit === 0
|
|
320
|
+
},
|
|
321
|
+
isNotWithdrawable: (context, event) => {
|
|
322
|
+
const { balance, withdrawLimit, paymentDetail } = context
|
|
323
|
+
const minWithdrawAmount = paymentDetail[0]?.minimum || 0
|
|
324
|
+
return withdrawLimit !== 0 || balance < minWithdrawAmount
|
|
325
|
+
},
|
|
326
|
+
isOtpRequired: (context, event) => {
|
|
327
|
+
return event.data?.status === 'otp-verifying'
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
services: {
|
|
331
|
+
fetchInitData: async (context, event) => {
|
|
332
|
+
const [{ config }, userInfo, paymentDetail = [], { bonus, bankInfo }] = await Promise.all([
|
|
333
|
+
request.send(common.getConfig({ appSecret })),
|
|
334
|
+
request.send(user.getUserInfo()),
|
|
335
|
+
request.send(payment.getPaymentDetail({ transferType: 'WITHDRAW' })),
|
|
336
|
+
request.send(payment.getPaymentInfo()),
|
|
337
|
+
])
|
|
338
|
+
const siteConfig = JSON.parse(window.atob(config))
|
|
339
|
+
const method = paymentDetail.find((payment) => payment.category === 'amb').method
|
|
340
|
+
const bankList = await request.send(payment.getBankList(method))
|
|
341
|
+
const newBankInfo = bankInfo.map((item) => {
|
|
342
|
+
return { ...item, ...bankList.find((bank) => bank.bankCode === item.bankCode) }
|
|
343
|
+
})
|
|
344
|
+
return { siteConfig, userInfo, paymentDetail, bonus, bankInfo: newBankInfo, bankList }
|
|
345
|
+
},
|
|
346
|
+
fetchPaymentData: async (context, event) => {
|
|
347
|
+
const paymentDetail = await request.send(payment.getPaymentDetail({ transferType: 'WITHDRAW' }))
|
|
348
|
+
const { bonus, bankInfo } = await request.send(payment.getPaymentInfo())
|
|
349
|
+
return { bonus, bankInfo, paymentDetail }
|
|
350
|
+
},
|
|
351
|
+
fetchWithdrawRules: async (context, event) => {
|
|
352
|
+
return await request.send(payment.getCurrentWithdrawRule())
|
|
353
|
+
},
|
|
354
|
+
submitWithdraw: async (context, event) => {
|
|
355
|
+
const { method } = context.paymentDetail[0]
|
|
356
|
+
return await request.send(payment.submitWithdrawTransactionAmb({ method }))
|
|
357
|
+
},
|
|
358
|
+
submitWithdrawFree: async (context, event) => {
|
|
359
|
+
return await request.send(payment.convertFreeCredit({ exchangeType: 1 }))
|
|
360
|
+
},
|
|
361
|
+
resetOtp: async (context, event) => {
|
|
362
|
+
const { requestId, target } = context
|
|
363
|
+
return await request.send(user.otpReset({ requestId, target }))
|
|
364
|
+
},
|
|
365
|
+
acknowledge: async (context, event) => {
|
|
366
|
+
const { requestId, target } = context
|
|
367
|
+
const code = event.data
|
|
368
|
+
return await request.send(user.otpAcknowledge({ requestId, target, code }))
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
}
|
|
372
|
+
)
|
|
373
|
+
}
|
|
@@ -84,13 +84,16 @@ export default function (request) {
|
|
|
84
84
|
converting: {
|
|
85
85
|
invoke: {
|
|
86
86
|
src: 'submitWithdrawFree',
|
|
87
|
-
onDone: [
|
|
87
|
+
onDone: [
|
|
88
|
+
{
|
|
88
89
|
target: '#withdraw_crypto.otp',
|
|
89
90
|
actions: 'setOtp',
|
|
90
|
-
cond: 'isOtpRequired'
|
|
91
|
-
},
|
|
91
|
+
cond: 'isOtpRequired',
|
|
92
|
+
},
|
|
93
|
+
{
|
|
92
94
|
target: 'converted',
|
|
93
|
-
}
|
|
95
|
+
},
|
|
96
|
+
],
|
|
94
97
|
onError: {
|
|
95
98
|
target: 'convertible',
|
|
96
99
|
},
|
|
@@ -158,13 +161,16 @@ export default function (request) {
|
|
|
158
161
|
submitting: {
|
|
159
162
|
invoke: {
|
|
160
163
|
src: 'submitWithdraw',
|
|
161
|
-
onDone: [
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
164
|
+
onDone: [
|
|
165
|
+
{
|
|
166
|
+
target: '#withdraw_crypto.otp',
|
|
167
|
+
actions: 'setOtp',
|
|
168
|
+
cond: 'isOtpRequired',
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
target: 'submitted',
|
|
172
|
+
},
|
|
173
|
+
],
|
|
168
174
|
onError: {
|
|
169
175
|
target: 'withdrawable',
|
|
170
176
|
},
|
|
@@ -196,23 +202,29 @@ export default function (request) {
|
|
|
196
202
|
RESET_OTP: {
|
|
197
203
|
target: 'reset',
|
|
198
204
|
},
|
|
199
|
-
BACK: [
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
+
BACK: [
|
|
206
|
+
{
|
|
207
|
+
target: '#withdraw_crypto.free.convertible',
|
|
208
|
+
cond: 'isFree',
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
target: '#withdraw_crypto.cash.submittable',
|
|
212
|
+
},
|
|
213
|
+
],
|
|
205
214
|
},
|
|
206
215
|
},
|
|
207
216
|
acknowledging: {
|
|
208
217
|
invoke: {
|
|
209
218
|
src: 'acknowledge',
|
|
210
|
-
onDone: [
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
219
|
+
onDone: [
|
|
220
|
+
{
|
|
221
|
+
target: '#withdraw_crypto.free.converted',
|
|
222
|
+
cond: 'isFree',
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
target: '#withdraw_crypto.cash.submitted',
|
|
226
|
+
},
|
|
227
|
+
],
|
|
216
228
|
onError: {
|
|
217
229
|
target: 'idle',
|
|
218
230
|
},
|
|
@@ -389,7 +401,7 @@ export default function (request) {
|
|
|
389
401
|
},
|
|
390
402
|
isOtpRequired: (context, event) => {
|
|
391
403
|
return event.data?.status === 'otp-verifying'
|
|
392
|
-
}
|
|
404
|
+
},
|
|
393
405
|
},
|
|
394
406
|
services: {
|
|
395
407
|
fetchInitData: async (context, event) => {
|
|
@@ -411,7 +423,7 @@ export default function (request) {
|
|
|
411
423
|
submitWithdraw: async (context, event) => {
|
|
412
424
|
const { crypto, selectedNetwork, address, amount } = context
|
|
413
425
|
return await request.send(
|
|
414
|
-
api.
|
|
426
|
+
api.submitWithdrawTransactionCrypto({
|
|
415
427
|
method: crypto.method,
|
|
416
428
|
amount,
|
|
417
429
|
cryptoCurrency: crypto.channel,
|
|
@@ -215,7 +215,7 @@ export default function (request) {
|
|
|
215
215
|
const { crypto, currentNetwork, currentAddress, withdrawAmount } = context
|
|
216
216
|
const method = crypto.method
|
|
217
217
|
return await request.send(
|
|
218
|
-
api.
|
|
218
|
+
api.submitWithdrawTransactionCrypto({
|
|
219
219
|
method,
|
|
220
220
|
amount: withdrawAmount,
|
|
221
221
|
cryptoCurrency: crypto.channel,
|
package/src/util/constant.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const MY_FAVORITE = 'MyFavorite'
|
|
2
|
-
export const GAME_SEARCH = 'GameSearch'
|
|
2
|
+
export const GAME_SEARCH = 'GameSearch'
|
package/src/util/storage.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
export default {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
get(name, options) {
|
|
3
|
+
const itemStr = localStorage.getItem(name)
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
if (!itemStr) {
|
|
6
|
+
return null
|
|
7
|
+
}
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
const item = JSON.parse(itemStr)
|
|
10
|
+
if (item.expiry && new Date().getTime() > item.expiry) {
|
|
11
|
+
localStorage.removeItem(name)
|
|
12
|
+
return null
|
|
13
|
+
}
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
return item.value
|
|
16
|
+
},
|
|
17
|
+
set(name, value, options) {
|
|
18
|
+
const item = { value }
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
localStorage.setItem(name, JSON.stringify(item))
|
|
24
|
-
},
|
|
25
|
-
remove(name, options) {
|
|
26
|
-
localStorage.removeItem(name)
|
|
20
|
+
if (options?.maxAge) {
|
|
21
|
+
item.expiry = new Date().getTime() + options.maxAge * 1000
|
|
27
22
|
}
|
|
28
|
-
|
|
23
|
+
localStorage.setItem(name, JSON.stringify(item))
|
|
24
|
+
},
|
|
25
|
+
remove(name, options) {
|
|
26
|
+
localStorage.removeItem(name)
|
|
27
|
+
},
|
|
28
|
+
}
|