@meshsdk/react 1.6.0-alpha.20 → 1.6.1
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 +567 -0
- package/dist/index.css +731 -0
- package/dist/index.d.cts +72 -0
- package/dist/index.d.ts +72 -0
- package/dist/index.js +528 -0
- package/package.json +34 -12
- package/.eslintrc.js +0 -3
- 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,567 @@
|
|
|
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
|
+
var import_wallet3 = require("@meshsdk/wallet");
|
|
42
|
+
|
|
43
|
+
// src/common/button.tsx
|
|
44
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
45
|
+
function Button({
|
|
46
|
+
children,
|
|
47
|
+
isDarkMode = false,
|
|
48
|
+
hideMenuList = false,
|
|
49
|
+
setHideMenuList
|
|
50
|
+
}) {
|
|
51
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
52
|
+
"button",
|
|
53
|
+
{
|
|
54
|
+
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`}`,
|
|
55
|
+
onClick: () => setHideMenuList && setHideMenuList(!hideMenuList),
|
|
56
|
+
children
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/hooks/useAddress.ts
|
|
62
|
+
var import_react2 = require("react");
|
|
63
|
+
|
|
64
|
+
// src/contexts/WalletContext.ts
|
|
65
|
+
var import_react = require("react");
|
|
66
|
+
var import_wallet = require("@meshsdk/wallet");
|
|
67
|
+
var INITIAL_STATE = {
|
|
68
|
+
walletName: "",
|
|
69
|
+
walletInstance: {}
|
|
70
|
+
};
|
|
71
|
+
var useWalletStore = () => {
|
|
72
|
+
const [error, setError] = (0, import_react.useState)(void 0);
|
|
73
|
+
const [connectingWallet, setConnectingWallet] = (0, import_react.useState)(false);
|
|
74
|
+
const [connectedWalletInstance, setConnectedWalletInstance] = (0, import_react.useState)(INITIAL_STATE.walletInstance);
|
|
75
|
+
const [connectedWalletName, setConnectedWalletName] = (0, import_react.useState)(
|
|
76
|
+
INITIAL_STATE.walletName
|
|
77
|
+
);
|
|
78
|
+
const connectWallet = (0, import_react.useCallback)(async (walletName) => {
|
|
79
|
+
setConnectingWallet(true);
|
|
80
|
+
try {
|
|
81
|
+
const walletInstance = await import_wallet.BrowserWallet.enable(walletName);
|
|
82
|
+
setConnectedWalletInstance(walletInstance);
|
|
83
|
+
setConnectedWalletName(walletName);
|
|
84
|
+
setError(void 0);
|
|
85
|
+
} catch (error2) {
|
|
86
|
+
setError(error2);
|
|
87
|
+
console.error(error2);
|
|
88
|
+
}
|
|
89
|
+
setConnectingWallet(false);
|
|
90
|
+
}, []);
|
|
91
|
+
const disconnect = (0, import_react.useCallback)(() => {
|
|
92
|
+
setConnectedWalletName(INITIAL_STATE.walletName);
|
|
93
|
+
setConnectedWalletInstance(INITIAL_STATE.walletInstance);
|
|
94
|
+
}, []);
|
|
95
|
+
return {
|
|
96
|
+
hasConnectedWallet: INITIAL_STATE.walletName !== connectedWalletName,
|
|
97
|
+
connectedWalletInstance,
|
|
98
|
+
connectedWalletName,
|
|
99
|
+
connectingWallet,
|
|
100
|
+
connectWallet,
|
|
101
|
+
disconnect,
|
|
102
|
+
// setWallet,
|
|
103
|
+
error
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
var WalletContext = (0, import_react.createContext)({
|
|
107
|
+
hasConnectedWallet: false,
|
|
108
|
+
connectedWalletInstance: INITIAL_STATE.walletInstance,
|
|
109
|
+
connectedWalletName: INITIAL_STATE.walletName,
|
|
110
|
+
connectingWallet: false
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// src/contexts/index.tsx
|
|
114
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
115
|
+
var MeshProvider = (props) => {
|
|
116
|
+
const store = useWalletStore();
|
|
117
|
+
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 }) });
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// src/hooks/useAddress.ts
|
|
121
|
+
var useAddress = (accountId = 0) => {
|
|
122
|
+
const [address, setAddress] = (0, import_react2.useState)();
|
|
123
|
+
const { hasConnectedWallet, connectedWalletName, connectedWalletInstance } = (0, import_react2.useContext)(WalletContext);
|
|
124
|
+
(0, import_react2.useEffect)(() => {
|
|
125
|
+
if (hasConnectedWallet) {
|
|
126
|
+
connectedWalletInstance.getUsedAddresses().then((addresses) => {
|
|
127
|
+
if (addresses[accountId]) {
|
|
128
|
+
setAddress(addresses[accountId]);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}, [accountId, connectedWalletName]);
|
|
133
|
+
return address;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// src/hooks/useAssets.ts
|
|
137
|
+
var import_react3 = require("react");
|
|
138
|
+
var useAssets = () => {
|
|
139
|
+
const [assets, setAssets] = (0, import_react3.useState)();
|
|
140
|
+
const { hasConnectedWallet, connectedWalletName, connectedWalletInstance } = (0, import_react3.useContext)(WalletContext);
|
|
141
|
+
(0, import_react3.useEffect)(() => {
|
|
142
|
+
if (hasConnectedWallet) {
|
|
143
|
+
connectedWalletInstance.getAssets().then(setAssets);
|
|
144
|
+
}
|
|
145
|
+
}, [connectedWalletName]);
|
|
146
|
+
return assets;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
// src/hooks/useWalletList.ts
|
|
150
|
+
var import_react4 = require("react");
|
|
151
|
+
var import_wallet2 = require("@meshsdk/wallet");
|
|
152
|
+
var useWalletList = () => {
|
|
153
|
+
const [wallets, setWallets] = (0, import_react4.useState)([]);
|
|
154
|
+
(0, import_react4.useEffect)(() => {
|
|
155
|
+
setWallets(import_wallet2.BrowserWallet.getInstalledWallets());
|
|
156
|
+
}, []);
|
|
157
|
+
return wallets;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
// src/hooks/useLovelace.ts
|
|
161
|
+
var import_react5 = require("react");
|
|
162
|
+
var useLovelace = () => {
|
|
163
|
+
const [lovelace, setLovelace] = (0, import_react5.useState)();
|
|
164
|
+
const { hasConnectedWallet, connectedWalletName, connectedWalletInstance } = (0, import_react5.useContext)(WalletContext);
|
|
165
|
+
(0, import_react5.useEffect)(() => {
|
|
166
|
+
if (hasConnectedWallet) {
|
|
167
|
+
connectedWalletInstance.getLovelace().then(setLovelace);
|
|
168
|
+
}
|
|
169
|
+
}, [connectedWalletName]);
|
|
170
|
+
return lovelace;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
// src/hooks/useNetwork.ts
|
|
174
|
+
var import_react6 = require("react");
|
|
175
|
+
var useNetwork = () => {
|
|
176
|
+
const [networkId, setNetworkId] = (0, import_react6.useState)();
|
|
177
|
+
const { hasConnectedWallet, connectedWalletName, connectedWalletInstance } = (0, import_react6.useContext)(WalletContext);
|
|
178
|
+
(0, import_react6.useEffect)(() => {
|
|
179
|
+
if (hasConnectedWallet) {
|
|
180
|
+
connectedWalletInstance.getNetworkId().then(setNetworkId);
|
|
181
|
+
}
|
|
182
|
+
}, [connectedWalletName]);
|
|
183
|
+
return networkId;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// src/hooks/useRewardAddress.ts
|
|
187
|
+
var import_react7 = require("react");
|
|
188
|
+
var useRewardAddress = (accountId = 0) => {
|
|
189
|
+
const [rewardAddress, setRewardAddress] = (0, import_react7.useState)();
|
|
190
|
+
const { hasConnectedWallet, connectedWalletName, connectedWalletInstance } = (0, import_react7.useContext)(WalletContext);
|
|
191
|
+
(0, import_react7.useEffect)(() => {
|
|
192
|
+
if (hasConnectedWallet) {
|
|
193
|
+
connectedWalletInstance.getRewardAddresses().then((addresses) => {
|
|
194
|
+
if (addresses[accountId]) {
|
|
195
|
+
setRewardAddress(addresses[accountId]);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}, [accountId, connectedWalletName]);
|
|
200
|
+
return rewardAddress;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
// src/hooks/useWallet.ts
|
|
204
|
+
var import_react8 = require("react");
|
|
205
|
+
var useWallet = () => {
|
|
206
|
+
const {
|
|
207
|
+
hasConnectedWallet,
|
|
208
|
+
connectedWalletName,
|
|
209
|
+
connectedWalletInstance,
|
|
210
|
+
connectingWallet,
|
|
211
|
+
connectWallet,
|
|
212
|
+
disconnect,
|
|
213
|
+
error
|
|
214
|
+
} = (0, import_react8.useContext)(WalletContext);
|
|
215
|
+
if (connectWallet === void 0 || disconnect === void 0) {
|
|
216
|
+
throw new Error(
|
|
217
|
+
"Can't call useWallet outside of the WalletProvider context"
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
return {
|
|
221
|
+
name: connectedWalletName,
|
|
222
|
+
connecting: connectingWallet,
|
|
223
|
+
connected: hasConnectedWallet,
|
|
224
|
+
wallet: connectedWalletInstance,
|
|
225
|
+
connect: connectWallet,
|
|
226
|
+
disconnect,
|
|
227
|
+
error
|
|
228
|
+
};
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
// src/hooks/useWalletSubmit.ts
|
|
232
|
+
var import_react9 = require("react");
|
|
233
|
+
var useWalletSubmit = () => {
|
|
234
|
+
const [error, setError] = (0, import_react9.useState)();
|
|
235
|
+
const [result, setResult] = (0, import_react9.useState)();
|
|
236
|
+
const [submitting, setSubmitting] = (0, import_react9.useState)(false);
|
|
237
|
+
const { hasConnectedWallet, connectedWalletInstance } = (0, import_react9.useContext)(WalletContext);
|
|
238
|
+
const submitTx = (0, import_react9.useCallback)(async (signedTx) => {
|
|
239
|
+
setSubmitting(true);
|
|
240
|
+
try {
|
|
241
|
+
if (hasConnectedWallet) {
|
|
242
|
+
const txHash = await connectedWalletInstance.submitTx(signedTx);
|
|
243
|
+
setError(void 0);
|
|
244
|
+
setResult(txHash);
|
|
245
|
+
}
|
|
246
|
+
throw new Error(
|
|
247
|
+
"Please make sure to connect a wallet before calling useWalletSubmit"
|
|
248
|
+
);
|
|
249
|
+
} catch (error2) {
|
|
250
|
+
setError(error2);
|
|
251
|
+
console.error(error2);
|
|
252
|
+
}
|
|
253
|
+
setSubmitting(false);
|
|
254
|
+
}, []);
|
|
255
|
+
return {
|
|
256
|
+
error,
|
|
257
|
+
result,
|
|
258
|
+
submitting,
|
|
259
|
+
submitTx
|
|
260
|
+
};
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
// src/cardano-wallet/menu-item.tsx
|
|
264
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
265
|
+
function MenuItem({
|
|
266
|
+
icon,
|
|
267
|
+
label,
|
|
268
|
+
action,
|
|
269
|
+
active
|
|
270
|
+
}) {
|
|
271
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
272
|
+
"div",
|
|
273
|
+
{
|
|
274
|
+
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",
|
|
275
|
+
onClick: action,
|
|
276
|
+
children: [
|
|
277
|
+
icon && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("img", { className: "ui-pr-2 ui-m-1 ui-h-8", src: icon }),
|
|
278
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "ui-mr-menu-item ui-text-xl ui-font-normal", children: label.split(" ").map((word) => {
|
|
279
|
+
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
280
|
+
}).join(" ") })
|
|
281
|
+
]
|
|
282
|
+
}
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// src/cardano-wallet/chevron-down.tsx
|
|
287
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
288
|
+
var ChevronDown = () => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
289
|
+
"svg",
|
|
290
|
+
{
|
|
291
|
+
className: "ui-m-2 ui-h-6",
|
|
292
|
+
fill: "none",
|
|
293
|
+
"aria-hidden": "true",
|
|
294
|
+
viewBox: "0 0 24 24",
|
|
295
|
+
stroke: "currentColor",
|
|
296
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
297
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
298
|
+
"path",
|
|
299
|
+
{
|
|
300
|
+
strokeLinecap: "round",
|
|
301
|
+
strokeLinejoin: "round",
|
|
302
|
+
strokeWidth: "2",
|
|
303
|
+
d: "M19 9l-7 7-7-7"
|
|
304
|
+
}
|
|
305
|
+
)
|
|
306
|
+
}
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
// src/cardano-wallet/wallet-balance.tsx
|
|
310
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
311
|
+
var WalletBalance = ({
|
|
312
|
+
connected,
|
|
313
|
+
connecting,
|
|
314
|
+
label,
|
|
315
|
+
wallet
|
|
316
|
+
}) => {
|
|
317
|
+
const lovelace = useLovelace();
|
|
318
|
+
return connected && lovelace && wallet?.icon ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
319
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("img", { className: "ui-m-2 ui-h-6", src: wallet.icon }),
|
|
320
|
+
"\u20B3",
|
|
321
|
+
" ",
|
|
322
|
+
parseInt((parseInt(lovelace, 10) / 1e6).toString(), 10),
|
|
323
|
+
".",
|
|
324
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "ui-text-xs", children: lovelace.substring(lovelace.length - 6) })
|
|
325
|
+
] }) : 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: [
|
|
326
|
+
label,
|
|
327
|
+
" ",
|
|
328
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ChevronDown, {})
|
|
329
|
+
] });
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
// src/cardano-wallet/index.tsx
|
|
333
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
334
|
+
var CardanoWallet = ({
|
|
335
|
+
label = "Connect Wallet",
|
|
336
|
+
onConnected = void 0,
|
|
337
|
+
isDark = false
|
|
338
|
+
}) => {
|
|
339
|
+
const [isDarkMode, setIsDarkMode] = (0, import_react10.useState)(false);
|
|
340
|
+
const [hideMenuList, setHideMenuList] = (0, import_react10.useState)(true);
|
|
341
|
+
const [wallets, setWallets] = (0, import_react10.useState)([]);
|
|
342
|
+
const { connect, connecting, connected, disconnect, name } = useWallet();
|
|
343
|
+
(0, import_react10.useEffect)(() => {
|
|
344
|
+
if (connected && onConnected) {
|
|
345
|
+
onConnected();
|
|
346
|
+
}
|
|
347
|
+
}, [connected]);
|
|
348
|
+
(0, import_react10.useEffect)(() => {
|
|
349
|
+
setWallets(import_wallet3.BrowserWallet.getInstalledWallets());
|
|
350
|
+
}, []);
|
|
351
|
+
(0, import_react10.useEffect)(() => {
|
|
352
|
+
setIsDarkMode(isDark);
|
|
353
|
+
}, [isDark]);
|
|
354
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
355
|
+
"div",
|
|
356
|
+
{
|
|
357
|
+
className: "w-fit",
|
|
358
|
+
onMouseEnter: () => setHideMenuList(false),
|
|
359
|
+
onMouseLeave: () => setHideMenuList(true),
|
|
360
|
+
children: [
|
|
361
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
362
|
+
Button,
|
|
363
|
+
{
|
|
364
|
+
isDarkMode,
|
|
365
|
+
hideMenuList,
|
|
366
|
+
setHideMenuList,
|
|
367
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
368
|
+
WalletBalance,
|
|
369
|
+
{
|
|
370
|
+
connected,
|
|
371
|
+
connecting,
|
|
372
|
+
label,
|
|
373
|
+
wallet: wallets.find((wallet) => wallet.name === name)
|
|
374
|
+
}
|
|
375
|
+
)
|
|
376
|
+
}
|
|
377
|
+
),
|
|
378
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
379
|
+
"div",
|
|
380
|
+
{
|
|
381
|
+
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`}`,
|
|
382
|
+
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)(
|
|
383
|
+
MenuItem,
|
|
384
|
+
{
|
|
385
|
+
icon: wallet.icon,
|
|
386
|
+
label: wallet.name,
|
|
387
|
+
action: () => {
|
|
388
|
+
connect(wallet.name);
|
|
389
|
+
setHideMenuList(!hideMenuList);
|
|
390
|
+
},
|
|
391
|
+
active: name === wallet.name
|
|
392
|
+
},
|
|
393
|
+
index
|
|
394
|
+
)) }) : 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)(
|
|
395
|
+
MenuItem,
|
|
396
|
+
{
|
|
397
|
+
active: false,
|
|
398
|
+
label: "disconnect",
|
|
399
|
+
action: disconnect,
|
|
400
|
+
icon: void 0
|
|
401
|
+
}
|
|
402
|
+
) })
|
|
403
|
+
}
|
|
404
|
+
)
|
|
405
|
+
]
|
|
406
|
+
}
|
|
407
|
+
);
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
// src/mesh-badge/mesh-logo.tsx
|
|
411
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
412
|
+
var MeshLogo = () => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
413
|
+
"svg",
|
|
414
|
+
{
|
|
415
|
+
className: "ui-h-16 ui-p-2",
|
|
416
|
+
fill: "currentColor",
|
|
417
|
+
viewBox: "0 0 300 200",
|
|
418
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
419
|
+
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" })
|
|
420
|
+
}
|
|
421
|
+
);
|
|
422
|
+
|
|
423
|
+
// src/mesh-badge/index.tsx
|
|
424
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
425
|
+
var MeshBadge = ({ isDark = false }) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
426
|
+
"a",
|
|
427
|
+
{
|
|
428
|
+
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`}`,
|
|
429
|
+
style: {
|
|
430
|
+
color: isDark ? "#EEEEEE" : "#111111",
|
|
431
|
+
backgroundColor: isDark ? "#111111" : "#EEEEEE"
|
|
432
|
+
},
|
|
433
|
+
href: "https://meshjs.dev/",
|
|
434
|
+
rel: "noopener noreferrer",
|
|
435
|
+
target: "_blank",
|
|
436
|
+
children: [
|
|
437
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(MeshLogo, {}),
|
|
438
|
+
"Mesh"
|
|
439
|
+
]
|
|
440
|
+
}
|
|
441
|
+
);
|
|
442
|
+
|
|
443
|
+
// src/stake-button/index.tsx
|
|
444
|
+
var import_react11 = require("react");
|
|
445
|
+
var import_transaction = require("@meshsdk/transaction");
|
|
446
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
447
|
+
var StakeButton = ({
|
|
448
|
+
label = "Stake your ADA",
|
|
449
|
+
isDark = false,
|
|
450
|
+
poolId,
|
|
451
|
+
onCheck,
|
|
452
|
+
onDelegated = void 0
|
|
453
|
+
}) => {
|
|
454
|
+
const [isDarkMode, setIsDarkMode] = (0, import_react11.useState)(false);
|
|
455
|
+
const { connected } = useWallet();
|
|
456
|
+
(0, import_react11.useEffect)(() => {
|
|
457
|
+
setIsDarkMode(isDark);
|
|
458
|
+
}, [isDark]);
|
|
459
|
+
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)(
|
|
460
|
+
Delegate,
|
|
461
|
+
{
|
|
462
|
+
poolId,
|
|
463
|
+
onCheck,
|
|
464
|
+
onDelegated
|
|
465
|
+
}
|
|
466
|
+
) }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(CardanoWallet, { label, isDark }) });
|
|
467
|
+
};
|
|
468
|
+
var Delegate = ({
|
|
469
|
+
poolId,
|
|
470
|
+
onCheck,
|
|
471
|
+
onDelegated
|
|
472
|
+
}) => {
|
|
473
|
+
const { wallet } = useWallet();
|
|
474
|
+
const rewardAddress = useRewardAddress();
|
|
475
|
+
const [error, setError] = (0, import_react11.useState)();
|
|
476
|
+
const [checking, setChecking] = (0, import_react11.useState)(false);
|
|
477
|
+
const [accountInfo, setAccountInfo] = (0, import_react11.useState)();
|
|
478
|
+
const [processing, setProcessing] = (0, import_react11.useState)(false);
|
|
479
|
+
const [done, setDone] = (0, import_react11.useState)(false);
|
|
480
|
+
const checkAccountStatus = async () => {
|
|
481
|
+
try {
|
|
482
|
+
setChecking(true);
|
|
483
|
+
if (rewardAddress) {
|
|
484
|
+
const info = await onCheck(rewardAddress);
|
|
485
|
+
setAccountInfo(info);
|
|
486
|
+
}
|
|
487
|
+
setChecking(false);
|
|
488
|
+
} catch (error2) {
|
|
489
|
+
setError(error2);
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
const registerAddress = async () => {
|
|
493
|
+
setProcessing(true);
|
|
494
|
+
setDone(false);
|
|
495
|
+
try {
|
|
496
|
+
if (rewardAddress) {
|
|
497
|
+
const tx = new import_transaction.Transaction({ initiator: wallet }).registerStake(rewardAddress).delegateStake(rewardAddress, poolId);
|
|
498
|
+
const unsignedTx = await tx.build();
|
|
499
|
+
const signedTx = await wallet.signTx(unsignedTx);
|
|
500
|
+
const txHash = await wallet.submitTx(signedTx);
|
|
501
|
+
if (onDelegated) {
|
|
502
|
+
onDelegated();
|
|
503
|
+
}
|
|
504
|
+
setDone(true);
|
|
505
|
+
}
|
|
506
|
+
} catch (error2) {
|
|
507
|
+
console.error("error", error2);
|
|
508
|
+
setError(error2);
|
|
509
|
+
}
|
|
510
|
+
setProcessing(false);
|
|
511
|
+
};
|
|
512
|
+
const delegateStake = async () => {
|
|
513
|
+
setProcessing(true);
|
|
514
|
+
setDone(false);
|
|
515
|
+
try {
|
|
516
|
+
if (rewardAddress) {
|
|
517
|
+
const tx = new import_transaction.Transaction({ initiator: wallet }).delegateStake(
|
|
518
|
+
rewardAddress,
|
|
519
|
+
poolId
|
|
520
|
+
);
|
|
521
|
+
const unsignedTx = await tx.build();
|
|
522
|
+
const signedTx = await wallet.signTx(unsignedTx);
|
|
523
|
+
const txHash = await wallet.submitTx(signedTx);
|
|
524
|
+
setDone(true);
|
|
525
|
+
}
|
|
526
|
+
} catch (error2) {
|
|
527
|
+
console.error("error", error2);
|
|
528
|
+
setError(error2);
|
|
529
|
+
}
|
|
530
|
+
setProcessing(false);
|
|
531
|
+
};
|
|
532
|
+
(0, import_react11.useEffect)(() => {
|
|
533
|
+
checkAccountStatus();
|
|
534
|
+
}, [rewardAddress]);
|
|
535
|
+
if (checking) {
|
|
536
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { children: "Checking..." });
|
|
537
|
+
}
|
|
538
|
+
if (processing) {
|
|
539
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { children: "Loading..." });
|
|
540
|
+
}
|
|
541
|
+
if (done) {
|
|
542
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { children: "Stake Delegated" });
|
|
543
|
+
}
|
|
544
|
+
if (accountInfo?.active) {
|
|
545
|
+
return accountInfo.poolId === poolId ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { children: "Stake Delegated" }) : (
|
|
546
|
+
// <span onClick={delegateStake}>Delegate Stake</span>
|
|
547
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { onClick: registerAddress, children: "Begin Staking" })
|
|
548
|
+
);
|
|
549
|
+
}
|
|
550
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { onClick: registerAddress, children: "Begin Staking" });
|
|
551
|
+
};
|
|
552
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
553
|
+
0 && (module.exports = {
|
|
554
|
+
CardanoWallet,
|
|
555
|
+
MeshBadge,
|
|
556
|
+
MeshProvider,
|
|
557
|
+
StakeButton,
|
|
558
|
+
WalletContext,
|
|
559
|
+
useAddress,
|
|
560
|
+
useAssets,
|
|
561
|
+
useLovelace,
|
|
562
|
+
useNetwork,
|
|
563
|
+
useRewardAddress,
|
|
564
|
+
useWallet,
|
|
565
|
+
useWalletList,
|
|
566
|
+
useWalletSubmit
|
|
567
|
+
});
|