@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,58 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,53 +0,0 @@
|
|
|
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,48 +0,0 @@
|
|
|
1
|
-
import { IHttpClient } from '@/common/http';
|
|
2
|
-
import { IJoliCoin, IGem } from '@/common/rewards/type';
|
|
3
|
-
import { IUnlockOptionsEvent } from '@/common/rewards/reward-emitter';
|
|
4
|
-
import { fetchBalance as fetchJoliCoinBalance } from '../jolicoin/fetch-balance';
|
|
5
|
-
import { fetchGemBalance } from '../joligem/fetch-gem-balance';
|
|
6
|
-
|
|
7
|
-
export type CurrencyType = 'JOLI_COIN' | 'JOLI_GEM';
|
|
8
|
-
|
|
9
|
-
export interface CurrencyHandler {
|
|
10
|
-
fetchBalance: (httpClient: IHttpClient) => Promise<{ balance: number } | undefined>;
|
|
11
|
-
getQuantity: (unlockOptions: IUnlockOptionsEvent | null) => number;
|
|
12
|
-
getCurrentUser: (unlockOptions: IUnlockOptionsEvent | null) => IJoliCoin | IGem;
|
|
13
|
-
createUpdatedUser: (balance: number, enableAutoDeduct: boolean) => IJoliCoin | IGem;
|
|
14
|
-
getUpdateKey: () => keyof Pick<IUnlockOptionsEvent, 'userJoliCoin' | 'userGem'>;
|
|
15
|
-
isEnough: (unlockOptions: IUnlockOptionsEvent | null, user: IJoliCoin | IGem) => boolean;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const CURRENCY_HANDLERS: Record<CurrencyType, CurrencyHandler> = {
|
|
19
|
-
JOLI_COIN: {
|
|
20
|
-
fetchBalance: fetchJoliCoinBalance,
|
|
21
|
-
getQuantity: (unlockOptions) =>
|
|
22
|
-
unlockOptions?.options?.find((option) => option.type === 'JOLI_COIN')?.joliCoinChoices[0]
|
|
23
|
-
.joliCoinQuantity ?? 0,
|
|
24
|
-
getCurrentUser: (unlockOptions) => unlockOptions?.userJoliCoin ?? { balance: 0, enableAutoDeduct: false },
|
|
25
|
-
createUpdatedUser: (balance, enableAutoDeduct) => ({ balance, enableAutoDeduct }),
|
|
26
|
-
getUpdateKey: () => 'userJoliCoin',
|
|
27
|
-
isEnough: (unlockOptions, user) =>
|
|
28
|
-
unlockOptions?.options?.some(
|
|
29
|
-
(option) =>
|
|
30
|
-
option.type === 'JOLI_COIN' &&
|
|
31
|
-
option.joliCoinChoices.some((choice) => choice.joliCoinQuantity <= (user?.balance ?? 0))
|
|
32
|
-
) ?? false
|
|
33
|
-
},
|
|
34
|
-
JOLI_GEM: {
|
|
35
|
-
fetchBalance: fetchGemBalance,
|
|
36
|
-
getQuantity: (unlockOptions) =>
|
|
37
|
-
unlockOptions?.options?.find((option) => option.type === 'JOLI_GEM')?.joliGemChoices?.joliGemQuantity ??
|
|
38
|
-
0,
|
|
39
|
-
getCurrentUser: (unlockOptions) => unlockOptions?.userGem ?? { balance: 0, enableAutoDeduct: false },
|
|
40
|
-
createUpdatedUser: (balance, enableAutoDeduct) => ({ balance, enableAutoDeduct }),
|
|
41
|
-
getUpdateKey: () => 'userGem',
|
|
42
|
-
isEnough: (unlockOptions, user) =>
|
|
43
|
-
unlockOptions?.options?.some(
|
|
44
|
-
(option) =>
|
|
45
|
-
option.type === 'JOLI_GEM' && (option.joliGemChoices?.joliGemQuantity ?? 0) <= (user?.balance ?? 0)
|
|
46
|
-
) ?? false
|
|
47
|
-
}
|
|
48
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export type CurrencyType = 'JOLI_COIN' | 'GEM';
|
|
2
|
-
|
|
3
|
-
export interface CurrencyConfig {
|
|
4
|
-
balanceEndpoint: string;
|
|
5
|
-
unlockEndpoint: string;
|
|
6
|
-
balanceDetailEndpoint: string;
|
|
7
|
-
unlockType: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const CURRENCY_CONFIG: Record<CurrencyType, CurrencyConfig> = {
|
|
11
|
-
JOLI_COIN: {
|
|
12
|
-
balanceEndpoint: '/api/joli-coin/balance',
|
|
13
|
-
balanceDetailEndpoint: '/api/joli-coin/balance-detail',
|
|
14
|
-
unlockEndpoint: '/api/joli-coin/unlock',
|
|
15
|
-
unlockType: 'JOLI_COIN'
|
|
16
|
-
},
|
|
17
|
-
GEM: {
|
|
18
|
-
balanceEndpoint: '/api/joli-gem/balance',
|
|
19
|
-
balanceDetailEndpoint: '/api/joli-gem/balance-detail',
|
|
20
|
-
unlockEndpoint: '/api/joli-gem/unlock',
|
|
21
|
-
unlockType: 'GEM'
|
|
22
|
-
}
|
|
23
|
-
};
|
|
@@ -1,149 +0,0 @@
|
|
|
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
|
-
import { CURRENCY_CONFIG, CurrencyType } from '../currency-config';
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
createInitiateAndAwaitPayment,
|
|
11
|
-
registerUseJolicoinCommand,
|
|
12
|
-
registerUsePaymentCommand,
|
|
13
|
-
registerUseUnloginCommand,
|
|
14
|
-
createShowUnlockWithCurrencyModal,
|
|
15
|
-
createShowUnloginModal
|
|
16
|
-
} from '../commands';
|
|
17
|
-
import { rewardsCommands } from '../rewards-command';
|
|
18
|
-
import { RewardsCommandType } from '@jolibox/types';
|
|
19
|
-
|
|
20
|
-
interface ICurrencyUnlockRes {
|
|
21
|
-
code: 'SUCCESS' | 'BALANCE_NOT_ENOUGH' | 'EPISODE_LOCK_JUMP' | 'EPISODE_UNLOCK_ALREADY';
|
|
22
|
-
message: string;
|
|
23
|
-
data: {
|
|
24
|
-
transactionId: string;
|
|
25
|
-
quantity: number;
|
|
26
|
-
balance: number;
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const createCommonCurrencyRewardHandler = (
|
|
31
|
-
type: 'JOLI_COIN' | 'ADS-JOLI_COIN',
|
|
32
|
-
httpClient: IHttpClient,
|
|
33
|
-
currencyType: CurrencyType,
|
|
34
|
-
{
|
|
35
|
-
handlers: {
|
|
36
|
-
handleUnlockSuccess,
|
|
37
|
-
handleUnlockFailed,
|
|
38
|
-
unlockOptionsHandler,
|
|
39
|
-
initiateAndAwaitPayment,
|
|
40
|
-
showUnlockWithCurrencyModal,
|
|
41
|
-
showUnloginModal
|
|
42
|
-
}
|
|
43
|
-
}: {
|
|
44
|
-
handlers: {
|
|
45
|
-
handleUnlockSuccess?: (data: { quantity: number; balance: number }) => void;
|
|
46
|
-
handleUnlockFailed?: (params: IAdBreakParams) => void;
|
|
47
|
-
unlockOptionsHandler: EventPromiseHandler<IUnlockOptionsEvent, typeof UnlockOptionsEventName>;
|
|
48
|
-
initiateAndAwaitPayment: ReturnType<typeof createInitiateAndAwaitPayment>;
|
|
49
|
-
showUnlockWithCurrencyModal: ReturnType<typeof createShowUnlockWithCurrencyModal>;
|
|
50
|
-
showUnloginModal: ReturnType<typeof createShowUnloginModal>;
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
) => {
|
|
54
|
-
registerUseUnloginCommand(type, 'JOLI_COIN', {
|
|
55
|
-
httpClient: httpClient,
|
|
56
|
-
showUnloginModal: showUnloginModal
|
|
57
|
-
});
|
|
58
|
-
registerUsePaymentCommand(type, 'JOLI_COIN', {
|
|
59
|
-
httpClient: httpClient,
|
|
60
|
-
initiateAndAwaitPayment: initiateAndAwaitPayment
|
|
61
|
-
});
|
|
62
|
-
registerUseJolicoinCommand(type, 'JOLI_COIN', {
|
|
63
|
-
showUnlockWithCurrencyModal
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
const commands = [`Rewards.${type}.usePayment`, `Rewards.${type}.useJolicoin`];
|
|
67
|
-
return async (params: IAdBreakParams) => {
|
|
68
|
-
try {
|
|
69
|
-
let result = true;
|
|
70
|
-
for (const command of commands) {
|
|
71
|
-
const commandResult = await rewardsCommands.executeCommand(command as RewardsCommandType);
|
|
72
|
-
result = result && commandResult.result !== 'FAILED';
|
|
73
|
-
if (commandResult.result !== 'CONTINUE') {
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (!result) {
|
|
79
|
-
handleUnlockFailed?.(params);
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const config = CURRENCY_CONFIG[currencyType];
|
|
84
|
-
const unlockWithCurrency = await httpClient.post<ICurrencyUnlockRes>(config.unlockEndpoint, {
|
|
85
|
-
data: {
|
|
86
|
-
// TODO: support drama
|
|
87
|
-
type: 'GAME_REWARD',
|
|
88
|
-
reqId: `${uuidv4()}-${context.mpType}-${Date.now()}`,
|
|
89
|
-
gameInfo: {
|
|
90
|
-
gameId: context.mpId
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
console.log('-----unlockWithCurrency request result-----', unlockWithCurrency);
|
|
96
|
-
if (unlockWithCurrency.code == 'SUCCESS') {
|
|
97
|
-
try {
|
|
98
|
-
params.adBreakDone?.({
|
|
99
|
-
breakType: params.type,
|
|
100
|
-
breakName: 'name' in params ? params.name ?? '' : '',
|
|
101
|
-
breakFormat: 'reward',
|
|
102
|
-
breakStatus: 'viewed'
|
|
103
|
-
});
|
|
104
|
-
if ('adViewed' in params) {
|
|
105
|
-
params.adViewed?.();
|
|
106
|
-
}
|
|
107
|
-
} catch (e) {
|
|
108
|
-
console.error('-----unlockWithJolicoin adBreakDone error-----', e);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
handleUnlockSuccess?.({
|
|
112
|
-
quantity: unlockWithCurrency.data.quantity,
|
|
113
|
-
balance: unlockWithCurrency.data.balance
|
|
114
|
-
});
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
handleUnlockFailed?.(params);
|
|
118
|
-
return false;
|
|
119
|
-
} catch (e) {
|
|
120
|
-
console.info(`JolicoinRewardHandler error:`, e);
|
|
121
|
-
if (e instanceof Error && e.message == 'CANCEL') {
|
|
122
|
-
// Cancel should terminate the reward handler, invoke unlock failed
|
|
123
|
-
throw e;
|
|
124
|
-
}
|
|
125
|
-
handleUnlockFailed?.(params);
|
|
126
|
-
return false;
|
|
127
|
-
} finally {
|
|
128
|
-
unlockOptionsHandler.clearCache();
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
// 向后兼容的 jolicoin 处理器
|
|
134
|
-
export const createCommonJolicoinRewardHandler = (
|
|
135
|
-
type: 'JOLI_COIN' | 'ADS-JOLI_COIN',
|
|
136
|
-
httpClient: IHttpClient,
|
|
137
|
-
config: {
|
|
138
|
-
handlers: {
|
|
139
|
-
handleUnlockSuccess?: (data: { quantity: number; balance: number }) => void;
|
|
140
|
-
handleUnlockFailed?: (params: IAdBreakParams) => void;
|
|
141
|
-
unlockOptionsHandler: EventPromiseHandler<IUnlockOptionsEvent, typeof UnlockOptionsEventName>;
|
|
142
|
-
initiateAndAwaitPayment: ReturnType<typeof createInitiateAndAwaitPayment>;
|
|
143
|
-
showUnlockWithCurrencyModal: ReturnType<typeof createShowUnlockWithCurrencyModal>;
|
|
144
|
-
showUnloginModal: ReturnType<typeof createShowUnloginModal>;
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
) => {
|
|
148
|
-
return createCommonCurrencyRewardHandler(type, httpClient, 'JOLI_COIN', config);
|
|
149
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { IHttpClient } from '@/common/http';
|
|
2
|
-
import { StandardResponse } from '@jolibox/types';
|
|
3
|
-
|
|
4
|
-
export const fetchGemBalance = async (httpClient: IHttpClient) => {
|
|
5
|
-
const res = await httpClient.get<
|
|
6
|
-
StandardResponse<{
|
|
7
|
-
balance: number;
|
|
8
|
-
}>
|
|
9
|
-
>('/api/joli-gem/balance', {
|
|
10
|
-
query: {
|
|
11
|
-
type: 'GEM'
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
return res.data;
|
|
15
|
-
};
|
|
@@ -1,131 +0,0 @@
|
|
|
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
|
-
import { CURRENCY_CONFIG } from '../currency-config';
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
createInitiateAndAwaitPayment,
|
|
11
|
-
registerUsePaymentCommand,
|
|
12
|
-
registerUseUnloginCommand,
|
|
13
|
-
createShowUnloginModal
|
|
14
|
-
} from '../commands';
|
|
15
|
-
import { registerUseJolicoinCommand, createShowUnlockWithCurrencyModal } from '../commands/use-jolicoin';
|
|
16
|
-
import { rewardsCommands } from '../rewards-command';
|
|
17
|
-
import { RewardsCommandType } from '@jolibox/types';
|
|
18
|
-
|
|
19
|
-
interface IGemUnlockRes {
|
|
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 createCommonGemRewardHandler = (
|
|
30
|
-
type: 'JOLI_GEM' | 'ADS-JOLI_GEM',
|
|
31
|
-
httpClient: IHttpClient,
|
|
32
|
-
{
|
|
33
|
-
handlers: {
|
|
34
|
-
handleUnlockSuccess,
|
|
35
|
-
handleUnlockFailed,
|
|
36
|
-
unlockOptionsHandler,
|
|
37
|
-
initiateAndAwaitPayment,
|
|
38
|
-
showUnlockWithCurrencyModal,
|
|
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
|
-
showUnlockWithCurrencyModal: ReturnType<typeof createShowUnlockWithCurrencyModal>;
|
|
48
|
-
showUnloginModal: ReturnType<typeof createShowUnloginModal>;
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
) => {
|
|
52
|
-
// register commands
|
|
53
|
-
registerUseUnloginCommand(type, 'JOLI_GEM', {
|
|
54
|
-
httpClient: httpClient,
|
|
55
|
-
showUnloginModal: showUnloginModal
|
|
56
|
-
});
|
|
57
|
-
registerUsePaymentCommand(type, 'JOLI_GEM', {
|
|
58
|
-
httpClient: httpClient,
|
|
59
|
-
initiateAndAwaitPayment: initiateAndAwaitPayment
|
|
60
|
-
});
|
|
61
|
-
registerUseJolicoinCommand(type, 'JOLI_GEM', {
|
|
62
|
-
showUnlockWithCurrencyModal: showUnlockWithCurrencyModal
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
const commands = [`Rewards.${type}.usePayment`, `Rewards.${type}.useJolicoin`];
|
|
66
|
-
|
|
67
|
-
return async (params: IAdBreakParams) => {
|
|
68
|
-
try {
|
|
69
|
-
let result = true;
|
|
70
|
-
for (const command of commands) {
|
|
71
|
-
const commandResult = await rewardsCommands.executeCommand(command as RewardsCommandType);
|
|
72
|
-
result = result && commandResult.result !== 'FAILED';
|
|
73
|
-
if (commandResult.result !== 'CONTINUE') {
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (!result) {
|
|
79
|
-
handleUnlockFailed?.(params);
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const config = CURRENCY_CONFIG['GEM'];
|
|
84
|
-
const unlockWithGem = await httpClient.post<IGemUnlockRes>(config.unlockEndpoint, {
|
|
85
|
-
data: {
|
|
86
|
-
// TODO: support drama
|
|
87
|
-
type: 'GAME_REWARD',
|
|
88
|
-
reqId: `${uuidv4()}-${context.mpType}-${Date.now()}`,
|
|
89
|
-
gameInfo: {
|
|
90
|
-
gameId: context.mpId
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
console.log('-----unlockWithGem request result-----', unlockWithGem);
|
|
96
|
-
if (unlockWithGem.code == 'SUCCESS') {
|
|
97
|
-
try {
|
|
98
|
-
params.adBreakDone?.({
|
|
99
|
-
breakType: params.type,
|
|
100
|
-
breakName: 'name' in params ? params.name ?? '' : '',
|
|
101
|
-
breakFormat: 'reward',
|
|
102
|
-
breakStatus: 'viewed'
|
|
103
|
-
});
|
|
104
|
-
if ('adViewed' in params) {
|
|
105
|
-
params.adViewed?.();
|
|
106
|
-
}
|
|
107
|
-
} catch (e) {
|
|
108
|
-
console.error('-----unlockWithGem adBreakDone error-----', e);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
handleUnlockSuccess?.({
|
|
112
|
-
quantity: unlockWithGem.data.quantity,
|
|
113
|
-
balance: unlockWithGem.data.balance
|
|
114
|
-
});
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
handleUnlockFailed?.(params);
|
|
118
|
-
return false;
|
|
119
|
-
} catch (e) {
|
|
120
|
-
console.info(`GemRewardHandler error:`, e);
|
|
121
|
-
if (e instanceof Error && e.message == 'CANCEL') {
|
|
122
|
-
// Cancel should terminate the reward handler, invoke unlock failed
|
|
123
|
-
throw e;
|
|
124
|
-
}
|
|
125
|
-
handleUnlockFailed?.(params);
|
|
126
|
-
return false;
|
|
127
|
-
} finally {
|
|
128
|
-
unlockOptionsHandler.clearCache();
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
};
|
|
File without changes
|
/package/src/common/rewards/registers/utils/coins/{jolicoin/fetch-balance.ts → fetch-balance.ts}
RENAMED
|
File without changes
|