@portal-hq/connect 1.1.0 → 1.1.2
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/lib/commonjs/index.js
CHANGED
|
@@ -77,6 +77,7 @@ class PortalConnect {
|
|
|
77
77
|
Authorization: `Bearer ${this.apiKey}`,
|
|
78
78
|
},
|
|
79
79
|
});
|
|
80
|
+
this.uri = uri;
|
|
80
81
|
this.bindToSocketEvents(this.socket, uri);
|
|
81
82
|
});
|
|
82
83
|
}
|
|
@@ -86,6 +87,16 @@ class PortalConnect {
|
|
|
86
87
|
disconnect() {
|
|
87
88
|
this.sendFinalMessageAndClose();
|
|
88
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Triggers the chain on the dapp to change to match the chain of the wallet
|
|
92
|
+
*
|
|
93
|
+
* @param chainId The number of the chainId to switch to
|
|
94
|
+
*/
|
|
95
|
+
setChainId(chainId) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
this.provider.setChainId(chainId, this);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
89
100
|
/**
|
|
90
101
|
* Invokes all registered event handlers with the data provided
|
|
91
102
|
* - If any `once` handlers exist, they are removed after all handlers are invoked
|
|
@@ -186,6 +197,18 @@ class PortalConnect {
|
|
|
186
197
|
},
|
|
187
198
|
}));
|
|
188
199
|
});
|
|
200
|
+
this.on('portalConnect_chainChanged', (data) => {
|
|
201
|
+
var _a;
|
|
202
|
+
// Tell the proxy server where to connect to downstream
|
|
203
|
+
(_a = this.socket) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify({
|
|
204
|
+
event: 'portal_chainChanged',
|
|
205
|
+
data: {
|
|
206
|
+
topic: this.topic,
|
|
207
|
+
uri: this.uri,
|
|
208
|
+
chainId: data.chainId,
|
|
209
|
+
},
|
|
210
|
+
}));
|
|
211
|
+
});
|
|
189
212
|
socket.onerror = (event) => __awaiter(this, void 0, void 0, function* () {
|
|
190
213
|
let errorMessage = 'An unexpected error occurred.';
|
|
191
214
|
if (event instanceof ErrorEvent) {
|
package/lib/esm/index.js
CHANGED
|
@@ -74,6 +74,7 @@ class PortalConnect {
|
|
|
74
74
|
Authorization: `Bearer ${this.apiKey}`,
|
|
75
75
|
},
|
|
76
76
|
});
|
|
77
|
+
this.uri = uri;
|
|
77
78
|
this.bindToSocketEvents(this.socket, uri);
|
|
78
79
|
});
|
|
79
80
|
}
|
|
@@ -83,6 +84,16 @@ class PortalConnect {
|
|
|
83
84
|
disconnect() {
|
|
84
85
|
this.sendFinalMessageAndClose();
|
|
85
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Triggers the chain on the dapp to change to match the chain of the wallet
|
|
89
|
+
*
|
|
90
|
+
* @param chainId The number of the chainId to switch to
|
|
91
|
+
*/
|
|
92
|
+
setChainId(chainId) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
this.provider.setChainId(chainId, this);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
86
97
|
/**
|
|
87
98
|
* Invokes all registered event handlers with the data provided
|
|
88
99
|
* - If any `once` handlers exist, they are removed after all handlers are invoked
|
|
@@ -183,6 +194,18 @@ class PortalConnect {
|
|
|
183
194
|
},
|
|
184
195
|
}));
|
|
185
196
|
});
|
|
197
|
+
this.on('portalConnect_chainChanged', (data) => {
|
|
198
|
+
var _a;
|
|
199
|
+
// Tell the proxy server where to connect to downstream
|
|
200
|
+
(_a = this.socket) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify({
|
|
201
|
+
event: 'portal_chainChanged',
|
|
202
|
+
data: {
|
|
203
|
+
topic: this.topic,
|
|
204
|
+
uri: this.uri,
|
|
205
|
+
chainId: data.chainId,
|
|
206
|
+
},
|
|
207
|
+
}));
|
|
208
|
+
});
|
|
186
209
|
socket.onerror = (event) => __awaiter(this, void 0, void 0, function* () {
|
|
187
210
|
let errorMessage = 'An unexpected error occurred.';
|
|
188
211
|
if (event instanceof ErrorEvent) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portal-hq/connect",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"main": "lib/commonjs/index",
|
|
5
5
|
"module": "lib/esm/index",
|
|
6
6
|
"source": "src/index",
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"react": "*",
|
|
33
33
|
"react-native": "*"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "fe11c271c1d85aca8f4e323a5a69b277483dbe89"
|
|
36
36
|
}
|
package/src/index.ts
CHANGED
|
@@ -8,13 +8,16 @@ import type {
|
|
|
8
8
|
SessionRequest,
|
|
9
9
|
WebsocketMessage,
|
|
10
10
|
} from '../types.d'
|
|
11
|
+
import { IPortalProvider } from '@portal-hq/utils'
|
|
12
|
+
import { SwitchEthereumChainParameter } from '@portal-hq/provider/types'
|
|
11
13
|
|
|
12
14
|
class PortalConnect {
|
|
13
15
|
private apiKey: string
|
|
14
16
|
private connectionState: ConnectionStates = ConnectionStates.DISCONNECTED
|
|
15
|
-
private provider:
|
|
17
|
+
private provider: IPortalProvider
|
|
16
18
|
private socket?: WebSocket
|
|
17
19
|
private topic?: string
|
|
20
|
+
private uri?: string
|
|
18
21
|
private websocketServer: string
|
|
19
22
|
|
|
20
23
|
private events: Record<string, RegisteredEventHandler[]>
|
|
@@ -108,6 +111,7 @@ class PortalConnect {
|
|
|
108
111
|
},
|
|
109
112
|
},
|
|
110
113
|
)
|
|
114
|
+
this.uri = uri
|
|
111
115
|
this.bindToSocketEvents(this.socket, uri)
|
|
112
116
|
}
|
|
113
117
|
|
|
@@ -119,6 +123,15 @@ class PortalConnect {
|
|
|
119
123
|
this.sendFinalMessageAndClose()
|
|
120
124
|
}
|
|
121
125
|
|
|
126
|
+
/**
|
|
127
|
+
* Triggers the chain on the dapp to change to match the chain of the wallet
|
|
128
|
+
*
|
|
129
|
+
* @param chainId The number of the chainId to switch to
|
|
130
|
+
*/
|
|
131
|
+
public async setChainId(chainId: number): Promise<void> {
|
|
132
|
+
this.provider.setChainId(chainId, this)
|
|
133
|
+
}
|
|
134
|
+
|
|
122
135
|
/**
|
|
123
136
|
* Invokes all registered event handlers with the data provided
|
|
124
137
|
* - If any `once` handlers exist, they are removed after all handlers are invoked
|
|
@@ -240,6 +253,20 @@ class PortalConnect {
|
|
|
240
253
|
)
|
|
241
254
|
}
|
|
242
255
|
|
|
256
|
+
this.on('portalConnect_chainChanged', (data) => {
|
|
257
|
+
// Tell the proxy server where to connect to downstream
|
|
258
|
+
this.socket?.send(
|
|
259
|
+
JSON.stringify({
|
|
260
|
+
event: 'portal_chainChanged',
|
|
261
|
+
data: {
|
|
262
|
+
topic: this.topic,
|
|
263
|
+
uri: this.uri,
|
|
264
|
+
chainId: (data as SwitchEthereumChainParameter).chainId,
|
|
265
|
+
},
|
|
266
|
+
}),
|
|
267
|
+
)
|
|
268
|
+
})
|
|
269
|
+
|
|
243
270
|
socket.onerror = async (event: Event) => {
|
|
244
271
|
let errorMessage = 'An unexpected error occurred.'
|
|
245
272
|
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const react_1 = __importDefault(require("react"));
|
|
7
|
-
const react_native_1 = require("react-native");
|
|
8
|
-
const WalletScanner = () => {
|
|
9
|
-
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
10
|
-
react_1.default.createElement(react_native_1.Text, null, "Yo!")));
|
|
11
|
-
};
|
|
12
|
-
exports.default = WalletScanner;
|