@jolibox/implement 1.3.2 → 1.3.3-beta.1

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.
@@ -11,3 +11,4 @@ import './runtime';
11
11
  import './is-native-support';
12
12
  import './call-host-method';
13
13
  import './payment';
14
+ import './rewards';
@@ -0,0 +1 @@
1
+ export {};
@@ -1,9 +1,9 @@
1
1
  Invoking: npm run clean && npm run build:esm && tsc
2
2
 
3
- > @jolibox/implement@1.3.2 clean
3
+ > @jolibox/implement@1.3.3-beta.1 clean
4
4
  > rimraf ./dist
5
5
 
6
6
 
7
- > @jolibox/implement@1.3.2 build:esm
7
+ > @jolibox/implement@1.3.3-beta.1 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,17 +1,17 @@
1
1
  {
2
2
  "name": "@jolibox/implement",
3
3
  "description": "This project is Jolibox JS-SDk implement for Native && H5",
4
- "version": "1.3.2",
4
+ "version": "1.3.3-beta.1",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
7
7
  "license": "MIT",
8
8
  "dependencies": {
9
- "@jolibox/common": "1.3.2",
10
- "@jolibox/types": "1.3.2",
11
- "@jolibox/native-bridge": "1.3.2",
12
- "@jolibox/ads": "1.3.2",
9
+ "@jolibox/common": "1.3.3-beta.1",
10
+ "@jolibox/types": "1.3.3-beta.1",
11
+ "@jolibox/native-bridge": "1.3.3-beta.1",
12
+ "@jolibox/ads": "1.3.3-beta.1",
13
13
  "localforage": "1.10.0",
14
- "@jolibox/ui": "1.0.0",
14
+ "@jolibox/ui": "1.3.3-beta.1",
15
15
  "web-vitals": "4.2.4"
16
16
  },
17
17
  "devDependencies": {
@@ -20,7 +20,7 @@
20
20
  "@types/node": "18.0.0",
21
21
  "rimraf": "6.0.1",
22
22
  "esbuild": "0.24.2",
23
- "@jolibox/eslint-config": "1.0.0"
23
+ "@jolibox/eslint-config": "1.0.1-beta.16"
24
24
  },
25
25
  "scripts": {
26
26
  "clean": "rimraf ./dist",
@@ -11,3 +11,4 @@ import './runtime';
11
11
  import './is-native-support';
12
12
  import './call-host-method';
13
13
  import './payment';
14
+ import './rewards';
@@ -0,0 +1,85 @@
1
+ import { BaseError, createCommands, wrapUserFunction } from '@jolibox/common';
2
+ import { canIUseNative, createAPI, registerCanIUse, t } from './base';
3
+ import { StandardResponse, ICoinDetailsData } from '@jolibox/types';
4
+ import { context } from '@/common/context';
5
+ import { createAPIError } from '@/common/report/errors';
6
+ import { invokeNative } from '@jolibox/native-bridge';
7
+
8
+ const commands = createCommands();
9
+
10
+ const safeCallbackWrapper = wrapUserFunction(reportError as (err: Error | BaseError) => void);
11
+
12
+ const getCoinDetails = createAPI('getCoinDetails', {
13
+ paramsSchema: t.tuple(t.object({ onUpdate: t.function().optional() })),
14
+ implement: async ({
15
+ onUpdate
16
+ }: {
17
+ onUpdate?: (data: ICoinDetailsData) => void | Promise<void>;
18
+ }): Promise<StandardResponse<ICoinDetailsData>> => {
19
+ try {
20
+ const currentType = context.mpType;
21
+ // check mp type
22
+ if (currentType !== 'miniApp') {
23
+ reportError(
24
+ createAPIError({
25
+ code: -1,
26
+ msg: '[JoliboxSDK]: rewards info not supported in games. Only supported in mini apps.'
27
+ })
28
+ );
29
+ return {
30
+ code: 'FAILURE',
31
+ message: '[JoliboxSDK]: rewards info not supported in games. Only supported in mini apps.'
32
+ };
33
+ }
34
+
35
+ // check native version
36
+ if (!canIUseNative('requestCoinDetailsSync')) {
37
+ reportError(
38
+ createAPIError({
39
+ code: -1,
40
+ msg: '[JoliboxSDK]: rewards info not supported in this platform.'
41
+ })
42
+ );
43
+ return {
44
+ code: 'FAILURE',
45
+ message: '[JoliboxSDK]: rewards info not supported in this platform. lower than 1.7.1'
46
+ };
47
+ }
48
+
49
+ const customOnUpdate = onUpdate
50
+ ? safeCallbackWrapper(onUpdate)
51
+ : (() => {
52
+ console.log('default update function called');
53
+ }).bind(this);
54
+ const { errNo, errMsg, data } = invokeNative('requestCoinDetailsSync');
55
+ if (errNo !== 0) {
56
+ throw createAPIError({
57
+ code: errNo ?? -1,
58
+ msg: errMsg
59
+ });
60
+ }
61
+
62
+ invokeNative('requestCoinDetailsAsync').then((res) => {
63
+ if (res.errNo == 0 && res.data) {
64
+ customOnUpdate(res.data);
65
+ }
66
+ });
67
+ return {
68
+ code: 'SUCCESS',
69
+ message: 'Successfully retrieved coin details',
70
+ data
71
+ };
72
+ } catch (error) {
73
+ return {
74
+ code: 'FAILURE',
75
+ message: '[JoliboxSDK]: Failed to get coin details: ' + (error as Error).message
76
+ };
77
+ }
78
+ }
79
+ });
80
+
81
+ commands.registerCommand('RewardsSDK.getCoinDetails', getCoinDetails);
82
+
83
+ registerCanIUse('rewards.getCoinDetails', {
84
+ version: '1.3.2'
85
+ });