@jolibox/implement 1.1.55 → 1.2.0-beta.9

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 (60) hide show
  1. package/.rush/temp/package-deps_build.json +34 -27
  2. package/dist/common/rewards/index.d.ts +2 -0
  3. package/dist/common/rewards/registers/use-gem-only.d.ts +10 -0
  4. package/dist/common/rewards/registers/use-gem.d.ts +10 -0
  5. package/dist/common/rewards/registers/utils/coins/commands/currency-handlers.d.ts +15 -0
  6. package/dist/common/rewards/registers/utils/coins/commands/index.d.ts +1 -1
  7. package/dist/common/rewards/registers/utils/coins/commands/use-jolicoin.d.ts +10 -8
  8. package/dist/common/rewards/registers/utils/coins/commands/use-payment.d.ts +10 -8
  9. package/dist/common/rewards/registers/utils/coins/commands/use-unlogin.d.ts +6 -8
  10. package/dist/common/rewards/registers/utils/coins/currency-config.d.ts +8 -0
  11. package/dist/common/rewards/registers/utils/coins/index.d.ts +2 -18
  12. package/dist/common/rewards/registers/utils/coins/jolicoin/jolicoin-handler.d.ts +18 -0
  13. package/dist/common/rewards/registers/utils/coins/joligem/fetch-gem-balance.d.ts +4 -0
  14. package/dist/common/rewards/registers/utils/coins/joligem/gem-handler.d.ts +19 -0
  15. package/dist/common/rewards/registers/utils/index.d.ts +3 -1
  16. package/dist/common/rewards/reward-emitter.d.ts +23 -13
  17. package/dist/common/rewards/reward-helper.d.ts +3 -1
  18. package/dist/common/rewards/type.d.ts +10 -1
  19. package/dist/index.js +25 -25
  20. package/dist/index.native.js +68 -53
  21. package/dist/native/api/ads.d.ts +4 -0
  22. package/dist/native/payment/payment-helper.d.ts +5 -1
  23. package/dist/native/rewards/check-frequency.d.ts +24 -0
  24. package/dist/native/rewards/ui/utils.d.ts +1 -1
  25. package/implement.build.log +2 -2
  26. package/package.json +5 -5
  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 +50 -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 +152 -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 +134 -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/rewards/index.ts +33 -20
  49. package/src/native/api/ads.ts +55 -1
  50. package/src/native/api/call-host-method.ts +36 -1
  51. package/src/native/bootstrap/index.ts +11 -7
  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 +115 -34
  56. package/src/native/rewards/ui/unlogin-modal.ts +182 -87
  57. package/src/native/rewards/ui/use-modal.ts +129 -68
  58. package/src/native/rewards/ui/utils.ts +2 -2
  59. /package/dist/common/rewards/registers/utils/coins/{fetch-balance.d.ts → jolicoin/fetch-balance.d.ts} +0 -0
  60. /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,60 @@ 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
+ apiEndpointAutoDeduct: string;
51
+ }
52
+
53
+ const CURRENCY_PAYMENT_CONFIG: Record<'JOLI_COIN' | 'JOLI_GEM', CurrencyPaymentConfig> = {
54
+ JOLI_COIN: {
55
+ frequencyConfigKey: 'charge',
56
+ trackEvents: {
57
+ modalShow: 'coinorder_show',
58
+ orderClick: 'coinorder_click',
59
+ payEnsure: 'order_pay_ensure',
60
+ payResult: 'order_pay_result',
61
+ adUnlock: 'ad_unlock_click'
62
+ },
63
+ frequencyChecker: checkPaymentFrequency,
64
+ frequencyUpdater: updatePaymentFrequency,
65
+ apiEndpoint: '/api/joli-coin/balance-detail',
66
+ apiEndpointAutoDeduct: '/api/joli-coin/user-config',
67
+ paymentType: 'JOLI_COIN_IAP'
68
+ },
69
+ JOLI_GEM: {
70
+ frequencyConfigKey: 'charge', // 暂时复用,可后续扩展
71
+ trackEvents: {
72
+ modalShow: 'gem_order_show',
73
+ orderClick: 'gem_order_click',
74
+ payEnsure: 'gem_pay_ensure',
75
+ payResult: 'gem_pay_result',
76
+ adUnlock: 'gem_ad_unlock_click'
77
+ },
78
+ frequencyChecker: checkPaymentFrequencyGem,
79
+ frequencyUpdater: updatePaymentFrequencyGem,
80
+ apiEndpoint: '/api/joli-gem/balance-detail',
81
+ apiEndpointAutoDeduct: '/api/joli-gem/user-config',
82
+ paymentType: 'JOLI_GEM_IAP'
83
+ }
84
+ };
26
85
 
27
86
  const loading = createLoading();
28
87
 
@@ -35,32 +94,35 @@ const modalUseFrequencyConfig = createEventPromiseHandler<
35
94
  */
36
95
  rewardsEmitter.on(
37
96
  InvokePaymentEventName,
38
- async (type: 'JOLI_COIN' | 'ADS-JOLI_COIN', params: IInvokePaymentEvent) => {
97
+ async (type: 'JOLI_COIN' | 'ADS-JOLI_COIN' | 'JOLI_GEM' | 'ADS-JOLI_GEM', params: IInvokePaymentEvent) => {
39
98
  try {
99
+ // 获取货币类型配置
100
+ const currencyType = params.currency;
101
+ const paymentConfig = CURRENCY_PAYMENT_CONFIG[currencyType];
40
102
  // TODO: temp remove it for dev
41
103
  if (!canIUseNative('requestPaymentSync:paymentBody:appStoreProductId')) {
42
104
  //TODO: show Toast
43
105
  console.info('requestPaymentSync:paymentBody:appStoreProductId not supported');
44
106
  setTimeout(() => {
45
- rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'FAILED' });
107
+ rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'FAILED', currency: currencyType });
46
108
  }, 0);
47
109
  return;
48
110
  }
49
111
 
50
112
  // handle showup frequecy
51
- if (type === 'ADS-JOLI_COIN') {
113
+ if (type.includes('ADS-')) {
52
114
  await loading.show({
53
115
  duration: 3000
54
116
  });
55
117
  const config = await modalUseFrequencyConfig.getData();
56
- const { canShow: canShowPaymentModal } = await checkPaymentFrequency(
57
- config.joliCoinUseAndCharge.charge
118
+ const { canShow: canShowPaymentModal } = await paymentConfig.frequencyChecker(
119
+ config.joliCoinUseAndCharge[paymentConfig.frequencyConfigKey]
58
120
  );
59
- console.log('use payment show by frequency', canShowPaymentModal);
121
+ console.log(`${currencyType} payment show by frequency`, canShowPaymentModal);
60
122
  loading.hide();
61
123
  if (!canShowPaymentModal) {
62
124
  // return by frequency control
63
- rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'FAILED' });
125
+ rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'FAILED', currency: currencyType });
64
126
  return;
65
127
  }
66
128
  console.log('show by frequency');
@@ -72,23 +134,25 @@ rewardsEmitter.on(
72
134
  await loading.show({
73
135
  duration: 3000
74
136
  });
75
- const balenceDetails = await getBalenceDetails();
137
+ const balenceDetails = await getBalenceDetails(paymentConfig.apiEndpoint);
76
138
  loading.hide();
77
139
 
78
140
  if (!balenceDetails) {
79
- rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'FAILED' });
141
+ rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'FAILED', currency: currencyType });
80
142
  return;
81
143
  }
82
144
 
83
- track('coinorder_show', {
145
+ track(paymentConfig.trackEvents.modalShow, {
84
146
  targetType: 'game',
85
- eventType: EventType.View
147
+ eventType: EventType.View,
148
+ currency: currencyType
86
149
  });
87
150
 
88
151
  const modal = createPaymentJolicoinModal({
89
152
  data: {
90
- userJolicoin: params.userJoliCoin,
91
- joliCoinQuantity: params.joliCoinQuantity,
153
+ userCurrency: params.userCurrency,
154
+ quantity: params.quantity,
155
+ currency: currencyType,
92
156
  paymentChoices:
93
157
  balenceDetails.paymentChoices?.map((choice) => ({
94
158
  ...choice,
@@ -100,11 +164,12 @@ rewardsEmitter.on(
100
164
  confirm: {
101
165
  text: params.confirmButtonText,
102
166
  onPress: async (productId: string) => {
103
- track('order_pay_ensure', {
167
+ track(paymentConfig.trackEvents.payEnsure, {
104
168
  targetType: 'game',
105
169
  eventType: EventType.Click,
106
170
  payWay: 'app_iap',
107
- coinAmount: params.joliCoinQuantity,
171
+ coinAmount: params.quantity,
172
+ currency: currencyType,
108
173
  orderPrice:
109
174
  balenceDetails.paymentChoices.find((choice) => choice.productId === productId)
110
175
  ?.totalAmountStr ?? ''
@@ -118,9 +183,12 @@ rewardsEmitter.on(
118
183
  return;
119
184
  }
120
185
 
121
- const balenceDetails = await getBalenceDetails();
122
- if ((balenceDetails?.balance ?? 0) >= params.joliCoinQuantity) {
123
- rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'SUCCESS' });
186
+ const balenceDetails = await getBalenceDetails(paymentConfig.apiEndpoint);
187
+ if ((balenceDetails?.balance ?? 0) >= params.quantity) {
188
+ rewardsEmitter.emit(PaymentResultEventName, {
189
+ paymentResult: 'SUCCESS',
190
+ currency: currencyType
191
+ });
124
192
  modal.destroy();
125
193
  return;
126
194
  }
@@ -131,34 +199,42 @@ rewardsEmitter.on(
131
199
  )?.appStoreProductId;
132
200
 
133
201
  if (!appStoreProductId) {
134
- rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'FAILED' });
202
+ rewardsEmitter.emit(PaymentResultEventName, {
203
+ paymentResult: 'FAILED',
204
+ currency: currencyType
205
+ });
135
206
  modal.destroy();
136
207
  return;
137
208
  }
138
209
  await loading.show({
139
210
  duration: 3000
140
211
  });
141
- const { code } = await paymentHelper.invokePayment('JOLI_COIN_IAP', {
212
+ const { code } = await paymentHelper.invokePayment(paymentConfig.paymentType, {
142
213
  productId,
143
214
  appStoreProductId
144
215
  });
145
216
  loading.hide();
146
- track('order_pay_result', {
217
+ track(paymentConfig.trackEvents.payResult, {
147
218
  eventType: EventType.Other,
148
219
  targetType: 'game',
149
220
  payWay: 'app_iap',
150
- coinAmount: params.joliCoinQuantity,
221
+ coinAmount: params.quantity,
222
+ currency: currencyType,
151
223
  orderPrice:
152
224
  balenceDetails.paymentChoices.find((choice) => choice.productId === productId)
153
225
  ?.totalAmountStr ?? '',
154
226
  payResult: code
155
227
  });
228
+ console.log('payment result', code);
156
229
  if (code !== 'SUCCESS') {
157
230
  /** add timeout for google panel closed */
158
231
  console.info('[JoliboxSDK] payment failed in payment.invokePaymet');
159
232
  return;
160
233
  }
161
- rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'SUCCESS' });
234
+ rewardsEmitter.emit(PaymentResultEventName, {
235
+ paymentResult: 'SUCCESS',
236
+ currency: currencyType
237
+ });
162
238
  modal.destroy();
163
239
  }
164
240
  },
@@ -166,24 +242,27 @@ rewardsEmitter.on(
166
242
  text: params.cancelButtonText,
167
243
  onPress: ({ type }) => {
168
244
  rewardsEmitter.emit(PaymentResultEventName, {
169
- paymentResult: (type ?? '') === 'CANCEL' ? 'CANCEL' : 'FAILED'
245
+ paymentResult: (type ?? '') === 'CANCEL' ? 'CANCEL' : 'FAILED',
246
+ currency: currencyType
170
247
  });
171
- track('ad_unlock_click', {
248
+ track(paymentConfig.trackEvents.adUnlock, {
172
249
  targetType: 'game',
173
- eventType: EventType.Click
250
+ eventType: EventType.Click,
251
+ currency: currencyType
174
252
  });
175
253
  modal.destroy();
176
254
  }
177
255
  },
178
256
  onEnableDeductChanged: async (enabled: boolean) => {
179
- await updateAutoDeductConfig(enabled);
257
+ await updateAutoDeductConfig(enabled, paymentConfig.apiEndpointAutoDeduct);
180
258
  }
181
259
  },
182
260
  onSelect: (productId: string) => {
183
- track('coinorder_click', {
261
+ track(paymentConfig.trackEvents.orderClick, {
184
262
  targetType: 'game',
185
263
  eventType: EventType.Click,
186
- coinAmount: params.joliCoinQuantity,
264
+ coinAmount: params.quantity,
265
+ currency: currencyType,
187
266
  orderPrice:
188
267
  balenceDetails.paymentChoices.find((choice) => choice.productId === productId)
189
268
  ?.totalAmountStr ?? ''
@@ -191,10 +270,10 @@ rewardsEmitter.on(
191
270
  }
192
271
  });
193
272
 
194
- await updatePaymentFrequency();
273
+ await paymentConfig.frequencyUpdater();
195
274
  } catch (error) {
196
275
  console.info('payment failed', error);
197
- rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'FAILED' });
276
+ rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'FAILED', currency: params.currency });
198
277
  }
199
278
  }
200
279
  );
@@ -215,7 +294,9 @@ const mergeResponseData = (
215
294
  ) as IPaymentChoice[];
216
295
  };
217
296
 
218
- const getBalenceDetails = async (): Promise<
297
+ const getBalenceDetails = async (
298
+ apiEndpoint: string
299
+ ): Promise<
219
300
  | {
220
301
  balance: number;
221
302
  enableAutoDeduct: boolean;
@@ -229,7 +310,7 @@ const getBalenceDetails = async (): Promise<
229
310
  enableAutoDeduct: boolean;
230
311
  paymentChoices: IPaymentChoice[];
231
312
  }>
232
- >('/api/joli-coin/balance-detail', {
313
+ >(apiEndpoint, {
233
314
  method: 'GET',
234
315
  appendHostCookie: true,
235
316
  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
  };