@onekeyfe/cross-inpage-provider-core 2.0.2 → 2.0.4

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,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const version = '2.0.2';
3
+ const version = '2.0.4';
4
4
  const versionBuild = '2020-0101-1';
5
5
  exports.default = {
6
6
  version,
@@ -3,7 +3,7 @@
3
3
  /* eslint-disable @typescript-eslint/no-unsafe-member-access */
4
4
  /* eslint-disable @typescript-eslint/no-unsafe-assignment */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.defineWindowProperty = exports.checkEnableDefineProperty = exports.checkWalletSwitchEnable = exports.ISpecialPropertyProviderNamesReflection = void 0;
6
+ exports.defineWindowProperty = exports.checkEnableDefineProperty = exports.checkWalletSwitchEnable = exports.checkPlatformEnable = exports.ISpecialPropertyProviderNamesReflection = void 0;
7
7
  const consts_1 = require("./consts");
8
8
  const loggerConsole_1 = require("./loggerConsole");
9
9
  /**
@@ -18,6 +18,32 @@ var ISpecialPropertyProviderNamesReflection;
18
18
  ISpecialPropertyProviderNamesReflection["sui"] = "suiWallet";
19
19
  ISpecialPropertyProviderNamesReflection["polkadot"] = "polkadot-js";
20
20
  })(ISpecialPropertyProviderNamesReflection = exports.ISpecialPropertyProviderNamesReflection || (exports.ISpecialPropertyProviderNamesReflection = {}));
21
+ function checkPlatformEnable(disablePlatform) {
22
+ var _a, _b, _c, _d;
23
+ const walletInfoLocalStr = localStorage.getItem(consts_1.WALLET_INFO_LOACAL_KEY_V5);
24
+ const walletInfoLocal = walletInfoLocalStr ? JSON.parse(walletInfoLocalStr) : null;
25
+ if (!walletInfoLocal) {
26
+ return true;
27
+ }
28
+ if (disablePlatform) {
29
+ for (const platform of disablePlatform) {
30
+ if (platform === 'web' && ((_a = walletInfoLocal === null || walletInfoLocal === void 0 ? void 0 : walletInfoLocal.platformEnv) === null || _a === void 0 ? void 0 : _a.isWeb)) {
31
+ return false;
32
+ }
33
+ if (platform === 'desktop' && ((_b = walletInfoLocal === null || walletInfoLocal === void 0 ? void 0 : walletInfoLocal.platformEnv) === null || _b === void 0 ? void 0 : _b.isDesktop)) {
34
+ return false;
35
+ }
36
+ if (platform === 'extension' && ((_c = walletInfoLocal === null || walletInfoLocal === void 0 ? void 0 : walletInfoLocal.platformEnv) === null || _c === void 0 ? void 0 : _c.isExtension)) {
37
+ return false;
38
+ }
39
+ if (platform === 'native' && ((_d = walletInfoLocal === null || walletInfoLocal === void 0 ? void 0 : walletInfoLocal.platformEnv) === null || _d === void 0 ? void 0 : _d.isNative)) {
40
+ return false;
41
+ }
42
+ }
43
+ }
44
+ return true;
45
+ }
46
+ exports.checkPlatformEnable = checkPlatformEnable;
21
47
  function checkWalletSwitchEnable() {
22
48
  try {
23
49
  const walletInfoLocalStr = localStorage.getItem(consts_1.WALLET_INFO_LOACAL_KEY_V5);
@@ -65,6 +91,8 @@ function checkEnableDefineProperty(property) {
65
91
  exports.checkEnableDefineProperty = checkEnableDefineProperty;
66
92
  function defineWindowProperty(property, provider, options) {
67
93
  var _a;
94
+ if (!checkPlatformEnable(options === null || options === void 0 ? void 0 : options.disablePlatform))
95
+ return;
68
96
  if (!checkWalletSwitchEnable())
69
97
  return;
70
98
  const enable = checkEnableDefineProperty(property);
@@ -1,4 +1,4 @@
1
- const version = '2.0.2';
1
+ const version = '2.0.4';
2
2
  const versionBuild = '2020-0101-1';
3
3
  export default {
4
4
  version,
@@ -9,8 +9,11 @@ export declare enum ISpecialPropertyProviderNamesReflection {
9
9
  sui = "suiWallet",
10
10
  polkadot = "polkadot-js"
11
11
  }
12
+ export type IPlatformType = 'native' | 'extension' | 'web' | 'desktop';
13
+ export declare function checkPlatformEnable(disablePlatform?: IPlatformType[]): boolean;
12
14
  export declare function checkWalletSwitchEnable(): boolean;
13
15
  export declare function checkEnableDefineProperty(property: string): boolean;
14
16
  export declare function defineWindowProperty(property: string, provider: unknown, options?: {
15
17
  enumerable?: boolean;
18
+ disablePlatform?: IPlatformType[];
16
19
  }): void;
@@ -15,6 +15,31 @@ export var ISpecialPropertyProviderNamesReflection;
15
15
  ISpecialPropertyProviderNamesReflection["sui"] = "suiWallet";
16
16
  ISpecialPropertyProviderNamesReflection["polkadot"] = "polkadot-js";
17
17
  })(ISpecialPropertyProviderNamesReflection || (ISpecialPropertyProviderNamesReflection = {}));
18
+ export function checkPlatformEnable(disablePlatform) {
19
+ var _a, _b, _c, _d;
20
+ const walletInfoLocalStr = localStorage.getItem(WALLET_INFO_LOACAL_KEY_V5);
21
+ const walletInfoLocal = walletInfoLocalStr ? JSON.parse(walletInfoLocalStr) : null;
22
+ if (!walletInfoLocal) {
23
+ return true;
24
+ }
25
+ if (disablePlatform) {
26
+ for (const platform of disablePlatform) {
27
+ if (platform === 'web' && ((_a = walletInfoLocal === null || walletInfoLocal === void 0 ? void 0 : walletInfoLocal.platformEnv) === null || _a === void 0 ? void 0 : _a.isWeb)) {
28
+ return false;
29
+ }
30
+ if (platform === 'desktop' && ((_b = walletInfoLocal === null || walletInfoLocal === void 0 ? void 0 : walletInfoLocal.platformEnv) === null || _b === void 0 ? void 0 : _b.isDesktop)) {
31
+ return false;
32
+ }
33
+ if (platform === 'extension' && ((_c = walletInfoLocal === null || walletInfoLocal === void 0 ? void 0 : walletInfoLocal.platformEnv) === null || _c === void 0 ? void 0 : _c.isExtension)) {
34
+ return false;
35
+ }
36
+ if (platform === 'native' && ((_d = walletInfoLocal === null || walletInfoLocal === void 0 ? void 0 : walletInfoLocal.platformEnv) === null || _d === void 0 ? void 0 : _d.isNative)) {
37
+ return false;
38
+ }
39
+ }
40
+ }
41
+ return true;
42
+ }
18
43
  export function checkWalletSwitchEnable() {
19
44
  try {
20
45
  const walletInfoLocalStr = localStorage.getItem(WALLET_INFO_LOACAL_KEY_V5);
@@ -60,6 +85,8 @@ export function checkEnableDefineProperty(property) {
60
85
  }
61
86
  export function defineWindowProperty(property, provider, options) {
62
87
  var _a;
88
+ if (!checkPlatformEnable(options === null || options === void 0 ? void 0 : options.disablePlatform))
89
+ return;
63
90
  if (!checkWalletSwitchEnable())
64
91
  return;
65
92
  const enable = checkEnableDefineProperty(property);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/cross-inpage-provider-core",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "keywords": [
5
5
  "cross-inpage-provider"
6
6
  ],
@@ -29,9 +29,9 @@
29
29
  "build-version-info": "node ./scripts/buildVersionInfo.js"
30
30
  },
31
31
  "dependencies": {
32
- "@onekeyfe/cross-inpage-provider-errors": "2.0.2",
33
- "@onekeyfe/cross-inpage-provider-events": "2.0.2",
34
- "@onekeyfe/cross-inpage-provider-types": "2.0.2",
32
+ "@onekeyfe/cross-inpage-provider-errors": "2.0.4",
33
+ "@onekeyfe/cross-inpage-provider-events": "2.0.4",
34
+ "@onekeyfe/cross-inpage-provider-types": "2.0.4",
35
35
  "events": "^3.3.0",
36
36
  "lodash-es": "^4.17.21",
37
37
  "ms": "^2.1.3"
@@ -39,5 +39,5 @@
39
39
  "devDependencies": {
40
40
  "@types/lodash-es": "^4.17.12"
41
41
  },
42
- "gitHead": "c1fc3cc6ea25726034b1f610fd1de95be8faf6c2"
42
+ "gitHead": "7f33acd16a25d7b1aa4d9a439d7474622630f2fc"
43
43
  }