@onekeyfe/cross-inpage-provider-core 1.1.21 → 1.1.22

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.
package/dist/cjs/index.js CHANGED
@@ -34,6 +34,7 @@ __exportStar(require("./injectedProviderReceiveHandler"), exports);
34
34
  __exportStar(require("./JsBridgeSimple"), exports);
35
35
  __exportStar(require("./JsBridgeIframe"), exports);
36
36
  __exportStar(require("./CrossEventEmitter"), exports);
37
+ __exportStar(require("./walletProperty"), exports);
37
38
  const consts = __importStar(require("./consts"));
38
39
  exports.consts = consts;
39
40
  const injectedFactory_1 = __importDefault(require("./injectedFactory"));
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const version = '1.1.21';
3
+ const version = '1.1.22';
4
4
  const versionBuild = '2020-0101-1';
5
5
  exports.default = {
6
6
  version,
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
3
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.defineWindowProperty = exports.checkEnableDefineProperty = exports.checkWalletSwitchEnable = void 0;
6
+ const consts_1 = require("./consts");
7
+ function checkWalletSwitchEnable(property) {
8
+ try {
9
+ const walletInfoLocalStr = localStorage.getItem(consts_1.WALLET_INFO_LOACAL_KEY);
10
+ const walletInfoLocal = walletInfoLocalStr ? JSON.parse(walletInfoLocalStr) : null;
11
+ if (walletInfoLocal && walletInfoLocal.walletSwitchConfig) {
12
+ const { enable, disable } = walletInfoLocal.walletSwitchConfig;
13
+ const enableList = enable || [];
14
+ const disableList = disable || [];
15
+ return ((enableList.includes(property) && !disableList.includes(property)) ||
16
+ (!enableList.includes(property) && !disableList.includes(property)));
17
+ }
18
+ }
19
+ catch (e) {
20
+ console.error(e);
21
+ }
22
+ return true;
23
+ }
24
+ exports.checkWalletSwitchEnable = checkWalletSwitchEnable;
25
+ function checkEnableDefineProperty(property) {
26
+ if (property === '$onekey')
27
+ return false;
28
+ try {
29
+ const walletInfoLocalStr = localStorage.getItem(consts_1.WALLET_INFO_LOACAL_KEY);
30
+ const walletInfoLocal = walletInfoLocalStr ? JSON.parse(walletInfoLocalStr) : null;
31
+ return !!(walletInfoLocal === null || walletInfoLocal === void 0 ? void 0 : walletInfoLocal.platformEnv.isExtension);
32
+ }
33
+ catch (e) {
34
+ console.error(e);
35
+ }
36
+ return false;
37
+ }
38
+ exports.checkEnableDefineProperty = checkEnableDefineProperty;
39
+ function defineWindowProperty(property, provider) {
40
+ if (!checkWalletSwitchEnable(property))
41
+ return;
42
+ const enable = checkEnableDefineProperty(property);
43
+ const proxyProvider = new Proxy(provider, {
44
+ defineProperty(target, property, attributes) {
45
+ // skip define Prevent overwriting
46
+ return true;
47
+ },
48
+ });
49
+ try {
50
+ if (enable) {
51
+ Object.keys(provider).forEach((key) => {
52
+ var _a;
53
+ ((_a = window[property]) !== null && _a !== void 0 ? _a : {})[key] = proxyProvider[key];
54
+ });
55
+ Object.defineProperty(window, property, {
56
+ configurable: false,
57
+ get() {
58
+ return proxyProvider;
59
+ },
60
+ set(val) {
61
+ // skip set
62
+ },
63
+ });
64
+ }
65
+ else {
66
+ window[property] = provider;
67
+ }
68
+ }
69
+ catch (ex) {
70
+ console.error(ex);
71
+ window[property] = provider;
72
+ }
73
+ }
74
+ exports.defineWindowProperty = defineWindowProperty;
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export * from './injectedProviderReceiveHandler';
6
6
  export * from './JsBridgeSimple';
7
7
  export * from './JsBridgeIframe';
8
8
  export * from './CrossEventEmitter';
9
+ export * from './walletProperty';
9
10
  import * as consts from './consts';
10
11
  export { consts };
11
12
  import injectedFactory from './injectedFactory';
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ export * from './injectedProviderReceiveHandler';
6
6
  export * from './JsBridgeSimple';
7
7
  export * from './JsBridgeIframe';
8
8
  export * from './CrossEventEmitter';
9
+ export * from './walletProperty';
9
10
  import * as consts from './consts';
10
11
  export { consts };
11
12
  import injectedFactory from './injectedFactory';
@@ -1,4 +1,4 @@
1
- const version = '1.1.21';
1
+ const version = '1.1.22';
2
2
  const versionBuild = '2020-0101-1';
3
3
  export default {
4
4
  version,
@@ -0,0 +1,3 @@
1
+ export declare function checkWalletSwitchEnable(property: string): boolean;
2
+ export declare function checkEnableDefineProperty(property: string): boolean;
3
+ export declare function defineWindowProperty(property: string, provider: unknown): void;
@@ -0,0 +1,68 @@
1
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
2
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
3
+ import { WALLET_INFO_LOACAL_KEY } from './consts';
4
+ export function checkWalletSwitchEnable(property) {
5
+ try {
6
+ const walletInfoLocalStr = localStorage.getItem(WALLET_INFO_LOACAL_KEY);
7
+ const walletInfoLocal = walletInfoLocalStr ? JSON.parse(walletInfoLocalStr) : null;
8
+ if (walletInfoLocal && walletInfoLocal.walletSwitchConfig) {
9
+ const { enable, disable } = walletInfoLocal.walletSwitchConfig;
10
+ const enableList = enable || [];
11
+ const disableList = disable || [];
12
+ return ((enableList.includes(property) && !disableList.includes(property)) ||
13
+ (!enableList.includes(property) && !disableList.includes(property)));
14
+ }
15
+ }
16
+ catch (e) {
17
+ console.error(e);
18
+ }
19
+ return true;
20
+ }
21
+ export function checkEnableDefineProperty(property) {
22
+ if (property === '$onekey')
23
+ return false;
24
+ try {
25
+ const walletInfoLocalStr = localStorage.getItem(WALLET_INFO_LOACAL_KEY);
26
+ const walletInfoLocal = walletInfoLocalStr ? JSON.parse(walletInfoLocalStr) : null;
27
+ return !!(walletInfoLocal === null || walletInfoLocal === void 0 ? void 0 : walletInfoLocal.platformEnv.isExtension);
28
+ }
29
+ catch (e) {
30
+ console.error(e);
31
+ }
32
+ return false;
33
+ }
34
+ export function defineWindowProperty(property, provider) {
35
+ if (!checkWalletSwitchEnable(property))
36
+ return;
37
+ const enable = checkEnableDefineProperty(property);
38
+ const proxyProvider = new Proxy(provider, {
39
+ defineProperty(target, property, attributes) {
40
+ // skip define Prevent overwriting
41
+ return true;
42
+ },
43
+ });
44
+ try {
45
+ if (enable) {
46
+ Object.keys(provider).forEach((key) => {
47
+ var _a;
48
+ ((_a = window[property]) !== null && _a !== void 0 ? _a : {})[key] = proxyProvider[key];
49
+ });
50
+ Object.defineProperty(window, property, {
51
+ configurable: false,
52
+ get() {
53
+ return proxyProvider;
54
+ },
55
+ set(val) {
56
+ // skip set
57
+ },
58
+ });
59
+ }
60
+ else {
61
+ window[property] = provider;
62
+ }
63
+ }
64
+ catch (ex) {
65
+ console.error(ex);
66
+ window[property] = provider;
67
+ }
68
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/cross-inpage-provider-core",
3
- "version": "1.1.21",
3
+ "version": "1.1.22",
4
4
  "keywords": [
5
5
  "cross-inpage-provider"
6
6
  ],
@@ -29,12 +29,12 @@
29
29
  "build-version-info": "node ./scripts/buildVersionInfo.js"
30
30
  },
31
31
  "dependencies": {
32
- "@onekeyfe/cross-inpage-provider-errors": "1.1.21",
33
- "@onekeyfe/cross-inpage-provider-events": "1.1.21",
34
- "@onekeyfe/cross-inpage-provider-types": "1.1.21",
32
+ "@onekeyfe/cross-inpage-provider-errors": "1.1.22",
33
+ "@onekeyfe/cross-inpage-provider-events": "1.1.22",
34
+ "@onekeyfe/cross-inpage-provider-types": "1.1.22",
35
35
  "events": "^3.3.0",
36
36
  "lodash": "^4.17.21",
37
37
  "ms": "^2.1.3"
38
38
  },
39
- "gitHead": "1a4b0188d8795ae0a3fed605fa53c056b6966b6a"
39
+ "gitHead": "605e8793b6ec2251f0f0c39cf13381495a1be500"
40
40
  }