@mictonode/widget 0.3.22 → 0.3.23
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/README.md +2 -2
- package/dist/{ConstantsUtil-df193f67.js → ConstantsUtil-f9dc60b6.js} +3 -3
- package/dist/{ConstantsUtil-1b0c0436.js → ConstantsUtil-fb0ff2e5.js} +1 -1
- package/dist/{ExchangeController-953f14bc.js → ExchangeController-173fd1dc.js} +2 -2
- package/dist/{HelpersUtil-3810bb58.js → HelpersUtil-4891ff5f.js} +4 -4
- package/dist/{ReownAuthentication-7c5b6e79.js → ReownAuthentication-bba89dc5.js} +2 -2
- package/dist/{SwapController-e1a7b5f8.js → SwapController-e8b097ca.js} +3 -3
- package/dist/{abis-61cccfbf.js → abis-96fed285.js} +1 -1
- package/dist/{assertCurrentChain-0c3d6c93.js → assertCurrentChain-b60aa59f.js} +1 -1
- package/dist/{ccip-80fe88fb.js → ccip-8f82ae2a.js} +6 -6
- package/dist/{data-capture-7edeb077.js → data-capture-7009ffa0.js} +8 -8
- package/dist/{email-40537ec5.js → email-d6e2da58.js} +12 -12
- package/dist/{embedded-wallet-f71f6169.js → embedded-wallet-48284179.js} +14 -14
- package/dist/{encodeFunctionData-91e7c0f6.js → encodeFunctionData-b24a0b2b.js} +2 -2
- package/dist/{fallback-1ab5a270.js → fallback-ae0315d4.js} +2 -2
- package/dist/features-82db0d52.js +8 -0
- package/dist/{hashTypedData-1e059dc4.js → hashTypedData-c13ba550.js} +2 -2
- package/dist/{http-d9e0a50a.js → http-90ef23f3.js} +2 -2
- package/dist/{index-d3f36c31.js → index-0ac134af.js} +34 -34
- package/dist/{index-2cd6a2b2.js → index-19f302c4.js} +3 -3
- package/dist/{index-78c5b9e2.js → index-22727038.js} +3 -3
- package/dist/{index-144edd3f.js → index-270ff8a2.js} +11 -11
- package/dist/{index-abb0ff46.js → index-29eb95bd.js} +3 -3
- package/dist/{index-9cc1116b.js → index-2a90711e.js} +2 -2
- package/dist/{index-289a865f.js → index-2de6c5bf.js} +4 -4
- package/dist/{index-fbced89b.js → index-3de7fa96.js} +3 -3
- package/dist/{index-26b53c8a.js → index-42a8a5ec.js} +15 -15
- package/dist/{index-58ec291c.js → index-4bd03aed.js} +7 -7
- package/dist/{index-85bc86d7.js → index-52edc95a.js} +2 -2
- package/dist/{index-04dd1ab3.js → index-577d2709.js} +4 -4
- package/dist/{index-4a4ee1e7.js → index-582e4199.js} +7 -7
- package/dist/{index-72706598.js → index-617b2147.js} +6 -6
- package/dist/{index-0b6166c5.js → index-6a0902fc.js} +2 -2
- package/dist/{index-a37d4c03.js → index-6d51f24f.js} +2 -2
- package/dist/{index-759b09b0.js → index-80954332.js} +3 -3
- package/dist/{index-0e2c49ad.js → index-95777860.js} +7 -7
- package/dist/{index-d9effd37.js → index-96729706.js} +13 -13
- package/dist/{index-39f31546.js → index-997bc756.js} +2 -2
- package/dist/{index-cb4d3345.js → index-a41841e6.js} +3 -3
- package/dist/{index-c10f5e72.js → index-adaa2ea4.js} +3 -3
- package/dist/{index-97b58f89.js → index-b37b670f.js} +11 -11
- package/dist/{index-0763de43.js → index-b8e2c282.js} +3 -3
- package/dist/{index-1f02e7d0.js → index-bb5e4071.js} +1 -1
- package/dist/{index-3678e7d8.js → index-bf40b971.js} +2 -2
- package/dist/{index-a4f054e9.js → index-cb69565e.js} +2 -2
- package/dist/{index-197dfd69.js → index-cbb6096a.js} +3 -3
- package/dist/{index-119c358f.js → index-ce6854ef.js} +14 -14
- package/dist/{index-4fdc7a25.js → index-d7e2a4a3.js} +2 -2
- package/dist/{index-0176180b.js → index-e7fbb597.js} +4 -4
- package/dist/{index-d5e3e4ba.js → index-f4cd8dd1.js} +3 -3
- package/dist/{index-a0c590f7.js → index-f886cf92.js} +2 -2
- package/dist/{index-95e1a01b.js → index-faade258.js} +3 -3
- package/dist/{localBatchGatewayRequest-8fd1b198.js → localBatchGatewayRequest-ade4aa2f.js} +3 -3
- package/dist/{main-7ddb238e.js → main-3b573cfc.js} +38694 -38472
- package/dist/{networks-d2ae1da7.js → networks-446d3512.js} +10 -10
- package/dist/{onramp-2966f1b1.js → onramp-57d19c5d.js} +19 -19
- package/dist/{parseSignature-fca372a1.js → parseSignature-783d626a.js} +8 -8
- package/dist/{pay-with-exchange-b0198b3f.js → pay-with-exchange-c59a5773.js} +22 -22
- package/dist/ping-widget.js +1 -1
- package/dist/ping-widget.umd.cjs +680 -680
- package/dist/{query.lcd-873499ca.js → query.lcd-447fb91a.js} +1 -1
- package/dist/{query.rpc.Query-d2bcf632.js → query.rpc.Query-97503d87.js} +1 -1
- package/dist/{receive-6fbb6662.js → receive-3073a49d.js} +6 -6
- package/dist/{ref-2c86b029.js → ref-6c3aabc7.js} +2 -2
- package/dist/{send-630ed203.js → send-42403797.js} +22 -22
- package/dist/{serializeAuthorizationList-e95a85d8.js → serializeAuthorizationList-70ec977c.js} +4 -4
- package/dist/{sha2-c04ffd62.js → sha2-249ae7eb.js} +2 -2
- package/dist/{socials-73a5efb0.js → socials-69b0cf18.js} +18 -18
- package/dist/{swaps-7b57265f.js → swaps-4e99bb0f.js} +18 -18
- package/dist/{transactions-876c066c.js → transactions-1d0c2669.js} +9 -9
- package/dist/{tx.rpc.msg-4d8bd1a4.js → tx.rpc.msg-8aa727ea.js} +1 -1
- package/dist/{tx.rpc.msg-d08b8ebe.js → tx.rpc.msg-a26b3557.js} +1 -1
- package/dist/{verifyHash-ee28e3d7.js → verifyHash-c8962067.js} +5 -5
- package/dist/{vue-bea1a08b.js → vue-9dc93a14.js} +10 -10
- package/dist/{w3m-modal-7d61c210.js → w3m-modal-291afec4.js} +25 -25
- package/dist/{zora-1091e7bb.js → zora-061565b0.js} +4 -4
- package/lib/components/ConnectWallet/index.vue +113 -31
- package/lib/wallet/KeplrSessionManager.ts +142 -0
- package/lib/wallet/WalletSessionManager.ts +111 -25
- package/lib/wallet/reown/EvmNetworkProvisioner.ts +97 -0
- package/lib/wallet/reown/ReownGateway.ts +22 -3
- package/package.json +1 -1
- package/test/components/ConnectWallet.test.ts +640 -2
- package/test/components/ConnectWalletStorage.test.ts +113 -3
- package/test/wallet/KeplrSessionManager.test.ts +269 -0
- package/test/wallet/WalletSessionManager.test.ts +901 -2
- package/test/wallet/reown/EvmNetworkProvisioner.test.ts +264 -0
- package/test/wallet/reown/ReownGateway.test.ts +66 -1
- package/dist/features-a2f2ff4f.js +0 -8
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import type { Eip1193Provider } from '../../../lib/wallet/providers/Eip1193Provider';
|
|
3
|
+
import type { ReownNetwork } from '../../../lib/wallet/reown/ReownConfig';
|
|
4
|
+
import { ensureEvmNetwork } from '../../../lib/wallet/reown/EvmNetworkProvisioner';
|
|
5
|
+
|
|
6
|
+
const network: ReownNetwork = {
|
|
7
|
+
id: 8765,
|
|
8
|
+
caipNetworkId: 'eip155:8765',
|
|
9
|
+
name: 'Warden Mainnet',
|
|
10
|
+
rpcUrl: 'https://evm.wardenprotocol.org/',
|
|
11
|
+
nativeCurrency: { name: 'WARD', symbol: 'WARD', decimals: 18 },
|
|
12
|
+
explorerUrl: 'https://explorer.wardenprotocol.org/',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
function providerWith(
|
|
16
|
+
request: Eip1193Provider['request'],
|
|
17
|
+
): Eip1193Provider {
|
|
18
|
+
return { request };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
describe('ensureEvmNetwork', () => {
|
|
22
|
+
it('does not add or switch an already active configured network', async () => {
|
|
23
|
+
const request = vi.fn(async ({ method }) => {
|
|
24
|
+
if (method === 'eth_chainId') return '0x223d';
|
|
25
|
+
throw new Error(`Unexpected method: ${method}`);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
await ensureEvmNetwork(providerWith(request), network);
|
|
29
|
+
|
|
30
|
+
expect(request).toHaveBeenCalledOnce();
|
|
31
|
+
expect(request).toHaveBeenCalledWith({ method: 'eth_chainId' });
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('switches a known network and verifies the resulting chain', async () => {
|
|
35
|
+
let chainRead = 0;
|
|
36
|
+
const request = vi.fn(async ({ method }) => {
|
|
37
|
+
if (method === 'eth_chainId') {
|
|
38
|
+
chainRead += 1;
|
|
39
|
+
return chainRead === 1 ? '0x1' : '0x223d';
|
|
40
|
+
}
|
|
41
|
+
if (method === 'wallet_switchEthereumChain') return null;
|
|
42
|
+
throw new Error(`Unexpected method: ${method}`);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
await ensureEvmNetwork(providerWith(request), network);
|
|
46
|
+
|
|
47
|
+
expect(request.mock.calls).toEqual([
|
|
48
|
+
[{ method: 'eth_chainId' }],
|
|
49
|
+
[{
|
|
50
|
+
method: 'wallet_switchEthereumChain',
|
|
51
|
+
params: [{ chainId: '0x223d' }],
|
|
52
|
+
}],
|
|
53
|
+
[{ method: 'eth_chainId' }],
|
|
54
|
+
]);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('adds an unknown network once before switching and verifying it', async () => {
|
|
58
|
+
let chainRead = 0;
|
|
59
|
+
let switchAttempt = 0;
|
|
60
|
+
const request = vi.fn(async ({ method }) => {
|
|
61
|
+
if (method === 'eth_chainId') {
|
|
62
|
+
chainRead += 1;
|
|
63
|
+
return chainRead === 1 ? '0x1' : '0x223d';
|
|
64
|
+
}
|
|
65
|
+
if (method === 'wallet_switchEthereumChain') {
|
|
66
|
+
switchAttempt += 1;
|
|
67
|
+
if (switchAttempt === 1) throw { code: 4902 };
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
if (method === 'wallet_addEthereumChain') return null;
|
|
71
|
+
throw new Error(`Unexpected method: ${method}`);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
await ensureEvmNetwork(providerWith(request), network);
|
|
75
|
+
|
|
76
|
+
expect(request.mock.calls).toEqual([
|
|
77
|
+
[{ method: 'eth_chainId' }],
|
|
78
|
+
[{
|
|
79
|
+
method: 'wallet_switchEthereumChain',
|
|
80
|
+
params: [{ chainId: '0x223d' }],
|
|
81
|
+
}],
|
|
82
|
+
[{
|
|
83
|
+
method: 'wallet_addEthereumChain',
|
|
84
|
+
params: [{
|
|
85
|
+
chainId: '0x223d',
|
|
86
|
+
chainName: 'Warden Mainnet',
|
|
87
|
+
nativeCurrency: {
|
|
88
|
+
name: 'WARD',
|
|
89
|
+
symbol: 'WARD',
|
|
90
|
+
decimals: 18,
|
|
91
|
+
},
|
|
92
|
+
rpcUrls: ['https://evm.wardenprotocol.org/'],
|
|
93
|
+
blockExplorerUrls: [
|
|
94
|
+
'https://explorer.wardenprotocol.org/',
|
|
95
|
+
],
|
|
96
|
+
}],
|
|
97
|
+
}],
|
|
98
|
+
[{
|
|
99
|
+
method: 'wallet_switchEthereumChain',
|
|
100
|
+
params: [{ chainId: '0x223d' }],
|
|
101
|
+
}],
|
|
102
|
+
[{ method: 'eth_chainId' }],
|
|
103
|
+
]);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it.each([
|
|
107
|
+
{ code: '4902' },
|
|
108
|
+
{ data: { originalError: { code: 4902 } } },
|
|
109
|
+
{ error: { data: { code: '4902' } } },
|
|
110
|
+
])(
|
|
111
|
+
'adds an unknown network when a provider wraps the 4902 error as %j',
|
|
112
|
+
async (unknownChainError) => {
|
|
113
|
+
let chainRead = 0;
|
|
114
|
+
let switchAttempt = 0;
|
|
115
|
+
const request = vi.fn(async ({ method }) => {
|
|
116
|
+
if (method === 'eth_chainId') {
|
|
117
|
+
chainRead += 1;
|
|
118
|
+
return chainRead === 1 ? '0x1' : '0x223d';
|
|
119
|
+
}
|
|
120
|
+
if (method === 'wallet_switchEthereumChain') {
|
|
121
|
+
switchAttempt += 1;
|
|
122
|
+
if (switchAttempt === 1) throw unknownChainError;
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
if (method === 'wallet_addEthereumChain') return null;
|
|
126
|
+
throw new Error(`Unexpected method: ${method}`);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
await ensureEvmNetwork(providerWith(request), network);
|
|
130
|
+
|
|
131
|
+
expect(request).toHaveBeenCalledWith({
|
|
132
|
+
method: 'wallet_addEthereumChain',
|
|
133
|
+
params: [expect.objectContaining({ chainId: '0x223d' })],
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
it('does not retry a rejected switch request', async () => {
|
|
139
|
+
const rejection = { code: 4001 };
|
|
140
|
+
const request = vi.fn(async ({ method }) => {
|
|
141
|
+
if (method === 'eth_chainId') return '0x1';
|
|
142
|
+
if (method === 'wallet_switchEthereumChain') throw rejection;
|
|
143
|
+
throw new Error(`Unexpected method: ${method}`);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
await expect(
|
|
147
|
+
ensureEvmNetwork(providerWith(request), network),
|
|
148
|
+
).rejects.toBe(rejection);
|
|
149
|
+
|
|
150
|
+
expect(request).toHaveBeenCalledTimes(2);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('does not add a network when an outer rejection wraps a 4902 error', async () => {
|
|
154
|
+
const rejection = {
|
|
155
|
+
code: 4001,
|
|
156
|
+
data: { originalError: { code: 4902 } },
|
|
157
|
+
};
|
|
158
|
+
const request = vi.fn(async ({ method }) => {
|
|
159
|
+
if (method === 'eth_chainId') return '0x1';
|
|
160
|
+
if (method === 'wallet_switchEthereumChain') throw rejection;
|
|
161
|
+
throw new Error(`Unexpected method: ${method}`);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
await expect(
|
|
165
|
+
ensureEvmNetwork(providerWith(request), network),
|
|
166
|
+
).rejects.toBe(rejection);
|
|
167
|
+
|
|
168
|
+
expect(request).toHaveBeenCalledTimes(2);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('does not retry a rejected add-network request', async () => {
|
|
172
|
+
const rejection = { code: 4001 };
|
|
173
|
+
const request = vi.fn(async ({ method }) => {
|
|
174
|
+
if (method === 'eth_chainId') return '0x1';
|
|
175
|
+
if (method === 'wallet_switchEthereumChain') throw { code: 4902 };
|
|
176
|
+
if (method === 'wallet_addEthereumChain') throw rejection;
|
|
177
|
+
throw new Error(`Unexpected method: ${method}`);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
await expect(
|
|
181
|
+
ensureEvmNetwork(providerWith(request), network),
|
|
182
|
+
).rejects.toBe(rejection);
|
|
183
|
+
|
|
184
|
+
expect(request).toHaveBeenCalledTimes(3);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('rejects when the provider resolves without changing chains', async () => {
|
|
188
|
+
const request = vi.fn(async ({ method }) => {
|
|
189
|
+
if (method === 'eth_chainId') return '0x1';
|
|
190
|
+
if (method === 'wallet_switchEthereumChain') return null;
|
|
191
|
+
throw new Error(`Unexpected method: ${method}`);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
await expect(
|
|
195
|
+
ensureEvmNetwork(providerWith(request), network),
|
|
196
|
+
).rejects.toThrow('EVM wallet did not switch to configured network');
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('does not add a network after the owning attempt becomes stale', async () => {
|
|
200
|
+
let active = true;
|
|
201
|
+
const request = vi.fn(async ({ method }) => {
|
|
202
|
+
if (method === 'eth_chainId') return '0x1';
|
|
203
|
+
if (method === 'wallet_switchEthereumChain') {
|
|
204
|
+
active = false;
|
|
205
|
+
throw { code: 4902 };
|
|
206
|
+
}
|
|
207
|
+
throw new Error(`Unexpected method: ${method}`);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
await expect(
|
|
211
|
+
ensureEvmNetwork(providerWith(request), network, () => active),
|
|
212
|
+
).rejects.toThrow('EVM network request is no longer active');
|
|
213
|
+
|
|
214
|
+
expect(request.mock.calls).toEqual([
|
|
215
|
+
[{ method: 'eth_chainId' }],
|
|
216
|
+
[{
|
|
217
|
+
method: 'wallet_switchEthereumChain',
|
|
218
|
+
params: [{ chainId: '0x223d' }],
|
|
219
|
+
}],
|
|
220
|
+
]);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('does not switch again after an add request loses ownership', async () => {
|
|
224
|
+
let active = true;
|
|
225
|
+
let switchAttempt = 0;
|
|
226
|
+
const request = vi.fn(async ({ method }) => {
|
|
227
|
+
if (method === 'eth_chainId') return '0x1';
|
|
228
|
+
if (method === 'wallet_switchEthereumChain') {
|
|
229
|
+
switchAttempt += 1;
|
|
230
|
+
if (switchAttempt === 1) throw { code: 4902 };
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
if (method === 'wallet_addEthereumChain') {
|
|
234
|
+
active = false;
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
throw new Error(`Unexpected method: ${method}`);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
await expect(
|
|
241
|
+
ensureEvmNetwork(providerWith(request), network, () => active),
|
|
242
|
+
).rejects.toThrow('EVM network request is no longer active');
|
|
243
|
+
|
|
244
|
+
expect(request).toHaveBeenCalledTimes(3);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it('does not verify a switch after the owning attempt becomes stale', async () => {
|
|
248
|
+
let active = true;
|
|
249
|
+
const request = vi.fn(async ({ method }) => {
|
|
250
|
+
if (method === 'eth_chainId') return '0x1';
|
|
251
|
+
if (method === 'wallet_switchEthereumChain') {
|
|
252
|
+
active = false;
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
throw new Error(`Unexpected method: ${method}`);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
await expect(
|
|
259
|
+
ensureEvmNetwork(providerWith(request), network, () => active),
|
|
260
|
+
).rejects.toThrow('EVM network request is no longer active');
|
|
261
|
+
|
|
262
|
+
expect(request).toHaveBeenCalledTimes(2);
|
|
263
|
+
});
|
|
264
|
+
});
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
2
|
|
|
3
|
-
const { appKit, createAppKit } = vi.hoisted(() => {
|
|
3
|
+
const { appKit, createAppKit, ethereumMainnet, provider } = vi.hoisted(() => {
|
|
4
4
|
const provider = { request: vi.fn() };
|
|
5
|
+
const ethereumMainnet = {
|
|
6
|
+
id: 1,
|
|
7
|
+
caipNetworkId: 'eip155:1',
|
|
8
|
+
name: 'Ethereum',
|
|
9
|
+
};
|
|
5
10
|
const appKit = {
|
|
6
11
|
ready: vi.fn(async () => undefined),
|
|
7
12
|
open: vi.fn(async () => undefined),
|
|
@@ -15,6 +20,9 @@ const { appKit, createAppKit } = vi.hoisted(() => {
|
|
|
15
20
|
caipAddress:
|
|
16
21
|
'eip155:9191:0x1111111111111111111111111111111111111111',
|
|
17
22
|
})),
|
|
23
|
+
getCaipNetwork: vi.fn(() => ({
|
|
24
|
+
caipNetworkId: 'eip155:9191',
|
|
25
|
+
})),
|
|
18
26
|
getWalletInfo: vi.fn(() => ({
|
|
19
27
|
name: 'Rabby Wallet',
|
|
20
28
|
type: 'injected',
|
|
@@ -26,6 +34,8 @@ const { appKit, createAppKit } = vi.hoisted(() => {
|
|
|
26
34
|
return {
|
|
27
35
|
appKit,
|
|
28
36
|
createAppKit: vi.fn(() => appKit),
|
|
37
|
+
ethereumMainnet,
|
|
38
|
+
provider,
|
|
29
39
|
};
|
|
30
40
|
});
|
|
31
41
|
|
|
@@ -35,6 +45,7 @@ vi.mock('@reown/appkit-adapter-ethers', () => ({
|
|
|
35
45
|
}));
|
|
36
46
|
vi.mock('@reown/appkit/networks', () => ({
|
|
37
47
|
defineChain: vi.fn((network) => network),
|
|
48
|
+
mainnet: ethereumMainnet,
|
|
38
49
|
}));
|
|
39
50
|
|
|
40
51
|
import {
|
|
@@ -65,6 +76,7 @@ describe('ReownGateway', () => {
|
|
|
65
76
|
beforeEach(() => {
|
|
66
77
|
resetReownGatewayForTests();
|
|
67
78
|
vi.clearAllMocks();
|
|
79
|
+
provider.request.mockResolvedValue('0x23e7');
|
|
68
80
|
});
|
|
69
81
|
|
|
70
82
|
it('initializes once and exposes the eip155 provider', async () => {
|
|
@@ -82,6 +94,59 @@ describe('ReownGateway', () => {
|
|
|
82
94
|
namespace: 'eip155',
|
|
83
95
|
});
|
|
84
96
|
expect(first.getProvider()).toBe(appKit.getProvider('eip155'));
|
|
97
|
+
expect(first.getNetwork()).toEqual({
|
|
98
|
+
caipNetworkId: 'eip155:9191',
|
|
99
|
+
});
|
|
100
|
+
expect(appKit.getCaipNetwork).toHaveBeenCalledWith('eip155');
|
|
101
|
+
expect(createAppKit).toHaveBeenCalledWith(
|
|
102
|
+
expect.objectContaining({ allowUnsupportedChain: true }),
|
|
103
|
+
);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('connects through Ethereum before provisioning the configured network', async () => {
|
|
107
|
+
await getReownGateway(config);
|
|
108
|
+
|
|
109
|
+
expect(createAppKit).toHaveBeenCalledWith(
|
|
110
|
+
expect.objectContaining({
|
|
111
|
+
networks: [
|
|
112
|
+
expect.objectContaining({
|
|
113
|
+
id: config.network.id,
|
|
114
|
+
caipNetworkId: config.network.caipNetworkId,
|
|
115
|
+
}),
|
|
116
|
+
ethereumMainnet,
|
|
117
|
+
],
|
|
118
|
+
defaultNetwork: ethereumMainnet,
|
|
119
|
+
enableNetworkSwitch: false,
|
|
120
|
+
}),
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('ensures the configured network through the active provider', async () => {
|
|
125
|
+
provider.request
|
|
126
|
+
.mockResolvedValueOnce('0x1')
|
|
127
|
+
.mockResolvedValueOnce(null)
|
|
128
|
+
.mockResolvedValueOnce('0x23e7');
|
|
129
|
+
const gateway = await getReownGateway(config);
|
|
130
|
+
|
|
131
|
+
await gateway.ensureNetwork();
|
|
132
|
+
|
|
133
|
+
expect(provider.request.mock.calls).toEqual([
|
|
134
|
+
[{ method: 'eth_chainId' }],
|
|
135
|
+
[{
|
|
136
|
+
method: 'wallet_switchEthereumChain',
|
|
137
|
+
params: [{ chainId: '0x23e7' }],
|
|
138
|
+
}],
|
|
139
|
+
[{ method: 'eth_chainId' }],
|
|
140
|
+
]);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('rejects network provisioning when no provider is active', async () => {
|
|
144
|
+
appKit.getProvider.mockImplementationOnce(() => undefined as never);
|
|
145
|
+
const gateway = await getReownGateway(config);
|
|
146
|
+
|
|
147
|
+
await expect(gateway.ensureNetwork()).rejects.toThrow(
|
|
148
|
+
'EVM wallet provider is unavailable',
|
|
149
|
+
);
|
|
85
150
|
});
|
|
86
151
|
|
|
87
152
|
it('creates a different gateway for a different network config', async () => {
|