@cordystackx/cordy_minikit 0.7.6 → 0.7.8
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/README.md +0 -1
- package/dist/components/UI_Comp.d.ts.map +1 -1
- package/dist/components/UI_Comp.js +4 -2
- package/dist/controllers/Get_Balance.d.ts +4 -1
- package/dist/controllers/Get_Balance.d.ts.map +1 -1
- package/dist/controllers/Get_Balance.js +12 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UI_Comp.d.ts","sourceRoot":"","sources":["../../components/UI_Comp.tsx"],"names":[],"mappings":"AASA,MAAM,CAAC,OAAO,UAAU,OAAO,
|
|
1
|
+
{"version":3,"file":"UI_Comp.d.ts","sourceRoot":"","sources":["../../components/UI_Comp.tsx"],"names":[],"mappings":"AASA,MAAM,CAAC,OAAO,UAAU,OAAO,4CAsF9B"}
|
|
@@ -13,21 +13,23 @@ export default function UI_Comp() {
|
|
|
13
13
|
const [loading, setLoading] = useState(false);
|
|
14
14
|
const [errorMsg, setErrorMsg] = useState();
|
|
15
15
|
const [balance, setBalance] = useState("");
|
|
16
|
+
const [symbol, setSymbol] = useState("");
|
|
16
17
|
useEffect(() => {
|
|
17
18
|
Get_Balance();
|
|
18
19
|
}, [balance]);
|
|
19
20
|
const Get_Balance = async () => {
|
|
20
21
|
if (!address || !process.env.NEXT_PUBLIC_TOKENADDRESS)
|
|
21
22
|
return;
|
|
22
|
-
const balance = await getTokenBalance(address, process.env.NEXT_PUBLIC_TOKENADDRESS);
|
|
23
|
+
const { balance, symbol } = await getTokenBalance(address, process.env.NEXT_PUBLIC_TOKENADDRESS);
|
|
23
24
|
setBalance(balance);
|
|
25
|
+
setSymbol(symbol);
|
|
24
26
|
return;
|
|
25
27
|
};
|
|
26
28
|
if (isConnected) {
|
|
27
29
|
if (balance === "") {
|
|
28
30
|
Get_Balance();
|
|
29
31
|
}
|
|
30
|
-
return (_jsx("div", { className: UI_Comp__css.container, children: _jsxs("div", { className: UI_Comp__css.connector, children: [_jsx("p", { className: UI_Comp__css.closed, onClick: closeModal, children: "\u2715" }), isConnected && (_jsx("div", { className: UI_Comp__css.info, children: balance ? (_jsxs("span", { children: [_jsx(FaUser, { size: 70 }),
|
|
32
|
+
return (_jsx("div", { className: UI_Comp__css.container, children: _jsxs("div", { className: UI_Comp__css.connector, children: [_jsx("p", { className: UI_Comp__css.closed, onClick: closeModal, children: "\u2715" }), isConnected && (_jsx("div", { className: UI_Comp__css.info, children: balance ? (_jsxs("span", { children: [_jsx(FaUser, { size: 70 }), _jsx("p", { style: { color: "#0f0" }, children: "Connected" }), _jsxs("p", { style: { color: "#f0f" }, children: ["Network: ", chain?.name || "Unknown"] }), _jsxs("p", { style: { color: "#0ff" }, children: ["Balance: ", Number(balance).toFixed(2), " ", symbol] }), _jsx("p", { style: { color: "#ff0" }, children: address })] })) : (_jsx("p", { style: { color: "var(--foreground_wagmi)" }, children: "Loading balance..." })) })), _jsx(Disconnect, {}), _jsx("a", { href: "https://cordy-stack-x.vercel.app/", children: "Powered By CordyStackX" })] }) }));
|
|
31
33
|
}
|
|
32
34
|
return (_jsx("div", { className: UI_Comp__css.container, children: _jsxs("div", { className: UI_Comp__css.connector, children: [_jsx("p", { className: UI_Comp__css.closed, onClick: closeModal, children: "\u2715" }), _jsx("img", { src: Image__src.logo, width: 50, height: 50 }), _jsx("h2", { children: "Cordy MiniKit" }), _jsxs("div", { children: [_jsx("h3", { children: loading ? "Loading..." : "" }), _jsx(WalletButton, { onStatusChange: ({ isPending, error }) => {
|
|
33
35
|
setLoading(isPending);
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
export default function getTokenBalance(address: string, tokenAddress: string, decimals?: number): Promise<
|
|
1
|
+
export default function getTokenBalance(address: string, tokenAddress: string, decimals?: number): Promise<{
|
|
2
|
+
balance: string;
|
|
3
|
+
symbol: string;
|
|
4
|
+
}>;
|
|
2
5
|
//# sourceMappingURL=Get_Balance.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Get_Balance.d.ts","sourceRoot":"","sources":["../../controllers/Get_Balance.tsx"],"names":[],"mappings":"AAGA,wBAA8B,eAAe,CAC3C,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,QAAQ,GAAE,MAAW
|
|
1
|
+
{"version":3,"file":"Get_Balance.d.ts","sourceRoot":"","sources":["../../controllers/Get_Balance.tsx"],"names":[],"mappings":"AAGA,wBAA8B,eAAe,CAC3C,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,QAAQ,GAAE,MAAW;;;GAuBtB"}
|
|
@@ -4,11 +4,21 @@ export default async function getTokenBalance(address, tokenAddress, decimals =
|
|
|
4
4
|
try {
|
|
5
5
|
const provider = new ethers.JsonRpcProvider(process.env.NEXT_PUBLIC_RPC_ENDPOINT);
|
|
6
6
|
const contract = new ethers.Contract(tokenAddress, ERC20_ABI, provider);
|
|
7
|
+
// Fetch balance
|
|
7
8
|
const balance = await contract.balanceOf(address);
|
|
8
|
-
|
|
9
|
+
const formattedBalance = ethers.formatUnits(balance, decimals);
|
|
10
|
+
// Fetch token symbol
|
|
11
|
+
let symbol;
|
|
12
|
+
try {
|
|
13
|
+
symbol = await contract.symbol();
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
symbol = ""; // fallback if the contract doesn't implement symbol()
|
|
17
|
+
}
|
|
18
|
+
return { balance: formattedBalance, symbol };
|
|
9
19
|
}
|
|
10
20
|
catch (err) {
|
|
11
21
|
console.error("Error fetching token balance:", err);
|
|
12
|
-
return "0";
|
|
22
|
+
return { balance: "0", symbol: "" };
|
|
13
23
|
}
|
|
14
24
|
}
|