@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
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from "react";
|
|
2
|
-
|
|
3
|
-
import { AccountInfo } from "@meshsdk/common";
|
|
4
|
-
import { Transaction } from "@meshsdk/transaction";
|
|
5
|
-
|
|
6
|
-
import { CardanoWallet } from "../cardano-wallet";
|
|
7
|
-
import Button from "../common/button";
|
|
8
|
-
import { useRewardAddress, useWallet } from "../hooks";
|
|
9
|
-
|
|
10
|
-
interface ButtonProps {
|
|
11
|
-
label?: string;
|
|
12
|
-
isDark?: boolean;
|
|
13
|
-
poolId: string;
|
|
14
|
-
onCheck: (rewardAddress: string) => Promise<AccountInfo>;
|
|
15
|
-
onDelegated?: () => void;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const StakeButton = ({
|
|
19
|
-
label = "Stake your ADA",
|
|
20
|
-
isDark = false,
|
|
21
|
-
poolId,
|
|
22
|
-
onCheck,
|
|
23
|
-
onDelegated = undefined,
|
|
24
|
-
}: ButtonProps) => {
|
|
25
|
-
const [isDarkMode, setIsDarkMode] = useState(false);
|
|
26
|
-
const { connected } = useWallet();
|
|
27
|
-
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
setIsDarkMode(isDark);
|
|
30
|
-
}, [isDark]);
|
|
31
|
-
|
|
32
|
-
return (
|
|
33
|
-
<>
|
|
34
|
-
{connected ? (
|
|
35
|
-
<Button isDarkMode={isDarkMode}>
|
|
36
|
-
<Delegate
|
|
37
|
-
poolId={poolId}
|
|
38
|
-
onCheck={onCheck}
|
|
39
|
-
onDelegated={onDelegated}
|
|
40
|
-
/>
|
|
41
|
-
</Button>
|
|
42
|
-
) : (
|
|
43
|
-
<CardanoWallet label={label} isDark={isDark} />
|
|
44
|
-
)}
|
|
45
|
-
</>
|
|
46
|
-
);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const Delegate = ({
|
|
50
|
-
poolId,
|
|
51
|
-
onCheck,
|
|
52
|
-
onDelegated,
|
|
53
|
-
}: {
|
|
54
|
-
poolId: string;
|
|
55
|
-
onCheck: (rewardAddress: string) => Promise<AccountInfo>;
|
|
56
|
-
onDelegated?: () => void;
|
|
57
|
-
}) => {
|
|
58
|
-
const { wallet } = useWallet();
|
|
59
|
-
const rewardAddress = useRewardAddress();
|
|
60
|
-
const [error, setError] = useState<unknown>();
|
|
61
|
-
const [checking, setChecking] = useState(false);
|
|
62
|
-
const [accountInfo, setAccountInfo] = useState<AccountInfo>();
|
|
63
|
-
const [processing, setProcessing] = useState(false);
|
|
64
|
-
const [done, setDone] = useState(false);
|
|
65
|
-
|
|
66
|
-
const checkAccountStatus = async () => {
|
|
67
|
-
try {
|
|
68
|
-
setChecking(true);
|
|
69
|
-
|
|
70
|
-
if (rewardAddress) {
|
|
71
|
-
const info = await onCheck(rewardAddress);
|
|
72
|
-
setAccountInfo(info);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
setChecking(false);
|
|
76
|
-
} catch (error) {
|
|
77
|
-
setError(error);
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const registerAddress = async () => {
|
|
82
|
-
setProcessing(true);
|
|
83
|
-
setDone(false);
|
|
84
|
-
try {
|
|
85
|
-
if (rewardAddress) {
|
|
86
|
-
const tx = new Transaction({ initiator: wallet })
|
|
87
|
-
.registerStake(rewardAddress)
|
|
88
|
-
.delegateStake(rewardAddress, poolId);
|
|
89
|
-
|
|
90
|
-
const unsignedTx = await tx.build();
|
|
91
|
-
const signedTx = await wallet.signTx(unsignedTx);
|
|
92
|
-
const txHash = await wallet.submitTx(signedTx);
|
|
93
|
-
|
|
94
|
-
if (onDelegated) {
|
|
95
|
-
onDelegated();
|
|
96
|
-
}
|
|
97
|
-
setDone(true);
|
|
98
|
-
}
|
|
99
|
-
} catch (error) {
|
|
100
|
-
console.error("error", error);
|
|
101
|
-
setError(error);
|
|
102
|
-
}
|
|
103
|
-
setProcessing(false);
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const delegateStake = async () => {
|
|
107
|
-
setProcessing(true);
|
|
108
|
-
setDone(false);
|
|
109
|
-
try {
|
|
110
|
-
if (rewardAddress) {
|
|
111
|
-
const tx = new Transaction({ initiator: wallet }).delegateStake(
|
|
112
|
-
rewardAddress,
|
|
113
|
-
poolId,
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
const unsignedTx = await tx.build();
|
|
117
|
-
const signedTx = await wallet.signTx(unsignedTx);
|
|
118
|
-
const txHash = await wallet.submitTx(signedTx);
|
|
119
|
-
setDone(true);
|
|
120
|
-
}
|
|
121
|
-
} catch (error) {
|
|
122
|
-
console.error("error", error);
|
|
123
|
-
setError(error);
|
|
124
|
-
}
|
|
125
|
-
setProcessing(false);
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
useEffect(() => {
|
|
129
|
-
checkAccountStatus();
|
|
130
|
-
}, [rewardAddress]);
|
|
131
|
-
|
|
132
|
-
if (checking) {
|
|
133
|
-
return <span>Checking...</span>;
|
|
134
|
-
}
|
|
135
|
-
if (processing) {
|
|
136
|
-
return <span>Loading...</span>;
|
|
137
|
-
}
|
|
138
|
-
if (done) {
|
|
139
|
-
return <span>Stake Delegated</span>;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (accountInfo?.active) {
|
|
143
|
-
return accountInfo.poolId === poolId ? (
|
|
144
|
-
<span>Stake Delegated</span>
|
|
145
|
-
) : (
|
|
146
|
-
// <span onClick={delegateStake}>Delegate Stake</span>
|
|
147
|
-
<span onClick={registerAddress}>Begin Staking</span>
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return <span onClick={registerAddress}>Begin Staking</span>;
|
|
152
|
-
};
|
package/src/styles.css
DELETED
package/tailwind.config.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Config } from "tailwindcss";
|
|
2
|
-
|
|
3
|
-
import sharedConfig from "@meshsdk/tailwind-config";
|
|
4
|
-
|
|
5
|
-
const config: Pick<Config, "prefix" | "presets" | "content"> = {
|
|
6
|
-
content: ["./src/**/*.tsx"],
|
|
7
|
-
prefix: "ui-",
|
|
8
|
-
presets: [sharedConfig],
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export default config;
|