@jolibox/implement 1.1.22 → 1.1.23

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.
@@ -1,9 +1,9 @@
1
1
  Invoking: npm run clean && npm run build:esm && tsc
2
2
 
3
- > @jolibox/implement@1.1.22 clean
3
+ > @jolibox/implement@1.1.23 clean
4
4
  > rimraf ./dist
5
5
 
6
6
 
7
- > @jolibox/implement@1.1.22 build:esm
7
+ > @jolibox/implement@1.1.23 build:esm
8
8
  > BUILD_VERSION=$(node -p "require('./package.json').version") node esbuild.config.js --format=esm
9
9
 
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@jolibox/implement",
3
3
  "description": "This project is Jolibox JS-SDk implement for Native && H5",
4
- "version": "1.1.22",
4
+ "version": "1.1.23",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
7
7
  "license": "MIT",
8
8
  "dependencies": {
9
- "@jolibox/common": "1.1.22",
10
- "@jolibox/types": "1.1.22",
11
- "@jolibox/native-bridge": "1.1.22",
12
- "@jolibox/ads": "1.1.22",
9
+ "@jolibox/common": "1.1.23",
10
+ "@jolibox/types": "1.1.23",
11
+ "@jolibox/native-bridge": "1.1.23",
12
+ "@jolibox/ads": "1.1.23",
13
13
  "localforage": "1.10.0",
14
14
  "@jolibox/ui": "1.0.0",
15
15
  "web-vitals": "4.2.4"
@@ -19,7 +19,7 @@ const reportNative: ReportHandler = (event, data, webviewId) => {
19
19
  mp_version: (_data.mp_version as string) ?? ''
20
20
  };
21
21
  invokeNative('trackAsync', {
22
- event,
22
+ event: data.tag ?? event,
23
23
  data: extra,
24
24
  webviewId
25
25
  });
@@ -27,6 +27,7 @@ import {
27
27
  checkPaymentFrequency,
28
28
  updatePaymentFrequency
29
29
  } from './check-frequency';
30
+
30
31
  const modalUseFrequencyConfig = createEventPromiseHandler<
31
32
  IUseModalFrequencyConfig,
32
33
  typeof UseModalFrequencyEventName
@@ -34,6 +35,31 @@ const modalUseFrequencyConfig = createEventPromiseHandler<
34
35
 
35
36
  modalUseFrequencyConfig.getData();
36
37
 
38
+ /**
39
+ * update config
40
+ */
41
+
42
+ let updateEnableConfigPromise = Promise.resolve();
43
+
44
+ /**
45
+ * 更新自动扣费配置的函数
46
+ * @param enabled 是否启用自动扣费
47
+ * @returns Promise 更新操作的Promise
48
+ */
49
+ const updateAutoDeductConfig = async (enabled: boolean): Promise<void> => {
50
+ updateEnableConfigPromise = updateEnableConfigPromise.then(async () => {
51
+ await fetch('/api/joli-coin/user-config', {
52
+ method: 'POST',
53
+ appendHostCookie: true,
54
+ data: {
55
+ enableAutoDeduct: enabled
56
+ }
57
+ });
58
+ });
59
+
60
+ await updateEnableConfigPromise;
61
+ };
62
+
37
63
  /**
38
64
  * confirm jolicoin modal
39
65
  */
@@ -71,6 +97,9 @@ rewardsEmitter.on(UseModalEventName, async (type: 'JOLI_COIN' | 'ADS-JOLI_COIN',
71
97
  });
72
98
  modal.destroy();
73
99
  }
100
+ },
101
+ onEnableDeductChanged: async (enabled: boolean) => {
102
+ await updateAutoDeductConfig(enabled);
74
103
  }
75
104
  }
76
105
  });
@@ -122,8 +151,16 @@ rewardsEmitter.on(
122
151
  console.log('login failed');
123
152
  return;
124
153
  }
154
+
155
+ const balenceDetails = await getBalenceDetails();
156
+ if ((balenceDetails?.balance ?? 0) >= params.joliCoinQuantity && params.enableAutoDeduct) {
157
+ rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'SUCCESS' });
158
+ modal.destroy();
159
+ return;
160
+ }
125
161
  }
126
162
  console.log('invokeNativePayment', productId);
163
+
127
164
  rewardsEmitter.emit(PaymentResultEventName, { paymentResult: 'SUCCESS' });
128
165
  modal.destroy();
129
166
  }
@@ -136,6 +173,9 @@ rewardsEmitter.on(
136
173
  });
137
174
  modal.destroy();
138
175
  }
176
+ },
177
+ onEnableDeductChanged: async (enabled: boolean) => {
178
+ await updateAutoDeductConfig(enabled);
139
179
  }
140
180
  }
141
181
  });
@@ -71,32 +71,9 @@ const openGameSchema = (game: IGame) => {
71
71
  });
72
72
  };
73
73
 
74
- export async function openRetentionSchema() {
75
- // const { data } = invokeNative('envSync');
76
- // const { orientation, webviewId } = data;
77
- // let joliPayload: Record<string, unknown> = {
78
- // __mpType: 'miniApp',
79
- // __transparent: true,
80
- // // set entryPath
81
- // __orientation: orientation ?? 'VERTICAL', // 默认竖屏
82
- // __showStatusBar: false,
83
- // __shouldInterupt: false,
84
- // __showCapsuleButton: false
85
- // };
86
- // if (webviewId) {
87
- // joliPayload = {
88
- // ...joliPayload,
89
- // __from: webviewId
90
- // };
91
- // }
92
-
93
- // const joliSource = context.encodeJoliSourceQuery(joliPayload);
94
-
95
- // const host = context.testMode
96
- // ? `https://G32115508989327465281365749294.app.jolibox.com`
97
- // : `https://G32115508989327465281365749294.app.jolibox.com`;
98
- // const retentionSchema = `${host}/recommended-guide/${context.mpId}?appId=${context.mpId}&joliSource=${joliSource}&navigationStyle=present`;
74
+ let isOpenRetentionSchema = false;
99
75
 
76
+ export async function openRetentionSchema() {
100
77
  const quitResultDeffer = new Deferred<boolean>();
101
78
  // 小程序不走挽留逻辑
102
79
  if (context.mpType !== 'game') {
@@ -104,6 +81,11 @@ export async function openRetentionSchema() {
104
81
  return quitResultDeffer.promise;
105
82
  }
106
83
 
84
+ if (isOpenRetentionSchema) {
85
+ quitResultDeffer.resolve(true);
86
+ return quitResultDeffer.promise;
87
+ }
88
+
107
89
  const data = await fetchExitRecommendations();
108
90
 
109
91
  if (data.code !== 'SUCCESS') {
@@ -113,11 +95,13 @@ export async function openRetentionSchema() {
113
95
 
114
96
  const { gameListInfo, title, buttons } = data.data;
115
97
 
98
+ isOpenRetentionSchema = true;
116
99
  const modal = createRecommendModal({
117
100
  games: gameListInfo.games,
118
101
  title,
119
102
  buttons,
120
103
  onClose: (params: RecommendModalOnCloseParams) => {
104
+ isOpenRetentionSchema = false;
121
105
  switch (params.type) {
122
106
  case 'quit':
123
107
  quitResultDeffer.resolve(false);
@@ -129,7 +113,11 @@ export async function openRetentionSchema() {
129
113
  case 'navigate':
130
114
  // TODO: 跳转游戏
131
115
  if (params.data?.game) {
132
- openGameSchema(params.data.game);
116
+ const game = params.data.game;
117
+ openGameSchema(game);
118
+ setTimeout(() => {
119
+ quitResultDeffer.resolve(false);
120
+ }, 0);
133
121
  } else {
134
122
  quitResultDeffer.resolve(true);
135
123
  }