@portal-hq/connect 3.0.6-rcb → 4.0.0
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 +48 -17
- package/lib/esm/index.js +48 -17
- package/package.json +3 -2
- package/src/index.ts +52 -16
- package/types.d.ts +2 -2
- package/lib/commonjs/components/scanner/index.js +0 -12
- package/lib/esm/components/scanner/index.js +0 -7
package/lib/commonjs/index.js
CHANGED
|
@@ -15,14 +15,11 @@ class PortalConnect {
|
|
|
15
15
|
get address() {
|
|
16
16
|
return this.provider.address;
|
|
17
17
|
}
|
|
18
|
-
get chainId() {
|
|
19
|
-
return this.provider.chainId;
|
|
20
|
-
}
|
|
21
18
|
get connected() {
|
|
22
19
|
return (this.connectionState === ConnectionStates.CONNECTED ||
|
|
23
20
|
this.connectionState === ConnectionStates.CONNECTING);
|
|
24
21
|
}
|
|
25
|
-
constructor({ apiKey,
|
|
22
|
+
constructor({ apiKey, keychain, gatewayConfig, chainId,
|
|
26
23
|
// Optional
|
|
27
24
|
isSimulator = false, autoApprove = false, version = 'v6', apiHost = 'api.portalhq.io', mpcHost = 'mpc.portalhq.io', webSocketServer = 'connect.portalhq.io', }) {
|
|
28
25
|
this.connectionState = ConnectionStates.DISCONNECTED;
|
|
@@ -42,9 +39,9 @@ class PortalConnect {
|
|
|
42
39
|
this.events = {};
|
|
43
40
|
this.websocketServer = webSocketServer;
|
|
44
41
|
this.gatewayConfig = gatewayConfig;
|
|
42
|
+
this.chainId = chainId;
|
|
45
43
|
this.provider = new provider_1.Provider({
|
|
46
44
|
apiKey,
|
|
47
|
-
chainId,
|
|
48
45
|
gatewayConfig,
|
|
49
46
|
keychain,
|
|
50
47
|
isSimulator,
|
|
@@ -105,7 +102,7 @@ class PortalConnect {
|
|
|
105
102
|
*/
|
|
106
103
|
setChainId(chainId) {
|
|
107
104
|
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
-
yield this.provider.setChainId(chainId
|
|
105
|
+
yield this.provider.setChainId(`eip155:${chainId}`, this);
|
|
109
106
|
});
|
|
110
107
|
}
|
|
111
108
|
/**
|
|
@@ -189,11 +186,12 @@ class PortalConnect {
|
|
|
189
186
|
* @returns session proposal with chains from gateway config added
|
|
190
187
|
*/
|
|
191
188
|
addChainsToProposal(proposal) {
|
|
189
|
+
var _a;
|
|
192
190
|
if (!('params' in proposal) || !('requiredNamespaces' in proposal.params)) {
|
|
193
191
|
throw new Error('Invalid proposal structure.');
|
|
194
192
|
}
|
|
195
193
|
// Ensure eip155 is present in requiredNamespaces
|
|
196
|
-
if (!proposal.params.requiredNamespaces.eip155) {
|
|
194
|
+
if (!((_a = proposal.params.requiredNamespaces) === null || _a === void 0 ? void 0 : _a.eip155)) {
|
|
197
195
|
proposal.params.requiredNamespaces.eip155 = {
|
|
198
196
|
chains: [],
|
|
199
197
|
methods: [],
|
|
@@ -204,7 +202,16 @@ class PortalConnect {
|
|
|
204
202
|
// Get chains from gatewayConfig with 'eip155:' prefix, but only if they're not already in the proposal
|
|
205
203
|
const existingChains = proposal.params.requiredNamespaces.eip155.chains;
|
|
206
204
|
const newChains = Object.keys(this.gatewayConfig)
|
|
207
|
-
.
|
|
205
|
+
.filter((chain) => !chain.includes('solana:')) // Remove chains that include 'solana:'
|
|
206
|
+
.reduce((acc, chain) => {
|
|
207
|
+
if (chain.includes('eip155')) {
|
|
208
|
+
acc.push(chain);
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
acc.push(`eip155:${chain}`);
|
|
212
|
+
}
|
|
213
|
+
return acc;
|
|
214
|
+
}, [])
|
|
208
215
|
.filter((chain) => !existingChains.includes(chain));
|
|
209
216
|
// Append new chains to the existing chains
|
|
210
217
|
proposal.params.requiredNamespaces.eip155.chains = [
|
|
@@ -228,13 +235,12 @@ class PortalConnect {
|
|
|
228
235
|
socket.onopen = () => __awaiter(this, void 0, void 0, function* () {
|
|
229
236
|
this.connectionState = ConnectionStates.CONNECTING;
|
|
230
237
|
const address = yield this.address;
|
|
231
|
-
const { chainId } = this.provider;
|
|
232
238
|
// Tell the proxy server where to connect to downstream
|
|
233
239
|
socket.send(JSON.stringify({
|
|
234
240
|
event: 'connect',
|
|
235
241
|
data: {
|
|
236
242
|
address,
|
|
237
|
-
chainId,
|
|
243
|
+
chainId: this.chainId,
|
|
238
244
|
uri,
|
|
239
245
|
},
|
|
240
246
|
}));
|
|
@@ -327,19 +333,34 @@ class PortalConnect {
|
|
|
327
333
|
}
|
|
328
334
|
});
|
|
329
335
|
// Pass the request along to the provider
|
|
330
|
-
yield this.provider.request({
|
|
336
|
+
yield this.provider.request({
|
|
337
|
+
method,
|
|
338
|
+
params,
|
|
339
|
+
chainId: `eip155:${chainId}`,
|
|
340
|
+
connect: this,
|
|
341
|
+
});
|
|
331
342
|
});
|
|
332
343
|
}
|
|
333
344
|
handleSessionApproved(data, request) {
|
|
334
|
-
var _a;
|
|
345
|
+
var _a, _b, _c;
|
|
335
346
|
return __awaiter(this, void 0, void 0, function* () {
|
|
336
347
|
const address = yield this.address;
|
|
348
|
+
let chainId;
|
|
349
|
+
if (((_a = request.params.params.requiredNamespaces) === null || _a === void 0 ? void 0 : _a.eip155) &&
|
|
350
|
+
request.params.params.requiredNamespaces
|
|
351
|
+
.eip155.chains.length !== 0) {
|
|
352
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
|
353
|
+
chainId = (_b = request.params.params.requiredNamespaces) === null || _b === void 0 ? void 0 : _b.eip155.chains[0].split(':')[1];
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
chainId = this.chainId;
|
|
357
|
+
}
|
|
337
358
|
// Notify the proxy server that the session request was approved
|
|
338
|
-
(
|
|
359
|
+
(_c = this.socket) === null || _c === void 0 ? void 0 : _c.send(JSON.stringify({
|
|
339
360
|
event: 'portal_dappSessionApproved',
|
|
340
361
|
data: {
|
|
341
362
|
address,
|
|
342
|
-
chainId
|
|
363
|
+
chainId,
|
|
343
364
|
topic: request.topic,
|
|
344
365
|
id: request.id,
|
|
345
366
|
params: data,
|
|
@@ -348,15 +369,25 @@ class PortalConnect {
|
|
|
348
369
|
});
|
|
349
370
|
}
|
|
350
371
|
handleSessionRejected(data, request) {
|
|
351
|
-
var _a;
|
|
372
|
+
var _a, _b, _c;
|
|
352
373
|
return __awaiter(this, void 0, void 0, function* () {
|
|
353
374
|
const address = yield this.address;
|
|
375
|
+
let chainId;
|
|
376
|
+
if (((_a = request.params.params.requiredNamespaces) === null || _a === void 0 ? void 0 : _a.eip155) &&
|
|
377
|
+
request.params.params.requiredNamespaces
|
|
378
|
+
.eip155.chains.length !== 0) {
|
|
379
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
|
380
|
+
chainId = (_b = request.params.params.requiredNamespaces) === null || _b === void 0 ? void 0 : _b.eip155.chains[0].split(':')[1];
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
chainId = this.chainId;
|
|
384
|
+
}
|
|
354
385
|
// Notify the proxy server that the session request was rejected
|
|
355
|
-
(
|
|
386
|
+
(_c = this.socket) === null || _c === void 0 ? void 0 : _c.send(JSON.stringify({
|
|
356
387
|
event: 'portal_dappSessionRejected',
|
|
357
388
|
data: {
|
|
358
389
|
address,
|
|
359
|
-
chainId
|
|
390
|
+
chainId,
|
|
360
391
|
topic: request.topic,
|
|
361
392
|
id: request.id,
|
|
362
393
|
params: data,
|
package/lib/esm/index.js
CHANGED
|
@@ -12,14 +12,11 @@ class PortalConnect {
|
|
|
12
12
|
get address() {
|
|
13
13
|
return this.provider.address;
|
|
14
14
|
}
|
|
15
|
-
get chainId() {
|
|
16
|
-
return this.provider.chainId;
|
|
17
|
-
}
|
|
18
15
|
get connected() {
|
|
19
16
|
return (this.connectionState === ConnectionStates.CONNECTED ||
|
|
20
17
|
this.connectionState === ConnectionStates.CONNECTING);
|
|
21
18
|
}
|
|
22
|
-
constructor({ apiKey,
|
|
19
|
+
constructor({ apiKey, keychain, gatewayConfig, chainId,
|
|
23
20
|
// Optional
|
|
24
21
|
isSimulator = false, autoApprove = false, version = 'v6', apiHost = 'api.portalhq.io', mpcHost = 'mpc.portalhq.io', webSocketServer = 'connect.portalhq.io', }) {
|
|
25
22
|
this.connectionState = ConnectionStates.DISCONNECTED;
|
|
@@ -39,9 +36,9 @@ class PortalConnect {
|
|
|
39
36
|
this.events = {};
|
|
40
37
|
this.websocketServer = webSocketServer;
|
|
41
38
|
this.gatewayConfig = gatewayConfig;
|
|
39
|
+
this.chainId = chainId;
|
|
42
40
|
this.provider = new Provider({
|
|
43
41
|
apiKey,
|
|
44
|
-
chainId,
|
|
45
42
|
gatewayConfig,
|
|
46
43
|
keychain,
|
|
47
44
|
isSimulator,
|
|
@@ -102,7 +99,7 @@ class PortalConnect {
|
|
|
102
99
|
*/
|
|
103
100
|
setChainId(chainId) {
|
|
104
101
|
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
-
yield this.provider.setChainId(chainId
|
|
102
|
+
yield this.provider.setChainId(`eip155:${chainId}`, this);
|
|
106
103
|
});
|
|
107
104
|
}
|
|
108
105
|
/**
|
|
@@ -186,11 +183,12 @@ class PortalConnect {
|
|
|
186
183
|
* @returns session proposal with chains from gateway config added
|
|
187
184
|
*/
|
|
188
185
|
addChainsToProposal(proposal) {
|
|
186
|
+
var _a;
|
|
189
187
|
if (!('params' in proposal) || !('requiredNamespaces' in proposal.params)) {
|
|
190
188
|
throw new Error('Invalid proposal structure.');
|
|
191
189
|
}
|
|
192
190
|
// Ensure eip155 is present in requiredNamespaces
|
|
193
|
-
if (!proposal.params.requiredNamespaces.eip155) {
|
|
191
|
+
if (!((_a = proposal.params.requiredNamespaces) === null || _a === void 0 ? void 0 : _a.eip155)) {
|
|
194
192
|
proposal.params.requiredNamespaces.eip155 = {
|
|
195
193
|
chains: [],
|
|
196
194
|
methods: [],
|
|
@@ -201,7 +199,16 @@ class PortalConnect {
|
|
|
201
199
|
// Get chains from gatewayConfig with 'eip155:' prefix, but only if they're not already in the proposal
|
|
202
200
|
const existingChains = proposal.params.requiredNamespaces.eip155.chains;
|
|
203
201
|
const newChains = Object.keys(this.gatewayConfig)
|
|
204
|
-
.
|
|
202
|
+
.filter((chain) => !chain.includes('solana:')) // Remove chains that include 'solana:'
|
|
203
|
+
.reduce((acc, chain) => {
|
|
204
|
+
if (chain.includes('eip155')) {
|
|
205
|
+
acc.push(chain);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
acc.push(`eip155:${chain}`);
|
|
209
|
+
}
|
|
210
|
+
return acc;
|
|
211
|
+
}, [])
|
|
205
212
|
.filter((chain) => !existingChains.includes(chain));
|
|
206
213
|
// Append new chains to the existing chains
|
|
207
214
|
proposal.params.requiredNamespaces.eip155.chains = [
|
|
@@ -225,13 +232,12 @@ class PortalConnect {
|
|
|
225
232
|
socket.onopen = () => __awaiter(this, void 0, void 0, function* () {
|
|
226
233
|
this.connectionState = ConnectionStates.CONNECTING;
|
|
227
234
|
const address = yield this.address;
|
|
228
|
-
const { chainId } = this.provider;
|
|
229
235
|
// Tell the proxy server where to connect to downstream
|
|
230
236
|
socket.send(JSON.stringify({
|
|
231
237
|
event: 'connect',
|
|
232
238
|
data: {
|
|
233
239
|
address,
|
|
234
|
-
chainId,
|
|
240
|
+
chainId: this.chainId,
|
|
235
241
|
uri,
|
|
236
242
|
},
|
|
237
243
|
}));
|
|
@@ -324,19 +330,34 @@ class PortalConnect {
|
|
|
324
330
|
}
|
|
325
331
|
});
|
|
326
332
|
// Pass the request along to the provider
|
|
327
|
-
yield this.provider.request({
|
|
333
|
+
yield this.provider.request({
|
|
334
|
+
method,
|
|
335
|
+
params,
|
|
336
|
+
chainId: `eip155:${chainId}`,
|
|
337
|
+
connect: this,
|
|
338
|
+
});
|
|
328
339
|
});
|
|
329
340
|
}
|
|
330
341
|
handleSessionApproved(data, request) {
|
|
331
|
-
var _a;
|
|
342
|
+
var _a, _b, _c;
|
|
332
343
|
return __awaiter(this, void 0, void 0, function* () {
|
|
333
344
|
const address = yield this.address;
|
|
345
|
+
let chainId;
|
|
346
|
+
if (((_a = request.params.params.requiredNamespaces) === null || _a === void 0 ? void 0 : _a.eip155) &&
|
|
347
|
+
request.params.params.requiredNamespaces
|
|
348
|
+
.eip155.chains.length !== 0) {
|
|
349
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
|
350
|
+
chainId = (_b = request.params.params.requiredNamespaces) === null || _b === void 0 ? void 0 : _b.eip155.chains[0].split(':')[1];
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
chainId = this.chainId;
|
|
354
|
+
}
|
|
334
355
|
// Notify the proxy server that the session request was approved
|
|
335
|
-
(
|
|
356
|
+
(_c = this.socket) === null || _c === void 0 ? void 0 : _c.send(JSON.stringify({
|
|
336
357
|
event: 'portal_dappSessionApproved',
|
|
337
358
|
data: {
|
|
338
359
|
address,
|
|
339
|
-
chainId
|
|
360
|
+
chainId,
|
|
340
361
|
topic: request.topic,
|
|
341
362
|
id: request.id,
|
|
342
363
|
params: data,
|
|
@@ -345,15 +366,25 @@ class PortalConnect {
|
|
|
345
366
|
});
|
|
346
367
|
}
|
|
347
368
|
handleSessionRejected(data, request) {
|
|
348
|
-
var _a;
|
|
369
|
+
var _a, _b, _c;
|
|
349
370
|
return __awaiter(this, void 0, void 0, function* () {
|
|
350
371
|
const address = yield this.address;
|
|
372
|
+
let chainId;
|
|
373
|
+
if (((_a = request.params.params.requiredNamespaces) === null || _a === void 0 ? void 0 : _a.eip155) &&
|
|
374
|
+
request.params.params.requiredNamespaces
|
|
375
|
+
.eip155.chains.length !== 0) {
|
|
376
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
|
377
|
+
chainId = (_b = request.params.params.requiredNamespaces) === null || _b === void 0 ? void 0 : _b.eip155.chains[0].split(':')[1];
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
chainId = this.chainId;
|
|
381
|
+
}
|
|
351
382
|
// Notify the proxy server that the session request was rejected
|
|
352
|
-
(
|
|
383
|
+
(_c = this.socket) === null || _c === void 0 ? void 0 : _c.send(JSON.stringify({
|
|
353
384
|
event: 'portal_dappSessionRejected',
|
|
354
385
|
data: {
|
|
355
386
|
address,
|
|
356
|
-
chainId
|
|
387
|
+
chainId,
|
|
357
388
|
topic: request.topic,
|
|
358
389
|
id: request.id,
|
|
359
390
|
params: data,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portal-hq/connect",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"main": "lib/commonjs/index",
|
|
5
5
|
"module": "lib/esm/index",
|
|
6
6
|
"source": "src/index",
|
|
@@ -31,5 +31,6 @@
|
|
|
31
31
|
"@portal-hq/core": "*",
|
|
32
32
|
"react": "*",
|
|
33
33
|
"react-native": "*"
|
|
34
|
-
}
|
|
34
|
+
},
|
|
35
|
+
"gitHead": "a1c6f51ff156d3d1922cdaa29ee43fe4cfefd932"
|
|
35
36
|
}
|
package/src/index.ts
CHANGED
|
@@ -17,6 +17,7 @@ import type {
|
|
|
17
17
|
} from '../types.d'
|
|
18
18
|
|
|
19
19
|
class PortalConnect {
|
|
20
|
+
public chainId: number
|
|
20
21
|
private apiKey: string
|
|
21
22
|
private connectionState: ConnectionStates = ConnectionStates.DISCONNECTED
|
|
22
23
|
private provider: IPortalProvider
|
|
@@ -25,17 +26,12 @@ class PortalConnect {
|
|
|
25
26
|
private topic?: string
|
|
26
27
|
private uri?: string
|
|
27
28
|
private websocketServer: string
|
|
28
|
-
|
|
29
29
|
private events: Record<string, RegisteredEventHandler[]>
|
|
30
30
|
|
|
31
31
|
private get address(): Promise<string | undefined> {
|
|
32
32
|
return this.provider.address
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
private get chainId(): number {
|
|
36
|
-
return this.provider.chainId
|
|
37
|
-
}
|
|
38
|
-
|
|
39
35
|
public get connected(): boolean {
|
|
40
36
|
return (
|
|
41
37
|
this.connectionState === ConnectionStates.CONNECTED ||
|
|
@@ -45,9 +41,9 @@ class PortalConnect {
|
|
|
45
41
|
|
|
46
42
|
constructor({
|
|
47
43
|
apiKey,
|
|
48
|
-
chainId,
|
|
49
44
|
keychain,
|
|
50
45
|
gatewayConfig,
|
|
46
|
+
chainId,
|
|
51
47
|
|
|
52
48
|
// Optional
|
|
53
49
|
isSimulator = false,
|
|
@@ -61,9 +57,10 @@ class PortalConnect {
|
|
|
61
57
|
this.events = {}
|
|
62
58
|
this.websocketServer = webSocketServer
|
|
63
59
|
this.gatewayConfig = gatewayConfig
|
|
60
|
+
this.chainId = chainId
|
|
61
|
+
|
|
64
62
|
this.provider = new Provider({
|
|
65
63
|
apiKey,
|
|
66
|
-
chainId,
|
|
67
64
|
gatewayConfig,
|
|
68
65
|
keychain,
|
|
69
66
|
isSimulator,
|
|
@@ -135,7 +132,7 @@ class PortalConnect {
|
|
|
135
132
|
* @param chainId The number of the chainId to switch to
|
|
136
133
|
*/
|
|
137
134
|
public async setChainId(chainId: number): Promise<void> {
|
|
138
|
-
await this.provider.setChainId(chainId
|
|
135
|
+
await this.provider.setChainId(`eip155:${chainId}`, this)
|
|
139
136
|
}
|
|
140
137
|
|
|
141
138
|
/**
|
|
@@ -243,7 +240,7 @@ class PortalConnect {
|
|
|
243
240
|
}
|
|
244
241
|
|
|
245
242
|
// Ensure eip155 is present in requiredNamespaces
|
|
246
|
-
if (!proposal.params.requiredNamespaces
|
|
243
|
+
if (!proposal.params.requiredNamespaces?.eip155) {
|
|
247
244
|
proposal.params.requiredNamespaces.eip155 = {
|
|
248
245
|
chains: [],
|
|
249
246
|
methods: [],
|
|
@@ -255,7 +252,15 @@ class PortalConnect {
|
|
|
255
252
|
// Get chains from gatewayConfig with 'eip155:' prefix, but only if they're not already in the proposal
|
|
256
253
|
const existingChains = proposal.params.requiredNamespaces.eip155.chains
|
|
257
254
|
const newChains = Object.keys(this.gatewayConfig)
|
|
258
|
-
.
|
|
255
|
+
.filter((chain) => !chain.includes('solana:')) // Remove chains that include 'solana:'
|
|
256
|
+
.reduce<string[]>((acc, chain) => {
|
|
257
|
+
if (chain.includes('eip155')) {
|
|
258
|
+
acc.push(chain)
|
|
259
|
+
} else {
|
|
260
|
+
acc.push(`eip155:${chain}`)
|
|
261
|
+
}
|
|
262
|
+
return acc
|
|
263
|
+
}, [])
|
|
259
264
|
.filter((chain) => !existingChains.includes(chain))
|
|
260
265
|
|
|
261
266
|
// Append new chains to the existing chains
|
|
@@ -282,7 +287,6 @@ class PortalConnect {
|
|
|
282
287
|
socket.onopen = async () => {
|
|
283
288
|
this.connectionState = ConnectionStates.CONNECTING
|
|
284
289
|
const address = await this.address
|
|
285
|
-
const { chainId } = this.provider
|
|
286
290
|
|
|
287
291
|
// Tell the proxy server where to connect to downstream
|
|
288
292
|
socket.send(
|
|
@@ -290,7 +294,7 @@ class PortalConnect {
|
|
|
290
294
|
event: 'connect',
|
|
291
295
|
data: {
|
|
292
296
|
address,
|
|
293
|
-
chainId,
|
|
297
|
+
chainId: this.chainId,
|
|
294
298
|
uri,
|
|
295
299
|
},
|
|
296
300
|
}),
|
|
@@ -413,7 +417,12 @@ class PortalConnect {
|
|
|
413
417
|
)
|
|
414
418
|
|
|
415
419
|
// Pass the request along to the provider
|
|
416
|
-
await this.provider.request({
|
|
420
|
+
await this.provider.request({
|
|
421
|
+
method,
|
|
422
|
+
params,
|
|
423
|
+
chainId: `eip155:${chainId}`,
|
|
424
|
+
connect: this,
|
|
425
|
+
})
|
|
417
426
|
}
|
|
418
427
|
|
|
419
428
|
private async handleSessionApproved(
|
|
@@ -421,6 +430,20 @@ class PortalConnect {
|
|
|
421
430
|
request: SessionRequest,
|
|
422
431
|
): Promise<void> {
|
|
423
432
|
const address = await this.address
|
|
433
|
+
let chainId
|
|
434
|
+
if (
|
|
435
|
+
(request.params as SessionProposalOrMetadata).params.requiredNamespaces
|
|
436
|
+
?.eip155 &&
|
|
437
|
+
(request.params as SessionProposalOrMetadata).params.requiredNamespaces
|
|
438
|
+
.eip155.chains.length !== 0
|
|
439
|
+
) {
|
|
440
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
|
441
|
+
chainId = (
|
|
442
|
+
request.params as SessionProposalOrMetadata
|
|
443
|
+
).params.requiredNamespaces?.eip155.chains[0].split(':')[1]
|
|
444
|
+
} else {
|
|
445
|
+
chainId = this.chainId
|
|
446
|
+
}
|
|
424
447
|
|
|
425
448
|
// Notify the proxy server that the session request was approved
|
|
426
449
|
this.socket?.send(
|
|
@@ -428,7 +451,7 @@ class PortalConnect {
|
|
|
428
451
|
event: 'portal_dappSessionApproved',
|
|
429
452
|
data: {
|
|
430
453
|
address,
|
|
431
|
-
chainId
|
|
454
|
+
chainId,
|
|
432
455
|
topic: request.topic,
|
|
433
456
|
id: request.id,
|
|
434
457
|
params: data,
|
|
@@ -442,14 +465,27 @@ class PortalConnect {
|
|
|
442
465
|
request: SessionRequest,
|
|
443
466
|
): Promise<void> {
|
|
444
467
|
const address = await this.address
|
|
445
|
-
|
|
468
|
+
let chainId
|
|
469
|
+
if (
|
|
470
|
+
(request.params as SessionProposalOrMetadata).params.requiredNamespaces
|
|
471
|
+
?.eip155 &&
|
|
472
|
+
(request.params as SessionProposalOrMetadata).params.requiredNamespaces
|
|
473
|
+
.eip155.chains.length !== 0
|
|
474
|
+
) {
|
|
475
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
|
476
|
+
chainId = (
|
|
477
|
+
request.params as SessionProposalOrMetadata
|
|
478
|
+
).params.requiredNamespaces?.eip155.chains[0].split(':')[1]
|
|
479
|
+
} else {
|
|
480
|
+
chainId = this.chainId
|
|
481
|
+
}
|
|
446
482
|
// Notify the proxy server that the session request was rejected
|
|
447
483
|
this.socket?.send(
|
|
448
484
|
JSON.stringify({
|
|
449
485
|
event: 'portal_dappSessionRejected',
|
|
450
486
|
data: {
|
|
451
487
|
address,
|
|
452
|
-
chainId
|
|
488
|
+
chainId,
|
|
453
489
|
topic: request.topic,
|
|
454
490
|
id: request.id,
|
|
455
491
|
params: data,
|
package/types.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { KeychainAdapter } from '@portal-hq/utils'
|
|
|
4
4
|
import { ConnectError } from 'src'
|
|
5
5
|
|
|
6
6
|
export type EventHandler = (data: any) => void
|
|
7
|
-
export type SessionProposalOrMetadata = SessionProposal
|
|
7
|
+
export type SessionProposalOrMetadata = SessionProposal
|
|
8
8
|
|
|
9
9
|
export interface ConnectRequest {
|
|
10
10
|
id: string
|
|
@@ -51,9 +51,9 @@ export interface PeerMetadata {
|
|
|
51
51
|
|
|
52
52
|
export interface PortalConnectOptions {
|
|
53
53
|
apiKey: string
|
|
54
|
-
chainId: number
|
|
55
54
|
keychain: KeychainAdapter
|
|
56
55
|
gatewayConfig: GatewayLike
|
|
56
|
+
chainId: number
|
|
57
57
|
|
|
58
58
|
// Optional
|
|
59
59
|
isSimulator?: boolean
|
|
@@ -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;
|