@getpara/wagmi-v2-integration 1.7.0 → 1.8.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/dist/ParaEIP1193Provider.js +269 -0
- package/dist/chunk-MMUBH76A.js +59 -0
- package/dist/connectorModal.js +36 -0
- package/dist/index.js +2 -407
- package/dist/paraConnector.d.ts +113 -10
- package/dist/paraConnector.js +67 -0
- package/package.json +6 -6
- package/dist/index.js.br +0 -0
- package/dist/index.js.gz +0 -0
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
__async,
|
|
4
|
+
__spreadProps,
|
|
5
|
+
__spreadValues
|
|
6
|
+
} from "./chunk-MMUBH76A.js";
|
|
7
|
+
import {
|
|
8
|
+
ProviderRpcError,
|
|
9
|
+
webSocket,
|
|
10
|
+
publicActions,
|
|
11
|
+
http,
|
|
12
|
+
formatTransaction
|
|
13
|
+
} from "viem";
|
|
14
|
+
import { EventEmitter } from "eventemitter3";
|
|
15
|
+
import { extractRpcUrls } from "@wagmi/core";
|
|
16
|
+
import { getViemChain, createParaViemClient, createParaAccount } from "@getpara/viem-v2-integration";
|
|
17
|
+
import { decimalToHex, hexToDecimal } from "@getpara/react-sdk";
|
|
18
|
+
import { renderModal } from "./connectorModal.js";
|
|
19
|
+
const STORAGE_CHAIN_ID_KEY = "@CAPSULE/chainId";
|
|
20
|
+
const TEN_MINUTES_MS = 6e5;
|
|
21
|
+
const serverSessionStorageStub = {
|
|
22
|
+
setItem: () => {
|
|
23
|
+
},
|
|
24
|
+
getItem: () => null
|
|
25
|
+
};
|
|
26
|
+
class ParaEIP1193Provider extends EventEmitter {
|
|
27
|
+
constructor(opts) {
|
|
28
|
+
super();
|
|
29
|
+
this.getRpcUrlsFromViemChain = (chain) => {
|
|
30
|
+
return extractRpcUrls({ chain, transports: this.transports });
|
|
31
|
+
};
|
|
32
|
+
this.wagmiChainToAddEthereumChainParameters = (chain) => {
|
|
33
|
+
const hexChainId = decimalToHex(`${chain.id}`);
|
|
34
|
+
return [
|
|
35
|
+
hexChainId,
|
|
36
|
+
{
|
|
37
|
+
chainId: hexChainId,
|
|
38
|
+
chainName: chain.name,
|
|
39
|
+
nativeCurrency: chain.nativeCurrency,
|
|
40
|
+
rpcUrls: this.getRpcUrlsFromViemChain(chain)
|
|
41
|
+
}
|
|
42
|
+
];
|
|
43
|
+
};
|
|
44
|
+
this.wagmiChainsToAddEthereumChainParameters = (chains) => {
|
|
45
|
+
return Object.fromEntries(chains.map(this.wagmiChainToAddEthereumChainParameters));
|
|
46
|
+
};
|
|
47
|
+
this.accountFromAddress = (address) => {
|
|
48
|
+
return createParaAccount(this.para, address);
|
|
49
|
+
};
|
|
50
|
+
this.setCurrentChain = (chainId) => {
|
|
51
|
+
const chain = this.chains[chainId];
|
|
52
|
+
this.setChainId(chainId);
|
|
53
|
+
const viemChain = this.viemChains[chainId] || getViemChain(hexToDecimal(chainId));
|
|
54
|
+
const rpcUrls = this.getRpcUrlsFromViemChain(viemChain);
|
|
55
|
+
let transport;
|
|
56
|
+
if (this.transports[viemChain.id]) {
|
|
57
|
+
transport = this.transports[viemChain.id];
|
|
58
|
+
} else if (rpcUrls[0].startsWith("ws")) {
|
|
59
|
+
transport = webSocket(chain.rpcUrls[0]);
|
|
60
|
+
} else {
|
|
61
|
+
transport = http(rpcUrls[0]);
|
|
62
|
+
this.chainTransportSubscribe = void 0;
|
|
63
|
+
}
|
|
64
|
+
const chainTransport = transport({
|
|
65
|
+
chain: viemChain
|
|
66
|
+
});
|
|
67
|
+
if (chainTransport.config.type === "ws") {
|
|
68
|
+
this.chainTransportSubscribe = chainTransport.value.subscribe;
|
|
69
|
+
}
|
|
70
|
+
this.walletClient = createParaViemClient(
|
|
71
|
+
this.para,
|
|
72
|
+
{
|
|
73
|
+
chain: viemChain,
|
|
74
|
+
transport
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
},
|
|
77
|
+
{ noAccount: true }
|
|
78
|
+
).extend(publicActions);
|
|
79
|
+
this.emit("chainChanged", this.currentHexChainId);
|
|
80
|
+
};
|
|
81
|
+
this.closeModal = () => {
|
|
82
|
+
this.isModalClosed = true;
|
|
83
|
+
};
|
|
84
|
+
this.request = (args) => __async(this, null, function* () {
|
|
85
|
+
const { method, params } = args;
|
|
86
|
+
switch (method) {
|
|
87
|
+
case "eth_accounts": {
|
|
88
|
+
const accounts = this.accounts;
|
|
89
|
+
return accounts || [];
|
|
90
|
+
}
|
|
91
|
+
case "eth_chainId": {
|
|
92
|
+
return this.currentHexChainId;
|
|
93
|
+
}
|
|
94
|
+
case "eth_requestAccounts": {
|
|
95
|
+
if (yield this.para.isFullyLoggedIn()) {
|
|
96
|
+
const accounts = this.accounts;
|
|
97
|
+
if (accounts && accounts.length > 0) {
|
|
98
|
+
return accounts;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (!this.disableModal) {
|
|
102
|
+
this.isModalClosed = false;
|
|
103
|
+
renderModal(this.para, this.modalProps, () => {
|
|
104
|
+
this.isModalClosed = true;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
yield this.waitForLogin();
|
|
108
|
+
try {
|
|
109
|
+
const accounts = yield this.waitForAccounts();
|
|
110
|
+
this.emit("accountsChanged", accounts);
|
|
111
|
+
return accounts;
|
|
112
|
+
} catch (error) {
|
|
113
|
+
throw new ProviderRpcError(new Error("accounts not available after login"), {
|
|
114
|
+
code: 4001,
|
|
115
|
+
shortMessage: "accounts not available after login"
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
case "eth_sendTransaction": {
|
|
120
|
+
const fromAddress = params[0].from;
|
|
121
|
+
return this.walletClient.sendTransaction(__spreadProps(__spreadValues({}, formatTransaction(params[0])), {
|
|
122
|
+
chain: void 0,
|
|
123
|
+
// uses the chain from the wallet client
|
|
124
|
+
account: this.accountFromAddress(fromAddress)
|
|
125
|
+
}));
|
|
126
|
+
}
|
|
127
|
+
case "eth_sign":
|
|
128
|
+
case "personal_sign": {
|
|
129
|
+
return this.walletClient.signMessage({
|
|
130
|
+
message: { raw: params[0] },
|
|
131
|
+
account: this.accountFromAddress(params[1])
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
case "eth_signTransaction": {
|
|
135
|
+
const fromAddress = params[0].from;
|
|
136
|
+
return this.accountFromAddress(fromAddress).signTransaction(formatTransaction(params[0]));
|
|
137
|
+
}
|
|
138
|
+
case "eth_signTypedData_v4": {
|
|
139
|
+
const fromAddress = params[0];
|
|
140
|
+
let typedMessage = params[1];
|
|
141
|
+
if (typeof typedMessage === "string") {
|
|
142
|
+
typedMessage = JSON.parse(typedMessage);
|
|
143
|
+
}
|
|
144
|
+
return this.walletClient.signTypedData(__spreadProps(__spreadValues({}, typedMessage), {
|
|
145
|
+
account: this.accountFromAddress(fromAddress)
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
case "eth_subscribe": {
|
|
149
|
+
if (!this.chainTransportSubscribe) {
|
|
150
|
+
throw new ProviderRpcError(new Error("chain does not support subscriptions"), {
|
|
151
|
+
code: 4200,
|
|
152
|
+
shortMessage: "chain does not support subscriptions"
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
const res = yield this.chainTransportSubscribe({
|
|
156
|
+
params,
|
|
157
|
+
onData: (data) => {
|
|
158
|
+
this.emit("message", {
|
|
159
|
+
type: "eth_subscription",
|
|
160
|
+
data
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
return res.subscriptionId;
|
|
165
|
+
}
|
|
166
|
+
case "wallet_addEthereumChain": {
|
|
167
|
+
if (!this.chains[params[0].chainId]) {
|
|
168
|
+
this.chains[params[0].chainId] = params[0];
|
|
169
|
+
}
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
case "wallet_getPermissions": {
|
|
173
|
+
return [];
|
|
174
|
+
}
|
|
175
|
+
case "wallet_requestPermissions": {
|
|
176
|
+
return [];
|
|
177
|
+
}
|
|
178
|
+
case "wallet_switchEthereumChain": {
|
|
179
|
+
if (!this.chains[params[0].chainId]) {
|
|
180
|
+
const chain = getViemChain(hexToDecimal(params[0].chainId));
|
|
181
|
+
const [hexChainId, addEthereumChainParameter] = this.wagmiChainToAddEthereumChainParameters(chain);
|
|
182
|
+
this.chains[hexChainId] = addEthereumChainParameter;
|
|
183
|
+
this.setCurrentChain(params[0].chainId);
|
|
184
|
+
}
|
|
185
|
+
if (this.currentHexChainId !== params[0].chainId) {
|
|
186
|
+
this.setCurrentChain(params[0].chainId);
|
|
187
|
+
}
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
case "wallet_watchAsset": {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
default: {
|
|
194
|
+
return this.walletClient.request({
|
|
195
|
+
method,
|
|
196
|
+
params
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
this.storage = opts.storageOverride || typeof window === "undefined" ? serverSessionStorageStub : sessionStorage;
|
|
202
|
+
this.isModalClosed = true;
|
|
203
|
+
this.para = opts.para;
|
|
204
|
+
this.modalProps = __spreadValues({}, opts);
|
|
205
|
+
this.disableModal = !!opts.disableModal;
|
|
206
|
+
this.viemChains = opts.chains.reduce((acc, curChain) => {
|
|
207
|
+
acc[decimalToHex(`${curChain.id}`)] = curChain;
|
|
208
|
+
return acc;
|
|
209
|
+
}, {});
|
|
210
|
+
this.chains = this.wagmiChainsToAddEthereumChainParameters(opts.chains);
|
|
211
|
+
this.transports = opts.transports;
|
|
212
|
+
const defaultChainId = this.getStorageChainId() || opts.chainId;
|
|
213
|
+
const currentChainId = this.chains[decimalToHex(defaultChainId)] ? defaultChainId : `${opts.chains[0].id}`;
|
|
214
|
+
this.setCurrentChain(decimalToHex(currentChainId));
|
|
215
|
+
this.emit("connect", { chainId: this.currentHexChainId });
|
|
216
|
+
}
|
|
217
|
+
get accounts() {
|
|
218
|
+
return this.para.getWalletsByType("EVM").map((w) => w.address);
|
|
219
|
+
}
|
|
220
|
+
getStorageChainId() {
|
|
221
|
+
return this.storage.getItem(STORAGE_CHAIN_ID_KEY);
|
|
222
|
+
}
|
|
223
|
+
setChainId(hexChainId) {
|
|
224
|
+
this.currentHexChainId = hexChainId;
|
|
225
|
+
this.storage.setItem(STORAGE_CHAIN_ID_KEY, hexToDecimal(hexChainId));
|
|
226
|
+
}
|
|
227
|
+
waitForLogin() {
|
|
228
|
+
return __async(this, arguments, function* (timeoutMs = TEN_MINUTES_MS) {
|
|
229
|
+
const startTime = Date.now();
|
|
230
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
231
|
+
if (yield this.para.isFullyLoggedIn()) {
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
if (!this.disableModal && this.isModalClosed) {
|
|
235
|
+
throw new ProviderRpcError(new Error("user closed modal"), {
|
|
236
|
+
code: 4001,
|
|
237
|
+
shortMessage: "user closed modal"
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
yield new Promise((resolve) => setTimeout(resolve, 2e3));
|
|
241
|
+
}
|
|
242
|
+
throw new ProviderRpcError(new Error("timed out waiting for user to log in"), {
|
|
243
|
+
code: 4900,
|
|
244
|
+
//provider is disconnected code
|
|
245
|
+
shortMessage: "timed out waiting for user to log in"
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
waitForAccounts(timeoutMs = 5e3) {
|
|
250
|
+
return __async(this, null, function* () {
|
|
251
|
+
const startTime = Date.now();
|
|
252
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
253
|
+
const accounts = this.accounts;
|
|
254
|
+
if (accounts && accounts.length > 0) {
|
|
255
|
+
return accounts;
|
|
256
|
+
}
|
|
257
|
+
yield new Promise((resolve) => setTimeout(resolve, 500));
|
|
258
|
+
}
|
|
259
|
+
throw new ProviderRpcError(new Error("timed out waiting for accounts to load"), {
|
|
260
|
+
code: 4900,
|
|
261
|
+
//provider is disconnected code
|
|
262
|
+
shortMessage: "timed out waiting for accounts to load"
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
export {
|
|
268
|
+
ParaEIP1193Provider
|
|
269
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
+
var __objRest = (source, exclude) => {
|
|
22
|
+
var target = {};
|
|
23
|
+
for (var prop in source)
|
|
24
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
25
|
+
target[prop] = source[prop];
|
|
26
|
+
if (source != null && __getOwnPropSymbols)
|
|
27
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
28
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
}
|
|
31
|
+
return target;
|
|
32
|
+
};
|
|
33
|
+
var __async = (__this, __arguments, generator) => {
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
var fulfilled = (value) => {
|
|
36
|
+
try {
|
|
37
|
+
step(generator.next(value));
|
|
38
|
+
} catch (e) {
|
|
39
|
+
reject(e);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var rejected = (value) => {
|
|
43
|
+
try {
|
|
44
|
+
step(generator.throw(value));
|
|
45
|
+
} catch (e) {
|
|
46
|
+
reject(e);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
50
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export {
|
|
55
|
+
__spreadValues,
|
|
56
|
+
__spreadProps,
|
|
57
|
+
__objRest,
|
|
58
|
+
__async
|
|
59
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
__async,
|
|
4
|
+
__spreadProps,
|
|
5
|
+
__spreadValues
|
|
6
|
+
} from "./chunk-MMUBH76A.js";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
import { ParaModal } from "@getpara/react-sdk";
|
|
9
|
+
function renderModal(para, modalProps, onCloseArg) {
|
|
10
|
+
const existingContainer = document.getElementById("para-modal");
|
|
11
|
+
const container = existingContainer != null ? existingContainer : document.createElement("div");
|
|
12
|
+
container.id = "para-modal";
|
|
13
|
+
if (!existingContainer) {
|
|
14
|
+
document.body.appendChild(container);
|
|
15
|
+
}
|
|
16
|
+
const onClose = () => {
|
|
17
|
+
onCloseArg();
|
|
18
|
+
modalProps.onClose && modalProps.onClose();
|
|
19
|
+
render(false);
|
|
20
|
+
};
|
|
21
|
+
const render = (isOpen) => __async(this, null, function* () {
|
|
22
|
+
const Modal = /* @__PURE__ */ jsx(ParaModal, __spreadProps(__spreadValues({}, modalProps), { onClose, para, isOpen }));
|
|
23
|
+
try {
|
|
24
|
+
const client = yield import("react-dom/client");
|
|
25
|
+
const root = client.createRoot(container);
|
|
26
|
+
root.render(Modal);
|
|
27
|
+
} catch (e) {
|
|
28
|
+
const ReactDOM = yield import("react-dom");
|
|
29
|
+
ReactDOM.render(Modal, container);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
render(true);
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
renderModal
|
|
36
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -1,408 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __spreadValues = (a, b) => {
|
|
10
|
-
for (var prop in b || (b = {}))
|
|
11
|
-
if (__hasOwnProp.call(b, prop))
|
|
12
|
-
__defNormalProp(a, prop, b[prop]);
|
|
13
|
-
if (__getOwnPropSymbols)
|
|
14
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
-
if (__propIsEnum.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
}
|
|
18
|
-
return a;
|
|
19
|
-
};
|
|
20
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
-
var __objRest = (source, exclude) => {
|
|
22
|
-
var target = {};
|
|
23
|
-
for (var prop in source)
|
|
24
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
25
|
-
target[prop] = source[prop];
|
|
26
|
-
if (source != null && __getOwnPropSymbols)
|
|
27
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
28
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
29
|
-
target[prop] = source[prop];
|
|
30
|
-
}
|
|
31
|
-
return target;
|
|
32
|
-
};
|
|
33
|
-
var __async = (__this, __arguments, generator) => {
|
|
34
|
-
return new Promise((resolve, reject) => {
|
|
35
|
-
var fulfilled = (value) => {
|
|
36
|
-
try {
|
|
37
|
-
step(generator.next(value));
|
|
38
|
-
} catch (e) {
|
|
39
|
-
reject(e);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
var rejected = (value) => {
|
|
43
|
-
try {
|
|
44
|
-
step(generator.throw(value));
|
|
45
|
-
} catch (e) {
|
|
46
|
-
reject(e);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
50
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
// src/paraConnector.ts
|
|
55
|
-
import { injected } from "wagmi/connectors";
|
|
56
|
-
|
|
57
|
-
// src/ParaEIP1193Provider.ts
|
|
58
|
-
import {
|
|
59
|
-
ProviderRpcError,
|
|
60
|
-
webSocket,
|
|
61
|
-
publicActions,
|
|
62
|
-
http,
|
|
63
|
-
formatTransaction
|
|
64
|
-
} from "viem";
|
|
65
|
-
import { EventEmitter } from "eventemitter3";
|
|
66
|
-
import { extractRpcUrls } from "@wagmi/core";
|
|
67
|
-
import { getViemChain, createParaViemClient, createParaAccount } from "@getpara/viem-v2-integration";
|
|
68
|
-
import { decimalToHex, hexToDecimal } from "@getpara/react-sdk";
|
|
69
|
-
|
|
70
|
-
// src/connectorModal.tsx
|
|
71
|
-
import { ParaModal } from "@getpara/react-sdk";
|
|
72
|
-
import { jsx } from "react/jsx-runtime";
|
|
73
|
-
function renderModal(para, modalProps, onCloseArg) {
|
|
74
|
-
const existingContainer = document.getElementById("para-modal");
|
|
75
|
-
const container = existingContainer != null ? existingContainer : document.createElement("div");
|
|
76
|
-
container.id = "para-modal";
|
|
77
|
-
if (!existingContainer) {
|
|
78
|
-
document.body.appendChild(container);
|
|
79
|
-
}
|
|
80
|
-
const onClose = () => {
|
|
81
|
-
onCloseArg();
|
|
82
|
-
modalProps.onClose && modalProps.onClose();
|
|
83
|
-
render(false);
|
|
84
|
-
};
|
|
85
|
-
const render = (isOpen) => __async(this, null, function* () {
|
|
86
|
-
const Modal = /* @__PURE__ */ jsx(ParaModal, __spreadProps(__spreadValues({}, modalProps), { onClose, para, isOpen }));
|
|
87
|
-
try {
|
|
88
|
-
const client = yield import("react-dom/client");
|
|
89
|
-
const root = client.createRoot(container);
|
|
90
|
-
root.render(Modal);
|
|
91
|
-
} catch (e) {
|
|
92
|
-
const ReactDOM = yield import("react-dom");
|
|
93
|
-
ReactDOM.render(Modal, container);
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
render(true);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// src/ParaEIP1193Provider.ts
|
|
100
|
-
var STORAGE_CHAIN_ID_KEY = "@CAPSULE/chainId";
|
|
101
|
-
var TEN_MINUTES_MS = 6e5;
|
|
102
|
-
var serverSessionStorageStub = {
|
|
103
|
-
setItem: () => {
|
|
104
|
-
},
|
|
105
|
-
getItem: () => null
|
|
106
|
-
};
|
|
107
|
-
var ParaEIP1193Provider = class extends EventEmitter {
|
|
108
|
-
constructor(opts) {
|
|
109
|
-
super();
|
|
110
|
-
this.getRpcUrlsFromViemChain = (chain) => {
|
|
111
|
-
return extractRpcUrls({ chain, transports: this.transports });
|
|
112
|
-
};
|
|
113
|
-
this.wagmiChainToAddEthereumChainParameters = (chain) => {
|
|
114
|
-
const hexChainId = decimalToHex(`${chain.id}`);
|
|
115
|
-
return [
|
|
116
|
-
hexChainId,
|
|
117
|
-
{
|
|
118
|
-
chainId: hexChainId,
|
|
119
|
-
chainName: chain.name,
|
|
120
|
-
nativeCurrency: chain.nativeCurrency,
|
|
121
|
-
rpcUrls: this.getRpcUrlsFromViemChain(chain)
|
|
122
|
-
}
|
|
123
|
-
];
|
|
124
|
-
};
|
|
125
|
-
this.wagmiChainsToAddEthereumChainParameters = (chains) => {
|
|
126
|
-
return Object.fromEntries(chains.map(this.wagmiChainToAddEthereumChainParameters));
|
|
127
|
-
};
|
|
128
|
-
this.accountFromAddress = (address) => {
|
|
129
|
-
return createParaAccount(this.para, address);
|
|
130
|
-
};
|
|
131
|
-
this.setCurrentChain = (chainId) => {
|
|
132
|
-
const chain = this.chains[chainId];
|
|
133
|
-
this.setChainId(chainId);
|
|
134
|
-
const viemChain = this.viemChains[chainId] || getViemChain(hexToDecimal(chainId));
|
|
135
|
-
const rpcUrls = this.getRpcUrlsFromViemChain(viemChain);
|
|
136
|
-
let transport;
|
|
137
|
-
if (this.transports[viemChain.id]) {
|
|
138
|
-
transport = this.transports[viemChain.id];
|
|
139
|
-
} else if (rpcUrls[0].startsWith("ws")) {
|
|
140
|
-
transport = webSocket(chain.rpcUrls[0]);
|
|
141
|
-
} else {
|
|
142
|
-
transport = http(rpcUrls[0]);
|
|
143
|
-
this.chainTransportSubscribe = void 0;
|
|
144
|
-
}
|
|
145
|
-
const chainTransport = transport({
|
|
146
|
-
chain: viemChain
|
|
147
|
-
});
|
|
148
|
-
if (chainTransport.config.type === "ws") {
|
|
149
|
-
this.chainTransportSubscribe = chainTransport.value.subscribe;
|
|
150
|
-
}
|
|
151
|
-
this.walletClient = createParaViemClient(
|
|
152
|
-
this.para,
|
|
153
|
-
{
|
|
154
|
-
chain: viemChain,
|
|
155
|
-
transport
|
|
156
|
-
// @ts-ignore
|
|
157
|
-
},
|
|
158
|
-
{ noAccount: true }
|
|
159
|
-
).extend(publicActions);
|
|
160
|
-
this.emit("chainChanged", this.currentHexChainId);
|
|
161
|
-
};
|
|
162
|
-
this.closeModal = () => {
|
|
163
|
-
this.isModalClosed = true;
|
|
164
|
-
};
|
|
165
|
-
this.request = (args) => __async(this, null, function* () {
|
|
166
|
-
const { method, params } = args;
|
|
167
|
-
switch (method) {
|
|
168
|
-
case "eth_accounts": {
|
|
169
|
-
const accounts = this.accounts;
|
|
170
|
-
return accounts || [];
|
|
171
|
-
}
|
|
172
|
-
case "eth_chainId": {
|
|
173
|
-
return this.currentHexChainId;
|
|
174
|
-
}
|
|
175
|
-
case "eth_requestAccounts": {
|
|
176
|
-
if (yield this.para.isFullyLoggedIn()) {
|
|
177
|
-
const accounts = this.accounts;
|
|
178
|
-
if (accounts && accounts.length > 0) {
|
|
179
|
-
return accounts;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
if (!this.disableModal) {
|
|
183
|
-
this.isModalClosed = false;
|
|
184
|
-
renderModal(this.para, this.modalProps, () => {
|
|
185
|
-
this.isModalClosed = true;
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
yield this.waitForLogin();
|
|
189
|
-
try {
|
|
190
|
-
const accounts = yield this.waitForAccounts();
|
|
191
|
-
this.emit("accountsChanged", accounts);
|
|
192
|
-
return accounts;
|
|
193
|
-
} catch (error) {
|
|
194
|
-
throw new ProviderRpcError(new Error("accounts not available after login"), {
|
|
195
|
-
code: 4001,
|
|
196
|
-
shortMessage: "accounts not available after login"
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
case "eth_sendTransaction": {
|
|
201
|
-
const fromAddress = params[0].from;
|
|
202
|
-
return this.walletClient.sendTransaction(__spreadProps(__spreadValues({}, formatTransaction(params[0])), {
|
|
203
|
-
chain: void 0,
|
|
204
|
-
// uses the chain from the wallet client
|
|
205
|
-
account: this.accountFromAddress(fromAddress)
|
|
206
|
-
}));
|
|
207
|
-
}
|
|
208
|
-
case "eth_sign":
|
|
209
|
-
case "personal_sign": {
|
|
210
|
-
return this.walletClient.signMessage({
|
|
211
|
-
message: { raw: params[0] },
|
|
212
|
-
account: this.accountFromAddress(params[1])
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
case "eth_signTransaction": {
|
|
216
|
-
const fromAddress = params[0].from;
|
|
217
|
-
return this.accountFromAddress(fromAddress).signTransaction(formatTransaction(params[0]));
|
|
218
|
-
}
|
|
219
|
-
case "eth_signTypedData_v4": {
|
|
220
|
-
const fromAddress = params[0];
|
|
221
|
-
let typedMessage = params[1];
|
|
222
|
-
if (typeof typedMessage === "string") {
|
|
223
|
-
typedMessage = JSON.parse(typedMessage);
|
|
224
|
-
}
|
|
225
|
-
return this.walletClient.signTypedData(__spreadProps(__spreadValues({}, typedMessage), {
|
|
226
|
-
account: this.accountFromAddress(fromAddress)
|
|
227
|
-
}));
|
|
228
|
-
}
|
|
229
|
-
case "eth_subscribe": {
|
|
230
|
-
if (!this.chainTransportSubscribe) {
|
|
231
|
-
throw new ProviderRpcError(new Error("chain does not support subscriptions"), {
|
|
232
|
-
code: 4200,
|
|
233
|
-
shortMessage: "chain does not support subscriptions"
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
const res = yield this.chainTransportSubscribe({
|
|
237
|
-
params,
|
|
238
|
-
onData: (data) => {
|
|
239
|
-
this.emit("message", {
|
|
240
|
-
type: "eth_subscription",
|
|
241
|
-
data
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
return res.subscriptionId;
|
|
246
|
-
}
|
|
247
|
-
case "wallet_addEthereumChain": {
|
|
248
|
-
if (!this.chains[params[0].chainId]) {
|
|
249
|
-
this.chains[params[0].chainId] = params[0];
|
|
250
|
-
}
|
|
251
|
-
return null;
|
|
252
|
-
}
|
|
253
|
-
case "wallet_getPermissions": {
|
|
254
|
-
return [];
|
|
255
|
-
}
|
|
256
|
-
case "wallet_requestPermissions": {
|
|
257
|
-
return [];
|
|
258
|
-
}
|
|
259
|
-
case "wallet_switchEthereumChain": {
|
|
260
|
-
if (!this.chains[params[0].chainId]) {
|
|
261
|
-
const chain = getViemChain(hexToDecimal(params[0].chainId));
|
|
262
|
-
const [hexChainId, addEthereumChainParameter] = this.wagmiChainToAddEthereumChainParameters(chain);
|
|
263
|
-
this.chains[hexChainId] = addEthereumChainParameter;
|
|
264
|
-
this.setCurrentChain(params[0].chainId);
|
|
265
|
-
}
|
|
266
|
-
if (this.currentHexChainId !== params[0].chainId) {
|
|
267
|
-
this.setCurrentChain(params[0].chainId);
|
|
268
|
-
}
|
|
269
|
-
return null;
|
|
270
|
-
}
|
|
271
|
-
case "wallet_watchAsset": {
|
|
272
|
-
return false;
|
|
273
|
-
}
|
|
274
|
-
default: {
|
|
275
|
-
return this.walletClient.request({
|
|
276
|
-
method,
|
|
277
|
-
params
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
});
|
|
282
|
-
this.storage = opts.storageOverride || typeof window === "undefined" ? serverSessionStorageStub : sessionStorage;
|
|
283
|
-
this.isModalClosed = true;
|
|
284
|
-
this.para = opts.para;
|
|
285
|
-
this.modalProps = __spreadValues({}, opts);
|
|
286
|
-
this.disableModal = !!opts.disableModal;
|
|
287
|
-
this.viemChains = opts.chains.reduce((acc, curChain) => {
|
|
288
|
-
acc[decimalToHex(`${curChain.id}`)] = curChain;
|
|
289
|
-
return acc;
|
|
290
|
-
}, {});
|
|
291
|
-
this.chains = this.wagmiChainsToAddEthereumChainParameters(opts.chains);
|
|
292
|
-
this.transports = opts.transports;
|
|
293
|
-
const defaultChainId = this.getStorageChainId() || opts.chainId;
|
|
294
|
-
const currentChainId = this.chains[decimalToHex(defaultChainId)] ? defaultChainId : `${opts.chains[0].id}`;
|
|
295
|
-
this.setCurrentChain(decimalToHex(currentChainId));
|
|
296
|
-
this.emit("connect", { chainId: this.currentHexChainId });
|
|
297
|
-
}
|
|
298
|
-
get accounts() {
|
|
299
|
-
return this.para.getWalletsByType("EVM").map((w) => w.address);
|
|
300
|
-
}
|
|
301
|
-
getStorageChainId() {
|
|
302
|
-
return this.storage.getItem(STORAGE_CHAIN_ID_KEY);
|
|
303
|
-
}
|
|
304
|
-
setChainId(hexChainId) {
|
|
305
|
-
this.currentHexChainId = hexChainId;
|
|
306
|
-
this.storage.setItem(STORAGE_CHAIN_ID_KEY, hexToDecimal(hexChainId));
|
|
307
|
-
}
|
|
308
|
-
waitForLogin() {
|
|
309
|
-
return __async(this, arguments, function* (timeoutMs = TEN_MINUTES_MS) {
|
|
310
|
-
const startTime = Date.now();
|
|
311
|
-
while (Date.now() - startTime < timeoutMs) {
|
|
312
|
-
if (yield this.para.isFullyLoggedIn()) {
|
|
313
|
-
return true;
|
|
314
|
-
}
|
|
315
|
-
if (!this.disableModal && this.isModalClosed) {
|
|
316
|
-
throw new ProviderRpcError(new Error("user closed modal"), {
|
|
317
|
-
code: 4001,
|
|
318
|
-
shortMessage: "user closed modal"
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
yield new Promise((resolve) => setTimeout(resolve, 2e3));
|
|
322
|
-
}
|
|
323
|
-
throw new ProviderRpcError(new Error("timed out waiting for user to log in"), {
|
|
324
|
-
code: 4900,
|
|
325
|
-
//provider is disconnected code
|
|
326
|
-
shortMessage: "timed out waiting for user to log in"
|
|
327
|
-
});
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
waitForAccounts(timeoutMs = 5e3) {
|
|
331
|
-
return __async(this, null, function* () {
|
|
332
|
-
const startTime = Date.now();
|
|
333
|
-
while (Date.now() - startTime < timeoutMs) {
|
|
334
|
-
const accounts = this.accounts;
|
|
335
|
-
if (accounts && accounts.length > 0) {
|
|
336
|
-
return accounts;
|
|
337
|
-
}
|
|
338
|
-
yield new Promise((resolve) => setTimeout(resolve, 500));
|
|
339
|
-
}
|
|
340
|
-
throw new ProviderRpcError(new Error("timed out waiting for accounts to load"), {
|
|
341
|
-
code: 4900,
|
|
342
|
-
//provider is disconnected code
|
|
343
|
-
shortMessage: "timed out waiting for accounts to load"
|
|
344
|
-
});
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
};
|
|
348
|
-
|
|
349
|
-
// src/paraConnector.ts
|
|
350
|
-
import { createConnector } from "wagmi";
|
|
351
|
-
var PARA_ID = "para";
|
|
352
|
-
var PARA_NAME = "Para";
|
|
353
|
-
var PARA_ICON = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjE2IiBoZWlnaHQ9IjIwNCIgdmlld0JveD0iMCAwIDIxNiAyMDQiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxwYXRoIGQ9Ik02MCAwSDE0NEMxODMuNzY0IDAgMjE2IDMyLjIzNTUgMjE2IDcyQzIxNiAxMTEuNzY1IDE4My43NjQgMTQ0IDE0NCAxNDRIOTZDODIuNzQ1MiAxNDQgNzIgMTU0Ljc0NSA3MiAxNjhWMjA0SDBWMTMySDM2QzQ5LjI1NDggMTMyIDYwIDEyMS4yNTUgNjAgMTA4TDYwIDBaIiBmaWxsPSJibGFjayIvPgo8L3N2Zz4K";
|
|
354
|
-
var paraConnector = (_a) => {
|
|
355
|
-
var _b = _a, {
|
|
356
|
-
para,
|
|
357
|
-
chains: _chains,
|
|
358
|
-
disableModal,
|
|
359
|
-
storageOverride,
|
|
360
|
-
options,
|
|
361
|
-
iconOverride,
|
|
362
|
-
nameOverride,
|
|
363
|
-
idOverride,
|
|
364
|
-
transports
|
|
365
|
-
} = _b, modalProps = __objRest(_b, [
|
|
366
|
-
"para",
|
|
367
|
-
"chains",
|
|
368
|
-
"disableModal",
|
|
369
|
-
"storageOverride",
|
|
370
|
-
"options",
|
|
371
|
-
"iconOverride",
|
|
372
|
-
"nameOverride",
|
|
373
|
-
"idOverride",
|
|
374
|
-
"transports"
|
|
375
|
-
]);
|
|
376
|
-
return createConnector((config) => {
|
|
377
|
-
const chains = [...config.chains];
|
|
378
|
-
const eip1193Provider = new ParaEIP1193Provider(__spreadValues({
|
|
379
|
-
para,
|
|
380
|
-
chainId: `${chains[0].id}`,
|
|
381
|
-
chains,
|
|
382
|
-
disableModal,
|
|
383
|
-
storageOverride,
|
|
384
|
-
transports: transports || config.transports
|
|
385
|
-
}, modalProps));
|
|
386
|
-
const injectedObj = injected(__spreadValues({
|
|
387
|
-
target: {
|
|
388
|
-
name: PARA_NAME,
|
|
389
|
-
id: idOverride != null ? idOverride : PARA_ID,
|
|
390
|
-
provider: eip1193Provider
|
|
391
|
-
}
|
|
392
|
-
}, options))(config);
|
|
393
|
-
return __spreadProps(__spreadValues({}, injectedObj), {
|
|
394
|
-
type: idOverride != null ? idOverride : PARA_ID,
|
|
395
|
-
name: nameOverride != null ? nameOverride : PARA_NAME,
|
|
396
|
-
icon: iconOverride != null ? iconOverride : PARA_ICON,
|
|
397
|
-
disconnect: () => __async(void 0, null, function* () {
|
|
398
|
-
eip1193Provider.closeModal();
|
|
399
|
-
yield injectedObj.disconnect();
|
|
400
|
-
para.logout();
|
|
401
|
-
})
|
|
402
|
-
});
|
|
403
|
-
});
|
|
404
|
-
};
|
|
405
|
-
export {
|
|
406
|
-
ParaEIP1193Provider,
|
|
407
|
-
paraConnector
|
|
408
|
-
};
|
|
2
|
+
export * from "./paraConnector.js";
|
|
3
|
+
export * from "./ParaEIP1193Provider.js";
|
package/dist/paraConnector.d.ts
CHANGED
|
@@ -17,12 +17,23 @@ interface ParaConnectorOpts extends Partial<ParaModalProps> {
|
|
|
17
17
|
nameOverride?: string;
|
|
18
18
|
transports?: Record<number, Transport>;
|
|
19
19
|
}
|
|
20
|
-
export declare const paraConnector: ({ para, chains: _chains, disableModal, storageOverride, options, iconOverride, nameOverride, idOverride, transports, ...modalProps }: ParaConnectorOpts) =>
|
|
20
|
+
export declare const paraConnector: ({ para, chains: _chains, disableModal, storageOverride, options, iconOverride, nameOverride, idOverride, transports, ...modalProps }: ParaConnectorOpts) => (config: {
|
|
21
|
+
chains: readonly [Chain, ...Chain[]];
|
|
22
|
+
emitter: import("@wagmi/core/internal").Emitter<import("wagmi").ConnectorEventMap>;
|
|
23
|
+
storage?: {
|
|
24
|
+
key: string;
|
|
25
|
+
getItem: <key extends string, value extends (import("@wagmi/core").StorageItemMap & Record<string, unknown>)[key], defaultValue extends value>(key: key, defaultValue?: defaultValue) => (defaultValue extends null ? value : value) | Promise<defaultValue extends null ? value : value>;
|
|
26
|
+
setItem: <key_1 extends string, value_1 extends (import("@wagmi/core").StorageItemMap & Record<string, unknown>)[key_1]>(key: key_1, value: value_1) => void | Promise<void>;
|
|
27
|
+
removeItem: (key: string) => void | Promise<void>;
|
|
28
|
+
};
|
|
29
|
+
transports?: Record<number, import("wagmi").Transport>;
|
|
30
|
+
}) => {
|
|
21
31
|
type: string;
|
|
22
32
|
name: string;
|
|
23
33
|
icon: string;
|
|
24
34
|
disconnect: () => Promise<void>;
|
|
25
35
|
id: string;
|
|
36
|
+
rdns?: string | readonly string[];
|
|
26
37
|
supportsSimulation?: boolean;
|
|
27
38
|
setup?: () => Promise<void>;
|
|
28
39
|
connect: (parameters?: {
|
|
@@ -37,8 +48,8 @@ export declare const paraConnector: ({ para, chains: _chains, disableModal, stor
|
|
|
37
48
|
getProvider: (parameters?: {
|
|
38
49
|
chainId?: number;
|
|
39
50
|
}) => Promise<{
|
|
40
|
-
on: <
|
|
41
|
-
removeListener: <
|
|
51
|
+
on: <event extends keyof import("viem").EIP1193EventMap>(event: event, listener: import("viem").EIP1193EventMap[event]) => void;
|
|
52
|
+
removeListener: <event_1 extends keyof import("viem").EIP1193EventMap>(event: event_1, listener: import("viem").EIP1193EventMap[event_1]) => void;
|
|
42
53
|
request: import("viem").EIP1193RequestFn<[{
|
|
43
54
|
Method: "web3_clientVersion";
|
|
44
55
|
Parameters?: undefined;
|
|
@@ -71,6 +82,13 @@ export declare const paraConnector: ({ para, chains: _chains, disableModal, stor
|
|
|
71
82
|
Method: "eth_call";
|
|
72
83
|
Parameters: [transaction: import("viem").ExactPartial<import("viem").RpcTransactionRequest>] | [transaction: import("viem").ExactPartial<import("viem").RpcTransactionRequest>, block: `0x${string}` | import("viem").BlockTag | import("viem").RpcBlockIdentifier] | [transaction: import("viem").ExactPartial<import("viem").RpcTransactionRequest>, block: `0x${string}` | import("viem").BlockTag | import("viem").RpcBlockIdentifier, stateOverrideSet: import("viem").RpcStateOverride];
|
|
73
84
|
ReturnType: `0x${string}`;
|
|
85
|
+
}, {
|
|
86
|
+
Method: "eth_createAccessList";
|
|
87
|
+
Parameters: [transaction: import("viem").ExactPartial<import("viem").RpcTransactionRequest>] | [transaction: import("viem").ExactPartial<import("viem").RpcTransactionRequest>, block: `0x${string}` | import("viem").BlockTag | import("viem").RpcBlockIdentifier];
|
|
88
|
+
ReturnType: {
|
|
89
|
+
accessList: import("viem").AccessList;
|
|
90
|
+
gasUsed: `0x${string}`;
|
|
91
|
+
};
|
|
74
92
|
}, {
|
|
75
93
|
Method: "eth_chainId";
|
|
76
94
|
Parameters?: undefined;
|
|
@@ -238,6 +256,40 @@ export declare const paraConnector: ({ para, chains: _chains, disableModal, stor
|
|
|
238
256
|
Method: "eth_sendRawTransaction";
|
|
239
257
|
Parameters: [signedTransaction: `0x${string}`];
|
|
240
258
|
ReturnType: `0x${string}`;
|
|
259
|
+
}, {
|
|
260
|
+
Method: "eth_simulateV1";
|
|
261
|
+
Parameters: [{
|
|
262
|
+
blockStateCalls: readonly {
|
|
263
|
+
blockOverrides?: import("viem").RpcBlockOverrides;
|
|
264
|
+
calls?: readonly import("viem").ExactPartial<import("viem").RpcTransactionRequest>[];
|
|
265
|
+
stateOverrides?: import("viem").RpcStateOverride;
|
|
266
|
+
}[];
|
|
267
|
+
returnFullTransactions?: boolean;
|
|
268
|
+
traceTransfers?: boolean;
|
|
269
|
+
validation?: boolean;
|
|
270
|
+
}, `0x${string}` | import("viem").BlockTag];
|
|
271
|
+
ReturnType: readonly (import("viem").RpcBlock & {
|
|
272
|
+
calls: readonly {
|
|
273
|
+
error?: {
|
|
274
|
+
data?: `0x${string}`;
|
|
275
|
+
code: number;
|
|
276
|
+
message: string;
|
|
277
|
+
};
|
|
278
|
+
logs?: readonly {
|
|
279
|
+
address: `0x${string}`;
|
|
280
|
+
blockHash: `0x${string}`;
|
|
281
|
+
blockNumber: `0x${string}`;
|
|
282
|
+
data: `0x${string}`;
|
|
283
|
+
logIndex: `0x${string}`;
|
|
284
|
+
transactionHash: `0x${string}`;
|
|
285
|
+
transactionIndex: `0x${string}`;
|
|
286
|
+
removed: boolean;
|
|
287
|
+
}[];
|
|
288
|
+
gasUsed: `0x${string}`;
|
|
289
|
+
returnData: `0x${string}`;
|
|
290
|
+
status: `0x${string}`;
|
|
291
|
+
}[];
|
|
292
|
+
})[];
|
|
241
293
|
}, {
|
|
242
294
|
Method: "eth_uninstallFilter";
|
|
243
295
|
Parameters: [filterId: `0x${string}`];
|
|
@@ -342,6 +394,10 @@ export declare const paraConnector: ({ para, chains: _chains, disableModal, stor
|
|
|
342
394
|
Method: "wallet_sendCalls";
|
|
343
395
|
Parameters?: import("viem").WalletSendCallsParameters<import("viem").WalletCapabilities, `0x${string}`, `0x${string}`>;
|
|
344
396
|
ReturnType: string;
|
|
397
|
+
}, {
|
|
398
|
+
Method: "wallet_sendTransaction";
|
|
399
|
+
Parameters: [transaction: import("viem").RpcTransactionRequest];
|
|
400
|
+
ReturnType: `0x${string}`;
|
|
345
401
|
}, {
|
|
346
402
|
Method: "wallet_showCallsStatus";
|
|
347
403
|
Parameters?: [string];
|
|
@@ -382,7 +438,7 @@ export declare const paraConnector: ({ para, chains: _chains, disableModal, stor
|
|
|
382
438
|
ReturnType: readonly `0x${string}`[];
|
|
383
439
|
}, {
|
|
384
440
|
Method: "pm_getPaymasterStubData";
|
|
385
|
-
Parameters?: [userOperation: import("viem").OneOf<import("
|
|
441
|
+
Parameters?: [userOperation: import("viem").OneOf<import("viem").PartialBy<Pick<{
|
|
386
442
|
callData: `0x${string}`;
|
|
387
443
|
callGasLimit: `0x${string}`;
|
|
388
444
|
initCode?: `0x${string}`;
|
|
@@ -394,7 +450,7 @@ export declare const paraConnector: ({ para, chains: _chains, disableModal, stor
|
|
|
394
450
|
sender: `0x${string}`;
|
|
395
451
|
signature: `0x${string}`;
|
|
396
452
|
verificationGasLimit: `0x${string}`;
|
|
397
|
-
}, "nonce" | "maxFeePerGas" | "maxPriorityFeePerGas" | "callData" | "callGasLimit" | "preVerificationGas" | "sender" | "verificationGasLimit" | "initCode">, "maxFeePerGas" | "maxPriorityFeePerGas" | "callGasLimit" | "preVerificationGas" | "verificationGasLimit" | "initCode"> | import("
|
|
453
|
+
}, "nonce" | "maxFeePerGas" | "maxPriorityFeePerGas" | "callData" | "callGasLimit" | "preVerificationGas" | "sender" | "verificationGasLimit" | "initCode">, "maxFeePerGas" | "maxPriorityFeePerGas" | "callGasLimit" | "preVerificationGas" | "verificationGasLimit" | "initCode"> | import("viem").PartialBy<Pick<{
|
|
398
454
|
callData: `0x${string}`;
|
|
399
455
|
callGasLimit: `0x${string}`;
|
|
400
456
|
factory?: `0x${string}`;
|
|
@@ -500,11 +556,12 @@ export declare const paraConnector: ({ para, chains: _chains, disableModal, stor
|
|
|
500
556
|
isTokenary?: true;
|
|
501
557
|
isTrust?: true;
|
|
502
558
|
isTrustWallet?: true;
|
|
559
|
+
isUniswapWallet?: true;
|
|
503
560
|
isXDEFI?: true;
|
|
504
561
|
isZerion?: true;
|
|
505
562
|
providers?: {
|
|
506
|
-
on: <
|
|
507
|
-
removeListener: <
|
|
563
|
+
on: <event_2 extends keyof import("viem").EIP1193EventMap>(event: event, listener: import("viem").EIP1193EventMap[event]) => void;
|
|
564
|
+
removeListener: <event_3 extends keyof import("viem").EIP1193EventMap>(event: event, listener: import("viem").EIP1193EventMap[event]) => void;
|
|
508
565
|
request: import("viem").EIP1193RequestFn<[{
|
|
509
566
|
Method: "web3_clientVersion";
|
|
510
567
|
Parameters?: undefined;
|
|
@@ -537,6 +594,13 @@ export declare const paraConnector: ({ para, chains: _chains, disableModal, stor
|
|
|
537
594
|
Method: "eth_call";
|
|
538
595
|
Parameters: [transaction: import("viem").ExactPartial<import("viem").RpcTransactionRequest>] | [transaction: import("viem").ExactPartial<import("viem").RpcTransactionRequest>, block: `0x${string}` | import("viem").BlockTag | import("viem").RpcBlockIdentifier] | [transaction: import("viem").ExactPartial<import("viem").RpcTransactionRequest>, block: `0x${string}` | import("viem").BlockTag | import("viem").RpcBlockIdentifier, stateOverrideSet: import("viem").RpcStateOverride];
|
|
539
596
|
ReturnType: `0x${string}`;
|
|
597
|
+
}, {
|
|
598
|
+
Method: "eth_createAccessList";
|
|
599
|
+
Parameters: [transaction: import("viem").ExactPartial<import("viem").RpcTransactionRequest>] | [transaction: import("viem").ExactPartial<import("viem").RpcTransactionRequest>, block: `0x${string}` | import("viem").BlockTag | import("viem").RpcBlockIdentifier];
|
|
600
|
+
ReturnType: {
|
|
601
|
+
accessList: import("viem").AccessList;
|
|
602
|
+
gasUsed: `0x${string}`;
|
|
603
|
+
};
|
|
540
604
|
}, {
|
|
541
605
|
Method: "eth_chainId";
|
|
542
606
|
Parameters?: undefined;
|
|
@@ -704,6 +768,40 @@ export declare const paraConnector: ({ para, chains: _chains, disableModal, stor
|
|
|
704
768
|
Method: "eth_sendRawTransaction";
|
|
705
769
|
Parameters: [signedTransaction: `0x${string}`];
|
|
706
770
|
ReturnType: `0x${string}`;
|
|
771
|
+
}, {
|
|
772
|
+
Method: "eth_simulateV1";
|
|
773
|
+
Parameters: [{
|
|
774
|
+
blockStateCalls: readonly {
|
|
775
|
+
blockOverrides?: import("viem").RpcBlockOverrides;
|
|
776
|
+
calls?: readonly import("viem").ExactPartial<import("viem").RpcTransactionRequest>[];
|
|
777
|
+
stateOverrides?: import("viem").RpcStateOverride;
|
|
778
|
+
}[];
|
|
779
|
+
returnFullTransactions?: boolean;
|
|
780
|
+
traceTransfers?: boolean;
|
|
781
|
+
validation?: boolean;
|
|
782
|
+
}, `0x${string}` | import("viem").BlockTag];
|
|
783
|
+
ReturnType: readonly (import("viem").RpcBlock & {
|
|
784
|
+
calls: readonly {
|
|
785
|
+
error?: {
|
|
786
|
+
data?: `0x${string}`;
|
|
787
|
+
code: number;
|
|
788
|
+
message: string;
|
|
789
|
+
};
|
|
790
|
+
logs?: readonly {
|
|
791
|
+
address: `0x${string}`;
|
|
792
|
+
blockHash: `0x${string}`;
|
|
793
|
+
blockNumber: `0x${string}`;
|
|
794
|
+
data: `0x${string}`;
|
|
795
|
+
logIndex: `0x${string}`;
|
|
796
|
+
transactionHash: `0x${string}`;
|
|
797
|
+
transactionIndex: `0x${string}`;
|
|
798
|
+
removed: boolean;
|
|
799
|
+
}[];
|
|
800
|
+
gasUsed: `0x${string}`;
|
|
801
|
+
returnData: `0x${string}`;
|
|
802
|
+
status: `0x${string}`;
|
|
803
|
+
}[];
|
|
804
|
+
})[];
|
|
707
805
|
}, {
|
|
708
806
|
Method: "eth_uninstallFilter";
|
|
709
807
|
Parameters: [filterId: `0x${string}`];
|
|
@@ -808,6 +906,10 @@ export declare const paraConnector: ({ para, chains: _chains, disableModal, stor
|
|
|
808
906
|
Method: "wallet_sendCalls";
|
|
809
907
|
Parameters?: import("viem").WalletSendCallsParameters<import("viem").WalletCapabilities, `0x${string}`, `0x${string}`>;
|
|
810
908
|
ReturnType: string;
|
|
909
|
+
}, {
|
|
910
|
+
Method: "wallet_sendTransaction";
|
|
911
|
+
Parameters: [transaction: import("viem").RpcTransactionRequest];
|
|
912
|
+
ReturnType: `0x${string}`;
|
|
811
913
|
}, {
|
|
812
914
|
Method: "wallet_showCallsStatus";
|
|
813
915
|
Parameters?: [string];
|
|
@@ -848,7 +950,7 @@ export declare const paraConnector: ({ para, chains: _chains, disableModal, stor
|
|
|
848
950
|
ReturnType: readonly `0x${string}`[];
|
|
849
951
|
}, {
|
|
850
952
|
Method: "pm_getPaymasterStubData";
|
|
851
|
-
Parameters?: [userOperation: import("viem").OneOf<import("
|
|
953
|
+
Parameters?: [userOperation: import("viem").OneOf<import("viem").PartialBy<Pick<{
|
|
852
954
|
callData: `0x${string}`;
|
|
853
955
|
callGasLimit: `0x${string}`;
|
|
854
956
|
initCode?: `0x${string}`;
|
|
@@ -860,7 +962,7 @@ export declare const paraConnector: ({ para, chains: _chains, disableModal, stor
|
|
|
860
962
|
sender: `0x${string}`;
|
|
861
963
|
signature: `0x${string}`;
|
|
862
964
|
verificationGasLimit: `0x${string}`;
|
|
863
|
-
}, "nonce" | "maxFeePerGas" | "maxPriorityFeePerGas" | "callData" | "callGasLimit" | "preVerificationGas" | "sender" | "verificationGasLimit" | "initCode">, "maxFeePerGas" | "maxPriorityFeePerGas" | "callGasLimit" | "preVerificationGas" | "verificationGasLimit" | "initCode"> | import("
|
|
965
|
+
}, "nonce" | "maxFeePerGas" | "maxPriorityFeePerGas" | "callData" | "callGasLimit" | "preVerificationGas" | "sender" | "verificationGasLimit" | "initCode">, "maxFeePerGas" | "maxPriorityFeePerGas" | "callGasLimit" | "preVerificationGas" | "verificationGasLimit" | "initCode"> | import("viem").PartialBy<Pick<{
|
|
864
966
|
callData: `0x${string}`;
|
|
865
967
|
callGasLimit: `0x${string}`;
|
|
866
968
|
factory?: `0x${string}`;
|
|
@@ -966,6 +1068,7 @@ export declare const paraConnector: ({ para, chains: _chains, disableModal, stor
|
|
|
966
1068
|
isTokenary?: true;
|
|
967
1069
|
isTrust?: true;
|
|
968
1070
|
isTrustWallet?: true;
|
|
1071
|
+
isUniswapWallet?: true;
|
|
969
1072
|
isXDEFI?: true;
|
|
970
1073
|
isZerion?: true;
|
|
971
1074
|
providers?: any[];
|
|
@@ -1004,5 +1107,5 @@ export declare const paraConnector: ({ para, chains: _chains, disableModal, stor
|
|
|
1004
1107
|
onConnect: ((connectInfo: import("viem").ProviderConnectInfo) => void) & ((connectInfo: import("viem").ProviderConnectInfo) => void);
|
|
1005
1108
|
onDisconnect: (error?: Error) => void;
|
|
1006
1109
|
onMessage?: (message: import("viem").ProviderMessage) => void;
|
|
1007
|
-
}
|
|
1110
|
+
};
|
|
1008
1111
|
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
__async,
|
|
4
|
+
__objRest,
|
|
5
|
+
__spreadProps,
|
|
6
|
+
__spreadValues
|
|
7
|
+
} from "./chunk-MMUBH76A.js";
|
|
8
|
+
import { injected } from "wagmi/connectors";
|
|
9
|
+
import { ParaEIP1193Provider } from "./ParaEIP1193Provider.js";
|
|
10
|
+
import { createConnector } from "wagmi";
|
|
11
|
+
const PARA_ID = "para";
|
|
12
|
+
const PARA_NAME = "Para";
|
|
13
|
+
const PARA_ICON = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjE2IiBoZWlnaHQ9IjIwNCIgdmlld0JveD0iMCAwIDIxNiAyMDQiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxwYXRoIGQ9Ik02MCAwSDE0NEMxODMuNzY0IDAgMjE2IDMyLjIzNTUgMjE2IDcyQzIxNiAxMTEuNzY1IDE4My43NjQgMTQ0IDE0NCAxNDRIOTZDODIuNzQ1MiAxNDQgNzIgMTU0Ljc0NSA3MiAxNjhWMjA0SDBWMTMySDM2QzQ5LjI1NDggMTMyIDYwIDEyMS4yNTUgNjAgMTA4TDYwIDBaIiBmaWxsPSJibGFjayIvPgo8L3N2Zz4K";
|
|
14
|
+
const paraConnector = (_a) => {
|
|
15
|
+
var _b = _a, {
|
|
16
|
+
para,
|
|
17
|
+
chains: _chains,
|
|
18
|
+
disableModal,
|
|
19
|
+
storageOverride,
|
|
20
|
+
options,
|
|
21
|
+
iconOverride,
|
|
22
|
+
nameOverride,
|
|
23
|
+
idOverride,
|
|
24
|
+
transports
|
|
25
|
+
} = _b, modalProps = __objRest(_b, [
|
|
26
|
+
"para",
|
|
27
|
+
"chains",
|
|
28
|
+
"disableModal",
|
|
29
|
+
"storageOverride",
|
|
30
|
+
"options",
|
|
31
|
+
"iconOverride",
|
|
32
|
+
"nameOverride",
|
|
33
|
+
"idOverride",
|
|
34
|
+
"transports"
|
|
35
|
+
]);
|
|
36
|
+
return createConnector((config) => {
|
|
37
|
+
const chains = [...config.chains];
|
|
38
|
+
const eip1193Provider = new ParaEIP1193Provider(__spreadValues({
|
|
39
|
+
para,
|
|
40
|
+
chainId: `${chains[0].id}`,
|
|
41
|
+
chains,
|
|
42
|
+
disableModal,
|
|
43
|
+
storageOverride,
|
|
44
|
+
transports: transports || config.transports
|
|
45
|
+
}, modalProps));
|
|
46
|
+
const injectedObj = injected(__spreadValues({
|
|
47
|
+
target: {
|
|
48
|
+
name: PARA_NAME,
|
|
49
|
+
id: idOverride != null ? idOverride : PARA_ID,
|
|
50
|
+
provider: eip1193Provider
|
|
51
|
+
}
|
|
52
|
+
}, options))(config);
|
|
53
|
+
return __spreadProps(__spreadValues({}, injectedObj), {
|
|
54
|
+
type: idOverride != null ? idOverride : PARA_ID,
|
|
55
|
+
name: nameOverride != null ? nameOverride : PARA_NAME,
|
|
56
|
+
icon: iconOverride != null ? iconOverride : PARA_ICON,
|
|
57
|
+
disconnect: () => __async(void 0, null, function* () {
|
|
58
|
+
eip1193Provider.closeModal();
|
|
59
|
+
yield injectedObj.disconnect();
|
|
60
|
+
para.logout();
|
|
61
|
+
})
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
export {
|
|
66
|
+
paraConnector
|
|
67
|
+
};
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/wagmi-v2-integration",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"sideEffects": false,
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@getpara/react-sdk": "1.
|
|
10
|
-
"@getpara/viem-v2-integration": "1.
|
|
9
|
+
"@getpara/react-sdk": "1.8.0",
|
|
10
|
+
"@getpara/viem-v2-integration": "1.8.0"
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
13
|
"build": "rm -rf dist && yarn typegen && node ./scripts/build.mjs",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"typescript": "5.1.6",
|
|
18
|
-
"viem": "2.
|
|
19
|
-
"wagmi": "2.
|
|
18
|
+
"viem": "^2.23.5",
|
|
19
|
+
"wagmi": "^2.14.12"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"react": "*",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"dist",
|
|
29
29
|
"package.json"
|
|
30
30
|
],
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "ef96e79558695ccbe148d25a8e3611c4596d1954"
|
|
32
32
|
}
|
package/dist/index.js.br
DELETED
|
Binary file
|
package/dist/index.js.gz
DELETED
|
Binary file
|