@jolibox/implement 1.1.52 → 1.1.53-beta.0

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.
Files changed (59) hide show
  1. package/.rush/temp/package-deps_build.json +35 -26
  2. package/CHANGELOG.json +11 -0
  3. package/CHANGELOG.md +9 -0
  4. package/dist/common/rewards/index.d.ts +2 -0
  5. package/dist/common/rewards/registers/use-gem-only.d.ts +10 -0
  6. package/dist/common/rewards/registers/use-gem.d.ts +10 -0
  7. package/dist/common/rewards/registers/utils/coins/commands/currency-handlers.d.ts +15 -0
  8. package/dist/common/rewards/registers/utils/coins/commands/index.d.ts +1 -1
  9. package/dist/common/rewards/registers/utils/coins/commands/use-jolicoin.d.ts +10 -8
  10. package/dist/common/rewards/registers/utils/coins/commands/use-payment.d.ts +10 -8
  11. package/dist/common/rewards/registers/utils/coins/commands/use-unlogin.d.ts +6 -8
  12. package/dist/common/rewards/registers/utils/coins/currency-config.d.ts +8 -0
  13. package/dist/common/rewards/registers/utils/coins/index.d.ts +2 -18
  14. package/dist/common/rewards/registers/utils/coins/jolicoin/jolicoin-handler.d.ts +18 -0
  15. package/dist/common/rewards/registers/utils/coins/joligem/fetch-gem-balance.d.ts +4 -0
  16. package/dist/common/rewards/registers/utils/coins/joligem/gem-handler.d.ts +19 -0
  17. package/dist/common/rewards/registers/utils/index.d.ts +3 -1
  18. package/dist/common/rewards/reward-emitter.d.ts +23 -13
  19. package/dist/common/rewards/reward-helper.d.ts +3 -1
  20. package/dist/common/rewards/type.d.ts +10 -1
  21. package/dist/index.js +25 -25
  22. package/dist/index.native.js +67 -67
  23. package/dist/native/payment/payment-helper.d.ts +5 -1
  24. package/dist/native/rewards/check-frequency.d.ts +24 -0
  25. package/implement.build.log +2 -2
  26. package/package.json +6 -6
  27. package/src/common/rewards/__tests__/can-use-jolicoin.test.ts +265 -9
  28. package/src/common/rewards/fetch-reward.ts +18 -3
  29. package/src/common/rewards/index.ts +2 -0
  30. package/src/common/rewards/registers/use-gem-only.ts +58 -0
  31. package/src/common/rewards/registers/use-gem.ts +53 -0
  32. package/src/common/rewards/registers/use-jolicoin-only.ts +4 -4
  33. package/src/common/rewards/registers/use-jolicoin.ts +4 -4
  34. package/src/common/rewards/registers/utils/coins/commands/currency-handlers.ts +48 -0
  35. package/src/common/rewards/registers/utils/coins/commands/index.ts +1 -1
  36. package/src/common/rewards/registers/utils/coins/commands/use-jolicoin.ts +31 -19
  37. package/src/common/rewards/registers/utils/coins/commands/use-payment.ts +32 -25
  38. package/src/common/rewards/registers/utils/coins/commands/use-unlogin.ts +22 -24
  39. package/src/common/rewards/registers/utils/coins/currency-config.ts +23 -0
  40. package/src/common/rewards/registers/utils/coins/index.ts +2 -139
  41. package/src/common/rewards/registers/utils/coins/jolicoin/jolicoin-handler.ts +149 -0
  42. package/src/common/rewards/registers/utils/coins/joligem/fetch-gem-balance.ts +15 -0
  43. package/src/common/rewards/registers/utils/coins/joligem/gem-handler.ts +131 -0
  44. package/src/common/rewards/registers/utils/index.ts +20 -1
  45. package/src/common/rewards/reward-emitter.ts +23 -13
  46. package/src/common/rewards/reward-helper.ts +3 -1
  47. package/src/common/rewards/type.ts +13 -1
  48. package/src/h5/api/ads.ts +5 -13
  49. package/src/h5/rewards/index.ts +33 -20
  50. package/src/native/api/ads.ts +22 -1
  51. package/src/native/api/call-host-method.ts +36 -1
  52. package/src/native/payment/index.ts +2 -0
  53. package/src/native/payment/payment-helper.ts +2 -1
  54. package/src/native/rewards/check-frequency.ts +10 -0
  55. package/src/native/rewards/ui/payment-modal.ts +110 -33
  56. package/src/native/rewards/ui/unlogin-modal.ts +182 -87
  57. package/src/native/rewards/ui/use-modal.ts +126 -68
  58. /package/dist/common/rewards/registers/utils/coins/{fetch-balance.d.ts → jolicoin/fetch-balance.d.ts} +0 -0
  59. /package/src/common/rewards/registers/utils/coins/{fetch-balance.ts → jolicoin/fetch-balance.ts} +0 -0
@@ -14,7 +14,12 @@ import { context } from '@/common/context';
14
14
  import { login } from '@/native/api/login';
15
15
  import { EventType } from '@jolibox/common';
16
16
 
17
- import { checkPaymentFrequency, updatePaymentFrequency } from '../check-frequency';
17
+ import {
18
+ checkPaymentFrequency,
19
+ updatePaymentFrequency,
20
+ checkPaymentFrequencyGem,
21
+ updatePaymentFrequencyGem
22
+ } from '../check-frequency';
18
23
  import { paymentHelper } from '@/native/payment';
19
24
  import { createLoading } from '@jolibox/ui';
20
25
  import { canIUseNative } from '@/native/api/base';
@@ -23,6 +28,57 @@ import { isUndefinedOrNull } from '@jolibox/common';
23
28
  import { track } from '@/native/report';
24
29
  import { updateAutoDeductConfig } from './utils';
25
30
  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
+ };
26
82
 
27
83
  const loading = createLoading();
28
84
 
@@ -35,32 +91,35 @@ const modalUseFrequencyConfig = createEventPromiseHandler<
35
91
  */
36
92
  rewardsEmitter.on(
37
93
  InvokePaymentEventName,
38
- async (type: 'JOLI_COIN' | 'ADS-JOLI_COIN', params: IInvokePaymentEvent) => {
94
+ async (type: 'JOLI_COIN' | 'ADS-JOLI_COIN' | 'JOLI_GEM' | 'ADS-JOLI_GEM', params: IInvokePaymentEvent) => {
39
95
  try {
96
+ // 获取货币类型配置
97
+ const currencyType = params.currency;
98
+ const paymentConfig = CURRENCY_PAYMENT_CONFIG[currencyType];
40
99
  // TODO: temp remove it for dev
41
100
  if (!canIUseNative('requestPaymentSync:paymentBody:appStoreProductId')) {
42
101
  //TODO: show Toast
43
102
  console.info('requestPaymentSync:paymentBody:appStoreProductId not supported');
44
103
  setTimeout(() => {
45
- rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'FAILED' });
104
+ rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'FAILED', currency: currencyType });
46
105
  }, 0);
47
106
  return;
48
107
  }
49
108
 
50
109
  // handle showup frequecy
51
- if (type === 'ADS-JOLI_COIN') {
110
+ if (type.includes('ADS-')) {
52
111
  await loading.show({
53
112
  duration: 3000
54
113
  });
55
114
  const config = await modalUseFrequencyConfig.getData();
56
- const { canShow: canShowPaymentModal } = await checkPaymentFrequency(
57
- config.joliCoinUseAndCharge.charge
115
+ const { canShow: canShowPaymentModal } = await paymentConfig.frequencyChecker(
116
+ config.joliCoinUseAndCharge[paymentConfig.frequencyConfigKey]
58
117
  );
59
- console.log('use payment show by frequency', canShowPaymentModal);
118
+ console.log(`${currencyType} payment show by frequency`, canShowPaymentModal);
60
119
  loading.hide();
61
120
  if (!canShowPaymentModal) {
62
121
  // return by frequency control
63
- rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'FAILED' });
122
+ rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'FAILED', currency: currencyType });
64
123
  return;
65
124
  }
66
125
  console.log('show by frequency');
@@ -72,23 +131,25 @@ rewardsEmitter.on(
72
131
  await loading.show({
73
132
  duration: 3000
74
133
  });
75
- const balenceDetails = await getBalenceDetails();
134
+ const balenceDetails = await getBalenceDetails(paymentConfig.apiEndpoint);
76
135
  loading.hide();
77
136
 
78
137
  if (!balenceDetails) {
79
- rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'FAILED' });
138
+ rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'FAILED', currency: currencyType });
80
139
  return;
81
140
  }
82
141
 
83
- track('coinorder_show', {
142
+ track(paymentConfig.trackEvents.modalShow, {
84
143
  targetType: 'game',
85
- eventType: EventType.View
144
+ eventType: EventType.View,
145
+ currency: currencyType
86
146
  });
87
147
 
88
148
  const modal = createPaymentJolicoinModal({
89
149
  data: {
90
- userJolicoin: params.userJoliCoin,
91
- joliCoinQuantity: params.joliCoinQuantity,
150
+ userCurrency: params.userCurrency,
151
+ quantity: params.quantity,
152
+ currency: currencyType,
92
153
  paymentChoices:
93
154
  balenceDetails.paymentChoices?.map((choice) => ({
94
155
  ...choice,
@@ -100,11 +161,12 @@ rewardsEmitter.on(
100
161
  confirm: {
101
162
  text: params.confirmButtonText,
102
163
  onPress: async (productId: string) => {
103
- track('order_pay_ensure', {
164
+ track(paymentConfig.trackEvents.payEnsure, {
104
165
  targetType: 'game',
105
166
  eventType: EventType.Click,
106
167
  payWay: 'app_iap',
107
- coinAmount: params.joliCoinQuantity,
168
+ coinAmount: params.quantity,
169
+ currency: currencyType,
108
170
  orderPrice:
109
171
  balenceDetails.paymentChoices.find((choice) => choice.productId === productId)
110
172
  ?.totalAmountStr ?? ''
@@ -118,9 +180,12 @@ rewardsEmitter.on(
118
180
  return;
119
181
  }
120
182
 
121
- const balenceDetails = await getBalenceDetails();
122
- if ((balenceDetails?.balance ?? 0) >= params.joliCoinQuantity) {
123
- rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'SUCCESS' });
183
+ const balenceDetails = await getBalenceDetails(paymentConfig.apiEndpoint);
184
+ if ((balenceDetails?.balance ?? 0) >= params.quantity) {
185
+ rewardsEmitter.emit(PaymentResultEventName, {
186
+ paymentResult: 'SUCCESS',
187
+ currency: currencyType
188
+ });
124
189
  modal.destroy();
125
190
  return;
126
191
  }
@@ -131,23 +196,27 @@ rewardsEmitter.on(
131
196
  )?.appStoreProductId;
132
197
 
133
198
  if (!appStoreProductId) {
134
- rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'FAILED' });
199
+ rewardsEmitter.emit(PaymentResultEventName, {
200
+ paymentResult: 'FAILED',
201
+ currency: currencyType
202
+ });
135
203
  modal.destroy();
136
204
  return;
137
205
  }
138
206
  await loading.show({
139
207
  duration: 3000
140
208
  });
141
- const { code } = await paymentHelper.invokePayment('JOLI_COIN_IAP', {
209
+ const { code } = await paymentHelper.invokePayment(paymentConfig.paymentType, {
142
210
  productId,
143
211
  appStoreProductId
144
212
  });
145
213
  loading.hide();
146
- track('order_pay_result', {
214
+ track(paymentConfig.trackEvents.payResult, {
147
215
  eventType: EventType.Other,
148
216
  targetType: 'game',
149
217
  payWay: 'app_iap',
150
- coinAmount: params.joliCoinQuantity,
218
+ coinAmount: params.quantity,
219
+ currency: currencyType,
151
220
  orderPrice:
152
221
  balenceDetails.paymentChoices.find((choice) => choice.productId === productId)
153
222
  ?.totalAmountStr ?? '',
@@ -158,7 +227,10 @@ rewardsEmitter.on(
158
227
  console.info('[JoliboxSDK] payment failed in payment.invokePaymet');
159
228
  return;
160
229
  }
161
- rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'SUCCESS' });
230
+ rewardsEmitter.emit(PaymentResultEventName, {
231
+ paymentResult: 'SUCCESS',
232
+ currency: currencyType
233
+ });
162
234
  modal.destroy();
163
235
  }
164
236
  },
@@ -166,11 +238,13 @@ rewardsEmitter.on(
166
238
  text: params.cancelButtonText,
167
239
  onPress: ({ type }) => {
168
240
  rewardsEmitter.emit(PaymentResultEventName, {
169
- paymentResult: (type ?? '') === 'CANCEL' ? 'CANCEL' : 'FAILED'
241
+ paymentResult: (type ?? '') === 'CANCEL' ? 'CANCEL' : 'FAILED',
242
+ currency: currencyType
170
243
  });
171
- track('ad_unlock_click', {
244
+ track(paymentConfig.trackEvents.adUnlock, {
172
245
  targetType: 'game',
173
- eventType: EventType.Click
246
+ eventType: EventType.Click,
247
+ currency: currencyType
174
248
  });
175
249
  modal.destroy();
176
250
  }
@@ -180,10 +254,11 @@ rewardsEmitter.on(
180
254
  }
181
255
  },
182
256
  onSelect: (productId: string) => {
183
- track('coinorder_click', {
257
+ track(paymentConfig.trackEvents.orderClick, {
184
258
  targetType: 'game',
185
259
  eventType: EventType.Click,
186
- coinAmount: params.joliCoinQuantity,
260
+ coinAmount: params.quantity,
261
+ currency: currencyType,
187
262
  orderPrice:
188
263
  balenceDetails.paymentChoices.find((choice) => choice.productId === productId)
189
264
  ?.totalAmountStr ?? ''
@@ -191,10 +266,10 @@ rewardsEmitter.on(
191
266
  }
192
267
  });
193
268
 
194
- await updatePaymentFrequency();
269
+ await paymentConfig.frequencyUpdater();
195
270
  } catch (error) {
196
271
  console.info('payment failed', error);
197
- rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'FAILED' });
272
+ rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'FAILED', currency: params.currency });
198
273
  }
199
274
  }
200
275
  );
@@ -215,7 +290,9 @@ const mergeResponseData = (
215
290
  ) as IPaymentChoice[];
216
291
  };
217
292
 
218
- const getBalenceDetails = async (): Promise<
293
+ const getBalenceDetails = async (
294
+ apiEndpoint: string
295
+ ): Promise<
219
296
  | {
220
297
  balance: number;
221
298
  enableAutoDeduct: boolean;
@@ -229,7 +306,7 @@ const getBalenceDetails = async (): Promise<
229
306
  enableAutoDeduct: boolean;
230
307
  paymentChoices: IPaymentChoice[];
231
308
  }>
232
- >('/api/joli-coin/balance-detail', {
309
+ >(apiEndpoint, {
233
310
  method: 'GET',
234
311
  appendHostCookie: true,
235
312
  responseType: 'json'
@@ -6,8 +6,13 @@ import {
6
6
  UseUnloginModalResultEventName
7
7
  } from '@/common/rewards/reward-emitter';
8
8
  import { createEventPromiseHandler } from '@/common/rewards/registers/utils/event-listener';
9
- import { checkUnloginModalFrequency, updateUnloginModalFrequency } from '../check-frequency';
10
- import { StandardResponse } from '@jolibox/types';
9
+ import {
10
+ checkUnloginModalFrequency,
11
+ updateUnloginModalFrequency,
12
+ checkUnloginModalFrequencyGem,
13
+ updateUnloginModalFrequencyGem
14
+ } from '../check-frequency';
15
+ import { StandardResponse, TrackEvent } from '@jolibox/types';
11
16
  import { innerFetch as fetch } from '@/native/network';
12
17
  import { reportError } from '@/common/report/errors/report';
13
18
  import { EventType, InternalInvokeMethodError } from '@jolibox/common';
@@ -15,6 +20,63 @@ import { loginImplement } from '@/native/api/login';
15
20
  import { createToast, createUnloginJolicoinModal } from '@jolibox/ui';
16
21
  import { track } from '@/native/report';
17
22
 
23
+ // 货币配置映射
24
+ interface CurrencyUnloginConfig {
25
+ frequencyChecker: (config: {
26
+ show: boolean;
27
+ dailyMaxPopUps?: number;
28
+ minInterval?: number;
29
+ }) => Promise<{ canShow: boolean; isFirst: boolean }>;
30
+ frequencyUpdater: () => Promise<void>;
31
+ trackEvents: {
32
+ modalExpose: TrackEvent;
33
+ clickConfirm: TrackEvent;
34
+ clickConfirmLogin: TrackEvent;
35
+ modalHide: TrackEvent;
36
+ clickClose: TrackEvent;
37
+ clickWatchAds: TrackEvent;
38
+ };
39
+ toastMessage: {
40
+ i18nKey: string;
41
+ usedText: string;
42
+ };
43
+ }
44
+
45
+ const CURRENCY_UNLOGIN_CONFIG: Record<'JOLI_COIN' | 'JOLI_GEM', CurrencyUnloginConfig> = {
46
+ JOLI_COIN: {
47
+ frequencyChecker: checkUnloginModalFrequency,
48
+ frequencyUpdater: updateUnloginModalFrequency,
49
+ trackEvents: {
50
+ modalExpose: 'LoginGuideModal',
51
+ clickConfirm: 'LoginGuideModal',
52
+ clickConfirmLogin: 'LoginGuideModal',
53
+ modalHide: 'LoginGuideModal',
54
+ clickClose: 'LoginGuideModal',
55
+ clickWatchAds: 'LoginGuideModal'
56
+ },
57
+ toastMessage: {
58
+ i18nKey: '{slot-i18ntran-loginGuide.rewardTips}',
59
+ usedText: 'Jolicoin Used'
60
+ }
61
+ },
62
+ JOLI_GEM: {
63
+ frequencyChecker: checkUnloginModalFrequencyGem,
64
+ frequencyUpdater: updateUnloginModalFrequencyGem,
65
+ trackEvents: {
66
+ modalExpose: 'GemLoginGuideModal', // 暂时复用,可后续扩展为 GemLoginGuideModal
67
+ clickConfirm: 'GemLoginGuideModal',
68
+ clickConfirmLogin: 'GemLoginGuideModal',
69
+ modalHide: 'GemLoginGuideModal',
70
+ clickClose: 'GemLoginGuideModal',
71
+ clickWatchAds: 'GemLoginGuideModal'
72
+ },
73
+ toastMessage: {
74
+ i18nKey: '{slot-i18ntran-loginGuide.gemRewardTips}',
75
+ usedText: 'Gem Used'
76
+ }
77
+ }
78
+ };
79
+
18
80
  const unloginModalConfig = createEventPromiseHandler<
19
81
  IUseModalFrequencyConfig,
20
82
  typeof UseModalFrequencyEventName
@@ -22,109 +84,142 @@ const unloginModalConfig = createEventPromiseHandler<
22
84
 
23
85
  unloginModalConfig.getData();
24
86
 
25
- rewardsEmitter.on(InvokeUnloginModalEventName, async (type: 'JOLI_COIN' | 'ADS-JOLI_COIN', params) => {
26
- try {
27
- if (type === 'ADS-JOLI_COIN') {
28
- const config = await unloginModalConfig.getData();
29
- console.log('unlogin guide config', config.loginGuide);
87
+ rewardsEmitter.on(
88
+ InvokeUnloginModalEventName,
89
+ async (type: 'JOLI_COIN' | 'ADS-JOLI_COIN' | 'JOLI_GEM' | 'ADS-JOLI_GEM', params) => {
90
+ try {
91
+ // 获取货币类型配置
92
+ const currencyType = params.currency;
93
+ const unloginConfig = CURRENCY_UNLOGIN_CONFIG[currencyType];
30
94
 
31
- if (!config.loginGuide.show) {
32
- rewardsEmitter.emit(UseUnloginModalResultEventName, { result: 'NOT_SUPPORT' });
33
- return;
95
+ if (type.includes('ADS-')) {
96
+ const config = await unloginModalConfig.getData();
97
+ console.log(`${currencyType} unlogin guide config`, config.loginGuide);
98
+
99
+ if (!config.loginGuide.show) {
100
+ rewardsEmitter.emit(UseUnloginModalResultEventName, { result: 'NOT_SUPPORT' });
101
+ return;
102
+ }
103
+ const { canShow: canShowUseModal } = await unloginConfig.frequencyChecker(config.loginGuide);
104
+
105
+ console.log(`${currencyType} canShowUseModal`, canShowUseModal);
106
+ if (!canShowUseModal) {
107
+ rewardsEmitter.emit(UseUnloginModalResultEventName, { result: 'FAILED' });
108
+ return;
109
+ }
34
110
  }
35
- const { canShow: canShowUseModal } = await checkUnloginModalFrequency(config.loginGuide);
36
111
 
37
- console.log('canShowUseModal', canShowUseModal);
38
- if (!canShowUseModal) {
39
- rewardsEmitter.emit(UseUnloginModalResultEventName, { result: 'FAILED' });
112
+ const { firstLogin } = (await getRewardCoin()) ?? {};
113
+ if (!firstLogin?.reward) {
114
+ console.log('[JoliboxSDK] unlogin modal reward is empty');
115
+ rewardsEmitter.emit(UseUnloginModalResultEventName, { result: 'NOT_SUPPORT' });
40
116
  return;
41
117
  }
42
- }
43
-
44
- const { firstLogin } = (await getRewardCoin()) ?? {};
45
- if (!firstLogin?.reward) {
46
- console.log('[JoliboxSDK] unlogin modal reward is empty');
47
- rewardsEmitter.emit(UseUnloginModalResultEventName, { result: 'NOT_SUPPORT' });
48
- return;
49
- }
50
118
 
51
- track(
52
- 'LoginGuideModal',
53
- {
54
- eventType: EventType.Expose
55
- },
56
- EventType.Expose
57
- );
58
- const modal = createUnloginJolicoinModal({
59
- data: {
60
- rewardType: type,
61
- rewardValue: firstLogin.reward.rewardValue
62
- },
63
- buttons: {
64
- confirm: {
65
- text: params.confirmButtonText,
66
- onPress: async () => {
67
- track('LoginGuideModal', { type: 'click_confirm', eventType: EventType.Click }, EventType.Click);
68
- const { isLogin, extra, isFirstLogin } = await loginImplement({}, true);
69
- if (!isLogin) {
70
- console.log('login failed');
71
- return;
72
- }
119
+ // 根据货币类型上报不同的埋点
120
+ track(
121
+ unloginConfig.trackEvents.modalExpose,
122
+ {
123
+ eventType: EventType.Expose,
124
+ currency: currencyType
125
+ },
126
+ EventType.Expose
127
+ );
128
+ const modal = createUnloginJolicoinModal({
129
+ data: {
130
+ rewardType: type,
131
+ rewardValue: firstLogin.reward.rewardValue,
132
+ currency: params.currency
133
+ },
134
+ buttons: {
135
+ confirm: {
136
+ text: params.confirmButtonText,
137
+ onPress: async () => {
138
+ // 根据货币类型上报不同的埋点
139
+ track(
140
+ unloginConfig.trackEvents.clickConfirm,
141
+ { type: 'click_confirm', eventType: EventType.Click, currency: currencyType },
142
+ EventType.Click
143
+ );
144
+ const { isLogin, extra, isFirstLogin } = await loginImplement({}, true);
145
+ if (!isLogin) {
146
+ console.log('login failed');
147
+ return;
148
+ }
73
149
 
74
- track(
75
- 'LoginGuideModal',
76
- { type: 'click_confirm_login', isFirstLogin, eventType: EventType.Click },
77
- EventType.Click
78
- );
79
- if (isFirstLogin && extra?.firstLogin?.reward) {
80
- const { rewardValue } = extra.firstLogin.reward;
81
- createToast(`{slot-i18ntran-loginGuide.rewardTips}`, {
82
- i18nParams: {
83
- text: 'Jolicoin Used',
84
- coin: rewardValue
150
+ track(
151
+ unloginConfig.trackEvents.clickConfirmLogin,
152
+ {
153
+ type: 'click_confirm_login',
154
+ isFirstLogin,
155
+ eventType: EventType.Click,
156
+ currency: currencyType
85
157
  },
86
- position: 'top',
87
- duration: 3000
88
- });
89
- }
158
+ EventType.Click
159
+ );
160
+ if (isFirstLogin && extra?.firstLogin?.reward) {
161
+ const { rewardValue } = extra.firstLogin.reward;
162
+ createToast(unloginConfig.toastMessage.i18nKey, {
163
+ i18nParams: {
164
+ text: unloginConfig.toastMessage.usedText,
165
+ coin: rewardValue
166
+ },
167
+ position: 'top',
168
+ duration: 3000
169
+ });
170
+ }
90
171
 
91
- rewardsEmitter.emit(UseUnloginModalResultEventName, {
92
- result: 'SUCCESS',
93
- rewards: {
94
- jolicoin: {
172
+ rewardsEmitter.emit(UseUnloginModalResultEventName, {
173
+ result: 'SUCCESS',
174
+ rewards: {
95
175
  claimedRewardValue: extra?.firstLogin?.reward?.rewardValue ?? 0,
96
- isFirstLogin: isFirstLogin ?? false
176
+ isFirstLogin: isFirstLogin ?? false,
177
+ currency: params.currency
97
178
  }
98
- }
99
- });
100
- modal.destroy();
101
- return;
102
- }
103
- },
104
- cancel: {
105
- text: params.cancelButtonText,
106
- onPress: ({ type }) => {
107
- track('LoginGuideModal', { eventType: EventType.Hide }, EventType.Hide);
108
-
109
- const trackType = type === 'CANCEL' ? 'click_close' : 'click_watch_ads';
110
- track('LoginGuideModal', { type: trackType, eventType: EventType.Click }, EventType.Click);
111
- rewardsEmitter.emit(UseUnloginModalResultEventName, { result: 'FAILED' });
112
- modal.destroy();
179
+ });
180
+ modal.destroy();
181
+ return;
182
+ }
183
+ },
184
+ cancel: {
185
+ text: params.cancelButtonText,
186
+ onPress: ({ type }) => {
187
+ // 根据货币类型上报不同的埋点
188
+ track(
189
+ unloginConfig.trackEvents.modalHide,
190
+ { eventType: EventType.Hide, currency: currencyType },
191
+ EventType.Hide
192
+ );
193
+
194
+ const trackType = type === 'CANCEL' ? 'click_close' : 'click_watch_ads';
195
+ const trackEvent =
196
+ type === 'CANCEL'
197
+ ? unloginConfig.trackEvents.clickClose
198
+ : unloginConfig.trackEvents.clickWatchAds;
199
+
200
+ track(
201
+ trackEvent,
202
+ { type: trackType, eventType: EventType.Click, currency: currencyType },
203
+ EventType.Click
204
+ );
205
+ rewardsEmitter.emit(UseUnloginModalResultEventName, { result: 'FAILED' });
206
+ modal.destroy();
207
+ }
113
208
  }
114
209
  }
115
- }
116
- });
117
- await updateUnloginModalFrequency();
118
- } catch (e) {
119
- reportError(new InternalInvokeMethodError(e as Error));
120
- rewardsEmitter.emit(UseUnloginModalResultEventName, { result: 'FAILED' });
210
+ });
211
+ await unloginConfig.frequencyUpdater();
212
+ } catch (e) {
213
+ reportError(new InternalInvokeMethodError(e as Error));
214
+ rewardsEmitter.emit(UseUnloginModalResultEventName, { result: 'FAILED' });
215
+ }
121
216
  }
122
- });
217
+ );
123
218
 
124
219
  interface IRewardCoinResponse {
125
220
  firstLogin: {
126
221
  reward: {
127
- rewardType: 'JOLI_COIN';
222
+ rewardType: 'JOLI_COIN' | 'JOLI_GEM';
128
223
  rewardValue: number;
129
224
  };
130
225
  };