@meshsdk/react 1.6.0-alpha.21 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +573 -0
- package/dist/index.css +13 -0
- package/dist/index.d.cts +75 -0
- package/dist/index.d.ts +75 -0
- package/dist/index.js +534 -0
- package/package.json +37 -15
- package/.eslintrc.js +0 -3
- package/.turbo/turbo-build$colon$docs.log +0 -15
- package/.turbo/turbo-build$colon$mesh.log +0 -9
- package/.turbo/turbo-build.log +0 -9
- package/postcss.config.js +0 -9
- package/src/cardano-wallet/checkmark.tsx +0 -10
- package/src/cardano-wallet/chevron-down.tsx +0 -17
- package/src/cardano-wallet/index.tsx +0 -106
- package/src/cardano-wallet/menu-item.tsx +0 -28
- package/src/cardano-wallet/wallet-balance.tsx +0 -36
- package/src/common/button.tsx +0 -22
- package/src/contexts/WalletContext.ts +0 -76
- package/src/contexts/index.tsx +0 -16
- package/src/hooks/index.ts +0 -9
- package/src/hooks/useAddress.ts +0 -21
- package/src/hooks/useAssets.ts +0 -19
- package/src/hooks/useLovelace.ts +0 -17
- package/src/hooks/useNetwork.ts +0 -17
- package/src/hooks/useRewardAddress.ts +0 -21
- package/src/hooks/useWallet.ts +0 -31
- package/src/hooks/useWalletList.ts +0 -14
- package/src/hooks/useWalletSubmit.ts +0 -40
- package/src/hooks/useWalletTx.ts +0 -32
- package/src/index.ts +0 -5
- package/src/mesh-badge/index.tsx +0 -17
- package/src/mesh-badge/mesh-logo.tsx +0 -10
- package/src/stake-button/index.tsx +0 -152
- package/src/styles.css +0 -3
- package/tailwind.config.ts +0 -11
- package/tsconfig.json +0 -8
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,573 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
CardanoWallet: () => CardanoWallet,
|
|
24
|
+
MeshBadge: () => MeshBadge,
|
|
25
|
+
MeshProvider: () => MeshProvider,
|
|
26
|
+
StakeButton: () => StakeButton,
|
|
27
|
+
WalletContext: () => WalletContext,
|
|
28
|
+
useAddress: () => useAddress,
|
|
29
|
+
useAssets: () => useAssets,
|
|
30
|
+
useLovelace: () => useLovelace,
|
|
31
|
+
useNetwork: () => useNetwork,
|
|
32
|
+
useRewardAddress: () => useRewardAddress,
|
|
33
|
+
useWallet: () => useWallet,
|
|
34
|
+
useWalletList: () => useWalletList,
|
|
35
|
+
useWalletSubmit: () => useWalletSubmit
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(src_exports);
|
|
38
|
+
|
|
39
|
+
// src/cardano-wallet/index.tsx
|
|
40
|
+
var import_react10 = require("react");
|
|
41
|
+
|
|
42
|
+
// src/common/button.tsx
|
|
43
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
44
|
+
function Button({
|
|
45
|
+
children,
|
|
46
|
+
isDarkMode = false,
|
|
47
|
+
hideMenuList = false,
|
|
48
|
+
setHideMenuList,
|
|
49
|
+
onMouseEnter,
|
|
50
|
+
onMouseLeave
|
|
51
|
+
}) {
|
|
52
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
53
|
+
"button",
|
|
54
|
+
{
|
|
55
|
+
className: `ui-mr-menu-list ui-flex ui-w-60 ui-items-center ui-justify-center ui-rounded-t-md ui-border ui-px-4 ui-py-2 ui-text-lg ui-font-normal ui-shadow-sm ${isDarkMode ? `ui-bg-neutral-950 ui-text-neutral-50` : `ui-bg-neutral-50 ui-text-neutral-950`}`,
|
|
56
|
+
onClick: () => setHideMenuList && setHideMenuList(!hideMenuList),
|
|
57
|
+
onMouseEnter,
|
|
58
|
+
onMouseLeave,
|
|
59
|
+
children
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/hooks/useAddress.ts
|
|
65
|
+
var import_react2 = require("react");
|
|
66
|
+
|
|
67
|
+
// src/contexts/WalletContext.ts
|
|
68
|
+
var import_react = require("react");
|
|
69
|
+
var import_wallet = require("@meshsdk/wallet");
|
|
70
|
+
var INITIAL_STATE = {
|
|
71
|
+
walletName: "",
|
|
72
|
+
walletInstance: {}
|
|
73
|
+
};
|
|
74
|
+
var useWalletStore = () => {
|
|
75
|
+
const [error, setError] = (0, import_react.useState)(void 0);
|
|
76
|
+
const [connectingWallet, setConnectingWallet] = (0, import_react.useState)(false);
|
|
77
|
+
const [connectedWalletInstance, setConnectedWalletInstance] = (0, import_react.useState)(INITIAL_STATE.walletInstance);
|
|
78
|
+
const [connectedWalletName, setConnectedWalletName] = (0, import_react.useState)(
|
|
79
|
+
INITIAL_STATE.walletName
|
|
80
|
+
);
|
|
81
|
+
const connectWallet = (0, import_react.useCallback)(async (walletName) => {
|
|
82
|
+
setConnectingWallet(true);
|
|
83
|
+
try {
|
|
84
|
+
const walletInstance = await import_wallet.BrowserWallet.enable(walletName);
|
|
85
|
+
setConnectedWalletInstance(walletInstance);
|
|
86
|
+
setConnectedWalletName(walletName);
|
|
87
|
+
setError(void 0);
|
|
88
|
+
} catch (error2) {
|
|
89
|
+
setError(error2);
|
|
90
|
+
console.error(error2);
|
|
91
|
+
}
|
|
92
|
+
setConnectingWallet(false);
|
|
93
|
+
}, []);
|
|
94
|
+
const disconnect = (0, import_react.useCallback)(() => {
|
|
95
|
+
setConnectedWalletName(INITIAL_STATE.walletName);
|
|
96
|
+
setConnectedWalletInstance(INITIAL_STATE.walletInstance);
|
|
97
|
+
}, []);
|
|
98
|
+
return {
|
|
99
|
+
hasConnectedWallet: INITIAL_STATE.walletName !== connectedWalletName,
|
|
100
|
+
connectedWalletInstance,
|
|
101
|
+
connectedWalletName,
|
|
102
|
+
connectingWallet,
|
|
103
|
+
connectWallet,
|
|
104
|
+
disconnect,
|
|
105
|
+
// setWallet,
|
|
106
|
+
error
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
var WalletContext = (0, import_react.createContext)({
|
|
110
|
+
hasConnectedWallet: false,
|
|
111
|
+
connectedWalletInstance: INITIAL_STATE.walletInstance,
|
|
112
|
+
connectedWalletName: INITIAL_STATE.walletName,
|
|
113
|
+
connectingWallet: false
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// src/contexts/index.tsx
|
|
117
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
118
|
+
var MeshProvider = (props) => {
|
|
119
|
+
const store = useWalletStore();
|
|
120
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(WalletContext.Provider, { value: store, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: props.children }) });
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
// src/hooks/useAddress.ts
|
|
124
|
+
var useAddress = (accountId = 0) => {
|
|
125
|
+
const [address, setAddress] = (0, import_react2.useState)();
|
|
126
|
+
const { hasConnectedWallet, connectedWalletName, connectedWalletInstance } = (0, import_react2.useContext)(WalletContext);
|
|
127
|
+
(0, import_react2.useEffect)(() => {
|
|
128
|
+
if (hasConnectedWallet) {
|
|
129
|
+
connectedWalletInstance.getUsedAddresses().then((addresses) => {
|
|
130
|
+
if (addresses[accountId]) {
|
|
131
|
+
setAddress(addresses[accountId]);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}, [accountId, connectedWalletName]);
|
|
136
|
+
return address;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// src/hooks/useAssets.ts
|
|
140
|
+
var import_react3 = require("react");
|
|
141
|
+
var useAssets = () => {
|
|
142
|
+
const [assets, setAssets] = (0, import_react3.useState)();
|
|
143
|
+
const { hasConnectedWallet, connectedWalletName, connectedWalletInstance } = (0, import_react3.useContext)(WalletContext);
|
|
144
|
+
(0, import_react3.useEffect)(() => {
|
|
145
|
+
if (hasConnectedWallet) {
|
|
146
|
+
connectedWalletInstance.getAssets().then(setAssets);
|
|
147
|
+
}
|
|
148
|
+
}, [connectedWalletName]);
|
|
149
|
+
return assets;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
// src/hooks/useWalletList.ts
|
|
153
|
+
var import_react4 = require("react");
|
|
154
|
+
var import_wallet2 = require("@meshsdk/wallet");
|
|
155
|
+
var useWalletList = ({
|
|
156
|
+
nufiNetwork = "preprod"
|
|
157
|
+
} = {}) => {
|
|
158
|
+
const [wallets, setWallets] = (0, import_react4.useState)([]);
|
|
159
|
+
(0, import_react4.useEffect)(() => {
|
|
160
|
+
async function get() {
|
|
161
|
+
setWallets(await import_wallet2.BrowserWallet.getAvailableWallets({ nufiNetwork }));
|
|
162
|
+
}
|
|
163
|
+
get();
|
|
164
|
+
}, []);
|
|
165
|
+
return wallets;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// src/hooks/useLovelace.ts
|
|
169
|
+
var import_react5 = require("react");
|
|
170
|
+
var useLovelace = () => {
|
|
171
|
+
const [lovelace, setLovelace] = (0, import_react5.useState)();
|
|
172
|
+
const { hasConnectedWallet, connectedWalletName, connectedWalletInstance } = (0, import_react5.useContext)(WalletContext);
|
|
173
|
+
(0, import_react5.useEffect)(() => {
|
|
174
|
+
if (hasConnectedWallet) {
|
|
175
|
+
connectedWalletInstance.getLovelace().then(setLovelace);
|
|
176
|
+
}
|
|
177
|
+
}, [connectedWalletName]);
|
|
178
|
+
return lovelace;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
// src/hooks/useNetwork.ts
|
|
182
|
+
var import_react6 = require("react");
|
|
183
|
+
var useNetwork = () => {
|
|
184
|
+
const [networkId, setNetworkId] = (0, import_react6.useState)();
|
|
185
|
+
const { hasConnectedWallet, connectedWalletName, connectedWalletInstance } = (0, import_react6.useContext)(WalletContext);
|
|
186
|
+
(0, import_react6.useEffect)(() => {
|
|
187
|
+
if (hasConnectedWallet) {
|
|
188
|
+
connectedWalletInstance.getNetworkId().then(setNetworkId);
|
|
189
|
+
}
|
|
190
|
+
}, [connectedWalletName]);
|
|
191
|
+
return networkId;
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
// src/hooks/useRewardAddress.ts
|
|
195
|
+
var import_react7 = require("react");
|
|
196
|
+
var useRewardAddress = (accountId = 0) => {
|
|
197
|
+
const [rewardAddress, setRewardAddress] = (0, import_react7.useState)();
|
|
198
|
+
const { hasConnectedWallet, connectedWalletName, connectedWalletInstance } = (0, import_react7.useContext)(WalletContext);
|
|
199
|
+
(0, import_react7.useEffect)(() => {
|
|
200
|
+
if (hasConnectedWallet) {
|
|
201
|
+
connectedWalletInstance.getRewardAddresses().then((addresses) => {
|
|
202
|
+
if (addresses[accountId]) {
|
|
203
|
+
setRewardAddress(addresses[accountId]);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}, [accountId, connectedWalletName]);
|
|
208
|
+
return rewardAddress;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
// src/hooks/useWallet.ts
|
|
212
|
+
var import_react8 = require("react");
|
|
213
|
+
var useWallet = () => {
|
|
214
|
+
const {
|
|
215
|
+
hasConnectedWallet,
|
|
216
|
+
connectedWalletName,
|
|
217
|
+
connectedWalletInstance,
|
|
218
|
+
connectingWallet,
|
|
219
|
+
connectWallet,
|
|
220
|
+
disconnect,
|
|
221
|
+
error
|
|
222
|
+
} = (0, import_react8.useContext)(WalletContext);
|
|
223
|
+
if (connectWallet === void 0 || disconnect === void 0) {
|
|
224
|
+
throw new Error(
|
|
225
|
+
"Can't call useWallet outside of the WalletProvider context"
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
return {
|
|
229
|
+
name: connectedWalletName,
|
|
230
|
+
connecting: connectingWallet,
|
|
231
|
+
connected: hasConnectedWallet,
|
|
232
|
+
wallet: connectedWalletInstance,
|
|
233
|
+
connect: connectWallet,
|
|
234
|
+
disconnect,
|
|
235
|
+
error
|
|
236
|
+
};
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
// src/hooks/useWalletSubmit.ts
|
|
240
|
+
var import_react9 = require("react");
|
|
241
|
+
var useWalletSubmit = () => {
|
|
242
|
+
const [error, setError] = (0, import_react9.useState)();
|
|
243
|
+
const [result, setResult] = (0, import_react9.useState)();
|
|
244
|
+
const [submitting, setSubmitting] = (0, import_react9.useState)(false);
|
|
245
|
+
const { hasConnectedWallet, connectedWalletInstance } = (0, import_react9.useContext)(WalletContext);
|
|
246
|
+
const submitTx = (0, import_react9.useCallback)(async (signedTx) => {
|
|
247
|
+
setSubmitting(true);
|
|
248
|
+
try {
|
|
249
|
+
if (hasConnectedWallet) {
|
|
250
|
+
const txHash = await connectedWalletInstance.submitTx(signedTx);
|
|
251
|
+
setError(void 0);
|
|
252
|
+
setResult(txHash);
|
|
253
|
+
}
|
|
254
|
+
throw new Error(
|
|
255
|
+
"Please make sure to connect a wallet before calling useWalletSubmit"
|
|
256
|
+
);
|
|
257
|
+
} catch (error2) {
|
|
258
|
+
setError(error2);
|
|
259
|
+
console.error(error2);
|
|
260
|
+
}
|
|
261
|
+
setSubmitting(false);
|
|
262
|
+
}, []);
|
|
263
|
+
return {
|
|
264
|
+
error,
|
|
265
|
+
result,
|
|
266
|
+
submitting,
|
|
267
|
+
submitTx
|
|
268
|
+
};
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
// src/cardano-wallet/menu-item.tsx
|
|
272
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
273
|
+
function MenuItem({
|
|
274
|
+
icon,
|
|
275
|
+
label,
|
|
276
|
+
action,
|
|
277
|
+
active
|
|
278
|
+
}) {
|
|
279
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
280
|
+
"div",
|
|
281
|
+
{
|
|
282
|
+
className: "ui-flex ui-cursor-pointer ui-items-center ui-px-4 ui-py-2 ui-opacity-80 hover:ui-opacity-100 ui-h-16",
|
|
283
|
+
onClick: action,
|
|
284
|
+
children: [
|
|
285
|
+
icon && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("img", { className: "ui-pr-2 ui-m-1 ui-h-8", src: icon }),
|
|
286
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "ui-mr-menu-item ui-text-xl ui-font-normal", children: label.split(" ").map((word) => {
|
|
287
|
+
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
288
|
+
}).join(" ") })
|
|
289
|
+
]
|
|
290
|
+
}
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// src/cardano-wallet/chevron-down.tsx
|
|
295
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
296
|
+
var ChevronDown = () => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
297
|
+
"svg",
|
|
298
|
+
{
|
|
299
|
+
className: "ui-m-2 ui-h-6",
|
|
300
|
+
fill: "none",
|
|
301
|
+
"aria-hidden": "true",
|
|
302
|
+
viewBox: "0 0 24 24",
|
|
303
|
+
stroke: "currentColor",
|
|
304
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
305
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
306
|
+
"path",
|
|
307
|
+
{
|
|
308
|
+
strokeLinecap: "round",
|
|
309
|
+
strokeLinejoin: "round",
|
|
310
|
+
strokeWidth: "2",
|
|
311
|
+
d: "M19 9l-7 7-7-7"
|
|
312
|
+
}
|
|
313
|
+
)
|
|
314
|
+
}
|
|
315
|
+
);
|
|
316
|
+
|
|
317
|
+
// src/cardano-wallet/wallet-balance.tsx
|
|
318
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
319
|
+
var WalletBalance = ({
|
|
320
|
+
connected,
|
|
321
|
+
connecting,
|
|
322
|
+
label,
|
|
323
|
+
wallet
|
|
324
|
+
}) => {
|
|
325
|
+
const lovelace = useLovelace();
|
|
326
|
+
return connected && lovelace && wallet?.icon ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
327
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("img", { className: "ui-m-2 ui-h-6", src: wallet.icon }),
|
|
328
|
+
"\u20B3",
|
|
329
|
+
" ",
|
|
330
|
+
parseInt((parseInt(lovelace, 10) / 1e6).toString(), 10),
|
|
331
|
+
".",
|
|
332
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "ui-text-xs", children: lovelace.substring(lovelace.length - 6) })
|
|
333
|
+
] }) : connected && wallet?.icon ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("img", { className: "ui-m-2 ui-h-6", src: wallet.icon }) }) : connecting ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: "Connecting..." }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
334
|
+
label,
|
|
335
|
+
" ",
|
|
336
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ChevronDown, {})
|
|
337
|
+
] });
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
// src/cardano-wallet/index.tsx
|
|
341
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
342
|
+
var CardanoWallet = ({
|
|
343
|
+
label = "Connect Wallet",
|
|
344
|
+
onConnected = void 0,
|
|
345
|
+
isDark = false,
|
|
346
|
+
nufiNetwork = "preprod"
|
|
347
|
+
}) => {
|
|
348
|
+
const [isDarkMode, setIsDarkMode] = (0, import_react10.useState)(false);
|
|
349
|
+
const [hideMenuList, setHideMenuList] = (0, import_react10.useState)(true);
|
|
350
|
+
const { connect, connecting, connected, disconnect, name } = useWallet();
|
|
351
|
+
const wallets = useWalletList({ nufiNetwork });
|
|
352
|
+
(0, import_react10.useEffect)(() => {
|
|
353
|
+
if (connected && onConnected) {
|
|
354
|
+
onConnected();
|
|
355
|
+
}
|
|
356
|
+
}, [connected]);
|
|
357
|
+
(0, import_react10.useEffect)(() => {
|
|
358
|
+
setIsDarkMode(isDark);
|
|
359
|
+
}, [isDark]);
|
|
360
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
361
|
+
"div",
|
|
362
|
+
{
|
|
363
|
+
onMouseEnter: () => setHideMenuList(false),
|
|
364
|
+
onMouseLeave: () => setHideMenuList(true),
|
|
365
|
+
style: { width: "min-content", zIndex: 50 },
|
|
366
|
+
children: [
|
|
367
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
368
|
+
Button,
|
|
369
|
+
{
|
|
370
|
+
isDarkMode,
|
|
371
|
+
hideMenuList,
|
|
372
|
+
setHideMenuList,
|
|
373
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
374
|
+
WalletBalance,
|
|
375
|
+
{
|
|
376
|
+
connected,
|
|
377
|
+
connecting,
|
|
378
|
+
label,
|
|
379
|
+
wallet: wallets.find((wallet) => wallet.id === name)
|
|
380
|
+
}
|
|
381
|
+
)
|
|
382
|
+
}
|
|
383
|
+
),
|
|
384
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
385
|
+
"div",
|
|
386
|
+
{
|
|
387
|
+
className: `ui-mr-menu-list ui-absolute ui-w-60 ui-rounded-b-md ui-border ui-text-center ui-shadow-sm ui-backdrop-blur ${hideMenuList && "ui-hidden"} ${isDarkMode ? `ui-bg-neutral-950 ui-text-neutral-50` : `ui-bg-neutral-50 ui-text-neutral-950`}`,
|
|
388
|
+
children: !connected && wallets.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_jsx_runtime6.Fragment, { children: wallets.map((wallet, index) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
389
|
+
MenuItem,
|
|
390
|
+
{
|
|
391
|
+
icon: wallet.icon,
|
|
392
|
+
label: wallet.name,
|
|
393
|
+
action: () => {
|
|
394
|
+
connect(wallet.id);
|
|
395
|
+
setHideMenuList(!hideMenuList);
|
|
396
|
+
},
|
|
397
|
+
active: name === wallet.id
|
|
398
|
+
},
|
|
399
|
+
index
|
|
400
|
+
)) }) : wallets.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: "No Wallet Found" }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_jsx_runtime6.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
401
|
+
MenuItem,
|
|
402
|
+
{
|
|
403
|
+
active: false,
|
|
404
|
+
label: "disconnect",
|
|
405
|
+
action: disconnect,
|
|
406
|
+
icon: void 0
|
|
407
|
+
}
|
|
408
|
+
) })
|
|
409
|
+
}
|
|
410
|
+
)
|
|
411
|
+
]
|
|
412
|
+
}
|
|
413
|
+
);
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
// src/mesh-badge/mesh-logo.tsx
|
|
417
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
418
|
+
var MeshLogo = () => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
419
|
+
"svg",
|
|
420
|
+
{
|
|
421
|
+
className: "ui-h-16 ui-p-2",
|
|
422
|
+
fill: "currentColor",
|
|
423
|
+
viewBox: "0 0 300 200",
|
|
424
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
425
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("path", { d: "m289 127-45-60-45-60c-.9-1.3-2.4-2-4-2s-3.1.7-4 2l-37 49.3c-2 2.7-6 2.7-8 0l-37-49.3c-.9-1.3-2.4-2-4-2s-3.1.7-4 2l-45 60-45 60c-1.3 1.8-1.3 4.2 0 6l45 60c.9 1.3 2.4 2 4 2s3.1-.7 4-2l37-49.3c2-2.7 6-2.7 8 0l37 49.3c.9 1.3 2.4 2 4 2s3.1-.7 4-2l37-49.3c2-2.7 6-2.7 8 0l37 49.3c.9 1.3 2.4 2 4 2s3.1-.7 4-2l45-60c1.3-1.8 1.3-4.2 0-6zm-90-103.3 32.5 43.3c1.3 1.8 1.3 4.2 0 6l-32.5 43.3c-2 2.7-6 2.7-8 0l-32.5-43.3c-1.3-1.8-1.3-4.2 0-6l32.5-43.3c2-2.7 6-2.7 8 0zm-90 0 32.5 43.3c1.3 1.8 1.3 4.2 0 6l-32.5 43.3c-2 2.7-6 2.7-8 0l-32.5-43.3c-1.3-1.8-1.3-4.2 0-6l32.5-43.3c2-2.7 6-2.7 8 0zm-53 152.6-32.5-43.3c-1.3-1.8-1.3-4.2 0-6l32.5-43.3c2-2.7 6-2.7 8 0l32.5 43.3c1.3 1.8 1.3 4.2 0 6l-32.5 43.3c-2 2.7-6 2.7-8 0zm90 0-32.5-43.3c-1.3-1.8-1.3-4.2 0-6l32.5-43.3c2-2.7 6-2.7 8 0l32.5 43.3c1.3 1.8 1.3 4.2 0 6l-32.5 43.3c-2 2.7-6 2.7-8 0zm90 0-32.5-43.3c-1.3-1.8-1.3-4.2 0-6l32.5-43.3c2-2.7 6-2.7 8 0l32.5 43.3c1.3 1.8 1.3 4.2 0 6l-32.5 43.3c-2 2.7-6 2.7-8 0z" })
|
|
426
|
+
}
|
|
427
|
+
);
|
|
428
|
+
|
|
429
|
+
// src/mesh-badge/index.tsx
|
|
430
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
431
|
+
var MeshBadge = ({ isDark = false }) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
432
|
+
"a",
|
|
433
|
+
{
|
|
434
|
+
className: `ui-flex ui-max-w-fit ui-flex-col ui-items-center ui-rounded-md ui-border ui-border-solid ui-border-current ui-p-1 ui-text-xl ui-font-semibold ui-no-underline ${isDark ? `ui-bg-neutral-950 ui-text-neutral-50` : `ui-bg-neutral-50 ui-text-neutral-950`}`,
|
|
435
|
+
style: {
|
|
436
|
+
color: isDark ? "#EEEEEE" : "#111111",
|
|
437
|
+
backgroundColor: isDark ? "#111111" : "#EEEEEE"
|
|
438
|
+
},
|
|
439
|
+
href: "https://meshjs.dev/",
|
|
440
|
+
rel: "noopener noreferrer",
|
|
441
|
+
target: "_blank",
|
|
442
|
+
children: [
|
|
443
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(MeshLogo, {}),
|
|
444
|
+
"Mesh"
|
|
445
|
+
]
|
|
446
|
+
}
|
|
447
|
+
);
|
|
448
|
+
|
|
449
|
+
// src/stake-button/index.tsx
|
|
450
|
+
var import_react11 = require("react");
|
|
451
|
+
var import_transaction = require("@meshsdk/transaction");
|
|
452
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
453
|
+
var StakeButton = ({
|
|
454
|
+
label = "Stake your ADA",
|
|
455
|
+
isDark = false,
|
|
456
|
+
poolId,
|
|
457
|
+
onCheck,
|
|
458
|
+
onDelegated = void 0
|
|
459
|
+
}) => {
|
|
460
|
+
const [isDarkMode, setIsDarkMode] = (0, import_react11.useState)(false);
|
|
461
|
+
const { connected } = useWallet();
|
|
462
|
+
(0, import_react11.useEffect)(() => {
|
|
463
|
+
setIsDarkMode(isDark);
|
|
464
|
+
}, [isDark]);
|
|
465
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_jsx_runtime9.Fragment, { children: connected ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Button, { isDarkMode, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
466
|
+
Delegate,
|
|
467
|
+
{
|
|
468
|
+
poolId,
|
|
469
|
+
onCheck,
|
|
470
|
+
onDelegated
|
|
471
|
+
}
|
|
472
|
+
) }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(CardanoWallet, { label, isDark }) });
|
|
473
|
+
};
|
|
474
|
+
var Delegate = ({
|
|
475
|
+
poolId,
|
|
476
|
+
onCheck,
|
|
477
|
+
onDelegated
|
|
478
|
+
}) => {
|
|
479
|
+
const { wallet } = useWallet();
|
|
480
|
+
const rewardAddress = useRewardAddress();
|
|
481
|
+
const [error, setError] = (0, import_react11.useState)();
|
|
482
|
+
const [checking, setChecking] = (0, import_react11.useState)(false);
|
|
483
|
+
const [accountInfo, setAccountInfo] = (0, import_react11.useState)();
|
|
484
|
+
const [processing, setProcessing] = (0, import_react11.useState)(false);
|
|
485
|
+
const [done, setDone] = (0, import_react11.useState)(false);
|
|
486
|
+
const checkAccountStatus = async () => {
|
|
487
|
+
try {
|
|
488
|
+
setChecking(true);
|
|
489
|
+
if (rewardAddress) {
|
|
490
|
+
const info = await onCheck(rewardAddress);
|
|
491
|
+
setAccountInfo(info);
|
|
492
|
+
}
|
|
493
|
+
setChecking(false);
|
|
494
|
+
} catch (error2) {
|
|
495
|
+
setError(error2);
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
const registerAddress = async () => {
|
|
499
|
+
setProcessing(true);
|
|
500
|
+
setDone(false);
|
|
501
|
+
try {
|
|
502
|
+
if (rewardAddress) {
|
|
503
|
+
const tx = new import_transaction.Transaction({ initiator: wallet }).registerStake(rewardAddress).delegateStake(rewardAddress, poolId);
|
|
504
|
+
const unsignedTx = await tx.build();
|
|
505
|
+
const signedTx = await wallet.signTx(unsignedTx);
|
|
506
|
+
const txHash = await wallet.submitTx(signedTx);
|
|
507
|
+
if (onDelegated) {
|
|
508
|
+
onDelegated();
|
|
509
|
+
}
|
|
510
|
+
setDone(true);
|
|
511
|
+
}
|
|
512
|
+
} catch (error2) {
|
|
513
|
+
console.error("error", error2);
|
|
514
|
+
setError(error2);
|
|
515
|
+
}
|
|
516
|
+
setProcessing(false);
|
|
517
|
+
};
|
|
518
|
+
const delegateStake = async () => {
|
|
519
|
+
setProcessing(true);
|
|
520
|
+
setDone(false);
|
|
521
|
+
try {
|
|
522
|
+
if (rewardAddress) {
|
|
523
|
+
const tx = new import_transaction.Transaction({ initiator: wallet }).delegateStake(
|
|
524
|
+
rewardAddress,
|
|
525
|
+
poolId
|
|
526
|
+
);
|
|
527
|
+
const unsignedTx = await tx.build();
|
|
528
|
+
const signedTx = await wallet.signTx(unsignedTx);
|
|
529
|
+
const txHash = await wallet.submitTx(signedTx);
|
|
530
|
+
setDone(true);
|
|
531
|
+
}
|
|
532
|
+
} catch (error2) {
|
|
533
|
+
console.error("error", error2);
|
|
534
|
+
setError(error2);
|
|
535
|
+
}
|
|
536
|
+
setProcessing(false);
|
|
537
|
+
};
|
|
538
|
+
(0, import_react11.useEffect)(() => {
|
|
539
|
+
checkAccountStatus();
|
|
540
|
+
}, [rewardAddress]);
|
|
541
|
+
if (checking) {
|
|
542
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { children: "Checking..." });
|
|
543
|
+
}
|
|
544
|
+
if (processing) {
|
|
545
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { children: "Loading..." });
|
|
546
|
+
}
|
|
547
|
+
if (done) {
|
|
548
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { children: "Stake Delegated" });
|
|
549
|
+
}
|
|
550
|
+
if (accountInfo?.active) {
|
|
551
|
+
return accountInfo.poolId === poolId ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { children: "Stake Delegated" }) : (
|
|
552
|
+
// <span onClick={delegateStake}>Delegate Stake</span>
|
|
553
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { onClick: registerAddress, children: "Begin Staking" })
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { onClick: registerAddress, children: "Begin Staking" });
|
|
557
|
+
};
|
|
558
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
559
|
+
0 && (module.exports = {
|
|
560
|
+
CardanoWallet,
|
|
561
|
+
MeshBadge,
|
|
562
|
+
MeshProvider,
|
|
563
|
+
StakeButton,
|
|
564
|
+
WalletContext,
|
|
565
|
+
useAddress,
|
|
566
|
+
useAssets,
|
|
567
|
+
useLovelace,
|
|
568
|
+
useNetwork,
|
|
569
|
+
useRewardAddress,
|
|
570
|
+
useWallet,
|
|
571
|
+
useWalletList,
|
|
572
|
+
useWalletSubmit
|
|
573
|
+
});
|
package/dist/index.css
CHANGED
|
@@ -558,6 +558,10 @@ video {
|
|
|
558
558
|
position: absolute;
|
|
559
559
|
}
|
|
560
560
|
|
|
561
|
+
.ui-m-1 {
|
|
562
|
+
margin: 0.25rem;
|
|
563
|
+
}
|
|
564
|
+
|
|
561
565
|
.ui-m-2 {
|
|
562
566
|
margin: 0.5rem;
|
|
563
567
|
}
|
|
@@ -578,6 +582,10 @@ video {
|
|
|
578
582
|
height: 1.5rem;
|
|
579
583
|
}
|
|
580
584
|
|
|
585
|
+
.ui-h-8 {
|
|
586
|
+
height: 2rem;
|
|
587
|
+
}
|
|
588
|
+
|
|
581
589
|
.ui-w-60 {
|
|
582
590
|
width: 15rem;
|
|
583
591
|
}
|
|
@@ -675,6 +683,11 @@ video {
|
|
|
675
683
|
line-height: 1.75rem;
|
|
676
684
|
}
|
|
677
685
|
|
|
686
|
+
.ui-text-xs {
|
|
687
|
+
font-size: 0.75rem;
|
|
688
|
+
line-height: 1rem;
|
|
689
|
+
}
|
|
690
|
+
|
|
678
691
|
.ui-font-normal {
|
|
679
692
|
font-weight: 400;
|
|
680
693
|
}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { Asset, Wallet, AccountInfo } from '@meshsdk/common';
|
|
3
|
+
import * as _meshsdk_wallet from '@meshsdk/wallet';
|
|
4
|
+
import { BrowserWallet } from '@meshsdk/wallet';
|
|
5
|
+
import * as react from 'react';
|
|
6
|
+
|
|
7
|
+
interface ButtonProps$1 {
|
|
8
|
+
label?: string;
|
|
9
|
+
onConnected?: Function;
|
|
10
|
+
isDark?: boolean;
|
|
11
|
+
nufiNetwork?: string;
|
|
12
|
+
}
|
|
13
|
+
declare const CardanoWallet: ({ label, onConnected, isDark, nufiNetwork, }: ButtonProps$1) => react_jsx_runtime.JSX.Element;
|
|
14
|
+
|
|
15
|
+
interface WalletContext {
|
|
16
|
+
hasConnectedWallet: boolean;
|
|
17
|
+
connectedWalletInstance: BrowserWallet;
|
|
18
|
+
connectedWalletName: string;
|
|
19
|
+
connectingWallet: boolean;
|
|
20
|
+
connectWallet?: (walletName: string) => Promise<void>;
|
|
21
|
+
disconnect?: () => void;
|
|
22
|
+
error?: unknown;
|
|
23
|
+
}
|
|
24
|
+
declare const WalletContext: react.Context<WalletContext>;
|
|
25
|
+
|
|
26
|
+
interface Props {
|
|
27
|
+
children: React.ReactNode;
|
|
28
|
+
}
|
|
29
|
+
declare const MeshProvider: React.FC<Props>;
|
|
30
|
+
|
|
31
|
+
declare const useAddress: (accountId?: number) => string | undefined;
|
|
32
|
+
|
|
33
|
+
declare const useAssets: () => Asset[] | undefined;
|
|
34
|
+
|
|
35
|
+
declare const useWalletList: ({ nufiNetwork, }?: {
|
|
36
|
+
nufiNetwork?: string;
|
|
37
|
+
}) => Wallet[];
|
|
38
|
+
|
|
39
|
+
declare const useLovelace: () => string | undefined;
|
|
40
|
+
|
|
41
|
+
declare const useNetwork: () => number | undefined;
|
|
42
|
+
|
|
43
|
+
declare const useRewardAddress: (accountId?: number) => string | undefined;
|
|
44
|
+
|
|
45
|
+
declare const useWallet: () => {
|
|
46
|
+
name: string;
|
|
47
|
+
connecting: boolean;
|
|
48
|
+
connected: boolean;
|
|
49
|
+
wallet: _meshsdk_wallet.BrowserWallet;
|
|
50
|
+
connect: (walletName: string) => Promise<void>;
|
|
51
|
+
disconnect: () => void;
|
|
52
|
+
error: unknown;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
declare const useWalletSubmit: () => {
|
|
56
|
+
error: unknown;
|
|
57
|
+
result: string | undefined;
|
|
58
|
+
submitting: boolean;
|
|
59
|
+
submitTx: (signedTx: string) => Promise<void>;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
declare const MeshBadge: ({ isDark }: {
|
|
63
|
+
isDark?: boolean | undefined;
|
|
64
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
65
|
+
|
|
66
|
+
interface ButtonProps {
|
|
67
|
+
label?: string;
|
|
68
|
+
isDark?: boolean;
|
|
69
|
+
poolId: string;
|
|
70
|
+
onCheck: (rewardAddress: string) => Promise<AccountInfo>;
|
|
71
|
+
onDelegated?: () => void;
|
|
72
|
+
}
|
|
73
|
+
declare const StakeButton: ({ label, isDark, poolId, onCheck, onDelegated, }: ButtonProps) => react_jsx_runtime.JSX.Element;
|
|
74
|
+
|
|
75
|
+
export { CardanoWallet, MeshBadge, MeshProvider, StakeButton, WalletContext, useAddress, useAssets, useLovelace, useNetwork, useRewardAddress, useWallet, useWalletList, useWalletSubmit };
|