@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
package/src/h5/rewards/index.ts
CHANGED
|
@@ -33,24 +33,17 @@ onCustomEvent('ON_JOLIBOX_JOLI_COIN_USE_RESULT', (data) => {
|
|
|
33
33
|
useModalResult: UseCoinEventMap[data.result]
|
|
34
34
|
});
|
|
35
35
|
});
|
|
36
|
-
rewardsEmitter.on(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
enableAutoDeduct: params.enableAutoDeduct
|
|
48
|
-
},
|
|
49
|
-
type: type as 'JOLI_COIN' | 'ADS-JOLI_COIN',
|
|
50
|
-
sequenceId: params.sequenceId ?? v4()
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
);
|
|
36
|
+
rewardsEmitter.on(UseModalEventName, (type: 'JOLI_COIN' | 'ADS-JOLI_COIN', params: IUseModalEvent) => {
|
|
37
|
+
notifyCustomEvent('JOLIBOX_JOLI_COIN_USE_EVENT', {
|
|
38
|
+
JOLI_COIN: {
|
|
39
|
+
quantity: params.joliCoinQuantity,
|
|
40
|
+
balance: params.userJoliCoin.balance,
|
|
41
|
+
enableAutoDeduct: params.enableAutoDeduct
|
|
42
|
+
},
|
|
43
|
+
type,
|
|
44
|
+
sequenceId: params.sequenceId ?? v4()
|
|
45
|
+
});
|
|
46
|
+
});
|
|
54
47
|
|
|
55
48
|
/**
|
|
56
49
|
* payment jolicoin modal
|
|
@@ -58,26 +51,21 @@ rewardsEmitter.on(
|
|
|
58
51
|
onCustomEvent('ON_JOLIBOX_TOPUP_JOLI_COIN_RESULT', (data) => {
|
|
59
52
|
rewardsEmitter.emit(PaymentResultEventName, {
|
|
60
53
|
paymentResult: data.result == 'ADS' ? 'FAILED' : data.result,
|
|
61
|
-
userJoliCoin: data.joliCoin
|
|
62
|
-
currency: 'JOLI_COIN' // h5 only support jolicoin, should get currency from data later
|
|
54
|
+
userJoliCoin: data.joliCoin
|
|
63
55
|
});
|
|
64
56
|
});
|
|
65
57
|
|
|
66
58
|
rewardsEmitter.on(
|
|
67
59
|
InvokePaymentEventName,
|
|
68
|
-
async (type: 'JOLI_COIN' | 'ADS-JOLI_COIN'
|
|
60
|
+
async (type: 'JOLI_COIN' | 'ADS-JOLI_COIN', params: IInvokePaymentEvent) => {
|
|
69
61
|
// 充值面板
|
|
70
|
-
if (type == 'ADS-JOLI_GEM' || type == 'JOLI_GEM') {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
62
|
notifyCustomEvent('JOLIBOX_TOPUP_EVENT', {
|
|
75
63
|
JOLI_COIN: {
|
|
76
|
-
quantity: params.
|
|
77
|
-
balance: params.
|
|
64
|
+
quantity: params.joliCoinQuantity,
|
|
65
|
+
balance: params.userJoliCoin.balance,
|
|
78
66
|
enableAutoDeduct: params.enableAutoDeduct
|
|
79
67
|
},
|
|
80
|
-
type
|
|
68
|
+
type,
|
|
81
69
|
sequenceId: params.sequenceId ?? v4()
|
|
82
70
|
});
|
|
83
71
|
}
|
|
@@ -88,8 +76,10 @@ onCustomEvent('ON_JOLIBOX_JOLI_UNLOGIN_MODAL_RESULT_EVENT', (data) => {
|
|
|
88
76
|
rewardsEmitter.emit(UseUnloginModalResultEventName, {
|
|
89
77
|
result: data.result == 'ADS' ? 'FAILED' : data.result,
|
|
90
78
|
rewards: {
|
|
91
|
-
|
|
92
|
-
|
|
79
|
+
jolicoin: {
|
|
80
|
+
claimedRewardValue: data.extra?.firstLogin?.reward?.rewardValue ?? 0,
|
|
81
|
+
isFirstLogin: data.isFirstLogin ?? false
|
|
82
|
+
}
|
|
93
83
|
}
|
|
94
84
|
});
|
|
95
85
|
|
|
@@ -100,9 +90,6 @@ onCustomEvent('ON_JOLIBOX_JOLI_UNLOGIN_MODAL_RESULT_EVENT', (data) => {
|
|
|
100
90
|
|
|
101
91
|
rewardsEmitter.on(InvokeUnloginModalEventName, async (type) => {
|
|
102
92
|
// 未登录面板
|
|
103
|
-
if (type == 'ADS-JOLI_GEM' || type == 'JOLI_GEM') {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
93
|
notifyCustomEvent('JOLIBOX_JOLI_UNLOGIN_MODAL_EVENT', {
|
|
107
94
|
sequenceId: v4(),
|
|
108
95
|
type: type
|
package/src/native/api/ads.ts
CHANGED
|
@@ -23,9 +23,7 @@ import {
|
|
|
23
23
|
rewardsHelper,
|
|
24
24
|
createAdsRewardHandler,
|
|
25
25
|
createJolicoinRewardHandler,
|
|
26
|
-
createJolicoinOnlyRewardHandler
|
|
27
|
-
createGemRewardHandler,
|
|
28
|
-
createGemOnlyRewardHandler
|
|
26
|
+
createJolicoinOnlyRewardHandler
|
|
29
27
|
} from '@/common/rewards';
|
|
30
28
|
import { adEventEmitter } from '@/common/ads';
|
|
31
29
|
|
|
@@ -117,25 +115,6 @@ rewardsHelper.registerRewardHandler(
|
|
|
117
115
|
}) as unknown as (params?: unknown) => Promise<boolean>
|
|
118
116
|
);
|
|
119
117
|
|
|
120
|
-
// gem
|
|
121
|
-
rewardsHelper.registerRewardHandler(
|
|
122
|
-
'JOLI_GEM',
|
|
123
|
-
createGemRewardHandler(httpClient, {
|
|
124
|
-
onUnlockSuccess: (params) => {
|
|
125
|
-
showUnlockSuccessToast(params);
|
|
126
|
-
}
|
|
127
|
-
}) as unknown as (params?: unknown) => Promise<boolean>
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
rewardsHelper.registerRewardHandler(
|
|
131
|
-
'JOLI_GEM_ONLY',
|
|
132
|
-
createGemOnlyRewardHandler(httpClient, {
|
|
133
|
-
onUnlockSuccess: (params) => {
|
|
134
|
-
showUnlockSuccessToast(params);
|
|
135
|
-
}
|
|
136
|
-
}) as unknown as (params?: unknown) => Promise<boolean>
|
|
137
|
-
);
|
|
138
|
-
|
|
139
118
|
const showUnlockSuccessToast = (params: { quantity: number; balance: number }) => {
|
|
140
119
|
const { quantity } = params;
|
|
141
120
|
const toastTemplate = `{slot-coin} ${quantity} {slot-i18n-jolicoin.coinUsed}`;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { canIUseNative, createAPI, registerCanIUse, t
|
|
1
|
+
import { canIUseNative, createAPI, registerCanIUse, t } from './base';
|
|
2
2
|
import { invokeNative } from '@jolibox/native-bridge';
|
|
3
3
|
import { hostEmitter, UserCustomError } from '@jolibox/common';
|
|
4
4
|
import { createCommands } from '@jolibox/common';
|
|
@@ -95,38 +95,3 @@ commands.registerCommand('API.callHostMethod', callHostMethodAsync);
|
|
|
95
95
|
registerCanIUse('callHostMethod', {
|
|
96
96
|
version: '1.1.49'
|
|
97
97
|
});
|
|
98
|
-
|
|
99
|
-
//user track
|
|
100
|
-
const userTrackAsync = createAPI('userTrackAsync', {
|
|
101
|
-
paramsSchema: t.tuple(
|
|
102
|
-
t.object({
|
|
103
|
-
event: t.string(),
|
|
104
|
-
eventType: t.number(),
|
|
105
|
-
params: t.object().optional().default({})
|
|
106
|
-
})
|
|
107
|
-
),
|
|
108
|
-
implement: async ({ event, eventType, params }) => {
|
|
109
|
-
const supportedMethods = await getSupportedMethods();
|
|
110
|
-
if (!supportedMethods.includes('userTrackAsync')) {
|
|
111
|
-
throw new UserCustomError('Method not supported', 10001);
|
|
112
|
-
}
|
|
113
|
-
const { errNo, errMsg } = await invokeNative('trackAsync', {
|
|
114
|
-
event,
|
|
115
|
-
eventType,
|
|
116
|
-
data: {
|
|
117
|
-
...params
|
|
118
|
-
},
|
|
119
|
-
webviewId: context.webviewId
|
|
120
|
-
});
|
|
121
|
-
if (errNo !== 0) {
|
|
122
|
-
throw new UserCustomError(errMsg, errNo);
|
|
123
|
-
}
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
commands.registerCommand('API.track', userTrackAsync);
|
|
129
|
-
|
|
130
|
-
registerCanIUse('track', {
|
|
131
|
-
version: '1.1.53'
|
|
132
|
-
});
|
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
isString,
|
|
3
|
+
logger,
|
|
4
|
+
Deferred,
|
|
5
|
+
isObject,
|
|
6
|
+
hostEmitter,
|
|
7
|
+
isUndefined,
|
|
8
|
+
uuidv4,
|
|
9
|
+
getApiHost
|
|
10
|
+
} from '@jolibox/common';
|
|
2
11
|
import { FetchResponse, FetchOptions } from './types';
|
|
3
12
|
import { invokeNative, onNative } from '@jolibox/native-bridge';
|
|
4
13
|
import { AnyFunction } from '@jolibox/types';
|
|
5
14
|
import { reportError } from '@/common/report/errors/report';
|
|
6
15
|
import { createAPIError } from '@/common/report/errors';
|
|
16
|
+
import { context } from '@/common/context';
|
|
7
17
|
|
|
8
18
|
type Fetch = <T>(
|
|
9
19
|
url: string,
|
|
@@ -69,7 +79,7 @@ export function createFetch(
|
|
|
69
79
|
}
|
|
70
80
|
) {
|
|
71
81
|
const promiseMap = new Map<string, { resolve: AnyFunction; reject: AnyFunction }>();
|
|
72
|
-
const baseUrl = options?.baseUrl ??
|
|
82
|
+
const baseUrl = options?.baseUrl ?? getApiHost(context.testMode);
|
|
73
83
|
const type = options?.type ?? 'public';
|
|
74
84
|
const defaultHeaders = options?.defaultHeaders ?? {};
|
|
75
85
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { xUserAgent } from '@/common/http/xua';
|
|
2
2
|
import { createFetch } from './create-fetch';
|
|
3
3
|
import { context } from '@/common/context';
|
|
4
|
+
import { getApiHost } from '@jolibox/common';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* inner fetch
|
|
@@ -15,6 +16,6 @@ if (context.joliSource) {
|
|
|
15
16
|
|
|
16
17
|
export const innerFetch = createFetch('createRequestTaskSync', 'operateRequestTaskSync', {
|
|
17
18
|
type: 'inner',
|
|
18
|
-
baseUrl: context.testMode
|
|
19
|
+
baseUrl: getApiHost(context.testMode),
|
|
19
20
|
defaultHeaders
|
|
20
21
|
});
|
|
@@ -5,5 +5,3 @@ import { createJolicoinIAPPaymentHandler } from './registers/jolicoin-iap';
|
|
|
5
5
|
export const paymentHelper = createPaymentHelper();
|
|
6
6
|
paymentHelper.registerPaymentHandler('JOLI_COIN', createJolicoinPaymentHandler());
|
|
7
7
|
paymentHelper.registerPaymentHandler('JOLI_COIN_IAP', createJolicoinIAPPaymentHandler());
|
|
8
|
-
// Temporarily reuse the same IAP handler for gem, can be extended later with gem-specific logic
|
|
9
|
-
paymentHelper.registerPaymentHandler('JOLI_GEM_IAP', createJolicoinIAPPaymentHandler());
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type PaymentType = 'JOLI_COIN' | 'JOLI_COIN_IAP'
|
|
1
|
+
export type PaymentType = 'JOLI_COIN' | 'JOLI_COIN_IAP'; // current only jolicoin
|
|
2
2
|
|
|
3
3
|
import { StandardResponse } from '@jolibox/types';
|
|
4
4
|
import { reportError } from '@/common/report/errors/report';
|
|
@@ -9,7 +9,6 @@ type PaymentResult = StandardResponse<void>;
|
|
|
9
9
|
export interface PaymentHandlerMap {
|
|
10
10
|
JOLI_COIN: (productId: string) => Promise<PaymentResult>; // jolicoin
|
|
11
11
|
JOLI_COIN_IAP: (params: { productId: string; appStoreProductId: string }) => Promise<PaymentResult>; // jolicoin iap
|
|
12
|
-
JOLI_GEM_IAP: (params: { productId: string; appStoreProductId: string }) => Promise<PaymentResult>; // gem iap
|
|
13
12
|
}
|
|
14
13
|
|
|
15
14
|
export type PaymentHandler<T extends PaymentType> = PaymentHandlerMap[T];
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { context } from '@/common/context';
|
|
6
6
|
import { TaskTracker, TaskPoint } from '@/common/report/task-track';
|
|
7
|
-
import { EventEmitter } from '@jolibox/common';
|
|
7
|
+
import { EventEmitter, getApiHost } from '@jolibox/common';
|
|
8
8
|
import { innerFetch as fetch } from '../network';
|
|
9
9
|
import { applyNative } from '@jolibox/native-bridge';
|
|
10
10
|
import type { Track } from '.';
|
|
@@ -36,9 +36,7 @@ export class NativeTaskTracker extends TaskTracker {
|
|
|
36
36
|
this.gameId = context.mpId;
|
|
37
37
|
this.sessionId = context.sessionId;
|
|
38
38
|
this.track = track;
|
|
39
|
-
this.taskUrl = context.testMode
|
|
40
|
-
? 'https://stg-api.jolibox.com/api/base/app-event'
|
|
41
|
-
: 'https://api.jolibox.com/api/base/app-event';
|
|
39
|
+
this.taskUrl = getApiHost(context.testMode) + '/api/base/app-event';
|
|
42
40
|
}
|
|
43
41
|
async reporter(point: TaskPoint): Promise<void> {
|
|
44
42
|
const { event, params, extraParams } = point;
|
|
@@ -53,11 +53,6 @@ export const checkUseModalFrequency = createFrequencyChecker('joli_coin_use_moda
|
|
|
53
53
|
export const checkPaymentFrequency = createFrequencyChecker('joli_coin_payment_frequency');
|
|
54
54
|
export const checkUnloginModalFrequency = createFrequencyChecker('joli_coin_unlogin_modal_frequency');
|
|
55
55
|
|
|
56
|
-
// gem frequency
|
|
57
|
-
export const checkUseModalFrequencyGem = createFrequencyChecker('joli_gem_use_modal_frequency');
|
|
58
|
-
export const checkPaymentFrequencyGem = createFrequencyChecker('joli_gem_payment_frequency');
|
|
59
|
-
export const checkUnloginModalFrequencyGem = createFrequencyChecker('joli_gem_unlogin_modal_frequency');
|
|
60
|
-
|
|
61
56
|
// common update frequency
|
|
62
57
|
function createFrequencyUpdater(storageKey: string) {
|
|
63
58
|
return async () => {
|
|
@@ -73,8 +68,3 @@ function createFrequencyUpdater(storageKey: string) {
|
|
|
73
68
|
export const updateUseModalFrequency = createFrequencyUpdater('joli_coin_use_modal_frequency');
|
|
74
69
|
export const updatePaymentFrequency = createFrequencyUpdater('joli_coin_payment_frequency');
|
|
75
70
|
export const updateUnloginModalFrequency = createFrequencyUpdater('joli_coin_unlogin_modal_frequency');
|
|
76
|
-
|
|
77
|
-
// gem frequency
|
|
78
|
-
export const updateUseModalFrequencyGem = createFrequencyUpdater('joli_gem_use_modal_frequency');
|
|
79
|
-
export const updatePaymentFrequencyGem = createFrequencyUpdater('joli_gem_payment_frequency');
|
|
80
|
-
export const updateUnloginModalFrequencyGem = createFrequencyUpdater('joli_gem_unlogin_modal_frequency');
|
|
@@ -14,12 +14,7 @@ import { context } from '@/common/context';
|
|
|
14
14
|
import { login } from '@/native/api/login';
|
|
15
15
|
import { EventType } from '@jolibox/common';
|
|
16
16
|
|
|
17
|
-
import {
|
|
18
|
-
checkPaymentFrequency,
|
|
19
|
-
updatePaymentFrequency,
|
|
20
|
-
checkPaymentFrequencyGem,
|
|
21
|
-
updatePaymentFrequencyGem
|
|
22
|
-
} from '../check-frequency';
|
|
17
|
+
import { checkPaymentFrequency, updatePaymentFrequency } from '../check-frequency';
|
|
23
18
|
import { paymentHelper } from '@/native/payment';
|
|
24
19
|
import { createLoading } from '@jolibox/ui';
|
|
25
20
|
import { canIUseNative } from '@/native/api/base';
|
|
@@ -28,57 +23,6 @@ import { isUndefinedOrNull } from '@jolibox/common';
|
|
|
28
23
|
import { track } from '@/native/report';
|
|
29
24
|
import { updateAutoDeductConfig } from './utils';
|
|
30
25
|
import { createEventPromiseHandler } from '@/common/rewards/registers/utils/event-listener';
|
|
31
|
-
import { TrackEvent } from '@jolibox/types';
|
|
32
|
-
|
|
33
|
-
// 货币配置映射
|
|
34
|
-
interface CurrencyPaymentConfig {
|
|
35
|
-
frequencyConfigKey: keyof IUseModalFrequencyConfig['joliCoinUseAndCharge'];
|
|
36
|
-
trackEvents: {
|
|
37
|
-
modalShow: TrackEvent;
|
|
38
|
-
orderClick: TrackEvent;
|
|
39
|
-
payEnsure: TrackEvent;
|
|
40
|
-
payResult: TrackEvent;
|
|
41
|
-
adUnlock: TrackEvent;
|
|
42
|
-
};
|
|
43
|
-
frequencyChecker: (config: {
|
|
44
|
-
dailyMaxPopUps?: number;
|
|
45
|
-
minInterval?: number;
|
|
46
|
-
}) => Promise<{ canShow: boolean; isFirst: boolean }>;
|
|
47
|
-
frequencyUpdater: () => Promise<void>;
|
|
48
|
-
apiEndpoint: string;
|
|
49
|
-
paymentType: 'JOLI_COIN_IAP' | 'JOLI_GEM_IAP';
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const CURRENCY_PAYMENT_CONFIG: Record<'JOLI_COIN' | 'JOLI_GEM', CurrencyPaymentConfig> = {
|
|
53
|
-
JOLI_COIN: {
|
|
54
|
-
frequencyConfigKey: 'charge',
|
|
55
|
-
trackEvents: {
|
|
56
|
-
modalShow: 'coinorder_show',
|
|
57
|
-
orderClick: 'coinorder_click',
|
|
58
|
-
payEnsure: 'order_pay_ensure',
|
|
59
|
-
payResult: 'order_pay_result',
|
|
60
|
-
adUnlock: 'ad_unlock_click'
|
|
61
|
-
},
|
|
62
|
-
frequencyChecker: checkPaymentFrequency,
|
|
63
|
-
frequencyUpdater: updatePaymentFrequency,
|
|
64
|
-
apiEndpoint: '/api/joli-coin/balance-detail',
|
|
65
|
-
paymentType: 'JOLI_COIN_IAP'
|
|
66
|
-
},
|
|
67
|
-
JOLI_GEM: {
|
|
68
|
-
frequencyConfigKey: 'charge', // 暂时复用,可后续扩展
|
|
69
|
-
trackEvents: {
|
|
70
|
-
modalShow: 'gem_order_show',
|
|
71
|
-
orderClick: 'gem_order_click',
|
|
72
|
-
payEnsure: 'gem_pay_ensure',
|
|
73
|
-
payResult: 'gem_pay_result',
|
|
74
|
-
adUnlock: 'gem_ad_unlock_click'
|
|
75
|
-
},
|
|
76
|
-
frequencyChecker: checkPaymentFrequencyGem,
|
|
77
|
-
frequencyUpdater: updatePaymentFrequencyGem,
|
|
78
|
-
apiEndpoint: '/api/joli-gem/balance-detail',
|
|
79
|
-
paymentType: 'JOLI_GEM_IAP'
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
26
|
|
|
83
27
|
const loading = createLoading();
|
|
84
28
|
|
|
@@ -91,35 +35,32 @@ const modalUseFrequencyConfig = createEventPromiseHandler<
|
|
|
91
35
|
*/
|
|
92
36
|
rewardsEmitter.on(
|
|
93
37
|
InvokePaymentEventName,
|
|
94
|
-
async (type: 'JOLI_COIN' | 'ADS-JOLI_COIN'
|
|
38
|
+
async (type: 'JOLI_COIN' | 'ADS-JOLI_COIN', params: IInvokePaymentEvent) => {
|
|
95
39
|
try {
|
|
96
|
-
// 获取货币类型配置
|
|
97
|
-
const currencyType = params.currency;
|
|
98
|
-
const paymentConfig = CURRENCY_PAYMENT_CONFIG[currencyType];
|
|
99
40
|
// TODO: temp remove it for dev
|
|
100
41
|
if (!canIUseNative('requestPaymentSync:paymentBody:appStoreProductId')) {
|
|
101
42
|
//TODO: show Toast
|
|
102
43
|
console.info('requestPaymentSync:paymentBody:appStoreProductId not supported');
|
|
103
44
|
setTimeout(() => {
|
|
104
|
-
rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'FAILED'
|
|
45
|
+
rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'FAILED' });
|
|
105
46
|
}, 0);
|
|
106
47
|
return;
|
|
107
48
|
}
|
|
108
49
|
|
|
109
50
|
// handle showup frequecy
|
|
110
|
-
if (type
|
|
51
|
+
if (type === 'ADS-JOLI_COIN') {
|
|
111
52
|
await loading.show({
|
|
112
53
|
duration: 3000
|
|
113
54
|
});
|
|
114
55
|
const config = await modalUseFrequencyConfig.getData();
|
|
115
|
-
const { canShow: canShowPaymentModal } = await
|
|
116
|
-
config.joliCoinUseAndCharge
|
|
56
|
+
const { canShow: canShowPaymentModal } = await checkPaymentFrequency(
|
|
57
|
+
config.joliCoinUseAndCharge.charge
|
|
117
58
|
);
|
|
118
|
-
console.log(
|
|
59
|
+
console.log('use payment show by frequency', canShowPaymentModal);
|
|
119
60
|
loading.hide();
|
|
120
61
|
if (!canShowPaymentModal) {
|
|
121
62
|
// return by frequency control
|
|
122
|
-
rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'FAILED'
|
|
63
|
+
rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'FAILED' });
|
|
123
64
|
return;
|
|
124
65
|
}
|
|
125
66
|
console.log('show by frequency');
|
|
@@ -131,25 +72,23 @@ rewardsEmitter.on(
|
|
|
131
72
|
await loading.show({
|
|
132
73
|
duration: 3000
|
|
133
74
|
});
|
|
134
|
-
const balenceDetails = await getBalenceDetails(
|
|
75
|
+
const balenceDetails = await getBalenceDetails();
|
|
135
76
|
loading.hide();
|
|
136
77
|
|
|
137
78
|
if (!balenceDetails) {
|
|
138
|
-
rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'FAILED'
|
|
79
|
+
rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'FAILED' });
|
|
139
80
|
return;
|
|
140
81
|
}
|
|
141
82
|
|
|
142
|
-
track(
|
|
83
|
+
track('coinorder_show', {
|
|
143
84
|
targetType: 'game',
|
|
144
|
-
eventType: EventType.View
|
|
145
|
-
currency: currencyType
|
|
85
|
+
eventType: EventType.View
|
|
146
86
|
});
|
|
147
87
|
|
|
148
88
|
const modal = createPaymentJolicoinModal({
|
|
149
89
|
data: {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
currency: currencyType,
|
|
90
|
+
userJolicoin: params.userJoliCoin,
|
|
91
|
+
joliCoinQuantity: params.joliCoinQuantity,
|
|
153
92
|
paymentChoices:
|
|
154
93
|
balenceDetails.paymentChoices?.map((choice) => ({
|
|
155
94
|
...choice,
|
|
@@ -161,12 +100,11 @@ rewardsEmitter.on(
|
|
|
161
100
|
confirm: {
|
|
162
101
|
text: params.confirmButtonText,
|
|
163
102
|
onPress: async (productId: string) => {
|
|
164
|
-
track(
|
|
103
|
+
track('order_pay_ensure', {
|
|
165
104
|
targetType: 'game',
|
|
166
105
|
eventType: EventType.Click,
|
|
167
106
|
payWay: 'app_iap',
|
|
168
|
-
coinAmount: params.
|
|
169
|
-
currency: currencyType,
|
|
107
|
+
coinAmount: params.joliCoinQuantity,
|
|
170
108
|
orderPrice:
|
|
171
109
|
balenceDetails.paymentChoices.find((choice) => choice.productId === productId)
|
|
172
110
|
?.totalAmountStr ?? ''
|
|
@@ -180,12 +118,9 @@ rewardsEmitter.on(
|
|
|
180
118
|
return;
|
|
181
119
|
}
|
|
182
120
|
|
|
183
|
-
const balenceDetails = await getBalenceDetails(
|
|
184
|
-
if ((balenceDetails?.balance ?? 0) >= params.
|
|
185
|
-
rewardsEmitter.emit(PaymentResultEventName, {
|
|
186
|
-
paymentResult: 'SUCCESS',
|
|
187
|
-
currency: currencyType
|
|
188
|
-
});
|
|
121
|
+
const balenceDetails = await getBalenceDetails();
|
|
122
|
+
if ((balenceDetails?.balance ?? 0) >= params.joliCoinQuantity) {
|
|
123
|
+
rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'SUCCESS' });
|
|
189
124
|
modal.destroy();
|
|
190
125
|
return;
|
|
191
126
|
}
|
|
@@ -196,27 +131,23 @@ rewardsEmitter.on(
|
|
|
196
131
|
)?.appStoreProductId;
|
|
197
132
|
|
|
198
133
|
if (!appStoreProductId) {
|
|
199
|
-
rewardsEmitter.emit(PaymentResultEventName, {
|
|
200
|
-
paymentResult: 'FAILED',
|
|
201
|
-
currency: currencyType
|
|
202
|
-
});
|
|
134
|
+
rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'FAILED' });
|
|
203
135
|
modal.destroy();
|
|
204
136
|
return;
|
|
205
137
|
}
|
|
206
138
|
await loading.show({
|
|
207
139
|
duration: 3000
|
|
208
140
|
});
|
|
209
|
-
const { code } = await paymentHelper.invokePayment(
|
|
141
|
+
const { code } = await paymentHelper.invokePayment('JOLI_COIN_IAP', {
|
|
210
142
|
productId,
|
|
211
143
|
appStoreProductId
|
|
212
144
|
});
|
|
213
145
|
loading.hide();
|
|
214
|
-
track(
|
|
146
|
+
track('order_pay_result', {
|
|
215
147
|
eventType: EventType.Other,
|
|
216
148
|
targetType: 'game',
|
|
217
149
|
payWay: 'app_iap',
|
|
218
|
-
coinAmount: params.
|
|
219
|
-
currency: currencyType,
|
|
150
|
+
coinAmount: params.joliCoinQuantity,
|
|
220
151
|
orderPrice:
|
|
221
152
|
balenceDetails.paymentChoices.find((choice) => choice.productId === productId)
|
|
222
153
|
?.totalAmountStr ?? '',
|
|
@@ -227,10 +158,7 @@ rewardsEmitter.on(
|
|
|
227
158
|
console.info('[JoliboxSDK] payment failed in payment.invokePaymet');
|
|
228
159
|
return;
|
|
229
160
|
}
|
|
230
|
-
rewardsEmitter.emit(PaymentResultEventName, {
|
|
231
|
-
paymentResult: 'SUCCESS',
|
|
232
|
-
currency: currencyType
|
|
233
|
-
});
|
|
161
|
+
rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'SUCCESS' });
|
|
234
162
|
modal.destroy();
|
|
235
163
|
}
|
|
236
164
|
},
|
|
@@ -238,13 +166,11 @@ rewardsEmitter.on(
|
|
|
238
166
|
text: params.cancelButtonText,
|
|
239
167
|
onPress: ({ type }) => {
|
|
240
168
|
rewardsEmitter.emit(PaymentResultEventName, {
|
|
241
|
-
paymentResult: (type ?? '') === 'CANCEL' ? 'CANCEL' : 'FAILED'
|
|
242
|
-
currency: currencyType
|
|
169
|
+
paymentResult: (type ?? '') === 'CANCEL' ? 'CANCEL' : 'FAILED'
|
|
243
170
|
});
|
|
244
|
-
track(
|
|
171
|
+
track('ad_unlock_click', {
|
|
245
172
|
targetType: 'game',
|
|
246
|
-
eventType: EventType.Click
|
|
247
|
-
currency: currencyType
|
|
173
|
+
eventType: EventType.Click
|
|
248
174
|
});
|
|
249
175
|
modal.destroy();
|
|
250
176
|
}
|
|
@@ -254,11 +180,10 @@ rewardsEmitter.on(
|
|
|
254
180
|
}
|
|
255
181
|
},
|
|
256
182
|
onSelect: (productId: string) => {
|
|
257
|
-
track(
|
|
183
|
+
track('coinorder_click', {
|
|
258
184
|
targetType: 'game',
|
|
259
185
|
eventType: EventType.Click,
|
|
260
|
-
coinAmount: params.
|
|
261
|
-
currency: currencyType,
|
|
186
|
+
coinAmount: params.joliCoinQuantity,
|
|
262
187
|
orderPrice:
|
|
263
188
|
balenceDetails.paymentChoices.find((choice) => choice.productId === productId)
|
|
264
189
|
?.totalAmountStr ?? ''
|
|
@@ -266,10 +191,10 @@ rewardsEmitter.on(
|
|
|
266
191
|
}
|
|
267
192
|
});
|
|
268
193
|
|
|
269
|
-
await
|
|
194
|
+
await updatePaymentFrequency();
|
|
270
195
|
} catch (error) {
|
|
271
196
|
console.info('payment failed', error);
|
|
272
|
-
rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'FAILED'
|
|
197
|
+
rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'FAILED' });
|
|
273
198
|
}
|
|
274
199
|
}
|
|
275
200
|
);
|
|
@@ -290,9 +215,7 @@ const mergeResponseData = (
|
|
|
290
215
|
) as IPaymentChoice[];
|
|
291
216
|
};
|
|
292
217
|
|
|
293
|
-
const getBalenceDetails = async (
|
|
294
|
-
apiEndpoint: string
|
|
295
|
-
): Promise<
|
|
218
|
+
const getBalenceDetails = async (): Promise<
|
|
296
219
|
| {
|
|
297
220
|
balance: number;
|
|
298
221
|
enableAutoDeduct: boolean;
|
|
@@ -306,7 +229,7 @@ const getBalenceDetails = async (
|
|
|
306
229
|
enableAutoDeduct: boolean;
|
|
307
230
|
paymentChoices: IPaymentChoice[];
|
|
308
231
|
}>
|
|
309
|
-
>(
|
|
232
|
+
>('/api/joli-coin/balance-detail', {
|
|
310
233
|
method: 'GET',
|
|
311
234
|
appendHostCookie: true,
|
|
312
235
|
responseType: 'json'
|