@onekeyfe/onekey-private-provider 1.1.7 → 1.1.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.
|
@@ -2,6 +2,7 @@ import { IInjectedProviderNamesStrings } from '@onekeyfe/cross-inpage-provider-t
|
|
|
2
2
|
import { IInpageProviderConfig, ProviderBase } from '@onekeyfe/cross-inpage-provider-core';
|
|
3
3
|
declare class ProviderPrivate extends ProviderBase {
|
|
4
4
|
constructor(props: IInpageProviderConfig);
|
|
5
|
+
private _registerEvents;
|
|
5
6
|
protected providerName: IInjectedProviderNamesStrings;
|
|
6
7
|
request(data: unknown): Promise<unknown>;
|
|
7
8
|
}
|
package/dist/ProviderPrivate.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { IInjectedProviderNames, } from '@onekeyfe/cross-inpage-provider-types';
|
|
2
2
|
import { ProviderBase } from '@onekeyfe/cross-inpage-provider-core';
|
|
3
|
+
import { consts } from '@onekeyfe/cross-inpage-provider-core';
|
|
4
|
+
const { WALLET_INFO_LOACAL_KEY } = consts;
|
|
5
|
+
const PROVIDER_EVENTS = {
|
|
6
|
+
'message_low_level': 'message_low_level',
|
|
7
|
+
};
|
|
8
|
+
const METHODS = {
|
|
9
|
+
wallet_events_ext_switch_changed: 'wallet_events_ext_switch_changed',
|
|
10
|
+
};
|
|
3
11
|
class ProviderPrivate extends ProviderBase {
|
|
4
12
|
constructor(props) {
|
|
5
13
|
super(props);
|
|
@@ -16,6 +24,33 @@ class ProviderPrivate extends ProviderBase {
|
|
|
16
24
|
catch (error) {
|
|
17
25
|
console.error(error);
|
|
18
26
|
}
|
|
27
|
+
this._registerEvents();
|
|
28
|
+
}
|
|
29
|
+
_registerEvents() {
|
|
30
|
+
try {
|
|
31
|
+
// platform check
|
|
32
|
+
const walletInfoLocalStr = localStorage.getItem(WALLET_INFO_LOACAL_KEY);
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
34
|
+
const walletInfoLocal = walletInfoLocalStr ? JSON.parse(walletInfoLocalStr) : null;
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
36
|
+
if (!walletInfoLocal || (walletInfoLocal && walletInfoLocal.platformEnv.isExtension)) {
|
|
37
|
+
this.on(PROVIDER_EVENTS.message_low_level, (payload) => {
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
39
|
+
const { method, params } = payload;
|
|
40
|
+
if (method === METHODS.wallet_events_ext_switch_changed) {
|
|
41
|
+
try {
|
|
42
|
+
localStorage.setItem(WALLET_INFO_LOACAL_KEY, JSON.stringify(params));
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
console.error(e);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
console.error(e);
|
|
53
|
+
}
|
|
19
54
|
}
|
|
20
55
|
request(data) {
|
|
21
56
|
return this.bridgeRequest(data);
|
|
@@ -3,6 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ProviderPrivate = void 0;
|
|
4
4
|
const cross_inpage_provider_types_1 = require("@onekeyfe/cross-inpage-provider-types");
|
|
5
5
|
const cross_inpage_provider_core_1 = require("@onekeyfe/cross-inpage-provider-core");
|
|
6
|
+
const cross_inpage_provider_core_2 = require("@onekeyfe/cross-inpage-provider-core");
|
|
7
|
+
const { WALLET_INFO_LOACAL_KEY } = cross_inpage_provider_core_2.consts;
|
|
8
|
+
const PROVIDER_EVENTS = {
|
|
9
|
+
'message_low_level': 'message_low_level',
|
|
10
|
+
};
|
|
11
|
+
const METHODS = {
|
|
12
|
+
wallet_events_ext_switch_changed: 'wallet_events_ext_switch_changed',
|
|
13
|
+
};
|
|
6
14
|
class ProviderPrivate extends cross_inpage_provider_core_1.ProviderBase {
|
|
7
15
|
constructor(props) {
|
|
8
16
|
super(props);
|
|
@@ -19,6 +27,33 @@ class ProviderPrivate extends cross_inpage_provider_core_1.ProviderBase {
|
|
|
19
27
|
catch (error) {
|
|
20
28
|
console.error(error);
|
|
21
29
|
}
|
|
30
|
+
this._registerEvents();
|
|
31
|
+
}
|
|
32
|
+
_registerEvents() {
|
|
33
|
+
try {
|
|
34
|
+
// platform check
|
|
35
|
+
const walletInfoLocalStr = localStorage.getItem(WALLET_INFO_LOACAL_KEY);
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
37
|
+
const walletInfoLocal = walletInfoLocalStr ? JSON.parse(walletInfoLocalStr) : null;
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
39
|
+
if (!walletInfoLocal || (walletInfoLocal && walletInfoLocal.platformEnv.isExtension)) {
|
|
40
|
+
this.on(PROVIDER_EVENTS.message_low_level, (payload) => {
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
42
|
+
const { method, params } = payload;
|
|
43
|
+
if (method === METHODS.wallet_events_ext_switch_changed) {
|
|
44
|
+
try {
|
|
45
|
+
localStorage.setItem(WALLET_INFO_LOACAL_KEY, JSON.stringify(params));
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
console.error(e);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
console.error(e);
|
|
56
|
+
}
|
|
22
57
|
}
|
|
23
58
|
request(data) {
|
|
24
59
|
return this.bridgeRequest(data);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/onekey-private-provider",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"cross-inpage-provider"
|
|
6
6
|
],
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"start": "tsc --watch"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@onekeyfe/cross-inpage-provider-core": "1.1.
|
|
32
|
-
"@onekeyfe/cross-inpage-provider-errors": "1.1.
|
|
33
|
-
"@onekeyfe/cross-inpage-provider-types": "1.1.
|
|
34
|
-
"@onekeyfe/extension-bridge-injected": "1.1.
|
|
31
|
+
"@onekeyfe/cross-inpage-provider-core": "1.1.9",
|
|
32
|
+
"@onekeyfe/cross-inpage-provider-errors": "1.1.9",
|
|
33
|
+
"@onekeyfe/cross-inpage-provider-types": "1.1.9",
|
|
34
|
+
"@onekeyfe/extension-bridge-injected": "1.1.9"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "f85353fac92b26f8f0923ad669a99f2dc4d22dc7"
|
|
37
37
|
}
|