@jolibox/implement 1.2.5 → 1.2.6
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 +21 -16
- package/dist/common/rewards/cached-fetch-reward.d.ts +2 -2
- package/dist/common/rewards/cached-reward-service.d.ts +2 -2
- package/dist/common/rewards/index.d.ts +1 -0
- package/dist/common/rewards/registers/use-subscription.d.ts +7 -0
- package/dist/common/rewards/registers/utils/coins/jolicoin/cached-fetch-balance.d.ts +2 -2
- package/dist/common/rewards/registers/utils/coins/joligem/cached-fetch-gem-balance.d.ts +2 -2
- package/dist/common/rewards/registers/utils/subscription/commands/index.d.ts +1 -0
- package/dist/common/rewards/registers/utils/subscription/commands/use-subscription.d.ts +4 -0
- package/dist/common/rewards/registers/utils/subscription/sub-handler.d.ts +13 -0
- package/dist/common/rewards/reward-emitter.d.ts +7 -0
- package/dist/common/rewards/reward-helper.d.ts +2 -1
- package/dist/common/utils/index.d.ts +18 -0
- package/dist/h5/api/platformAdsHandle/JoliboxAdsHandler.d.ts +1 -0
- package/dist/h5/bootstrap/auth/index.d.ts +2 -0
- package/dist/h5/bootstrap/auth/sub.d.ts +2 -0
- package/dist/index.js +9 -9
- package/dist/index.native.js +46 -46
- package/dist/native/payment/payment-service.d.ts +1 -1
- package/implement.build.log +2 -2
- package/package.json +5 -5
- package/src/common/rewards/cached-fetch-reward.ts +19 -2
- package/src/common/rewards/cached-reward-service.ts +3 -3
- package/src/common/rewards/index.ts +1 -0
- package/src/common/rewards/registers/use-subscription.ts +34 -0
- package/src/common/rewards/registers/utils/coins/jolicoin/cached-fetch-balance.ts +1 -1
- package/src/common/rewards/registers/utils/coins/joligem/cached-fetch-gem-balance.ts +1 -1
- package/src/common/rewards/registers/utils/subscription/commands/index.ts +1 -0
- package/src/common/rewards/registers/utils/subscription/commands/use-subscription.ts +29 -0
- package/src/common/rewards/registers/utils/subscription/sub-handler.ts +88 -0
- package/src/common/rewards/reward-emitter.ts +8 -0
- package/src/common/rewards/reward-helper.ts +8 -1
- package/src/common/utils/index.ts +23 -0
- package/src/h5/api/ads.ts +14 -2
- package/src/h5/api/platformAdsHandle/JoliboxAdsHandler.ts +25 -1
- package/src/h5/bootstrap/auth/__tests__/auth.test.ts +308 -0
- package/src/h5/bootstrap/auth/index.ts +20 -0
- package/src/h5/bootstrap/auth/sub.ts +56 -0
- package/src/h5/bootstrap/index.ts +4 -19
- package/src/h5/rewards/index.ts +18 -1
- package/src/native/payment/payment-service.ts +1 -1
- package/dist/common/cache/request-cache-service.d.ts +0 -111
- package/src/common/cache/__tests__/request-cache-service.test.ts +0 -686
- package/src/common/cache/request-cache-service.ts +0 -393
- /package/dist/{common/cache/__tests__/request-cache-service.test.d.ts → h5/bootstrap/auth/__tests__/auth.test.d.ts} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IPaymentChoice } from '@/common/rewards/reward-emitter';
|
|
2
2
|
import type { PaymentResult } from './payment-helper';
|
|
3
|
-
import { RequestCacheService } from '
|
|
3
|
+
import { RequestCacheService } from '@jolibox/common';
|
|
4
4
|
type PaymentPurchaseType = 'JOLI_COIN' | 'JOLI_GEM';
|
|
5
5
|
type PaymentRequest = Record<string, never>;
|
|
6
6
|
interface PaymentResponse {
|
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.2.
|
|
3
|
+
> @jolibox/implement@1.2.6 clean
|
|
4
4
|
> rimraf ./dist
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
> @jolibox/implement@1.2.
|
|
7
|
+
> @jolibox/implement@1.2.6 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.2.
|
|
4
|
+
"version": "1.2.6",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@jolibox/common": "1.2.
|
|
10
|
-
"@jolibox/types": "1.2.
|
|
11
|
-
"@jolibox/native-bridge": "1.2.
|
|
12
|
-
"@jolibox/ads": "1.2.
|
|
9
|
+
"@jolibox/common": "1.2.6",
|
|
10
|
+
"@jolibox/types": "1.2.6",
|
|
11
|
+
"@jolibox/native-bridge": "1.2.6",
|
|
12
|
+
"@jolibox/ads": "1.2.6",
|
|
13
13
|
"localforage": "1.10.0",
|
|
14
14
|
"@jolibox/ui": "1.0.0",
|
|
15
15
|
"web-vitals": "4.2.4"
|
|
@@ -16,6 +16,7 @@ const priority = () => {
|
|
|
16
16
|
return (a: RewardType, b: RewardType) => {
|
|
17
17
|
// Priority order: GEM > JOLI_COIN > ADS
|
|
18
18
|
const priorityMap: Record<RewardType, number> = {
|
|
19
|
+
SUBSCRIPTION: 4,
|
|
19
20
|
JOLI_GEM: 3,
|
|
20
21
|
JOLI_GEM_ONLY: 3,
|
|
21
22
|
JOLI_COIN: 2,
|
|
@@ -29,8 +30,24 @@ const priority = () => {
|
|
|
29
30
|
|
|
30
31
|
const sortRewards = (rewardsTypes: RewardType[]): RewardType[] => {
|
|
31
32
|
if (!rewardsTypes.length) return ['ADS'];
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
|
|
34
|
+
// Handle JOLI_GEM cases
|
|
35
|
+
if (rewardsTypes.includes('JOLI_GEM')) {
|
|
36
|
+
if (rewardsTypes.length === 1) {
|
|
37
|
+
return ['JOLI_GEM_ONLY'];
|
|
38
|
+
} else if (rewardsTypes.includes('SUBSCRIPTION') && rewardsTypes.length === 2) {
|
|
39
|
+
return ['SUBSCRIPTION', 'JOLI_GEM_ONLY'];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Handle JOLI_COIN cases
|
|
44
|
+
if (rewardsTypes.includes('JOLI_COIN')) {
|
|
45
|
+
if (rewardsTypes.length === 1) {
|
|
46
|
+
return ['JOLI_COIN_ONLY'];
|
|
47
|
+
} else if (rewardsTypes.includes('SUBSCRIPTION') && rewardsTypes.length === 2) {
|
|
48
|
+
return ['SUBSCRIPTION', 'JOLI_COIN_ONLY'];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
34
51
|
|
|
35
52
|
return rewardsTypes.sort(priority());
|
|
36
53
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RequestCacheService, RequestAdapter } from '
|
|
1
|
+
import { RequestCacheService, RequestAdapter } from '@jolibox/common';
|
|
2
2
|
import { IHttpClient } from '../http';
|
|
3
3
|
import { StandardResponse, GlobalConfig } from '@jolibox/types';
|
|
4
4
|
import { IJolicoinRewardOption, IUnlockOption, IJoliCoin, IGem } from './type';
|
|
@@ -50,8 +50,8 @@ class RewardRequestAdapter
|
|
|
50
50
|
extractCacheableData(response: IJolicoinRewardOption): UnlockOptionsCacheData {
|
|
51
51
|
return {
|
|
52
52
|
unlockOptions: response.data?.unlockOptions || [],
|
|
53
|
-
joliCoin: response.extra
|
|
54
|
-
joliGem: response.extra
|
|
53
|
+
joliCoin: response.extra?.joliCoin,
|
|
54
|
+
joliGem: response.extra?.joliGem || { balance: 0, enableAutoDeduct: false }
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
|
|
@@ -10,6 +10,7 @@ export * from './registers/use-jolicoin';
|
|
|
10
10
|
export * from './registers/use-jolicoin-only';
|
|
11
11
|
export * from './registers/use-gem';
|
|
12
12
|
export * from './registers/use-gem-only';
|
|
13
|
+
export * from './registers/use-subscription';
|
|
13
14
|
|
|
14
15
|
export { warmupBalanceCache } from './registers/utils/coins/jolicoin/cached-fetch-balance';
|
|
15
16
|
export { warmupGemBalanceCache } from './registers/utils/coins/joligem/cached-fetch-gem-balance';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { IHttpClient } from '@/common/http';
|
|
2
|
+
import { IAdBreakParams } from '@/common/ads';
|
|
3
|
+
import { unlockOptionsHandler } from './utils/common';
|
|
4
|
+
import { createCommonSubscriptionHandler } from './utils/subscription/sub-handler';
|
|
5
|
+
import { createShowSubscriptionModal } from './utils/subscription/commands/use-subscription';
|
|
6
|
+
|
|
7
|
+
export type SubscriptionRewardsHandler = (params: IAdBreakParams) => Promise<boolean>;
|
|
8
|
+
export const createSubscriptionRewardHandler = (
|
|
9
|
+
httpClient: IHttpClient,
|
|
10
|
+
{
|
|
11
|
+
onSubSuccess,
|
|
12
|
+
onSubFailed
|
|
13
|
+
}: {
|
|
14
|
+
onSubSuccess?: () => void;
|
|
15
|
+
onSubFailed?: () => void;
|
|
16
|
+
}
|
|
17
|
+
): SubscriptionRewardsHandler => {
|
|
18
|
+
const handleUnlockFailed = () => {
|
|
19
|
+
onSubFailed?.();
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const showSubscriptionModal = createShowSubscriptionModal('SUBSCRIPTION');
|
|
23
|
+
|
|
24
|
+
const subscriptionRewardHandler = createCommonSubscriptionHandler('SUBSCRIPTION', httpClient, {
|
|
25
|
+
handlers: {
|
|
26
|
+
handleSubSuccess: onSubSuccess,
|
|
27
|
+
handleSubFailed: handleUnlockFailed,
|
|
28
|
+
unlockOptionsHandler,
|
|
29
|
+
showSubscriptionModal
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return subscriptionRewardHandler;
|
|
34
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './use-subscription';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { rewardsCommands } from '../../coins/rewards-command';
|
|
2
|
+
import { createEventPromiseHandler } from '../../event-listener';
|
|
3
|
+
import { IUseSubscriptionResultEvent, UseSubscriptionResultEventName } from '@/common/rewards/reward-emitter';
|
|
4
|
+
import { rewardsEmitter, InvokeSubscriptionEventName } from '@/common/rewards/reward-emitter';
|
|
5
|
+
|
|
6
|
+
export const registerUseSubscriptionCommand = (params: {
|
|
7
|
+
showSubscriptionModal: () => Promise<'SUCCESS' | 'CANCEL' | 'FAILED'>;
|
|
8
|
+
}) => {
|
|
9
|
+
const { showSubscriptionModal } = params;
|
|
10
|
+
rewardsCommands.registerCommand(`Rewards.subscription`, async () => {
|
|
11
|
+
const subscriptionResult = await showSubscriptionModal();
|
|
12
|
+
return {
|
|
13
|
+
result: subscriptionResult === 'SUCCESS' ? 'SUCCESS' : 'FAILED'
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// EVENTS
|
|
19
|
+
export const createShowSubscriptionModal = (type: 'SUBSCRIPTION') => {
|
|
20
|
+
return async () => {
|
|
21
|
+
const modalHandler = createEventPromiseHandler<
|
|
22
|
+
IUseSubscriptionResultEvent,
|
|
23
|
+
typeof UseSubscriptionResultEventName
|
|
24
|
+
>(rewardsEmitter, UseSubscriptionResultEventName);
|
|
25
|
+
rewardsEmitter.emit(InvokeSubscriptionEventName, type);
|
|
26
|
+
const modalResult = await modalHandler.getFreshData();
|
|
27
|
+
return modalResult.result;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { IHttpClient } from '@/common/http';
|
|
2
|
+
import { IAdBreakParams } from '@/common/ads';
|
|
3
|
+
import { EventPromiseHandler } from '../event-listener';
|
|
4
|
+
import { UnlockOptionsEventName, IUnlockOptionsEvent } from '@/common/rewards/reward-emitter';
|
|
5
|
+
import { rewardsCommands } from '../coins/rewards-command';
|
|
6
|
+
import { RewardsCommandType } from '@jolibox/types';
|
|
7
|
+
import { createShowSubscriptionModal } from './commands/use-subscription';
|
|
8
|
+
import { registerUseSubscriptionCommand } from './commands';
|
|
9
|
+
import { context } from '@/common/context';
|
|
10
|
+
|
|
11
|
+
export const createCommonSubscriptionHandler = (
|
|
12
|
+
type: 'SUBSCRIPTION',
|
|
13
|
+
httpClient: IHttpClient,
|
|
14
|
+
{
|
|
15
|
+
handlers: { handleSubSuccess, handleSubFailed, unlockOptionsHandler, showSubscriptionModal }
|
|
16
|
+
}: {
|
|
17
|
+
handlers: {
|
|
18
|
+
handleSubSuccess?: () => void;
|
|
19
|
+
handleSubFailed?: (params: IAdBreakParams) => void;
|
|
20
|
+
unlockOptionsHandler: EventPromiseHandler<IUnlockOptionsEvent, typeof UnlockOptionsEventName>;
|
|
21
|
+
showSubscriptionModal: ReturnType<typeof createShowSubscriptionModal>;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
) => {
|
|
25
|
+
// register commands
|
|
26
|
+
registerUseSubscriptionCommand({
|
|
27
|
+
showSubscriptionModal: showSubscriptionModal
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const commands = [`Rewards.subscription`];
|
|
31
|
+
|
|
32
|
+
return async (params: IAdBreakParams) => {
|
|
33
|
+
try {
|
|
34
|
+
let result = true;
|
|
35
|
+
for (const command of commands) {
|
|
36
|
+
const commandResult = await rewardsCommands.executeCommand(command as RewardsCommandType);
|
|
37
|
+
result = result && commandResult.result !== 'FAILED';
|
|
38
|
+
if (commandResult.result !== 'CONTINUE') {
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!result) {
|
|
44
|
+
handleSubFailed?.(params);
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
console.log('-----unlockWithSubscription result-----');
|
|
49
|
+
if (result) {
|
|
50
|
+
try {
|
|
51
|
+
params.adBreakDone?.({
|
|
52
|
+
breakType: params.type,
|
|
53
|
+
breakName: 'name' in params ? params.name ?? '' : '',
|
|
54
|
+
breakFormat: params.type === 'reward' ? 'reward' : 'interstitial',
|
|
55
|
+
breakStatus: 'viewed'
|
|
56
|
+
});
|
|
57
|
+
if ('adViewed' in params) {
|
|
58
|
+
params.adViewed?.();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
context.onEnvConfigChanged?.({
|
|
62
|
+
hostUserInfo: {
|
|
63
|
+
...(context.hostUserInfo ?? { isLogin: false }),
|
|
64
|
+
isSubUser: true
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
} catch (e) {
|
|
68
|
+
console.error('-----unlockWithSubscription adBreakDone error-----', e);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
handleSubSuccess?.();
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
handleSubFailed?.(params);
|
|
75
|
+
return false;
|
|
76
|
+
} catch (e) {
|
|
77
|
+
console.info(`SubscriptionRewardHandler error:`, e);
|
|
78
|
+
if (e instanceof Error && e.message == 'CANCEL') {
|
|
79
|
+
// Cancel should terminate the reward handler, invoke unlock failed
|
|
80
|
+
throw e;
|
|
81
|
+
}
|
|
82
|
+
handleSubFailed?.(params);
|
|
83
|
+
return false;
|
|
84
|
+
} finally {
|
|
85
|
+
unlockOptionsHandler.clearCache();
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
};
|
|
@@ -17,6 +17,8 @@ export const UseModalResultEventName = 'ON_USE_MODAL_RESULT' as const;
|
|
|
17
17
|
export const UseModalFrequencyEventName = 'ON_USE_MODAL_FREQUENCY' as const;
|
|
18
18
|
export const UseUnloginModalResultEventName = 'ON_USE_UNLOGIN_MODAL_EVENT' as const;
|
|
19
19
|
export const InvokeUnloginModalEventName = 'INVOKE_UNLOGIN_MODAL_EVENT' as const;
|
|
20
|
+
export const InvokeSubscriptionEventName = 'INVOKE_SUBSCRIPTION_EVENT' as const;
|
|
21
|
+
export const UseSubscriptionResultEventName = 'ON_USE_SUBSCRIPTION_RESULT' as const;
|
|
20
22
|
|
|
21
23
|
type IPaymentResult = 'SUCCESS' | 'FAILED' | 'CANCEL';
|
|
22
24
|
export interface IPaymentEvent {
|
|
@@ -90,6 +92,10 @@ export interface IUseModalFrequencyConfig {
|
|
|
90
92
|
};
|
|
91
93
|
}
|
|
92
94
|
|
|
95
|
+
export interface IUseSubscriptionResultEvent {
|
|
96
|
+
result: 'SUCCESS' | 'CANCEL' | 'FAILED';
|
|
97
|
+
}
|
|
98
|
+
|
|
93
99
|
export interface RewardsEventMap extends Record<string, unknown[]> {
|
|
94
100
|
[UnlockOptionsEventName]: [IUnlockOptionsEvent];
|
|
95
101
|
[InvokePaymentEventName]: [
|
|
@@ -105,6 +111,8 @@ export interface RewardsEventMap extends Record<string, unknown[]> {
|
|
|
105
111
|
IUseUnloginModalEvent
|
|
106
112
|
];
|
|
107
113
|
[UseUnloginModalResultEventName]: [IUseUnloginModalResultEvent];
|
|
114
|
+
[InvokeSubscriptionEventName]: ['SUBSCRIPTION'];
|
|
115
|
+
[UseSubscriptionResultEventName]: [IUseSubscriptionResultEvent];
|
|
108
116
|
}
|
|
109
117
|
|
|
110
118
|
export const originalRewardsEmitter = new EventEmitter<RewardsEventMap>();
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
export type RewardType =
|
|
1
|
+
export type RewardType =
|
|
2
|
+
| 'ADS'
|
|
3
|
+
| 'JOLI_COIN'
|
|
4
|
+
| 'JOLI_COIN_ONLY'
|
|
5
|
+
| 'JOLI_GEM'
|
|
6
|
+
| 'JOLI_GEM_ONLY'
|
|
7
|
+
| 'SUBSCRIPTION';
|
|
2
8
|
|
|
3
9
|
import { context } from '../context';
|
|
4
10
|
import type { AdsRewardsHandler } from './registers/use-ads';
|
|
@@ -10,6 +16,7 @@ export interface RewardHandlerMap {
|
|
|
10
16
|
JOLI_COIN_ONLY: (params?: unknown) => Promise<boolean>; // coins only
|
|
11
17
|
JOLI_GEM: (params?: unknown) => Promise<boolean>; // gem + ads
|
|
12
18
|
JOLI_GEM_ONLY: (params?: unknown) => Promise<boolean>; // gem only
|
|
19
|
+
SUBSCRIPTION: (params?: unknown) => Promise<boolean>; // subscription
|
|
13
20
|
}
|
|
14
21
|
|
|
15
22
|
export type RewardHandler<T extends RewardType> = RewardHandlerMap[T];
|
|
@@ -8,6 +8,11 @@ const JOLIBOX_JOLI_COIN_USE_EVENT = 'JOLIBOX_JOLI_COIN_USE_EVENT';
|
|
|
8
8
|
const JOLIBOX_JOLI_UNLOGIN_MODAL_EVENT = 'JOLIBOX_JOLI_UNLOGIN_MODAL_EVENT'; // unlogin modal event, triggered when unlogin
|
|
9
9
|
// unlogin modal result event success.
|
|
10
10
|
|
|
11
|
+
// subscrition
|
|
12
|
+
|
|
13
|
+
const JOLIBOX_GET_USER_SUB_STATUS = 'JOLIBOX_GET_USER_SUB_STATUS';
|
|
14
|
+
const JOLIBOX_SUB_EVENT = 'JOLIBOX_SUB_EVENT';
|
|
15
|
+
|
|
11
16
|
interface JoliboxCustomEvent {
|
|
12
17
|
[JOLIBOX_CUSTOM_ADS_EVENT_TYPE]: {
|
|
13
18
|
isAdShowing: boolean;
|
|
@@ -41,6 +46,12 @@ interface JoliboxCustomEvent {
|
|
|
41
46
|
sequenceId: string;
|
|
42
47
|
type: 'ADS-JOLI_COIN' | 'JOLI_COIN';
|
|
43
48
|
};
|
|
49
|
+
[JOLIBOX_GET_USER_SUB_STATUS]: {
|
|
50
|
+
sequenceId: string;
|
|
51
|
+
};
|
|
52
|
+
[JOLIBOX_SUB_EVENT]: {
|
|
53
|
+
sequenceId: string;
|
|
54
|
+
};
|
|
44
55
|
}
|
|
45
56
|
|
|
46
57
|
const notifyCustomEvent = <T extends keyof JoliboxCustomEvent>(eventName: T, data: JoliboxCustomEvent[T]) => {
|
|
@@ -66,6 +77,10 @@ const ON_JOLIBOX_TOPUP_JOLI_COIN_RESULT = 'ON_JOLIBOX_TOPUP_JOLI_COIN_RESULT';
|
|
|
66
77
|
const ON_JOLIBOX_JOLI_COIN_USE_RESULT = 'ON_JOLIBOX_JOLI_COIN_USE_RESULT';
|
|
67
78
|
const ON_JOLIBOX_JOLI_UNLOGIN_MODAL_RESULT_EVENT = 'ON_JOLIBOX_JOLI_UNLOGIN_MODAL_RESULT_EVENT';
|
|
68
79
|
|
|
80
|
+
// subscription
|
|
81
|
+
const ON_GET_USER_SUB_STATUS = 'ON_GET_USER_SUB_STATUS';
|
|
82
|
+
const ON_JOLIBOX_SUB_RESULT_EVENT = 'ON_JOLIBOX_SUB_RESULT_EVENT';
|
|
83
|
+
|
|
69
84
|
interface ReceivedJoliboxCustomEvent {
|
|
70
85
|
[ON_JOLIBOX_TOPUP_JOLI_COIN_RESULT]: {
|
|
71
86
|
sequenceId: string;
|
|
@@ -93,6 +108,14 @@ interface ReceivedJoliboxCustomEvent {
|
|
|
93
108
|
};
|
|
94
109
|
isFirstLogin?: boolean;
|
|
95
110
|
};
|
|
111
|
+
[ON_GET_USER_SUB_STATUS]: {
|
|
112
|
+
sequenceId: string;
|
|
113
|
+
isSubUser: boolean;
|
|
114
|
+
};
|
|
115
|
+
[ON_JOLIBOX_SUB_RESULT_EVENT]: {
|
|
116
|
+
sequenceId: string;
|
|
117
|
+
result: 'SUCCESS' | 'CANCEL' | 'FAILED';
|
|
118
|
+
};
|
|
96
119
|
}
|
|
97
120
|
|
|
98
121
|
type ReceivedJoliboxCustomEventResult = keyof ReceivedJoliboxCustomEvent;
|
package/src/h5/api/ads.ts
CHANGED
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
createAdsRewardHandler,
|
|
7
7
|
rewardsHelper,
|
|
8
8
|
createJolicoinRewardHandler,
|
|
9
|
-
createJolicoinOnlyRewardHandler
|
|
9
|
+
createJolicoinOnlyRewardHandler,
|
|
10
|
+
createSubscriptionRewardHandler
|
|
10
11
|
} from '@/common/rewards';
|
|
11
12
|
import {
|
|
12
13
|
JoliboxAdsForGame,
|
|
@@ -24,7 +25,7 @@ import GamedistributionAdsHandler from './platformAdsHandle/GamedistributionAdsH
|
|
|
24
25
|
import FunmaxAdsHandler from './platformAdsHandle/FunmaxAdsHandler';
|
|
25
26
|
import JoliboxAdsHandler from './platformAdsHandle/JoliboxAdsHandler';
|
|
26
27
|
import { warmupRewardCache } from '@/common/rewards/fetch-reward';
|
|
27
|
-
import { warmupBalanceCache
|
|
28
|
+
import { warmupBalanceCache } from '@/common/rewards';
|
|
28
29
|
|
|
29
30
|
declare global {
|
|
30
31
|
interface Window {
|
|
@@ -138,6 +139,10 @@ const handleUnlockSuccess = (params: { quantity: number; balance: number }) => {
|
|
|
138
139
|
});
|
|
139
140
|
};
|
|
140
141
|
|
|
142
|
+
const handleUnlockWithSubscriptionSuccess = () => {
|
|
143
|
+
track('subscription_unlock_success', {});
|
|
144
|
+
};
|
|
145
|
+
|
|
141
146
|
const adsManager = new H5AdsManager(adsContext);
|
|
142
147
|
const adsHandler = adsManager.getAdsHandler(context.sdkEnvironment);
|
|
143
148
|
|
|
@@ -156,6 +161,13 @@ rewardsHelper.registerRewardHandler(
|
|
|
156
161
|
}) as unknown as (params?: unknown) => Promise<boolean>
|
|
157
162
|
);
|
|
158
163
|
|
|
164
|
+
rewardsHelper.registerRewardHandler(
|
|
165
|
+
'SUBSCRIPTION',
|
|
166
|
+
createSubscriptionRewardHandler(httpClient, {
|
|
167
|
+
onSubSuccess: handleUnlockWithSubscriptionSuccess.bind(this)
|
|
168
|
+
}) as unknown as (params?: unknown) => Promise<boolean>
|
|
169
|
+
);
|
|
170
|
+
|
|
159
171
|
warmupRewardCache(httpClient);
|
|
160
172
|
warmupBalanceCache(httpClient);
|
|
161
173
|
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from '@jolibox/ads';
|
|
9
9
|
import { IAdsHandler } from '../ads';
|
|
10
10
|
import { JoliboxHttpClient } from '@/h5/http';
|
|
11
|
+
import { context } from '@/common/context';
|
|
11
12
|
|
|
12
13
|
export default class JoliboxAdsHandler implements IAdsHandler {
|
|
13
14
|
constructor(private ads: JoliboxAdsForGame, private httpClient: JoliboxHttpClient) {}
|
|
@@ -25,10 +26,21 @@ export default class JoliboxAdsHandler implements IAdsHandler {
|
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
async adBreak(params: IAdBreakParams): Promise<void> {
|
|
29
|
+
const isSubUser = context.hostUserInfo?.isSubUser;
|
|
30
|
+
|
|
31
|
+
// if is sub user, just call adBreakDone with viewed status
|
|
32
|
+
if (isSubUser) {
|
|
33
|
+
this.wrapAdBreadDoneViewed(params);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
28
37
|
if (params.type === 'reward') {
|
|
29
38
|
try {
|
|
30
39
|
const rewardsTypes = await rewardsHelper.getRewardsTypes(this.httpClient);
|
|
31
|
-
await rewardsHelper.handleReward(rewardsTypes, params);
|
|
40
|
+
const rewardResult = await rewardsHelper.handleReward(rewardsTypes, params);
|
|
41
|
+
if (!rewardResult) {
|
|
42
|
+
throw new Error('handleReward failed: fallback to unlock failed');
|
|
43
|
+
}
|
|
32
44
|
} catch (e) {
|
|
33
45
|
console.info('handleReward failed', e);
|
|
34
46
|
params.adBreakDone?.({
|
|
@@ -45,4 +57,16 @@ export default class JoliboxAdsHandler implements IAdsHandler {
|
|
|
45
57
|
adUnit(params: IAdUnitParams): void {
|
|
46
58
|
this.ads.adUnit(params);
|
|
47
59
|
}
|
|
60
|
+
|
|
61
|
+
private wrapAdBreadDoneViewed(params: IAdBreakParams) {
|
|
62
|
+
params.adBreakDone?.({
|
|
63
|
+
breakType: params.type,
|
|
64
|
+
breakName: 'name' in params ? params.name ?? '' : '',
|
|
65
|
+
breakFormat: params.type === 'reward' ? 'reward' : 'interstitial',
|
|
66
|
+
breakStatus: 'viewed'
|
|
67
|
+
});
|
|
68
|
+
if ('adViewed' in params) {
|
|
69
|
+
params.adViewed?.();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
48
72
|
}
|