@jolibox/implement 1.1.52-beta.1 → 1.1.53-beta.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.
Files changed (59) hide show
  1. package/.rush/temp/package-deps_build.json +33 -26
  2. package/dist/common/context/index.d.ts +1 -0
  3. package/dist/common/rewards/index.d.ts +2 -0
  4. package/dist/common/rewards/registers/use-gem-only.d.ts +10 -0
  5. package/dist/common/rewards/registers/use-gem.d.ts +10 -0
  6. package/dist/common/rewards/registers/utils/coins/commands/currency-handlers.d.ts +15 -0
  7. package/dist/common/rewards/registers/utils/coins/commands/index.d.ts +1 -1
  8. package/dist/common/rewards/registers/utils/coins/commands/use-jolicoin.d.ts +10 -8
  9. package/dist/common/rewards/registers/utils/coins/commands/use-payment.d.ts +10 -8
  10. package/dist/common/rewards/registers/utils/coins/commands/use-unlogin.d.ts +6 -8
  11. package/dist/common/rewards/registers/utils/coins/currency-config.d.ts +8 -0
  12. package/dist/common/rewards/registers/utils/coins/index.d.ts +2 -18
  13. package/dist/common/rewards/registers/utils/coins/jolicoin/jolicoin-handler.d.ts +18 -0
  14. package/dist/common/rewards/registers/utils/coins/joligem/fetch-gem-balance.d.ts +4 -0
  15. package/dist/common/rewards/registers/utils/coins/joligem/gem-handler.d.ts +19 -0
  16. package/dist/common/rewards/registers/utils/index.d.ts +3 -1
  17. package/dist/common/rewards/reward-emitter.d.ts +23 -13
  18. package/dist/common/rewards/reward-helper.d.ts +3 -1
  19. package/dist/common/rewards/type.d.ts +10 -1
  20. package/dist/index.js +25 -25
  21. package/dist/index.native.js +67 -67
  22. package/dist/native/payment/payment-helper.d.ts +5 -1
  23. package/dist/native/rewards/check-frequency.d.ts +24 -0
  24. package/implement.build.log +2 -2
  25. package/package.json +6 -6
  26. package/src/common/context/index.ts +3 -0
  27. package/src/common/rewards/__tests__/can-use-jolicoin.test.ts +265 -9
  28. package/src/common/rewards/fetch-reward.ts +18 -3
  29. package/src/common/rewards/index.ts +2 -0
  30. package/src/common/rewards/registers/use-gem-only.ts +58 -0
  31. package/src/common/rewards/registers/use-gem.ts +53 -0
  32. package/src/common/rewards/registers/use-jolicoin-only.ts +4 -4
  33. package/src/common/rewards/registers/use-jolicoin.ts +4 -4
  34. package/src/common/rewards/registers/utils/coins/commands/currency-handlers.ts +48 -0
  35. package/src/common/rewards/registers/utils/coins/commands/index.ts +1 -1
  36. package/src/common/rewards/registers/utils/coins/commands/use-jolicoin.ts +31 -19
  37. package/src/common/rewards/registers/utils/coins/commands/use-payment.ts +32 -25
  38. package/src/common/rewards/registers/utils/coins/commands/use-unlogin.ts +22 -24
  39. package/src/common/rewards/registers/utils/coins/currency-config.ts +23 -0
  40. package/src/common/rewards/registers/utils/coins/index.ts +2 -134
  41. package/src/common/rewards/registers/utils/coins/jolicoin/jolicoin-handler.ts +149 -0
  42. package/src/common/rewards/registers/utils/coins/joligem/fetch-gem-balance.ts +15 -0
  43. package/src/common/rewards/registers/utils/coins/joligem/gem-handler.ts +131 -0
  44. package/src/common/rewards/registers/utils/index.ts +20 -1
  45. package/src/common/rewards/reward-emitter.ts +23 -13
  46. package/src/common/rewards/reward-helper.ts +3 -1
  47. package/src/common/rewards/type.ts +13 -1
  48. package/src/h5/rewards/index.ts +33 -20
  49. package/src/native/api/ads.ts +22 -1
  50. package/src/native/api/call-host-method.ts +36 -1
  51. package/src/native/payment/index.ts +2 -0
  52. package/src/native/payment/payment-helper.ts +2 -1
  53. package/src/native/rewards/check-frequency.ts +10 -0
  54. package/src/native/rewards/ui/payment-modal.ts +110 -33
  55. package/src/native/rewards/ui/unlogin-modal.ts +182 -87
  56. package/src/native/rewards/ui/use-modal.ts +126 -68
  57. package/implementation.build.log +0 -9
  58. /package/dist/common/rewards/registers/utils/coins/{fetch-balance.d.ts → jolicoin/fetch-balance.d.ts} +0 -0
  59. /package/src/common/rewards/registers/utils/coins/{fetch-balance.ts → jolicoin/fetch-balance.ts} +0 -0
@@ -1,4 +1,4 @@
1
- export type PaymentType = 'JOLI_COIN' | 'JOLI_COIN_IAP';
1
+ export type PaymentType = 'JOLI_COIN' | 'JOLI_COIN_IAP' | 'JOLI_GEM_IAP';
2
2
  import { StandardResponse } from '@jolibox/types';
3
3
  type PaymentResult = StandardResponse<void>;
4
4
  export interface PaymentHandlerMap {
@@ -7,6 +7,10 @@ export interface PaymentHandlerMap {
7
7
  productId: string;
8
8
  appStoreProductId: string;
9
9
  }) => Promise<PaymentResult>;
10
+ JOLI_GEM_IAP: (params: {
11
+ productId: string;
12
+ appStoreProductId: string;
13
+ }) => Promise<PaymentResult>;
10
14
  }
11
15
  export type PaymentHandler<T extends PaymentType> = PaymentHandlerMap[T];
12
16
  export declare function createPaymentHelper(): {
@@ -19,6 +19,30 @@ export declare const checkUnloginModalFrequency: (config: {
19
19
  canShow: boolean;
20
20
  isFirst: boolean;
21
21
  }>;
22
+ export declare const checkUseModalFrequencyGem: (config: {
23
+ dailyMaxPopUps?: number;
24
+ minInterval?: number;
25
+ }) => Promise<{
26
+ canShow: boolean;
27
+ isFirst: boolean;
28
+ }>;
29
+ export declare const checkPaymentFrequencyGem: (config: {
30
+ dailyMaxPopUps?: number;
31
+ minInterval?: number;
32
+ }) => Promise<{
33
+ canShow: boolean;
34
+ isFirst: boolean;
35
+ }>;
36
+ export declare const checkUnloginModalFrequencyGem: (config: {
37
+ dailyMaxPopUps?: number;
38
+ minInterval?: number;
39
+ }) => Promise<{
40
+ canShow: boolean;
41
+ isFirst: boolean;
42
+ }>;
22
43
  export declare const updateUseModalFrequency: () => Promise<void>;
23
44
  export declare const updatePaymentFrequency: () => Promise<void>;
24
45
  export declare const updateUnloginModalFrequency: () => Promise<void>;
46
+ export declare const updateUseModalFrequencyGem: () => Promise<void>;
47
+ export declare const updatePaymentFrequencyGem: () => Promise<void>;
48
+ export declare const updateUnloginModalFrequencyGem: () => Promise<void>;
@@ -1,9 +1,9 @@
1
1
  Invoking: npm run clean && npm run build:esm && tsc
2
2
 
3
- > @jolibox/implement@1.1.52-beta.1 clean
3
+ > @jolibox/implement@1.1.53-beta.0 clean
4
4
  > rimraf ./dist
5
5
 
6
6
 
7
- > @jolibox/implement@1.1.52-beta.1 build:esm
7
+ > @jolibox/implement@1.1.53-beta.0 build:esm
8
8
  > BUILD_VERSION=$(node -p "require('./package.json').version") node esbuild.config.js --format=esm
9
9
 
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@jolibox/implement",
3
3
  "description": "This project is Jolibox JS-SDk implement for Native && H5",
4
- "version": "1.1.52-beta.1",
4
+ "version": "1.1.53-beta.0",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
7
7
  "license": "MIT",
8
8
  "dependencies": {
9
- "@jolibox/common": "1.1.52-beta.1",
10
- "@jolibox/types": "1.1.52-beta.1",
11
- "@jolibox/native-bridge": "1.1.52-beta.1",
12
- "@jolibox/ads": "1.1.52-beta.1",
9
+ "@jolibox/common": "1.1.53-beta.0",
10
+ "@jolibox/types": "1.1.53-beta.0",
11
+ "@jolibox/native-bridge": "1.1.53-beta.0",
12
+ "@jolibox/ads": "1.1.53-beta.0",
13
13
  "localforage": "1.10.0",
14
14
  "@jolibox/ui": "1.0.0",
15
15
  "web-vitals": "4.2.4"
@@ -19,7 +19,7 @@
19
19
  "@types/jest": "28.1.1",
20
20
  "rimraf": "6.0.1",
21
21
  "esbuild": "0.24.2",
22
- "@jolibox/eslint-config": "1.0.1-beta.6"
22
+ "@jolibox/eslint-config": "1.0.1-beta.8"
23
23
  },
24
24
  "scripts": {
25
25
  "clean": "rimraf ./dist",
@@ -162,6 +162,9 @@ const wrapContext = () => {
162
162
  navigationBarHeight: rawNavHeight !== undefined ? rawNavHeight / pixelRatio : 10
163
163
  };
164
164
  },
165
+ get abTests(): string[] {
166
+ return env.abValues?.split(',') ?? [];
167
+ },
165
168
  onEnvConfigChanged: (newConfig: Partial<Env>) => {
166
169
  mergeWith(env, newConfig, mergeArray);
167
170
  },
@@ -1,12 +1,13 @@
1
- import { IUnlockOptionType } from '../type';
2
- import { canUseJolicoin } from '../registers/utils';
1
+ import { IUnlockOptionType, IGem } from '../type';
2
+ import { canUseJolicoin, joliCoinIsEnough, canUseGem, gemIsEnough } from '../registers/utils';
3
3
 
4
4
  describe('canUseJolicoin', () => {
5
5
  it('should return true when joliCoin balance is sufficient and autoDeduct is enabled', () => {
6
6
  const unlockOptions = [
7
7
  {
8
8
  type: 'JOLI_COIN' as IUnlockOptionType,
9
- joliCoinChoices: [{ joliCoinQuantity: 100 }]
9
+ joliCoinChoices: [{ joliCoinQuantity: 100 }],
10
+ joliGemChoices: null
10
11
  }
11
12
  ];
12
13
  const joliCoin = { balance: 100, enableAutoDeduct: true };
@@ -18,7 +19,8 @@ describe('canUseJolicoin', () => {
18
19
  const unlockOptions = [
19
20
  {
20
21
  type: 'JOLI_COIN' as IUnlockOptionType,
21
- joliCoinChoices: [{ joliCoinQuantity: 50 }]
22
+ joliCoinChoices: [{ joliCoinQuantity: 50 }],
23
+ joliGemChoices: null
22
24
  }
23
25
  ];
24
26
  const joliCoin = { balance: 100, enableAutoDeduct: true };
@@ -30,7 +32,8 @@ describe('canUseJolicoin', () => {
30
32
  const unlockOptions = [
31
33
  {
32
34
  type: 'JOLI_COIN' as IUnlockOptionType,
33
- joliCoinChoices: [{ joliCoinQuantity: 150 }]
35
+ joliCoinChoices: [{ joliCoinQuantity: 150 }],
36
+ joliGemChoices: null
34
37
  }
35
38
  ];
36
39
  const joliCoin = { balance: 100, enableAutoDeduct: true };
@@ -42,7 +45,8 @@ describe('canUseJolicoin', () => {
42
45
  const unlockOptions = [
43
46
  {
44
47
  type: 'JOLI_COIN' as IUnlockOptionType,
45
- joliCoinChoices: [{ joliCoinQuantity: 50 }]
48
+ joliCoinChoices: [{ joliCoinQuantity: 50 }],
49
+ joliGemChoices: null
46
50
  }
47
51
  ];
48
52
  const joliCoin = { balance: 100, enableAutoDeduct: false };
@@ -54,7 +58,8 @@ describe('canUseJolicoin', () => {
54
58
  const unlockOptions = [
55
59
  {
56
60
  type: 'ADS' as IUnlockOptionType,
57
- joliCoinChoices: []
61
+ joliCoinChoices: [],
62
+ joliGemChoices: null
58
63
  }
59
64
  ];
60
65
  const joliCoin = { balance: 100, enableAutoDeduct: true };
@@ -73,7 +78,8 @@ describe('canUseJolicoin', () => {
73
78
  const unlockOptions = [
74
79
  {
75
80
  type: 'JOLI_COIN' as IUnlockOptionType,
76
- joliCoinChoices: [{ joliCoinQuantity: 50 }]
81
+ joliCoinChoices: [{ joliCoinQuantity: 50 }],
82
+ joliGemChoices: null
77
83
  }
78
84
  ];
79
85
 
@@ -84,7 +90,8 @@ describe('canUseJolicoin', () => {
84
90
  const unlockOptions = [
85
91
  {
86
92
  type: 'JOLI_COIN' as IUnlockOptionType,
87
- joliCoinChoices: [{ joliCoinQuantity: 200 }, { joliCoinQuantity: 50 }]
93
+ joliCoinChoices: [{ joliCoinQuantity: 200 }, { joliCoinQuantity: 50 }],
94
+ joliGemChoices: null
88
95
  }
89
96
  ];
90
97
  const joliCoin = { balance: 100, enableAutoDeduct: true };
@@ -92,3 +99,252 @@ describe('canUseJolicoin', () => {
92
99
  expect(canUseJolicoin(unlockOptions, joliCoin)).toBe(true);
93
100
  });
94
101
  });
102
+
103
+ describe('joliCoinIsEnough', () => {
104
+ it('should return true when joliCoin balance is sufficient', () => {
105
+ const unlockOptions = [
106
+ {
107
+ type: 'JOLI_COIN' as IUnlockOptionType,
108
+ joliCoinChoices: [{ joliCoinQuantity: 100 }],
109
+ joliGemChoices: null
110
+ }
111
+ ];
112
+ const joliCoin = { balance: 100, enableAutoDeduct: false }; // autoDeduct disabled but should still return true
113
+
114
+ expect(joliCoinIsEnough(unlockOptions, joliCoin)).toBe(true);
115
+ });
116
+
117
+ it('should return false when joliCoin balance is insufficient', () => {
118
+ const unlockOptions = [
119
+ {
120
+ type: 'JOLI_COIN' as IUnlockOptionType,
121
+ joliCoinChoices: [{ joliCoinQuantity: 150 }],
122
+ joliGemChoices: null
123
+ }
124
+ ];
125
+ const joliCoin = { balance: 100, enableAutoDeduct: true };
126
+
127
+ expect(joliCoinIsEnough(unlockOptions, joliCoin)).toBe(false);
128
+ });
129
+
130
+ it('should return false when there is no JOLI_COIN option', () => {
131
+ const unlockOptions = [
132
+ {
133
+ type: 'ADS' as IUnlockOptionType,
134
+ joliCoinChoices: [],
135
+ joliGemChoices: null
136
+ }
137
+ ];
138
+ const joliCoin = { balance: 100, enableAutoDeduct: true };
139
+
140
+ expect(joliCoinIsEnough(unlockOptions, joliCoin)).toBe(false);
141
+ });
142
+ });
143
+
144
+ describe('canUseGem', () => {
145
+ it('should return true when gem balance is sufficient and autoDeduct is enabled', () => {
146
+ const unlockOptions = [
147
+ {
148
+ type: 'JOLI_GEM' as IUnlockOptionType,
149
+ joliCoinChoices: [],
150
+ joliGemChoices: { joliGemQuantity: 50 }
151
+ }
152
+ ];
153
+ const gem = { balance: 50, enableAutoDeduct: true };
154
+
155
+ expect(canUseGem(unlockOptions, gem)).toBe(true);
156
+ });
157
+
158
+ it('should return true when gem balance is more than required', () => {
159
+ const unlockOptions = [
160
+ {
161
+ type: 'JOLI_GEM' as IUnlockOptionType,
162
+ joliCoinChoices: [],
163
+ joliGemChoices: { joliGemQuantity: 25 }
164
+ }
165
+ ];
166
+ const gem = { balance: 50, enableAutoDeduct: true };
167
+
168
+ expect(canUseGem(unlockOptions, gem)).toBe(true);
169
+ });
170
+
171
+ it('should return false when gem balance is insufficient', () => {
172
+ const unlockOptions = [
173
+ {
174
+ type: 'JOLI_GEM' as IUnlockOptionType,
175
+ joliCoinChoices: [],
176
+ joliGemChoices: { joliGemQuantity: 75 }
177
+ }
178
+ ];
179
+ const gem = { balance: 50, enableAutoDeduct: true };
180
+
181
+ expect(canUseGem(unlockOptions, gem)).toBe(false);
182
+ });
183
+
184
+ it('should return false when autoDeduct is disabled', () => {
185
+ const unlockOptions = [
186
+ {
187
+ type: 'JOLI_GEM' as IUnlockOptionType,
188
+ joliCoinChoices: [],
189
+ joliGemChoices: { joliGemQuantity: 25 }
190
+ }
191
+ ];
192
+ const gem = { balance: 50, enableAutoDeduct: false };
193
+
194
+ expect(canUseGem(unlockOptions, gem)).toBe(false);
195
+ });
196
+
197
+ it('should return false when there is no JOLI_GEM option', () => {
198
+ const unlockOptions = [
199
+ {
200
+ type: 'ADS' as IUnlockOptionType,
201
+ joliCoinChoices: [],
202
+ joliGemChoices: null
203
+ }
204
+ ];
205
+ const gem = { balance: 50, enableAutoDeduct: true };
206
+
207
+ expect(canUseGem(unlockOptions, gem)).toBe(false);
208
+ });
209
+
210
+ it('should return false with empty unlockOptions', () => {
211
+ const unlockOptions: any[] = [];
212
+ const gem = { balance: 50, enableAutoDeduct: true };
213
+
214
+ expect(canUseGem(unlockOptions, gem)).toBe(false);
215
+ });
216
+
217
+ it('should return false when gem is undefined', () => {
218
+ const unlockOptions = [
219
+ {
220
+ type: 'JOLI_GEM' as IUnlockOptionType,
221
+ joliCoinChoices: [],
222
+ joliGemChoices: { joliGemQuantity: 25 }
223
+ }
224
+ ];
225
+
226
+ expect(canUseGem(unlockOptions, undefined)).toBe(false);
227
+ });
228
+
229
+ it('should return true when at least one gem choice is valid', () => {
230
+ const unlockOptions = [
231
+ {
232
+ type: 'JOLI_GEM' as IUnlockOptionType,
233
+ joliCoinChoices: [],
234
+ joliGemChoices: { joliGemQuantity: 25 }
235
+ }
236
+ ];
237
+ const gem = { balance: 50, enableAutoDeduct: true };
238
+
239
+ expect(canUseGem(unlockOptions, gem)).toBe(true);
240
+ });
241
+ });
242
+
243
+ describe('gemIsEnough', () => {
244
+ it('should return true when gem balance is sufficient', () => {
245
+ const unlockOptions = [
246
+ {
247
+ type: 'JOLI_GEM' as IUnlockOptionType,
248
+ joliCoinChoices: [],
249
+ joliGemChoices: { joliGemQuantity: 50 }
250
+ }
251
+ ];
252
+ const gem = { balance: 50, enableAutoDeduct: false }; // autoDeduct disabled but should still return true
253
+
254
+ expect(gemIsEnough(unlockOptions, gem)).toBe(true);
255
+ });
256
+
257
+ it('should return false when gem balance is insufficient', () => {
258
+ const unlockOptions = [
259
+ {
260
+ type: 'JOLI_GEM' as IUnlockOptionType,
261
+ joliCoinChoices: [],
262
+ joliGemChoices: { joliGemQuantity: 75 }
263
+ }
264
+ ];
265
+ const gem = { balance: 50, enableAutoDeduct: true };
266
+
267
+ expect(gemIsEnough(unlockOptions, gem)).toBe(false);
268
+ });
269
+
270
+ it('should return false when there is no JOLI_GEM option', () => {
271
+ const unlockOptions = [
272
+ {
273
+ type: 'ADS' as IUnlockOptionType,
274
+ joliCoinChoices: [],
275
+ joliGemChoices: null
276
+ }
277
+ ];
278
+ const gem = { balance: 50, enableAutoDeduct: true };
279
+
280
+ expect(gemIsEnough(unlockOptions, gem)).toBe(false);
281
+ });
282
+
283
+ it('should return true when at least one gem choice has sufficient balance', () => {
284
+ const unlockOptions = [
285
+ {
286
+ type: 'JOLI_GEM' as IUnlockOptionType,
287
+ joliCoinChoices: [],
288
+ joliGemChoices: { joliGemQuantity: 24 }
289
+ }
290
+ ];
291
+ const gem = { balance: 50, enableAutoDeduct: false };
292
+
293
+ expect(gemIsEnough(unlockOptions, gem)).toBe(true);
294
+ });
295
+ });
296
+
297
+ describe('Mixed currency options', () => {
298
+ it('should work correctly with both JOLI_COIN and JOLI_GEM options', () => {
299
+ const unlockOptions = [
300
+ {
301
+ type: 'JOLI_COIN' as IUnlockOptionType,
302
+ joliCoinChoices: [{ joliCoinQuantity: 100 }],
303
+ joliGemChoices: null
304
+ },
305
+ {
306
+ type: 'JOLI_GEM' as IUnlockOptionType,
307
+ joliCoinChoices: [],
308
+ joliGemChoices: { joliGemQuantity: 50 }
309
+ }
310
+ ];
311
+
312
+ const joliCoin = { balance: 100, enableAutoDeduct: true };
313
+ const gem = { balance: 50, enableAutoDeduct: true };
314
+
315
+ expect(canUseJolicoin(unlockOptions, joliCoin)).toBe(true);
316
+ expect(canUseGem(unlockOptions, gem)).toBe(true);
317
+ expect(joliCoinIsEnough(unlockOptions, joliCoin)).toBe(true);
318
+ expect(gemIsEnough(unlockOptions, gem)).toBe(true);
319
+ });
320
+
321
+ it('should return false for coin when only gem options available', () => {
322
+ const unlockOptions = [
323
+ {
324
+ type: 'JOLI_GEM' as IUnlockOptionType,
325
+ joliCoinChoices: [],
326
+ joliGemChoices: { joliGemQuantity: 50 }
327
+ }
328
+ ];
329
+
330
+ const joliCoin = { balance: 100, enableAutoDeduct: true };
331
+
332
+ expect(canUseJolicoin(unlockOptions, joliCoin)).toBe(false);
333
+ expect(joliCoinIsEnough(unlockOptions, joliCoin)).toBe(false);
334
+ });
335
+
336
+ it('should return false for gem when only coin options available', () => {
337
+ const unlockOptions = [
338
+ {
339
+ type: 'JOLI_COIN' as IUnlockOptionType,
340
+ joliCoinChoices: [{ joliCoinQuantity: 100 }],
341
+ joliGemChoices: null
342
+ }
343
+ ];
344
+
345
+ const gem = { balance: 50, enableAutoDeduct: true };
346
+
347
+ expect(canUseGem(unlockOptions, gem)).toBe(false);
348
+ expect(gemIsEnough(unlockOptions, gem)).toBe(false);
349
+ });
350
+ });
@@ -14,15 +14,24 @@ import { hostEmitter } from '@jolibox/common';
14
14
 
15
15
  const priority = () => {
16
16
  return (a: RewardType, b: RewardType) => {
17
- if (a === 'JOLI_COIN' && b === 'ADS') return -1;
18
- if (a === 'ADS' && b === 'JOLI_COIN') return 1;
19
- return 0;
17
+ // Priority order: GEM > JOLI_COIN > ADS
18
+ const priorityMap: Record<RewardType, number> = {
19
+ JOLI_GEM: 3,
20
+ JOLI_GEM_ONLY: 3,
21
+ JOLI_COIN: 2,
22
+ JOLI_COIN_ONLY: 2,
23
+ ADS: 1
24
+ };
25
+
26
+ return priorityMap[b] - priorityMap[a];
20
27
  };
21
28
  };
22
29
 
23
30
  const sortRewards = (rewardsTypes: RewardType[]): RewardType[] => {
24
31
  if (!rewardsTypes.length) return ['ADS'];
32
+ if (rewardsTypes.includes('JOLI_GEM') && rewardsTypes.length <= 1) return ['JOLI_GEM_ONLY'];
25
33
  if (rewardsTypes.includes('JOLI_COIN') && rewardsTypes.length <= 1) return ['JOLI_COIN_ONLY'];
34
+
26
35
  return rewardsTypes.sort(priority());
27
36
  };
28
37
 
@@ -34,11 +43,17 @@ export const createRewardFetcher = (rewardsHelper: RewardsHelper) => {
34
43
  if (res.code !== 'SUCCESS') {
35
44
  return defaultRewards;
36
45
  }
46
+
47
+ console.log('-----res fetch reward-----', res);
37
48
  rewardsEmitter.emit(UnlockOptionsEventName, {
38
49
  options: res.data?.unlockOptions || [],
39
50
  userJoliCoin: res.extra?.joliCoin || {
40
51
  balance: 0,
41
52
  enableAutoDeduct: false
53
+ },
54
+ userGem: res.extra?.joliGem || {
55
+ balance: 0,
56
+ enableAutoDeduct: false
42
57
  }
43
58
  });
44
59
 
@@ -8,3 +8,5 @@ createRewardFrequencyConfigFetcher(rewardsHelper);
8
8
  export * from './registers/use-ads';
9
9
  export * from './registers/use-jolicoin';
10
10
  export * from './registers/use-jolicoin-only';
11
+ export * from './registers/use-gem';
12
+ export * from './registers/use-gem-only';
@@ -0,0 +1,58 @@
1
+ import { IHttpClient } from '@/common/http';
2
+ import { IAdBreakParams } from '@/common/ads';
3
+ import { createCommonGemRewardHandler } from './utils/coins/joligem/gem-handler';
4
+ import { unlockOptionsHandler } from './utils/common';
5
+ import {
6
+ createShowUnlockWithCurrencyModal,
7
+ createInitiateAndAwaitPayment,
8
+ createShowUnloginModal
9
+ } from './utils/coins/commands';
10
+
11
+ export type GemOnlyRewardsHandler = (params: IAdBreakParams) => Promise<boolean>;
12
+ export const createGemOnlyRewardHandler = (
13
+ httpClient: IHttpClient,
14
+ {
15
+ onUnlockSuccess,
16
+ onUnlockFailed
17
+ }: {
18
+ onUnlockSuccess?: (data: { quantity: number; balance: number }) => void;
19
+ onUnlockFailed?: () => void;
20
+ }
21
+ ): GemOnlyRewardsHandler => {
22
+ const handleUnlockFailed = (() => (params: IAdBreakParams) => {
23
+ onUnlockFailed?.();
24
+ params.adBreakDone?.({
25
+ breakType: params.type,
26
+ breakFormat: params.type === 'reward' ? 'reward' : 'interstitial',
27
+ breakStatus: 'noAdPreloaded'
28
+ });
29
+ })();
30
+
31
+ const showUnlockWithGemModal = createShowUnlockWithCurrencyModal('JOLI_GEM', {
32
+ confirmButtonText: 'gem.useGem',
33
+ cancelButtonText: 'gem.noThanks'
34
+ });
35
+
36
+ const initiateAndAwaitPayment = createInitiateAndAwaitPayment('JOLI_GEM', {
37
+ confirmButtonText: 'gem.payAndUnlock',
38
+ cancelButtonText: 'gem.noThanks'
39
+ });
40
+
41
+ const showUnloginModal = createShowUnloginModal('JOLI_GEM', {
42
+ confirmButtonText: 'loginGuide.login',
43
+ cancelButtonText: 'loginGuide.noThanks'
44
+ });
45
+
46
+ const gemOnlyRewardHandler = createCommonGemRewardHandler('JOLI_GEM', httpClient, {
47
+ handlers: {
48
+ handleUnlockSuccess: onUnlockSuccess,
49
+ handleUnlockFailed,
50
+ unlockOptionsHandler,
51
+ initiateAndAwaitPayment,
52
+ showUnlockWithCurrencyModal: showUnlockWithGemModal,
53
+ showUnloginModal
54
+ }
55
+ });
56
+
57
+ return gemOnlyRewardHandler;
58
+ };
@@ -0,0 +1,53 @@
1
+ import { IHttpClient } from '@/common/http';
2
+ import { IAdBreakParams } from '@/common/ads';
3
+ import { unlockOptionsHandler } from './utils/common';
4
+ import { createCommonGemRewardHandler } from './utils/coins/joligem/gem-handler';
5
+ import {
6
+ createShowUnlockWithCurrencyModal,
7
+ createInitiateAndAwaitPayment,
8
+ createShowUnloginModal
9
+ } from './utils/coins/commands';
10
+
11
+ export type GemRewardsHandler = (params: IAdBreakParams) => Promise<boolean>;
12
+ export const createGemRewardHandler = (
13
+ httpClient: IHttpClient,
14
+ {
15
+ onUnlockSuccess,
16
+ onUnlockFailed
17
+ }: {
18
+ onUnlockSuccess?: (data: { quantity: number; balance: number }) => void;
19
+ onUnlockFailed?: () => void;
20
+ }
21
+ ): GemRewardsHandler => {
22
+ const handleUnlockFailed = () => {
23
+ onUnlockFailed?.();
24
+ };
25
+
26
+ const showUnlockWithGemModal = createShowUnlockWithCurrencyModal('ADS-JOLI_GEM', {
27
+ confirmButtonText: 'gem.useGem',
28
+ cancelButtonText: 'gem.noWatchAds'
29
+ });
30
+
31
+ const initiateAndAwaitPayment = createInitiateAndAwaitPayment('ADS-JOLI_GEM', {
32
+ confirmButtonText: 'gem.payAndUnlock',
33
+ cancelButtonText: 'gem.noWatchAds'
34
+ });
35
+
36
+ const showUnloginModal = createShowUnloginModal('ADS-JOLI_GEM', {
37
+ confirmButtonText: 'loginGuide.login',
38
+ cancelButtonText: 'loginGuide.noWatchAds'
39
+ });
40
+
41
+ const gemRewardHandler = createCommonGemRewardHandler('ADS-JOLI_GEM', httpClient, {
42
+ handlers: {
43
+ handleUnlockSuccess: onUnlockSuccess,
44
+ handleUnlockFailed,
45
+ unlockOptionsHandler,
46
+ initiateAndAwaitPayment,
47
+ showUnlockWithCurrencyModal: showUnlockWithGemModal,
48
+ showUnloginModal
49
+ }
50
+ });
51
+
52
+ return gemRewardHandler;
53
+ };
@@ -1,9 +1,9 @@
1
1
  import { IHttpClient } from '@/common/http';
2
2
  import { IAdBreakParams } from '@/common/ads';
3
- import { createCommonJolicoinRewardHandler } from './utils/coins';
3
+ import { createCommonJolicoinRewardHandler } from './utils/coins/jolicoin/jolicoin-handler';
4
4
  import { unlockOptionsHandler } from './utils/common';
5
5
  import {
6
- createShowUnlockWithJolicoinModal,
6
+ createShowUnlockWithCurrencyModal,
7
7
  createInitiateAndAwaitPayment,
8
8
  createShowUnloginModal
9
9
  } from './utils/coins/commands';
@@ -28,7 +28,7 @@ export const createJolicoinOnlyRewardHandler = (
28
28
  });
29
29
  })();
30
30
 
31
- const showUnlockWithJolicoinModal = createShowUnlockWithJolicoinModal('JOLI_COIN', {
31
+ const showUnlockWithJolicoinModal = createShowUnlockWithCurrencyModal('JOLI_COIN', {
32
32
  confirmButtonText: 'jolicoin.useJolicoin',
33
33
  cancelButtonText: 'jolicoin.noThanks'
34
34
  });
@@ -49,7 +49,7 @@ export const createJolicoinOnlyRewardHandler = (
49
49
  handleUnlockFailed,
50
50
  unlockOptionsHandler,
51
51
  initiateAndAwaitPayment,
52
- showUnlockWithJolicoinModal,
52
+ showUnlockWithCurrencyModal: showUnlockWithJolicoinModal,
53
53
  showUnloginModal
54
54
  }
55
55
  });
@@ -1,9 +1,9 @@
1
1
  import { IHttpClient } from '@/common/http';
2
2
  import { IAdBreakParams } from '@/common/ads';
3
3
  import { unlockOptionsHandler } from './utils/common';
4
- import { createCommonJolicoinRewardHandler } from './utils/coins';
4
+ import { createCommonJolicoinRewardHandler } from './utils/coins/jolicoin/jolicoin-handler';
5
5
  import {
6
- createShowUnlockWithJolicoinModal,
6
+ createShowUnlockWithCurrencyModal,
7
7
  createInitiateAndAwaitPayment,
8
8
  createShowUnloginModal
9
9
  } from './utils/coins/commands';
@@ -23,7 +23,7 @@ export const createJolicoinRewardHandler = (
23
23
  onUnlockFailed?.();
24
24
  };
25
25
 
26
- const showUnlockWithJolicoinModal = createShowUnlockWithJolicoinModal('ADS-JOLI_COIN', {
26
+ const showUnlockWithJolicoinModal = createShowUnlockWithCurrencyModal('ADS-JOLI_COIN', {
27
27
  confirmButtonText: 'jolicoin.useJolicoin',
28
28
  cancelButtonText: 'jolicoin.noWatchAds'
29
29
  });
@@ -44,7 +44,7 @@ export const createJolicoinRewardHandler = (
44
44
  handleUnlockFailed,
45
45
  unlockOptionsHandler,
46
46
  initiateAndAwaitPayment,
47
- showUnlockWithJolicoinModal,
47
+ showUnlockWithCurrencyModal: showUnlockWithJolicoinModal,
48
48
  showUnloginModal
49
49
  }
50
50
  });