@jolibox/implement 1.1.53-beta.0 → 1.1.54
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/.rush/temp/package-deps_build.json +34 -43
- package/dist/common/rewards/index.d.ts +0 -2
- package/dist/common/rewards/registers/utils/coins/commands/index.d.ts +1 -1
- package/dist/common/rewards/registers/utils/coins/commands/use-jolicoin.d.ts +8 -10
- package/dist/common/rewards/registers/utils/coins/commands/use-payment.d.ts +8 -10
- package/dist/common/rewards/registers/utils/coins/commands/use-unlogin.d.ts +8 -6
- package/dist/common/rewards/registers/utils/coins/index.d.ts +18 -2
- package/dist/common/rewards/registers/utils/index.d.ts +1 -3
- package/dist/common/rewards/reward-emitter.d.ts +13 -23
- package/dist/common/rewards/reward-helper.d.ts +1 -3
- package/dist/common/rewards/type.d.ts +1 -10
- package/dist/h5/report/event-tracker.d.ts +0 -1
- package/dist/index.js +9 -9
- package/dist/index.native.js +33 -33
- package/dist/native/payment/payment-helper.d.ts +1 -5
- package/dist/native/rewards/check-frequency.d.ts +0 -24
- package/implement.build.log +2 -2
- package/package.json +6 -6
- package/src/common/context/index.ts +2 -2
- package/src/common/report/base-tracker.ts +2 -2
- package/src/common/rewards/__tests__/can-use-jolicoin.test.ts +9 -265
- package/src/common/rewards/fetch-reward.ts +3 -18
- package/src/common/rewards/index.ts +0 -2
- package/src/common/rewards/registers/use-jolicoin-only.ts +4 -4
- package/src/common/rewards/registers/use-jolicoin.ts +4 -4
- package/src/common/rewards/registers/utils/coins/commands/index.ts +1 -1
- package/src/common/rewards/registers/utils/coins/commands/use-jolicoin.ts +19 -31
- package/src/common/rewards/registers/utils/coins/commands/use-payment.ts +25 -32
- package/src/common/rewards/registers/utils/coins/commands/use-unlogin.ts +24 -22
- package/src/common/rewards/registers/utils/coins/index.ts +139 -2
- package/src/common/rewards/registers/utils/index.ts +1 -20
- package/src/common/rewards/reward-emitter.ts +13 -23
- package/src/common/rewards/reward-helper.ts +1 -3
- package/src/common/rewards/type.ts +1 -13
- package/src/h5/api/ads.ts +13 -5
- package/src/h5/api/storage.ts +2 -2
- package/src/h5/http/index.ts +2 -2
- package/src/h5/report/event-tracker.ts +2 -17
- package/src/h5/rewards/index.ts +20 -33
- package/src/native/api/ads.ts +1 -22
- package/src/native/api/call-host-method.ts +1 -36
- package/src/native/network/create-fetch.ts +12 -2
- package/src/native/network/index.ts +2 -1
- package/src/native/payment/index.ts +0 -2
- package/src/native/payment/payment-helper.ts +1 -2
- package/src/native/report/task-tracker.ts +2 -4
- package/src/native/rewards/check-frequency.ts +0 -10
- package/src/native/rewards/ui/payment-modal.ts +33 -110
- package/src/native/rewards/ui/unlogin-modal.ts +87 -182
- package/src/native/rewards/ui/use-modal.ts +68 -126
- package/CHANGELOG.json +0 -11
- package/CHANGELOG.md +0 -9
- package/dist/common/rewards/registers/use-gem-only.d.ts +0 -10
- package/dist/common/rewards/registers/use-gem.d.ts +0 -10
- package/dist/common/rewards/registers/utils/coins/commands/currency-handlers.d.ts +0 -15
- package/dist/common/rewards/registers/utils/coins/currency-config.d.ts +0 -8
- package/dist/common/rewards/registers/utils/coins/jolicoin/jolicoin-handler.d.ts +0 -18
- package/dist/common/rewards/registers/utils/coins/joligem/fetch-gem-balance.d.ts +0 -4
- package/dist/common/rewards/registers/utils/coins/joligem/gem-handler.d.ts +0 -19
- package/src/common/rewards/registers/use-gem-only.ts +0 -58
- package/src/common/rewards/registers/use-gem.ts +0 -53
- package/src/common/rewards/registers/utils/coins/commands/currency-handlers.ts +0 -48
- package/src/common/rewards/registers/utils/coins/currency-config.ts +0 -23
- package/src/common/rewards/registers/utils/coins/jolicoin/jolicoin-handler.ts +0 -149
- package/src/common/rewards/registers/utils/coins/joligem/fetch-gem-balance.ts +0 -15
- package/src/common/rewards/registers/utils/coins/joligem/gem-handler.ts +0 -131
- /package/dist/common/rewards/registers/utils/coins/{jolicoin/fetch-balance.d.ts → fetch-balance.d.ts} +0 -0
- /package/src/common/rewards/registers/utils/coins/{jolicoin/fetch-balance.ts → 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';
|
|
2
2
|
import { StandardResponse } from '@jolibox/types';
|
|
3
3
|
type PaymentResult = StandardResponse<void>;
|
|
4
4
|
export interface PaymentHandlerMap {
|
|
@@ -7,10 +7,6 @@ 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>;
|
|
14
10
|
}
|
|
15
11
|
export type PaymentHandler<T extends PaymentType> = PaymentHandlerMap[T];
|
|
16
12
|
export declare function createPaymentHelper(): {
|
|
@@ -19,30 +19,6 @@ 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
|
-
}>;
|
|
43
22
|
export declare const updateUseModalFrequency: () => Promise<void>;
|
|
44
23
|
export declare const updatePaymentFrequency: () => Promise<void>;
|
|
45
24
|
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>;
|
package/implement.build.log
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Invoking: npm run clean && npm run build:esm && tsc
|
|
2
2
|
|
|
3
|
-
> @jolibox/implement@1.1.
|
|
3
|
+
> @jolibox/implement@1.1.54 clean
|
|
4
4
|
> rimraf ./dist
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
> @jolibox/implement@1.1.
|
|
7
|
+
> @jolibox/implement@1.1.54 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.
|
|
4
|
+
"version": "1.1.54",
|
|
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.
|
|
10
|
-
"@jolibox/types": "1.1.
|
|
11
|
-
"@jolibox/native-bridge": "1.1.
|
|
12
|
-
"@jolibox/ads": "1.1.
|
|
9
|
+
"@jolibox/common": "1.1.54",
|
|
10
|
+
"@jolibox/types": "1.1.54",
|
|
11
|
+
"@jolibox/native-bridge": "1.1.54",
|
|
12
|
+
"@jolibox/ads": "1.1.54",
|
|
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.
|
|
22
|
+
"@jolibox/eslint-config": "1.0.0"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
25
|
"clean": "rimraf ./dist",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getAdvertisingId, mergeArray, mergeWith } from '@jolibox/common';
|
|
1
|
+
import { getAdvertisingId, mergeArray, mergeWith, getApiDomain } from '@jolibox/common';
|
|
2
2
|
import { DeviceInfo, HostInfo, HostUserInfo, SdkInfo } from './types';
|
|
3
3
|
import { Env } from '@jolibox/types';
|
|
4
4
|
import { parseUrlQuery, encodeJoliSourceQuery, QueryParams } from './url-parse';
|
|
@@ -130,7 +130,7 @@ const wrapContext = () => {
|
|
|
130
130
|
return payloadJson?.__from;
|
|
131
131
|
},
|
|
132
132
|
get baseApiHost(): string {
|
|
133
|
-
return testMode
|
|
133
|
+
return getApiDomain(testMode);
|
|
134
134
|
},
|
|
135
135
|
get adId(): string {
|
|
136
136
|
return env.deviceInfo.adId ?? env.deviceInfo.did;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { context } from '@/common/context';
|
|
2
|
-
import { logger } from '@jolibox/common';
|
|
2
|
+
import { logger, getApiHost } from '@jolibox/common';
|
|
3
3
|
import { IDevice, IPage, IEventPackage, IEvent, EProject, serializeEventPackage } from '@jolibox/common';
|
|
4
4
|
|
|
5
5
|
interface ISamplesConfig {
|
|
@@ -27,7 +27,7 @@ export abstract class EventTracker {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
private async fetchSamplesConfig() {
|
|
30
|
-
const host = context.testMode
|
|
30
|
+
const host = getApiHost(context.testMode);
|
|
31
31
|
const path = `${host}/api/fe-configs/js-sdk/samples-config`;
|
|
32
32
|
const samplesConfig = (await (await fetch(path)).json()) as ISamplesConfig;
|
|
33
33
|
this.samplesConfig = samplesConfig;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { IUnlockOptionType
|
|
2
|
-
import { canUseJolicoin
|
|
1
|
+
import { IUnlockOptionType } from '../type';
|
|
2
|
+
import { canUseJolicoin } 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 }]
|
|
10
|
-
joliGemChoices: null
|
|
9
|
+
joliCoinChoices: [{ joliCoinQuantity: 100 }]
|
|
11
10
|
}
|
|
12
11
|
];
|
|
13
12
|
const joliCoin = { balance: 100, enableAutoDeduct: true };
|
|
@@ -19,8 +18,7 @@ describe('canUseJolicoin', () => {
|
|
|
19
18
|
const unlockOptions = [
|
|
20
19
|
{
|
|
21
20
|
type: 'JOLI_COIN' as IUnlockOptionType,
|
|
22
|
-
joliCoinChoices: [{ joliCoinQuantity: 50 }]
|
|
23
|
-
joliGemChoices: null
|
|
21
|
+
joliCoinChoices: [{ joliCoinQuantity: 50 }]
|
|
24
22
|
}
|
|
25
23
|
];
|
|
26
24
|
const joliCoin = { balance: 100, enableAutoDeduct: true };
|
|
@@ -32,8 +30,7 @@ describe('canUseJolicoin', () => {
|
|
|
32
30
|
const unlockOptions = [
|
|
33
31
|
{
|
|
34
32
|
type: 'JOLI_COIN' as IUnlockOptionType,
|
|
35
|
-
joliCoinChoices: [{ joliCoinQuantity: 150 }]
|
|
36
|
-
joliGemChoices: null
|
|
33
|
+
joliCoinChoices: [{ joliCoinQuantity: 150 }]
|
|
37
34
|
}
|
|
38
35
|
];
|
|
39
36
|
const joliCoin = { balance: 100, enableAutoDeduct: true };
|
|
@@ -45,8 +42,7 @@ describe('canUseJolicoin', () => {
|
|
|
45
42
|
const unlockOptions = [
|
|
46
43
|
{
|
|
47
44
|
type: 'JOLI_COIN' as IUnlockOptionType,
|
|
48
|
-
joliCoinChoices: [{ joliCoinQuantity: 50 }]
|
|
49
|
-
joliGemChoices: null
|
|
45
|
+
joliCoinChoices: [{ joliCoinQuantity: 50 }]
|
|
50
46
|
}
|
|
51
47
|
];
|
|
52
48
|
const joliCoin = { balance: 100, enableAutoDeduct: false };
|
|
@@ -58,8 +54,7 @@ describe('canUseJolicoin', () => {
|
|
|
58
54
|
const unlockOptions = [
|
|
59
55
|
{
|
|
60
56
|
type: 'ADS' as IUnlockOptionType,
|
|
61
|
-
joliCoinChoices: []
|
|
62
|
-
joliGemChoices: null
|
|
57
|
+
joliCoinChoices: []
|
|
63
58
|
}
|
|
64
59
|
];
|
|
65
60
|
const joliCoin = { balance: 100, enableAutoDeduct: true };
|
|
@@ -78,8 +73,7 @@ describe('canUseJolicoin', () => {
|
|
|
78
73
|
const unlockOptions = [
|
|
79
74
|
{
|
|
80
75
|
type: 'JOLI_COIN' as IUnlockOptionType,
|
|
81
|
-
joliCoinChoices: [{ joliCoinQuantity: 50 }]
|
|
82
|
-
joliGemChoices: null
|
|
76
|
+
joliCoinChoices: [{ joliCoinQuantity: 50 }]
|
|
83
77
|
}
|
|
84
78
|
];
|
|
85
79
|
|
|
@@ -90,8 +84,7 @@ describe('canUseJolicoin', () => {
|
|
|
90
84
|
const unlockOptions = [
|
|
91
85
|
{
|
|
92
86
|
type: 'JOLI_COIN' as IUnlockOptionType,
|
|
93
|
-
joliCoinChoices: [{ joliCoinQuantity: 200 }, { joliCoinQuantity: 50 }]
|
|
94
|
-
joliGemChoices: null
|
|
87
|
+
joliCoinChoices: [{ joliCoinQuantity: 200 }, { joliCoinQuantity: 50 }]
|
|
95
88
|
}
|
|
96
89
|
];
|
|
97
90
|
const joliCoin = { balance: 100, enableAutoDeduct: true };
|
|
@@ -99,252 +92,3 @@ describe('canUseJolicoin', () => {
|
|
|
99
92
|
expect(canUseJolicoin(unlockOptions, joliCoin)).toBe(true);
|
|
100
93
|
});
|
|
101
94
|
});
|
|
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,24 +14,15 @@ import { hostEmitter } from '@jolibox/common';
|
|
|
14
14
|
|
|
15
15
|
const priority = () => {
|
|
16
16
|
return (a: RewardType, b: RewardType) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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];
|
|
17
|
+
if (a === 'JOLI_COIN' && b === 'ADS') return -1;
|
|
18
|
+
if (a === 'ADS' && b === 'JOLI_COIN') return 1;
|
|
19
|
+
return 0;
|
|
27
20
|
};
|
|
28
21
|
};
|
|
29
22
|
|
|
30
23
|
const sortRewards = (rewardsTypes: RewardType[]): RewardType[] => {
|
|
31
24
|
if (!rewardsTypes.length) return ['ADS'];
|
|
32
|
-
if (rewardsTypes.includes('JOLI_GEM') && rewardsTypes.length <= 1) return ['JOLI_GEM_ONLY'];
|
|
33
25
|
if (rewardsTypes.includes('JOLI_COIN') && rewardsTypes.length <= 1) return ['JOLI_COIN_ONLY'];
|
|
34
|
-
|
|
35
26
|
return rewardsTypes.sort(priority());
|
|
36
27
|
};
|
|
37
28
|
|
|
@@ -43,17 +34,11 @@ export const createRewardFetcher = (rewardsHelper: RewardsHelper) => {
|
|
|
43
34
|
if (res.code !== 'SUCCESS') {
|
|
44
35
|
return defaultRewards;
|
|
45
36
|
}
|
|
46
|
-
|
|
47
|
-
console.log('-----res fetch reward-----', res);
|
|
48
37
|
rewardsEmitter.emit(UnlockOptionsEventName, {
|
|
49
38
|
options: res.data?.unlockOptions || [],
|
|
50
39
|
userJoliCoin: res.extra?.joliCoin || {
|
|
51
40
|
balance: 0,
|
|
52
41
|
enableAutoDeduct: false
|
|
53
|
-
},
|
|
54
|
-
userGem: res.extra?.joliGem || {
|
|
55
|
-
balance: 0,
|
|
56
|
-
enableAutoDeduct: false
|
|
57
42
|
}
|
|
58
43
|
});
|
|
59
44
|
|
|
@@ -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';
|
|
4
4
|
import { unlockOptionsHandler } from './utils/common';
|
|
5
5
|
import {
|
|
6
|
-
|
|
6
|
+
createShowUnlockWithJolicoinModal,
|
|
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 =
|
|
31
|
+
const showUnlockWithJolicoinModal = createShowUnlockWithJolicoinModal('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
|
-
|
|
52
|
+
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';
|
|
5
5
|
import {
|
|
6
|
-
|
|
6
|
+
createShowUnlockWithJolicoinModal,
|
|
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 =
|
|
26
|
+
const showUnlockWithJolicoinModal = createShowUnlockWithJolicoinModal('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
|
-
|
|
47
|
+
showUnlockWithJolicoinModal,
|
|
48
48
|
showUnloginModal
|
|
49
49
|
}
|
|
50
50
|
});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { registerUseJolicoinCommand,
|
|
1
|
+
export { registerUseJolicoinCommand, createShowUnlockWithJolicoinModal } from './use-jolicoin';
|
|
2
2
|
export { registerUsePaymentCommand, createInitiateAndAwaitPayment } from './use-payment';
|
|
3
3
|
export { registerUseUnloginCommand, createShowUnloginModal } from './use-unlogin';
|
|
@@ -1,39 +1,33 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IJoliCoin } from '@/common/rewards/type';
|
|
2
2
|
import { rewardsCommands } from '../rewards-command';
|
|
3
3
|
import { unlockOptionsHandler } from '@/common/rewards/registers/utils/common';
|
|
4
4
|
import { createEventPromiseHandler } from '../../event-listener';
|
|
5
5
|
import { IUseModalResultEvent, UseModalResultEventName } from '@/common/rewards/reward-emitter';
|
|
6
6
|
import { rewardsEmitter, UseModalEventName } from '@/common/rewards/reward-emitter';
|
|
7
|
-
import { CURRENCY_HANDLERS } from './currency-handlers';
|
|
8
7
|
|
|
9
|
-
export const registerUseJolicoinCommand =
|
|
10
|
-
prefix: 'JOLI_COIN' | 'ADS-JOLI_COIN'
|
|
11
|
-
currency: 'JOLI_COIN' | 'JOLI_GEM',
|
|
8
|
+
export const registerUseJolicoinCommand = (
|
|
9
|
+
prefix: 'JOLI_COIN' | 'ADS-JOLI_COIN',
|
|
12
10
|
params: {
|
|
13
|
-
|
|
11
|
+
showUnlockWithJolicoinModal: (params: {
|
|
14
12
|
enableAutoDeduct: boolean;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
currency: T extends IJoliCoin ? 'JOLI_COIN' : 'JOLI_GEM';
|
|
13
|
+
userJoliCoin: IJoliCoin;
|
|
14
|
+
joliCoinQuantity: number;
|
|
18
15
|
}) => Promise<'CONFIRM' | 'CANCEL' | 'FAILED'>;
|
|
19
16
|
}
|
|
20
17
|
) => {
|
|
21
|
-
const {
|
|
18
|
+
const { showUnlockWithJolicoinModal } = params;
|
|
22
19
|
rewardsCommands.registerCommand(`Rewards.${prefix}.useJolicoin`, async () => {
|
|
23
20
|
const unlockOptions = await unlockOptionsHandler.getData();
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const joliCoinQuantity = handler.getQuantity(unlockOptions);
|
|
29
|
-
const enableAutoDeduct = !!currentUser?.enableAutoDeduct;
|
|
21
|
+
const enableAutoDeduct = !!unlockOptions?.userJoliCoin?.enableAutoDeduct;
|
|
22
|
+
const joliCoinQuantity =
|
|
23
|
+
unlockOptions?.options?.find((option) => option.type === 'JOLI_COIN')?.joliCoinChoices[0]
|
|
24
|
+
.joliCoinQuantity ?? 0;
|
|
30
25
|
|
|
31
26
|
console.log('-----unlockOptions usemodal-----', unlockOptions, enableAutoDeduct, joliCoinQuantity);
|
|
32
|
-
const shouldUnlock = await
|
|
27
|
+
const shouldUnlock = await showUnlockWithJolicoinModal({
|
|
33
28
|
enableAutoDeduct,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
currency: currency as T extends IJoliCoin ? 'JOLI_COIN' : 'JOLI_GEM'
|
|
29
|
+
userJoliCoin: unlockOptions?.userJoliCoin,
|
|
30
|
+
joliCoinQuantity
|
|
37
31
|
});
|
|
38
32
|
|
|
39
33
|
if (shouldUnlock !== 'CONFIRM') {
|
|
@@ -48,28 +42,22 @@ export const registerUseJolicoinCommand = <T extends IJoliCoin | IGem>(
|
|
|
48
42
|
};
|
|
49
43
|
|
|
50
44
|
// EVENTS
|
|
51
|
-
export const
|
|
52
|
-
type: 'JOLI_COIN' | 'ADS-JOLI_COIN'
|
|
45
|
+
export const createShowUnlockWithJolicoinModal = (
|
|
46
|
+
type: 'JOLI_COIN' | 'ADS-JOLI_COIN',
|
|
53
47
|
buttons: {
|
|
54
48
|
confirmButtonText: string;
|
|
55
49
|
cancelButtonText: string;
|
|
56
50
|
}
|
|
57
51
|
) => {
|
|
58
|
-
return async (params: {
|
|
59
|
-
enableAutoDeduct: boolean;
|
|
60
|
-
userCurrency: T;
|
|
61
|
-
quantity: number;
|
|
62
|
-
currency: T extends IJoliCoin ? 'JOLI_COIN' : 'JOLI_GEM';
|
|
63
|
-
}) => {
|
|
52
|
+
return async (params: { enableAutoDeduct: boolean; userJoliCoin: IJoliCoin; joliCoinQuantity: number }) => {
|
|
64
53
|
const modalHandler = createEventPromiseHandler<IUseModalResultEvent, typeof UseModalResultEventName>(
|
|
65
54
|
rewardsEmitter,
|
|
66
55
|
UseModalResultEventName
|
|
67
56
|
);
|
|
68
57
|
rewardsEmitter.emit(UseModalEventName, type, {
|
|
69
58
|
enableAutoDeduct: params.enableAutoDeduct,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
currency: params.currency,
|
|
59
|
+
userJoliCoin: params.userJoliCoin,
|
|
60
|
+
joliCoinQuantity: params.joliCoinQuantity,
|
|
73
61
|
confirmButtonText: buttons.confirmButtonText,
|
|
74
62
|
cancelButtonText: buttons.cancelButtonText
|
|
75
63
|
});
|