@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,7 +1,9 @@
|
|
|
1
|
-
import { IJoliCoin
|
|
1
|
+
import { IJoliCoin } from '@/common/rewards/type';
|
|
2
|
+
import { fetchBalance } from '../fetch-balance';
|
|
2
3
|
import { rewardsCommands } from '../rewards-command';
|
|
3
4
|
import { IHttpClient } from '@/common/http';
|
|
4
5
|
import { unlockOptionsHandler } from '../../common';
|
|
6
|
+
import { joliCoinIsEnough } from '../../index';
|
|
5
7
|
import { rewardsEmitter } from '@/common/rewards/reward-emitter';
|
|
6
8
|
import { createEventPromiseHandler } from '../../event-listener';
|
|
7
9
|
import {
|
|
@@ -9,43 +11,39 @@ import {
|
|
|
9
11
|
PaymentResultEventName,
|
|
10
12
|
InvokePaymentEventName
|
|
11
13
|
} from '@/common/rewards/reward-emitter';
|
|
12
|
-
import { CURRENCY_HANDLERS, CurrencyType } from './currency-handlers';
|
|
13
14
|
|
|
14
|
-
export const registerUsePaymentCommand =
|
|
15
|
-
prefix: 'JOLI_COIN' | 'ADS-JOLI_COIN'
|
|
16
|
-
currency: 'JOLI_COIN' | 'JOLI_GEM',
|
|
15
|
+
export const registerUsePaymentCommand = (
|
|
16
|
+
prefix: 'JOLI_COIN' | 'ADS-JOLI_COIN',
|
|
17
17
|
params: {
|
|
18
18
|
httpClient: IHttpClient;
|
|
19
19
|
initiateAndAwaitPayment: (params: {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
currency: T extends IJoliCoin ? 'JOLI_COIN' : 'JOLI_GEM';
|
|
20
|
+
userJoliCoin: IJoliCoin;
|
|
21
|
+
joliCoinQuantity: number;
|
|
23
22
|
}) => Promise<'SUCCESS' | 'FAILED' | 'CANCEL'>;
|
|
24
23
|
}
|
|
25
24
|
) => {
|
|
26
25
|
const { httpClient, initiateAndAwaitPayment } = params;
|
|
27
26
|
rewardsCommands.registerCommand(`Rewards.${prefix}.usePayment`, async () => {
|
|
28
27
|
const unlockOptions = await unlockOptionsHandler.getData();
|
|
28
|
+
const newBalance = await fetchBalance(httpClient);
|
|
29
|
+
const joliCoinQuantity =
|
|
30
|
+
unlockOptions?.options?.find((option) => option.type === 'JOLI_COIN')?.joliCoinChoices[0]
|
|
31
|
+
.joliCoinQuantity ?? 0;
|
|
29
32
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const currentUser = handler.getCurrentUser(unlockOptions);
|
|
35
|
-
|
|
36
|
-
const newUser = handler.createUpdatedUser(newBalance?.balance ?? 0, currentUser.enableAutoDeduct);
|
|
33
|
+
const newJoliCoin = {
|
|
34
|
+
balance: newBalance?.balance ?? 0,
|
|
35
|
+
enableAutoDeduct: unlockOptions?.userJoliCoin?.enableAutoDeduct ?? false
|
|
36
|
+
};
|
|
37
37
|
|
|
38
|
-
const updateKey = handler.getUpdateKey();
|
|
39
38
|
unlockOptionsHandler.updateData({
|
|
40
|
-
|
|
39
|
+
userJoliCoin: newJoliCoin
|
|
41
40
|
});
|
|
42
41
|
|
|
43
|
-
console.log('-----unlockOptions payment-----', unlockOptions,
|
|
44
|
-
if (!
|
|
42
|
+
console.log('-----unlockOptions payment-----', unlockOptions, newJoliCoin, joliCoinQuantity);
|
|
43
|
+
if (!joliCoinIsEnough(unlockOptions?.options || [], newJoliCoin)) {
|
|
45
44
|
const paymentResult = await initiateAndAwaitPayment({
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
currency: currency as T extends IJoliCoin ? 'JOLI_COIN' : 'JOLI_GEM'
|
|
45
|
+
userJoliCoin: newJoliCoin,
|
|
46
|
+
joliCoinQuantity
|
|
49
47
|
});
|
|
50
48
|
|
|
51
49
|
return {
|
|
@@ -60,27 +58,22 @@ export const registerUsePaymentCommand = <T extends IJoliCoin | IGem>(
|
|
|
60
58
|
|
|
61
59
|
// events
|
|
62
60
|
export const createInitiateAndAwaitPayment = (
|
|
63
|
-
type: 'JOLI_COIN' | 'ADS-JOLI_COIN'
|
|
61
|
+
type: 'JOLI_COIN' | 'ADS-JOLI_COIN',
|
|
64
62
|
buttons: {
|
|
65
63
|
confirmButtonText: string;
|
|
66
64
|
cancelButtonText: string;
|
|
67
65
|
}
|
|
68
66
|
) => {
|
|
69
|
-
return async
|
|
70
|
-
userCurrency: T;
|
|
71
|
-
currencyQuantity: number;
|
|
72
|
-
currency: T extends IJoliCoin ? 'JOLI_COIN' : 'JOLI_GEM';
|
|
73
|
-
}) => {
|
|
67
|
+
return async (params: { userJoliCoin: IJoliCoin; joliCoinQuantity: number }) => {
|
|
74
68
|
const paymentHandler = createEventPromiseHandler<IPaymentEvent, typeof PaymentResultEventName>(
|
|
75
69
|
rewardsEmitter,
|
|
76
70
|
PaymentResultEventName
|
|
77
71
|
);
|
|
78
72
|
|
|
79
73
|
rewardsEmitter.emit(InvokePaymentEventName, type, {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
enableAutoDeduct: params.userCurrency.enableAutoDeduct,
|
|
74
|
+
userJoliCoin: params.userJoliCoin,
|
|
75
|
+
joliCoinQuantity: params.joliCoinQuantity,
|
|
76
|
+
enableAutoDeduct: params.userJoliCoin.enableAutoDeduct,
|
|
84
77
|
confirmButtonText: buttons.confirmButtonText,
|
|
85
78
|
cancelButtonText: buttons.cancelButtonText
|
|
86
79
|
});
|
|
@@ -3,21 +3,23 @@ import { rewardsCommands } from '../rewards-command';
|
|
|
3
3
|
import { createEventPromiseHandler } from '../../event-listener';
|
|
4
4
|
import { IUseUnloginModalResultEvent, UseUnloginModalResultEventName } from '@/common/rewards/reward-emitter';
|
|
5
5
|
import { rewardsEmitter, InvokeUnloginModalEventName } from '@/common/rewards/reward-emitter';
|
|
6
|
+
import { createToast } from '@jolibox/ui';
|
|
6
7
|
import { sleep } from '@jolibox/common';
|
|
8
|
+
import { fetchBalance } from '../fetch-balance';
|
|
7
9
|
import { IHttpClient } from '@/common/http';
|
|
8
10
|
import { unlockOptionsHandler } from '../../common';
|
|
9
|
-
import { CURRENCY_HANDLERS, CurrencyType } from './currency-handlers';
|
|
10
11
|
|
|
11
12
|
export const registerUseUnloginCommand = (
|
|
12
|
-
prefix: 'JOLI_COIN' | 'ADS-JOLI_COIN'
|
|
13
|
-
currency: 'JOLI_COIN' | 'JOLI_GEM',
|
|
13
|
+
prefix: 'JOLI_COIN' | 'ADS-JOLI_COIN',
|
|
14
14
|
params: {
|
|
15
15
|
httpClient: IHttpClient;
|
|
16
|
-
showUnloginModal: (
|
|
16
|
+
showUnloginModal: () => Promise<{
|
|
17
17
|
result: 'CANCEL' | 'FAILED' | 'SUCCESS' | 'ADS' | 'NOT_SUPPORT';
|
|
18
18
|
rewards?: {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
jolicoin?: {
|
|
20
|
+
isFirstLogin: boolean;
|
|
21
|
+
claimedRewardValue: number;
|
|
22
|
+
};
|
|
21
23
|
};
|
|
22
24
|
}>;
|
|
23
25
|
}
|
|
@@ -28,7 +30,7 @@ export const registerUseUnloginCommand = (
|
|
|
28
30
|
const unlockOptions = await unlockOptionsHandler.getData();
|
|
29
31
|
console.log('-----isLogin-----', !!isLogin);
|
|
30
32
|
if (!isLogin) {
|
|
31
|
-
const unloginModalResult = await showUnloginModal(
|
|
33
|
+
const unloginModalResult = await showUnloginModal();
|
|
32
34
|
|
|
33
35
|
console.log('-----unloginModalResult-----', unloginModalResult);
|
|
34
36
|
if (unloginModalResult.result == 'FAILED' || unloginModalResult.result == 'CANCEL') {
|
|
@@ -37,26 +39,27 @@ export const registerUseUnloginCommand = (
|
|
|
37
39
|
};
|
|
38
40
|
}
|
|
39
41
|
|
|
40
|
-
const { isFirstLogin, claimedRewardValue } = unloginModalResult.rewards ?? {};
|
|
42
|
+
const { isFirstLogin, claimedRewardValue } = unloginModalResult.rewards?.jolicoin ?? {};
|
|
41
43
|
if (unloginModalResult.result == 'SUCCESS') {
|
|
42
44
|
if (isFirstLogin && claimedRewardValue) {
|
|
43
45
|
await sleep(3000); // wait for center toast to show
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
//check balance
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
//check balance
|
|
49
|
+
const newBalance = await fetchBalance(httpClient);
|
|
50
|
+
const joliCoinQuantity =
|
|
51
|
+
unlockOptions?.options?.find((option) => option.type === 'JOLI_COIN')?.joliCoinChoices[0]
|
|
52
|
+
.joliCoinQuantity ?? 0;
|
|
51
53
|
|
|
52
|
-
const
|
|
54
|
+
const newJoliCoin = {
|
|
55
|
+
balance: newBalance?.balance ?? 0,
|
|
56
|
+
enableAutoDeduct: unlockOptions?.userJoliCoin?.enableAutoDeduct ?? false
|
|
57
|
+
};
|
|
53
58
|
|
|
54
|
-
const updateKey = handler.getUpdateKey();
|
|
55
59
|
unlockOptionsHandler.updateData({
|
|
56
|
-
|
|
60
|
+
userJoliCoin: newJoliCoin
|
|
57
61
|
});
|
|
58
|
-
|
|
59
|
-
if (newUser.balance >= currencyQuantity) {
|
|
62
|
+
if (newJoliCoin.balance >= joliCoinQuantity) {
|
|
60
63
|
return {
|
|
61
64
|
result: 'SUCCESS'
|
|
62
65
|
};
|
|
@@ -72,21 +75,20 @@ export const registerUseUnloginCommand = (
|
|
|
72
75
|
//EVENTS
|
|
73
76
|
|
|
74
77
|
export const createShowUnloginModal = (
|
|
75
|
-
type: 'JOLI_COIN' | 'ADS-JOLI_COIN'
|
|
78
|
+
type: 'JOLI_COIN' | 'ADS-JOLI_COIN',
|
|
76
79
|
buttons: {
|
|
77
80
|
confirmButtonText: string;
|
|
78
81
|
cancelButtonText: string;
|
|
79
82
|
}
|
|
80
83
|
) => {
|
|
81
|
-
return async (
|
|
84
|
+
return async () => {
|
|
82
85
|
const modalHandler = createEventPromiseHandler<
|
|
83
86
|
IUseUnloginModalResultEvent,
|
|
84
87
|
typeof UseUnloginModalResultEventName
|
|
85
88
|
>(rewardsEmitter, UseUnloginModalResultEventName);
|
|
86
89
|
rewardsEmitter.emit(InvokeUnloginModalEventName, type, {
|
|
87
90
|
confirmButtonText: buttons.confirmButtonText,
|
|
88
|
-
cancelButtonText: buttons.cancelButtonText
|
|
89
|
-
currency
|
|
91
|
+
cancelButtonText: buttons.cancelButtonText
|
|
90
92
|
});
|
|
91
93
|
const modalResult = await modalHandler.getFreshData();
|
|
92
94
|
return modalResult;
|
|
@@ -1,2 +1,139 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { IHttpClient } from '@/common/http';
|
|
2
|
+
import { context } from '@/common/context';
|
|
3
|
+
import { uuidv4 } from '@jolibox/common';
|
|
4
|
+
import { UnlockOptionsEventName, IUnlockOptionsEvent } from '@/common/rewards/reward-emitter';
|
|
5
|
+
import { IAdBreakParams } from '@/common/ads';
|
|
6
|
+
import { EventPromiseHandler } from '../event-listener';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
createInitiateAndAwaitPayment,
|
|
10
|
+
registerUseJolicoinCommand,
|
|
11
|
+
registerUsePaymentCommand,
|
|
12
|
+
registerUseUnloginCommand,
|
|
13
|
+
createShowUnlockWithJolicoinModal,
|
|
14
|
+
createShowUnloginModal
|
|
15
|
+
} from './commands';
|
|
16
|
+
import { rewardsCommands } from './rewards-command';
|
|
17
|
+
import { RewardsCommandType } from '@jolibox/types';
|
|
18
|
+
|
|
19
|
+
interface IJolicoinUnlockRes {
|
|
20
|
+
code: 'SUCCESS' | 'BALANCE_NOT_ENOUGH' | 'EPISODE_LOCK_JUMP' | 'EPISODE_UNLOCK_ALREADY';
|
|
21
|
+
message: string;
|
|
22
|
+
data: {
|
|
23
|
+
transactionId: string;
|
|
24
|
+
quantity: number;
|
|
25
|
+
balance: number;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const createCommonJolicoinRewardHandler = (
|
|
30
|
+
type: 'JOLI_COIN' | 'ADS-JOLI_COIN',
|
|
31
|
+
httpClient: IHttpClient,
|
|
32
|
+
{
|
|
33
|
+
handlers: {
|
|
34
|
+
handleUnlockSuccess,
|
|
35
|
+
handleUnlockFailed,
|
|
36
|
+
unlockOptionsHandler,
|
|
37
|
+
initiateAndAwaitPayment,
|
|
38
|
+
showUnlockWithJolicoinModal,
|
|
39
|
+
showUnloginModal
|
|
40
|
+
}
|
|
41
|
+
}: {
|
|
42
|
+
handlers: {
|
|
43
|
+
handleUnlockSuccess?: (data: { quantity: number; balance: number }) => void;
|
|
44
|
+
handleUnlockFailed?: (params: IAdBreakParams) => void;
|
|
45
|
+
unlockOptionsHandler: EventPromiseHandler<IUnlockOptionsEvent, typeof UnlockOptionsEventName>;
|
|
46
|
+
initiateAndAwaitPayment: ReturnType<typeof createInitiateAndAwaitPayment>;
|
|
47
|
+
showUnlockWithJolicoinModal: ReturnType<typeof createShowUnlockWithJolicoinModal>;
|
|
48
|
+
showUnloginModal: ReturnType<typeof createShowUnloginModal>;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
) => {
|
|
52
|
+
// register commands
|
|
53
|
+
registerUseUnloginCommand(type, {
|
|
54
|
+
httpClient: httpClient,
|
|
55
|
+
showUnloginModal: showUnloginModal
|
|
56
|
+
});
|
|
57
|
+
registerUsePaymentCommand(type, {
|
|
58
|
+
httpClient: httpClient,
|
|
59
|
+
initiateAndAwaitPayment: initiateAndAwaitPayment
|
|
60
|
+
});
|
|
61
|
+
registerUseJolicoinCommand(type, {
|
|
62
|
+
showUnlockWithJolicoinModal: showUnlockWithJolicoinModal
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const targetABTest = context.abTests.find((abTest) => abTest.startsWith('coinOpt_v1'));
|
|
66
|
+
let commands = [];
|
|
67
|
+
if (targetABTest) {
|
|
68
|
+
commands = [`Rewards.${type}.usePayment`, `Rewards.${type}.useJolicoin`];
|
|
69
|
+
} else {
|
|
70
|
+
commands = [
|
|
71
|
+
`Rewards.${type}.useUnloginModal`,
|
|
72
|
+
`Rewards.${type}.usePayment`,
|
|
73
|
+
`Rewards.${type}.useJolicoin`
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
return async (params: IAdBreakParams) => {
|
|
77
|
+
try {
|
|
78
|
+
let result = true;
|
|
79
|
+
for (const command of commands) {
|
|
80
|
+
const commandResult = await rewardsCommands.executeCommand(command as RewardsCommandType);
|
|
81
|
+
result = result && commandResult.result !== 'FAILED';
|
|
82
|
+
if (commandResult.result !== 'CONTINUE') {
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (!result) {
|
|
88
|
+
handleUnlockFailed?.(params);
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const unlockWithJolicoin = await httpClient.post<IJolicoinUnlockRes>('/api/joli-coin/unlock', {
|
|
93
|
+
data: {
|
|
94
|
+
// TODO: support drama
|
|
95
|
+
type: 'GAME_REWARD',
|
|
96
|
+
reqId: `${uuidv4()}-${context.mpType}-${Date.now()}`,
|
|
97
|
+
gameInfo: {
|
|
98
|
+
gameId: context.mpId
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
console.log('-----unlockWithJolicoin request result-----', unlockWithJolicoin);
|
|
104
|
+
if (unlockWithJolicoin.code == 'SUCCESS') {
|
|
105
|
+
try {
|
|
106
|
+
params.adBreakDone?.({
|
|
107
|
+
breakType: params.type,
|
|
108
|
+
breakName: 'name' in params ? params.name ?? '' : '',
|
|
109
|
+
breakFormat: 'reward',
|
|
110
|
+
breakStatus: 'viewed'
|
|
111
|
+
});
|
|
112
|
+
if ('adViewed' in params) {
|
|
113
|
+
params.adViewed?.();
|
|
114
|
+
}
|
|
115
|
+
} catch (e) {
|
|
116
|
+
console.error('-----unlockWithJolicoin adBreakDone error-----', e);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
handleUnlockSuccess?.({
|
|
120
|
+
quantity: unlockWithJolicoin.data.quantity,
|
|
121
|
+
balance: unlockWithJolicoin.data.balance
|
|
122
|
+
});
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
handleUnlockFailed?.(params);
|
|
126
|
+
return false;
|
|
127
|
+
} catch (e) {
|
|
128
|
+
console.info(`JolicoinRewardHandler error:`, e);
|
|
129
|
+
if (e instanceof Error && e.message == 'CANCEL') {
|
|
130
|
+
// Cancel should terminate the reward handler, invoke unlock failed
|
|
131
|
+
throw e;
|
|
132
|
+
}
|
|
133
|
+
handleUnlockFailed?.(params);
|
|
134
|
+
return false;
|
|
135
|
+
} finally {
|
|
136
|
+
unlockOptionsHandler.clearCache();
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { IJoliCoin,
|
|
2
|
-
import { isNumber } from '@jolibox/common';
|
|
1
|
+
import { IJoliCoin, IUnlockOption } from '@/common/rewards/type';
|
|
3
2
|
|
|
4
3
|
export const canUseJolicoin = (unlockOptions: IUnlockOption[], joliCoin?: IJoliCoin) => {
|
|
5
4
|
return unlockOptions.some(
|
|
@@ -18,21 +17,3 @@ export const joliCoinIsEnough = (unlockOptions: IUnlockOption[], joliCoin?: IJol
|
|
|
18
17
|
option.joliCoinChoices.some((choice) => choice.joliCoinQuantity <= (joliCoin?.balance ?? 0))
|
|
19
18
|
);
|
|
20
19
|
};
|
|
21
|
-
|
|
22
|
-
// Gem utility functions
|
|
23
|
-
export const canUseGem = (unlockOptions: IUnlockOption[], gem?: IGem) => {
|
|
24
|
-
return unlockOptions.some((option) => {
|
|
25
|
-
if (option.type === 'JOLI_GEM' && isNumber(option.joliGemChoices?.joliGemQuantity)) {
|
|
26
|
-
return option.joliGemChoices.joliGemQuantity <= (gem?.balance ?? 0) && !!gem?.enableAutoDeduct;
|
|
27
|
-
}
|
|
28
|
-
return false;
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export const gemIsEnough = (unlockOptions: IUnlockOption[], gem?: IGem) => {
|
|
33
|
-
const gemOptions = unlockOptions.find((option) => option.type === 'JOLI_GEM');
|
|
34
|
-
if (gemOptions) {
|
|
35
|
-
return (gemOptions.joliGemChoices?.joliGemQuantity ?? 0) <= (gem?.balance ?? 0);
|
|
36
|
-
}
|
|
37
|
-
return false;
|
|
38
|
-
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// rewards-emitter-wrapper.ts
|
|
2
2
|
|
|
3
3
|
import { EventEmitter } from '@jolibox/common';
|
|
4
|
-
import { IUnlockOption
|
|
4
|
+
import { IUnlockOption } from './type';
|
|
5
|
+
import { IJoliCoin } from './type';
|
|
5
6
|
|
|
6
7
|
export interface IUnlockOptionsEvent {
|
|
7
8
|
options: IUnlockOption[];
|
|
8
9
|
userJoliCoin: IJoliCoin;
|
|
9
|
-
userGem?: IGem;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export const UnlockOptionsEventName = 'UNLOCK_OPTIONS_CHANGED' as const;
|
|
@@ -21,8 +21,6 @@ export const InvokeUnloginModalEventName = 'INVOKE_UNLOGIN_MODAL_EVENT' as const
|
|
|
21
21
|
type IPaymentResult = 'SUCCESS' | 'FAILED' | 'CANCEL';
|
|
22
22
|
export interface IPaymentEvent {
|
|
23
23
|
userJoliCoin?: IJoliCoin;
|
|
24
|
-
userGem?: IGem;
|
|
25
|
-
currency: 'JOLI_COIN' | 'JOLI_GEM';
|
|
26
24
|
paymentResult: IPaymentResult;
|
|
27
25
|
}
|
|
28
26
|
|
|
@@ -34,9 +32,8 @@ export interface IPaymentChoice {
|
|
|
34
32
|
}
|
|
35
33
|
|
|
36
34
|
export interface IInvokePaymentEvent {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
currency: 'JOLI_COIN' | 'JOLI_GEM';
|
|
35
|
+
userJoliCoin: IJoliCoin;
|
|
36
|
+
joliCoinQuantity: number;
|
|
40
37
|
enableAutoDeduct: boolean;
|
|
41
38
|
confirmButtonText: string;
|
|
42
39
|
cancelButtonText: string;
|
|
@@ -45,9 +42,8 @@ export interface IInvokePaymentEvent {
|
|
|
45
42
|
|
|
46
43
|
export interface IUseModalEvent {
|
|
47
44
|
enableAutoDeduct: boolean;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
currency: 'JOLI_COIN' | 'JOLI_GEM';
|
|
45
|
+
userJoliCoin: IJoliCoin;
|
|
46
|
+
joliCoinQuantity: number;
|
|
51
47
|
confirmButtonText: string;
|
|
52
48
|
cancelButtonText: string;
|
|
53
49
|
sequenceId?: string;
|
|
@@ -56,7 +52,6 @@ export interface IUseModalEvent {
|
|
|
56
52
|
export interface IUseUnloginModalEvent {
|
|
57
53
|
confirmButtonText: string;
|
|
58
54
|
cancelButtonText: string;
|
|
59
|
-
currency: 'JOLI_COIN' | 'JOLI_GEM';
|
|
60
55
|
}
|
|
61
56
|
|
|
62
57
|
export interface IUseModalResultEvent {
|
|
@@ -66,9 +61,10 @@ export interface IUseModalResultEvent {
|
|
|
66
61
|
export interface IUseUnloginModalResultEvent {
|
|
67
62
|
result: 'SUCCESS' | 'CANCEL' | 'ADS' | 'FAILED' | 'NOT_SUPPORT';
|
|
68
63
|
rewards?: {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
jolicoin?: {
|
|
65
|
+
claimedRewardValue: number;
|
|
66
|
+
isFirstLogin: boolean;
|
|
67
|
+
};
|
|
72
68
|
};
|
|
73
69
|
}
|
|
74
70
|
|
|
@@ -92,18 +88,12 @@ export interface IUseModalFrequencyConfig {
|
|
|
92
88
|
|
|
93
89
|
export interface RewardsEventMap extends Record<string, unknown[]> {
|
|
94
90
|
[UnlockOptionsEventName]: [IUnlockOptionsEvent];
|
|
95
|
-
[InvokePaymentEventName]: [
|
|
96
|
-
'JOLI_COIN' | 'ADS-JOLI_COIN' | 'JOLI_GEM' | 'ADS-JOLI_GEM',
|
|
97
|
-
IInvokePaymentEvent
|
|
98
|
-
];
|
|
91
|
+
[InvokePaymentEventName]: ['JOLI_COIN' | 'ADS-JOLI_COIN', IInvokePaymentEvent];
|
|
99
92
|
[PaymentResultEventName]: [IPaymentEvent];
|
|
100
93
|
[UseModalResultEventName]: [IUseModalResultEvent];
|
|
101
|
-
[UseModalEventName]: ['JOLI_COIN' | 'ADS-JOLI_COIN'
|
|
94
|
+
[UseModalEventName]: ['JOLI_COIN' | 'ADS-JOLI_COIN', IUseModalEvent];
|
|
102
95
|
[UseModalFrequencyEventName]: [IUseModalFrequencyConfig];
|
|
103
|
-
[InvokeUnloginModalEventName]: [
|
|
104
|
-
'JOLI_COIN' | 'ADS-JOLI_COIN' | 'JOLI_GEM' | 'ADS-JOLI_GEM',
|
|
105
|
-
IUseUnloginModalEvent
|
|
106
|
-
];
|
|
96
|
+
[InvokeUnloginModalEventName]: ['JOLI_COIN' | 'ADS-JOLI_COIN', IUseUnloginModalEvent];
|
|
107
97
|
[UseUnloginModalResultEventName]: [IUseUnloginModalResultEvent];
|
|
108
98
|
}
|
|
109
99
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type RewardType = 'ADS' | 'JOLI_COIN' | 'JOLI_COIN_ONLY'
|
|
1
|
+
export type RewardType = 'ADS' | 'JOLI_COIN' | 'JOLI_COIN_ONLY';
|
|
2
2
|
|
|
3
3
|
import { context } from '../context';
|
|
4
4
|
import type { AdsRewardsHandler } from './registers/use-ads';
|
|
@@ -8,8 +8,6 @@ export interface RewardHandlerMap {
|
|
|
8
8
|
ADS: AdsRewardsHandler;
|
|
9
9
|
JOLI_COIN: (params?: unknown) => Promise<boolean>; // coins + ads
|
|
10
10
|
JOLI_COIN_ONLY: (params?: unknown) => Promise<boolean>; // coins only
|
|
11
|
-
JOLI_GEM: (params?: unknown) => Promise<boolean>; // gem + ads
|
|
12
|
-
JOLI_GEM_ONLY: (params?: unknown) => Promise<boolean>; // gem only
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
export type RewardHandler<T extends RewardType> = RewardHandlerMap[T];
|
|
@@ -3,25 +3,14 @@ export interface IJoliCoin {
|
|
|
3
3
|
enableAutoDeduct: boolean;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
export
|
|
7
|
-
balance: number;
|
|
8
|
-
enableAutoDeduct: boolean;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export type IUnlockOptionType = 'JOLI_COIN' | 'ADS' | 'JOLI_GEM';
|
|
6
|
+
export type IUnlockOptionType = 'JOLI_COIN' | 'ADS';
|
|
12
7
|
|
|
13
8
|
interface IJoliCoinChoice {
|
|
14
9
|
joliCoinQuantity: number;
|
|
15
10
|
}
|
|
16
|
-
|
|
17
|
-
interface IGemChoice {
|
|
18
|
-
joliGemQuantity: number;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
11
|
export interface IUnlockOption {
|
|
22
12
|
type: IUnlockOptionType;
|
|
23
13
|
joliCoinChoices: IJoliCoinChoice[];
|
|
24
|
-
joliGemChoices: IGemChoice | null;
|
|
25
14
|
}
|
|
26
15
|
|
|
27
16
|
export interface IJolicoinRewardOption {
|
|
@@ -32,6 +21,5 @@ export interface IJolicoinRewardOption {
|
|
|
32
21
|
};
|
|
33
22
|
extra: {
|
|
34
23
|
joliCoin: IJoliCoin;
|
|
35
|
-
joliGem?: IGem;
|
|
36
24
|
};
|
|
37
25
|
}
|
package/src/h5/api/ads.ts
CHANGED
|
@@ -127,6 +127,11 @@ const adsContext: IAdsContext<'GAME'> = {
|
|
|
127
127
|
}
|
|
128
128
|
};
|
|
129
129
|
|
|
130
|
+
const handleUnlockSuccess = (params: { quantity: number; balance: number }) => {
|
|
131
|
+
notifyCustomEvent('JOLIBOX_CUSTOM_REWARDS_EVENT', {
|
|
132
|
+
JOLI_COIN: params
|
|
133
|
+
});
|
|
134
|
+
};
|
|
130
135
|
|
|
131
136
|
const adsManager = new H5AdsManager(adsContext);
|
|
132
137
|
const adsHandler = adsManager.getAdsHandler(context.sdkEnvironment);
|
|
@@ -135,11 +140,14 @@ rewardsHelper.registerRewardHandler('ADS', createAdsRewardHandler(adsHandler.get
|
|
|
135
140
|
rewardsHelper.registerRewardHandler(
|
|
136
141
|
'JOLI_COIN',
|
|
137
142
|
createJolicoinRewardHandler(httpClient, {
|
|
138
|
-
onUnlockSuccess: (
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
+
onUnlockSuccess: handleUnlockSuccess.bind(this)
|
|
144
|
+
}) as unknown as (params?: unknown) => Promise<boolean>
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
rewardsHelper.registerRewardHandler(
|
|
148
|
+
'JOLI_COIN_ONLY',
|
|
149
|
+
createJolicoinOnlyRewardHandler(httpClient, {
|
|
150
|
+
onUnlockSuccess: handleUnlockSuccess.bind(this)
|
|
143
151
|
}) as unknown as (params?: unknown) => Promise<boolean>
|
|
144
152
|
);
|
|
145
153
|
|
package/src/h5/api/storage.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createAPI, t, registerCanIUse } from './base';
|
|
2
|
-
import { createCommands } from '@jolibox/common';
|
|
2
|
+
import { createCommands, getApiHost } from '@jolibox/common';
|
|
3
3
|
import { httpClientManager } from '@/h5/http';
|
|
4
4
|
import { context } from '@/common/context';
|
|
5
5
|
import { StorageResponse } from '@jolibox/types';
|
|
@@ -10,7 +10,7 @@ const commands = createCommands();
|
|
|
10
10
|
export class JoliboxCloudStorage {
|
|
11
11
|
private gameId: string;
|
|
12
12
|
private httpClient = httpClientManager.create({
|
|
13
|
-
baseUrl: context.testMode
|
|
13
|
+
baseUrl: getApiHost(context.testMode)
|
|
14
14
|
});
|
|
15
15
|
private gameStore: LocalForage;
|
|
16
16
|
constructor() {
|
package/src/h5/http/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IHttpClient } from '@/common/http';
|
|
2
2
|
import { xUserAgent } from '../../common/http/xua';
|
|
3
3
|
import { context } from '@/common/context';
|
|
4
|
-
import { platform } from '@jolibox/common';
|
|
4
|
+
import { getApiHost, platform } from '@jolibox/common';
|
|
5
5
|
|
|
6
6
|
declare global {
|
|
7
7
|
interface Window {
|
|
@@ -68,7 +68,7 @@ export class JoliboxHttpClient implements IHttpClient {
|
|
|
68
68
|
};
|
|
69
69
|
|
|
70
70
|
constructor(config?: IHttpClientInitParams) {
|
|
71
|
-
const defaultUrl = context.testMode
|
|
71
|
+
const defaultUrl = getApiHost(context.testMode);
|
|
72
72
|
this.baseUrl = config?.baseUrl ?? defaultUrl;
|
|
73
73
|
}
|
|
74
74
|
|
|
@@ -1,26 +1,11 @@
|
|
|
1
1
|
import { context } from '@/common/context';
|
|
2
2
|
import { EventTracker } from '@/common/report';
|
|
3
3
|
import { httpClientManager } from '@/h5/http';
|
|
4
|
+
import { getCollectHost } from '@jolibox/common';
|
|
4
5
|
|
|
5
6
|
export class H5EventTracker extends EventTracker {
|
|
6
|
-
private hostToApiMap: Record<string | 'default', { test: string; prod: string }> = {
|
|
7
|
-
default: {
|
|
8
|
-
test: 'https://stg-collect.jolibox.com',
|
|
9
|
-
prod: 'https://collect.jolibox.com'
|
|
10
|
-
},
|
|
11
|
-
'oss.jolibox.com': {
|
|
12
|
-
test: 'https://stg-collect.jolibox.com',
|
|
13
|
-
prod: 'https://collect.jolibox.com'
|
|
14
|
-
},
|
|
15
|
-
'oss.pico-game.com': {
|
|
16
|
-
test: 'https://stg-collect.pico-game.com',
|
|
17
|
-
prod: 'https://collect.pico-game.com'
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
|
|
21
7
|
private get apiBaseURL() {
|
|
22
|
-
|
|
23
|
-
return context.testMode ?? false ? api.test : api.prod;
|
|
8
|
+
return getCollectHost(context.testMode ?? false);
|
|
24
9
|
}
|
|
25
10
|
|
|
26
11
|
private httpClient = httpClientManager.create({
|