@meshsdk/react 1.5.29 → 1.5.32
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.css +13 -0
- package/dist/index.d.mts +72 -0
- package/dist/index.d.ts +72 -0
- package/dist/index.js +567 -0
- package/dist/index.mjs +528 -0
- package/package.json +19 -12
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.mts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
}
|
|
12
|
+
declare const CardanoWallet: ({ label, onConnected, isDark, }: ButtonProps$1) => react_jsx_runtime.JSX.Element;
|
|
13
|
+
|
|
14
|
+
interface WalletContext {
|
|
15
|
+
hasConnectedWallet: boolean;
|
|
16
|
+
connectedWalletInstance: BrowserWallet;
|
|
17
|
+
connectedWalletName: string;
|
|
18
|
+
connectingWallet: boolean;
|
|
19
|
+
connectWallet?: (walletName: string) => Promise<void>;
|
|
20
|
+
disconnect?: () => void;
|
|
21
|
+
error?: unknown;
|
|
22
|
+
}
|
|
23
|
+
declare const WalletContext: react.Context<WalletContext>;
|
|
24
|
+
|
|
25
|
+
interface Props {
|
|
26
|
+
children: React.ReactNode;
|
|
27
|
+
}
|
|
28
|
+
declare const MeshProvider: React.FC<Props>;
|
|
29
|
+
|
|
30
|
+
declare const useAddress: (accountId?: number) => string | undefined;
|
|
31
|
+
|
|
32
|
+
declare const useAssets: () => Asset[] | undefined;
|
|
33
|
+
|
|
34
|
+
declare const useWalletList: () => Wallet[];
|
|
35
|
+
|
|
36
|
+
declare const useLovelace: () => string | undefined;
|
|
37
|
+
|
|
38
|
+
declare const useNetwork: () => number | undefined;
|
|
39
|
+
|
|
40
|
+
declare const useRewardAddress: (accountId?: number) => string | undefined;
|
|
41
|
+
|
|
42
|
+
declare const useWallet: () => {
|
|
43
|
+
name: string;
|
|
44
|
+
connecting: boolean;
|
|
45
|
+
connected: boolean;
|
|
46
|
+
wallet: _meshsdk_wallet.BrowserWallet;
|
|
47
|
+
connect: (walletName: string) => Promise<void>;
|
|
48
|
+
disconnect: () => void;
|
|
49
|
+
error: unknown;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
declare const useWalletSubmit: () => {
|
|
53
|
+
error: unknown;
|
|
54
|
+
result: string | undefined;
|
|
55
|
+
submitting: boolean;
|
|
56
|
+
submitTx: (signedTx: string) => Promise<void>;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
declare const MeshBadge: ({ isDark }: {
|
|
60
|
+
isDark?: boolean | undefined;
|
|
61
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
62
|
+
|
|
63
|
+
interface ButtonProps {
|
|
64
|
+
label?: string;
|
|
65
|
+
isDark?: boolean;
|
|
66
|
+
poolId: string;
|
|
67
|
+
onCheck: (rewardAddress: string) => Promise<AccountInfo>;
|
|
68
|
+
onDelegated?: () => void;
|
|
69
|
+
}
|
|
70
|
+
declare const StakeButton: ({ label, isDark, poolId, onCheck, onDelegated, }: ButtonProps) => react_jsx_runtime.JSX.Element;
|
|
71
|
+
|
|
72
|
+
export { CardanoWallet, MeshBadge, MeshProvider, StakeButton, WalletContext, useAddress, useAssets, useLovelace, useNetwork, useRewardAddress, useWallet, useWalletList, useWalletSubmit };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
}
|
|
12
|
+
declare const CardanoWallet: ({ label, onConnected, isDark, }: ButtonProps$1) => react_jsx_runtime.JSX.Element;
|
|
13
|
+
|
|
14
|
+
interface WalletContext {
|
|
15
|
+
hasConnectedWallet: boolean;
|
|
16
|
+
connectedWalletInstance: BrowserWallet;
|
|
17
|
+
connectedWalletName: string;
|
|
18
|
+
connectingWallet: boolean;
|
|
19
|
+
connectWallet?: (walletName: string) => Promise<void>;
|
|
20
|
+
disconnect?: () => void;
|
|
21
|
+
error?: unknown;
|
|
22
|
+
}
|
|
23
|
+
declare const WalletContext: react.Context<WalletContext>;
|
|
24
|
+
|
|
25
|
+
interface Props {
|
|
26
|
+
children: React.ReactNode;
|
|
27
|
+
}
|
|
28
|
+
declare const MeshProvider: React.FC<Props>;
|
|
29
|
+
|
|
30
|
+
declare const useAddress: (accountId?: number) => string | undefined;
|
|
31
|
+
|
|
32
|
+
declare const useAssets: () => Asset[] | undefined;
|
|
33
|
+
|
|
34
|
+
declare const useWalletList: () => Wallet[];
|
|
35
|
+
|
|
36
|
+
declare const useLovelace: () => string | undefined;
|
|
37
|
+
|
|
38
|
+
declare const useNetwork: () => number | undefined;
|
|
39
|
+
|
|
40
|
+
declare const useRewardAddress: (accountId?: number) => string | undefined;
|
|
41
|
+
|
|
42
|
+
declare const useWallet: () => {
|
|
43
|
+
name: string;
|
|
44
|
+
connecting: boolean;
|
|
45
|
+
connected: boolean;
|
|
46
|
+
wallet: _meshsdk_wallet.BrowserWallet;
|
|
47
|
+
connect: (walletName: string) => Promise<void>;
|
|
48
|
+
disconnect: () => void;
|
|
49
|
+
error: unknown;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
declare const useWalletSubmit: () => {
|
|
53
|
+
error: unknown;
|
|
54
|
+
result: string | undefined;
|
|
55
|
+
submitting: boolean;
|
|
56
|
+
submitTx: (signedTx: string) => Promise<void>;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
declare const MeshBadge: ({ isDark }: {
|
|
60
|
+
isDark?: boolean | undefined;
|
|
61
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
62
|
+
|
|
63
|
+
interface ButtonProps {
|
|
64
|
+
label?: string;
|
|
65
|
+
isDark?: boolean;
|
|
66
|
+
poolId: string;
|
|
67
|
+
onCheck: (rewardAddress: string) => Promise<AccountInfo>;
|
|
68
|
+
onDelegated?: () => void;
|
|
69
|
+
}
|
|
70
|
+
declare const StakeButton: ({ label, isDark, poolId, onCheck, onDelegated, }: ButtonProps) => react_jsx_runtime.JSX.Element;
|
|
71
|
+
|
|
72
|
+
export { CardanoWallet, MeshBadge, MeshProvider, StakeButton, WalletContext, useAddress, useAssets, useLovelace, useNetwork, useRewardAddress, useWallet, useWalletList, useWalletSubmit };
|
package/dist/index.js
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
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
// src/cardano-wallet/index.tsx
|
|
2
|
+
import { useEffect as useEffect7, useState as useState9 } from "react";
|
|
3
|
+
import { BrowserWallet as BrowserWallet3 } from "@meshsdk/wallet";
|
|
4
|
+
|
|
5
|
+
// src/common/button.tsx
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
function Button({
|
|
8
|
+
children,
|
|
9
|
+
isDarkMode = false,
|
|
10
|
+
hideMenuList = false,
|
|
11
|
+
setHideMenuList
|
|
12
|
+
}) {
|
|
13
|
+
return /* @__PURE__ */ jsx(
|
|
14
|
+
"button",
|
|
15
|
+
{
|
|
16
|
+
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`}`,
|
|
17
|
+
onClick: () => setHideMenuList && setHideMenuList(!hideMenuList),
|
|
18
|
+
children
|
|
19
|
+
}
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// src/hooks/useAddress.ts
|
|
24
|
+
import { useContext, useEffect, useState as useState2 } from "react";
|
|
25
|
+
|
|
26
|
+
// src/contexts/WalletContext.ts
|
|
27
|
+
import { createContext, useCallback, useState } from "react";
|
|
28
|
+
import { BrowserWallet } from "@meshsdk/wallet";
|
|
29
|
+
var INITIAL_STATE = {
|
|
30
|
+
walletName: "",
|
|
31
|
+
walletInstance: {}
|
|
32
|
+
};
|
|
33
|
+
var useWalletStore = () => {
|
|
34
|
+
const [error, setError] = useState(void 0);
|
|
35
|
+
const [connectingWallet, setConnectingWallet] = useState(false);
|
|
36
|
+
const [connectedWalletInstance, setConnectedWalletInstance] = useState(INITIAL_STATE.walletInstance);
|
|
37
|
+
const [connectedWalletName, setConnectedWalletName] = useState(
|
|
38
|
+
INITIAL_STATE.walletName
|
|
39
|
+
);
|
|
40
|
+
const connectWallet = useCallback(async (walletName) => {
|
|
41
|
+
setConnectingWallet(true);
|
|
42
|
+
try {
|
|
43
|
+
const walletInstance = await BrowserWallet.enable(walletName);
|
|
44
|
+
setConnectedWalletInstance(walletInstance);
|
|
45
|
+
setConnectedWalletName(walletName);
|
|
46
|
+
setError(void 0);
|
|
47
|
+
} catch (error2) {
|
|
48
|
+
setError(error2);
|
|
49
|
+
console.error(error2);
|
|
50
|
+
}
|
|
51
|
+
setConnectingWallet(false);
|
|
52
|
+
}, []);
|
|
53
|
+
const disconnect = useCallback(() => {
|
|
54
|
+
setConnectedWalletName(INITIAL_STATE.walletName);
|
|
55
|
+
setConnectedWalletInstance(INITIAL_STATE.walletInstance);
|
|
56
|
+
}, []);
|
|
57
|
+
return {
|
|
58
|
+
hasConnectedWallet: INITIAL_STATE.walletName !== connectedWalletName,
|
|
59
|
+
connectedWalletInstance,
|
|
60
|
+
connectedWalletName,
|
|
61
|
+
connectingWallet,
|
|
62
|
+
connectWallet,
|
|
63
|
+
disconnect,
|
|
64
|
+
// setWallet,
|
|
65
|
+
error
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
var WalletContext = createContext({
|
|
69
|
+
hasConnectedWallet: false,
|
|
70
|
+
connectedWalletInstance: INITIAL_STATE.walletInstance,
|
|
71
|
+
connectedWalletName: INITIAL_STATE.walletName,
|
|
72
|
+
connectingWallet: false
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// src/contexts/index.tsx
|
|
76
|
+
import { Fragment, jsx as jsx2 } from "react/jsx-runtime";
|
|
77
|
+
var MeshProvider = (props) => {
|
|
78
|
+
const store = useWalletStore();
|
|
79
|
+
return /* @__PURE__ */ jsx2(WalletContext.Provider, { value: store, children: /* @__PURE__ */ jsx2(Fragment, { children: props.children }) });
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// src/hooks/useAddress.ts
|
|
83
|
+
var useAddress = (accountId = 0) => {
|
|
84
|
+
const [address, setAddress] = useState2();
|
|
85
|
+
const { hasConnectedWallet, connectedWalletName, connectedWalletInstance } = useContext(WalletContext);
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
if (hasConnectedWallet) {
|
|
88
|
+
connectedWalletInstance.getUsedAddresses().then((addresses) => {
|
|
89
|
+
if (addresses[accountId]) {
|
|
90
|
+
setAddress(addresses[accountId]);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}, [accountId, connectedWalletName]);
|
|
95
|
+
return address;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// src/hooks/useAssets.ts
|
|
99
|
+
import { useContext as useContext2, useEffect as useEffect2, useState as useState3 } from "react";
|
|
100
|
+
var useAssets = () => {
|
|
101
|
+
const [assets, setAssets] = useState3();
|
|
102
|
+
const { hasConnectedWallet, connectedWalletName, connectedWalletInstance } = useContext2(WalletContext);
|
|
103
|
+
useEffect2(() => {
|
|
104
|
+
if (hasConnectedWallet) {
|
|
105
|
+
connectedWalletInstance.getAssets().then(setAssets);
|
|
106
|
+
}
|
|
107
|
+
}, [connectedWalletName]);
|
|
108
|
+
return assets;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// src/hooks/useWalletList.ts
|
|
112
|
+
import { useEffect as useEffect3, useState as useState4 } from "react";
|
|
113
|
+
import { BrowserWallet as BrowserWallet2 } from "@meshsdk/wallet";
|
|
114
|
+
var useWalletList = () => {
|
|
115
|
+
const [wallets, setWallets] = useState4([]);
|
|
116
|
+
useEffect3(() => {
|
|
117
|
+
setWallets(BrowserWallet2.getInstalledWallets());
|
|
118
|
+
}, []);
|
|
119
|
+
return wallets;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// src/hooks/useLovelace.ts
|
|
123
|
+
import { useContext as useContext3, useEffect as useEffect4, useState as useState5 } from "react";
|
|
124
|
+
var useLovelace = () => {
|
|
125
|
+
const [lovelace, setLovelace] = useState5();
|
|
126
|
+
const { hasConnectedWallet, connectedWalletName, connectedWalletInstance } = useContext3(WalletContext);
|
|
127
|
+
useEffect4(() => {
|
|
128
|
+
if (hasConnectedWallet) {
|
|
129
|
+
connectedWalletInstance.getLovelace().then(setLovelace);
|
|
130
|
+
}
|
|
131
|
+
}, [connectedWalletName]);
|
|
132
|
+
return lovelace;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// src/hooks/useNetwork.ts
|
|
136
|
+
import { useContext as useContext4, useEffect as useEffect5, useState as useState6 } from "react";
|
|
137
|
+
var useNetwork = () => {
|
|
138
|
+
const [networkId, setNetworkId] = useState6();
|
|
139
|
+
const { hasConnectedWallet, connectedWalletName, connectedWalletInstance } = useContext4(WalletContext);
|
|
140
|
+
useEffect5(() => {
|
|
141
|
+
if (hasConnectedWallet) {
|
|
142
|
+
connectedWalletInstance.getNetworkId().then(setNetworkId);
|
|
143
|
+
}
|
|
144
|
+
}, [connectedWalletName]);
|
|
145
|
+
return networkId;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
// src/hooks/useRewardAddress.ts
|
|
149
|
+
import { useContext as useContext5, useEffect as useEffect6, useState as useState7 } from "react";
|
|
150
|
+
var useRewardAddress = (accountId = 0) => {
|
|
151
|
+
const [rewardAddress, setRewardAddress] = useState7();
|
|
152
|
+
const { hasConnectedWallet, connectedWalletName, connectedWalletInstance } = useContext5(WalletContext);
|
|
153
|
+
useEffect6(() => {
|
|
154
|
+
if (hasConnectedWallet) {
|
|
155
|
+
connectedWalletInstance.getRewardAddresses().then((addresses) => {
|
|
156
|
+
if (addresses[accountId]) {
|
|
157
|
+
setRewardAddress(addresses[accountId]);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}, [accountId, connectedWalletName]);
|
|
162
|
+
return rewardAddress;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
// src/hooks/useWallet.ts
|
|
166
|
+
import { useContext as useContext6 } from "react";
|
|
167
|
+
var useWallet = () => {
|
|
168
|
+
const {
|
|
169
|
+
hasConnectedWallet,
|
|
170
|
+
connectedWalletName,
|
|
171
|
+
connectedWalletInstance,
|
|
172
|
+
connectingWallet,
|
|
173
|
+
connectWallet,
|
|
174
|
+
disconnect,
|
|
175
|
+
error
|
|
176
|
+
} = useContext6(WalletContext);
|
|
177
|
+
if (connectWallet === void 0 || disconnect === void 0) {
|
|
178
|
+
throw new Error(
|
|
179
|
+
"Can't call useWallet outside of the WalletProvider context"
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
name: connectedWalletName,
|
|
184
|
+
connecting: connectingWallet,
|
|
185
|
+
connected: hasConnectedWallet,
|
|
186
|
+
wallet: connectedWalletInstance,
|
|
187
|
+
connect: connectWallet,
|
|
188
|
+
disconnect,
|
|
189
|
+
error
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
// src/hooks/useWalletSubmit.ts
|
|
194
|
+
import { useCallback as useCallback2, useContext as useContext7, useState as useState8 } from "react";
|
|
195
|
+
var useWalletSubmit = () => {
|
|
196
|
+
const [error, setError] = useState8();
|
|
197
|
+
const [result, setResult] = useState8();
|
|
198
|
+
const [submitting, setSubmitting] = useState8(false);
|
|
199
|
+
const { hasConnectedWallet, connectedWalletInstance } = useContext7(WalletContext);
|
|
200
|
+
const submitTx = useCallback2(async (signedTx) => {
|
|
201
|
+
setSubmitting(true);
|
|
202
|
+
try {
|
|
203
|
+
if (hasConnectedWallet) {
|
|
204
|
+
const txHash = await connectedWalletInstance.submitTx(signedTx);
|
|
205
|
+
setError(void 0);
|
|
206
|
+
setResult(txHash);
|
|
207
|
+
}
|
|
208
|
+
throw new Error(
|
|
209
|
+
"Please make sure to connect a wallet before calling useWalletSubmit"
|
|
210
|
+
);
|
|
211
|
+
} catch (error2) {
|
|
212
|
+
setError(error2);
|
|
213
|
+
console.error(error2);
|
|
214
|
+
}
|
|
215
|
+
setSubmitting(false);
|
|
216
|
+
}, []);
|
|
217
|
+
return {
|
|
218
|
+
error,
|
|
219
|
+
result,
|
|
220
|
+
submitting,
|
|
221
|
+
submitTx
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
// src/cardano-wallet/menu-item.tsx
|
|
226
|
+
import { jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
227
|
+
function MenuItem({
|
|
228
|
+
icon,
|
|
229
|
+
label,
|
|
230
|
+
action,
|
|
231
|
+
active
|
|
232
|
+
}) {
|
|
233
|
+
return /* @__PURE__ */ jsxs(
|
|
234
|
+
"div",
|
|
235
|
+
{
|
|
236
|
+
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",
|
|
237
|
+
onClick: action,
|
|
238
|
+
children: [
|
|
239
|
+
icon && /* @__PURE__ */ jsx3("img", { className: "ui-pr-2 ui-m-1 ui-h-8", src: icon }),
|
|
240
|
+
/* @__PURE__ */ jsx3("span", { className: "ui-mr-menu-item ui-text-xl ui-font-normal", children: label.split(" ").map((word) => {
|
|
241
|
+
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
242
|
+
}).join(" ") })
|
|
243
|
+
]
|
|
244
|
+
}
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// src/cardano-wallet/chevron-down.tsx
|
|
249
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
250
|
+
var ChevronDown = () => /* @__PURE__ */ jsx4(
|
|
251
|
+
"svg",
|
|
252
|
+
{
|
|
253
|
+
className: "ui-m-2 ui-h-6",
|
|
254
|
+
fill: "none",
|
|
255
|
+
"aria-hidden": "true",
|
|
256
|
+
viewBox: "0 0 24 24",
|
|
257
|
+
stroke: "currentColor",
|
|
258
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
259
|
+
children: /* @__PURE__ */ jsx4(
|
|
260
|
+
"path",
|
|
261
|
+
{
|
|
262
|
+
strokeLinecap: "round",
|
|
263
|
+
strokeLinejoin: "round",
|
|
264
|
+
strokeWidth: "2",
|
|
265
|
+
d: "M19 9l-7 7-7-7"
|
|
266
|
+
}
|
|
267
|
+
)
|
|
268
|
+
}
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
// src/cardano-wallet/wallet-balance.tsx
|
|
272
|
+
import { Fragment as Fragment2, jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
273
|
+
var WalletBalance = ({
|
|
274
|
+
connected,
|
|
275
|
+
connecting,
|
|
276
|
+
label,
|
|
277
|
+
wallet
|
|
278
|
+
}) => {
|
|
279
|
+
const lovelace = useLovelace();
|
|
280
|
+
return connected && lovelace && wallet?.icon ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
281
|
+
/* @__PURE__ */ jsx5("img", { className: "ui-m-2 ui-h-6", src: wallet.icon }),
|
|
282
|
+
"\u20B3",
|
|
283
|
+
" ",
|
|
284
|
+
parseInt((parseInt(lovelace, 10) / 1e6).toString(), 10),
|
|
285
|
+
".",
|
|
286
|
+
/* @__PURE__ */ jsx5("span", { className: "ui-text-xs", children: lovelace.substring(lovelace.length - 6) })
|
|
287
|
+
] }) : connected && wallet?.icon ? /* @__PURE__ */ jsx5(Fragment2, { children: /* @__PURE__ */ jsx5("img", { className: "ui-m-2 ui-h-6", src: wallet.icon }) }) : connecting ? /* @__PURE__ */ jsx5(Fragment2, { children: "Connecting..." }) : /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
288
|
+
label,
|
|
289
|
+
" ",
|
|
290
|
+
/* @__PURE__ */ jsx5(ChevronDown, {})
|
|
291
|
+
] });
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
// src/cardano-wallet/index.tsx
|
|
295
|
+
import { Fragment as Fragment3, jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
296
|
+
var CardanoWallet = ({
|
|
297
|
+
label = "Connect Wallet",
|
|
298
|
+
onConnected = void 0,
|
|
299
|
+
isDark = false
|
|
300
|
+
}) => {
|
|
301
|
+
const [isDarkMode, setIsDarkMode] = useState9(false);
|
|
302
|
+
const [hideMenuList, setHideMenuList] = useState9(true);
|
|
303
|
+
const [wallets, setWallets] = useState9([]);
|
|
304
|
+
const { connect, connecting, connected, disconnect, name } = useWallet();
|
|
305
|
+
useEffect7(() => {
|
|
306
|
+
if (connected && onConnected) {
|
|
307
|
+
onConnected();
|
|
308
|
+
}
|
|
309
|
+
}, [connected]);
|
|
310
|
+
useEffect7(() => {
|
|
311
|
+
setWallets(BrowserWallet3.getInstalledWallets());
|
|
312
|
+
}, []);
|
|
313
|
+
useEffect7(() => {
|
|
314
|
+
setIsDarkMode(isDark);
|
|
315
|
+
}, [isDark]);
|
|
316
|
+
return /* @__PURE__ */ jsxs3(
|
|
317
|
+
"div",
|
|
318
|
+
{
|
|
319
|
+
className: "w-fit",
|
|
320
|
+
onMouseEnter: () => setHideMenuList(false),
|
|
321
|
+
onMouseLeave: () => setHideMenuList(true),
|
|
322
|
+
children: [
|
|
323
|
+
/* @__PURE__ */ jsx6(
|
|
324
|
+
Button,
|
|
325
|
+
{
|
|
326
|
+
isDarkMode,
|
|
327
|
+
hideMenuList,
|
|
328
|
+
setHideMenuList,
|
|
329
|
+
children: /* @__PURE__ */ jsx6(
|
|
330
|
+
WalletBalance,
|
|
331
|
+
{
|
|
332
|
+
connected,
|
|
333
|
+
connecting,
|
|
334
|
+
label,
|
|
335
|
+
wallet: wallets.find((wallet) => wallet.name === name)
|
|
336
|
+
}
|
|
337
|
+
)
|
|
338
|
+
}
|
|
339
|
+
),
|
|
340
|
+
/* @__PURE__ */ jsx6(
|
|
341
|
+
"div",
|
|
342
|
+
{
|
|
343
|
+
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`}`,
|
|
344
|
+
children: !connected && wallets.length > 0 ? /* @__PURE__ */ jsx6(Fragment3, { children: wallets.map((wallet, index) => /* @__PURE__ */ jsx6(
|
|
345
|
+
MenuItem,
|
|
346
|
+
{
|
|
347
|
+
icon: wallet.icon,
|
|
348
|
+
label: wallet.name,
|
|
349
|
+
action: () => {
|
|
350
|
+
connect(wallet.name);
|
|
351
|
+
setHideMenuList(!hideMenuList);
|
|
352
|
+
},
|
|
353
|
+
active: name === wallet.name
|
|
354
|
+
},
|
|
355
|
+
index
|
|
356
|
+
)) }) : wallets.length === 0 ? /* @__PURE__ */ jsx6("span", { children: "No Wallet Found" }) : /* @__PURE__ */ jsx6(Fragment3, { children: /* @__PURE__ */ jsx6(
|
|
357
|
+
MenuItem,
|
|
358
|
+
{
|
|
359
|
+
active: false,
|
|
360
|
+
label: "disconnect",
|
|
361
|
+
action: disconnect,
|
|
362
|
+
icon: void 0
|
|
363
|
+
}
|
|
364
|
+
) })
|
|
365
|
+
}
|
|
366
|
+
)
|
|
367
|
+
]
|
|
368
|
+
}
|
|
369
|
+
);
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
// src/mesh-badge/mesh-logo.tsx
|
|
373
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
374
|
+
var MeshLogo = () => /* @__PURE__ */ jsx7(
|
|
375
|
+
"svg",
|
|
376
|
+
{
|
|
377
|
+
className: "ui-h-16 ui-p-2",
|
|
378
|
+
fill: "currentColor",
|
|
379
|
+
viewBox: "0 0 300 200",
|
|
380
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
381
|
+
children: /* @__PURE__ */ jsx7("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" })
|
|
382
|
+
}
|
|
383
|
+
);
|
|
384
|
+
|
|
385
|
+
// src/mesh-badge/index.tsx
|
|
386
|
+
import { jsx as jsx8, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
387
|
+
var MeshBadge = ({ isDark = false }) => /* @__PURE__ */ jsxs4(
|
|
388
|
+
"a",
|
|
389
|
+
{
|
|
390
|
+
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`}`,
|
|
391
|
+
style: {
|
|
392
|
+
color: isDark ? "#EEEEEE" : "#111111",
|
|
393
|
+
backgroundColor: isDark ? "#111111" : "#EEEEEE"
|
|
394
|
+
},
|
|
395
|
+
href: "https://meshjs.dev/",
|
|
396
|
+
rel: "noopener noreferrer",
|
|
397
|
+
target: "_blank",
|
|
398
|
+
children: [
|
|
399
|
+
/* @__PURE__ */ jsx8(MeshLogo, {}),
|
|
400
|
+
"Mesh"
|
|
401
|
+
]
|
|
402
|
+
}
|
|
403
|
+
);
|
|
404
|
+
|
|
405
|
+
// src/stake-button/index.tsx
|
|
406
|
+
import { useEffect as useEffect8, useState as useState10 } from "react";
|
|
407
|
+
import { Transaction } from "@meshsdk/transaction";
|
|
408
|
+
import { Fragment as Fragment4, jsx as jsx9 } from "react/jsx-runtime";
|
|
409
|
+
var StakeButton = ({
|
|
410
|
+
label = "Stake your ADA",
|
|
411
|
+
isDark = false,
|
|
412
|
+
poolId,
|
|
413
|
+
onCheck,
|
|
414
|
+
onDelegated = void 0
|
|
415
|
+
}) => {
|
|
416
|
+
const [isDarkMode, setIsDarkMode] = useState10(false);
|
|
417
|
+
const { connected } = useWallet();
|
|
418
|
+
useEffect8(() => {
|
|
419
|
+
setIsDarkMode(isDark);
|
|
420
|
+
}, [isDark]);
|
|
421
|
+
return /* @__PURE__ */ jsx9(Fragment4, { children: connected ? /* @__PURE__ */ jsx9(Button, { isDarkMode, children: /* @__PURE__ */ jsx9(
|
|
422
|
+
Delegate,
|
|
423
|
+
{
|
|
424
|
+
poolId,
|
|
425
|
+
onCheck,
|
|
426
|
+
onDelegated
|
|
427
|
+
}
|
|
428
|
+
) }) : /* @__PURE__ */ jsx9(CardanoWallet, { label, isDark }) });
|
|
429
|
+
};
|
|
430
|
+
var Delegate = ({
|
|
431
|
+
poolId,
|
|
432
|
+
onCheck,
|
|
433
|
+
onDelegated
|
|
434
|
+
}) => {
|
|
435
|
+
const { wallet } = useWallet();
|
|
436
|
+
const rewardAddress = useRewardAddress();
|
|
437
|
+
const [error, setError] = useState10();
|
|
438
|
+
const [checking, setChecking] = useState10(false);
|
|
439
|
+
const [accountInfo, setAccountInfo] = useState10();
|
|
440
|
+
const [processing, setProcessing] = useState10(false);
|
|
441
|
+
const [done, setDone] = useState10(false);
|
|
442
|
+
const checkAccountStatus = async () => {
|
|
443
|
+
try {
|
|
444
|
+
setChecking(true);
|
|
445
|
+
if (rewardAddress) {
|
|
446
|
+
const info = await onCheck(rewardAddress);
|
|
447
|
+
setAccountInfo(info);
|
|
448
|
+
}
|
|
449
|
+
setChecking(false);
|
|
450
|
+
} catch (error2) {
|
|
451
|
+
setError(error2);
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
const registerAddress = async () => {
|
|
455
|
+
setProcessing(true);
|
|
456
|
+
setDone(false);
|
|
457
|
+
try {
|
|
458
|
+
if (rewardAddress) {
|
|
459
|
+
const tx = new Transaction({ initiator: wallet }).registerStake(rewardAddress).delegateStake(rewardAddress, poolId);
|
|
460
|
+
const unsignedTx = await tx.build();
|
|
461
|
+
const signedTx = await wallet.signTx(unsignedTx);
|
|
462
|
+
const txHash = await wallet.submitTx(signedTx);
|
|
463
|
+
if (onDelegated) {
|
|
464
|
+
onDelegated();
|
|
465
|
+
}
|
|
466
|
+
setDone(true);
|
|
467
|
+
}
|
|
468
|
+
} catch (error2) {
|
|
469
|
+
console.error("error", error2);
|
|
470
|
+
setError(error2);
|
|
471
|
+
}
|
|
472
|
+
setProcessing(false);
|
|
473
|
+
};
|
|
474
|
+
const delegateStake = async () => {
|
|
475
|
+
setProcessing(true);
|
|
476
|
+
setDone(false);
|
|
477
|
+
try {
|
|
478
|
+
if (rewardAddress) {
|
|
479
|
+
const tx = new Transaction({ initiator: wallet }).delegateStake(
|
|
480
|
+
rewardAddress,
|
|
481
|
+
poolId
|
|
482
|
+
);
|
|
483
|
+
const unsignedTx = await tx.build();
|
|
484
|
+
const signedTx = await wallet.signTx(unsignedTx);
|
|
485
|
+
const txHash = await wallet.submitTx(signedTx);
|
|
486
|
+
setDone(true);
|
|
487
|
+
}
|
|
488
|
+
} catch (error2) {
|
|
489
|
+
console.error("error", error2);
|
|
490
|
+
setError(error2);
|
|
491
|
+
}
|
|
492
|
+
setProcessing(false);
|
|
493
|
+
};
|
|
494
|
+
useEffect8(() => {
|
|
495
|
+
checkAccountStatus();
|
|
496
|
+
}, [rewardAddress]);
|
|
497
|
+
if (checking) {
|
|
498
|
+
return /* @__PURE__ */ jsx9("span", { children: "Checking..." });
|
|
499
|
+
}
|
|
500
|
+
if (processing) {
|
|
501
|
+
return /* @__PURE__ */ jsx9("span", { children: "Loading..." });
|
|
502
|
+
}
|
|
503
|
+
if (done) {
|
|
504
|
+
return /* @__PURE__ */ jsx9("span", { children: "Stake Delegated" });
|
|
505
|
+
}
|
|
506
|
+
if (accountInfo?.active) {
|
|
507
|
+
return accountInfo.poolId === poolId ? /* @__PURE__ */ jsx9("span", { children: "Stake Delegated" }) : (
|
|
508
|
+
// <span onClick={delegateStake}>Delegate Stake</span>
|
|
509
|
+
/* @__PURE__ */ jsx9("span", { onClick: registerAddress, children: "Begin Staking" })
|
|
510
|
+
);
|
|
511
|
+
}
|
|
512
|
+
return /* @__PURE__ */ jsx9("span", { onClick: registerAddress, children: "Begin Staking" });
|
|
513
|
+
};
|
|
514
|
+
export {
|
|
515
|
+
CardanoWallet,
|
|
516
|
+
MeshBadge,
|
|
517
|
+
MeshProvider,
|
|
518
|
+
StakeButton,
|
|
519
|
+
WalletContext,
|
|
520
|
+
useAddress,
|
|
521
|
+
useAssets,
|
|
522
|
+
useLovelace,
|
|
523
|
+
useNetwork,
|
|
524
|
+
useRewardAddress,
|
|
525
|
+
useWallet,
|
|
526
|
+
useWalletList,
|
|
527
|
+
useWalletSubmit
|
|
528
|
+
};
|
package/package.json
CHANGED
|
@@ -1,28 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshsdk/react",
|
|
3
|
-
"version": "1.5.
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
"version": "1.5.32",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
7
8
|
"exports": {
|
|
8
9
|
"./styles.css": "./dist/index.css",
|
|
9
|
-
".":
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
10
14
|
},
|
|
11
15
|
"files": [
|
|
12
16
|
"dist/**"
|
|
13
17
|
],
|
|
14
|
-
"license": "MIT",
|
|
15
18
|
"scripts": {
|
|
16
|
-
"build:mesh": "tailwindcss -i ./src/styles.css -o ./dist/index.css",
|
|
19
|
+
"build:mesh": "tsup src/index.ts --format esm,cjs --dts && tailwindcss -i ./src/styles.css -o ./dist/index.css",
|
|
17
20
|
"lint": "eslint",
|
|
18
|
-
"
|
|
21
|
+
"dev_old": "tailwindcss -i ./src/styles.css -o ./dist/index.css --watch",
|
|
22
|
+
"dev": "tsup src/index.ts --format esm,cjs --watch --dts",
|
|
19
23
|
"type-check": "tsc --noEmit",
|
|
20
24
|
"clean": "rm -rf .turbo && rm -rf dist && rm -rf node_modules",
|
|
21
25
|
"format": "prettier --check . --ignore-path ../../.gitignore"
|
|
22
26
|
},
|
|
23
|
-
"
|
|
27
|
+
"dependencies": {
|
|
24
28
|
"react": "^18.2.0",
|
|
25
|
-
"@meshsdk/
|
|
29
|
+
"@meshsdk/common": "*",
|
|
30
|
+
"@meshsdk/transaction": "*",
|
|
31
|
+
"@meshsdk/wallet": "*"
|
|
26
32
|
},
|
|
27
33
|
"devDependencies": {
|
|
28
34
|
"@meshsdk/eslint-config": "*",
|
|
@@ -38,5 +44,6 @@
|
|
|
38
44
|
"prettier": "@meshsdk/prettier-config",
|
|
39
45
|
"publishConfig": {
|
|
40
46
|
"access": "public"
|
|
41
|
-
}
|
|
42
|
-
|
|
47
|
+
},
|
|
48
|
+
"license": "Apache-2.0"
|
|
49
|
+
}
|