@cordystackx/cordy_minikit 1.5.34 → 2.0.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/README.md +438 -58
- package/dist/components/Connect_wallet_bt.d.ts.map +1 -1
- package/dist/components/Connect_wallet_bt.js +62 -11
- package/dist/components/UI_Comp.d.ts.map +1 -1
- package/dist/components/UI_Comp.js +79 -17
- package/dist/config/Image.json +4 -3
- package/dist/controllers/DisConnect.d.ts +6 -0
- package/dist/controllers/DisConnect.d.ts.map +1 -0
- package/dist/controllers/DisConnect.js +56 -0
- package/dist/controllers/Get_Account_Info.d.ts +26 -0
- package/dist/controllers/Get_Account_Info.d.ts.map +1 -0
- package/dist/controllers/Get_Account_Info.js +158 -0
- package/dist/controllers/Get_Balance.d.ts.map +1 -1
- package/dist/controllers/Get_Balance.js +16 -3
- package/dist/controllers/StellarButton.d.ts +10 -0
- package/dist/controllers/StellarButton.d.ts.map +1 -0
- package/dist/controllers/StellarButton.js +43 -0
- package/dist/controllers/Transactions.d.ts +6 -0
- package/dist/controllers/Transactions.d.ts.map +1 -1
- package/dist/controllers/Transactions.js +87 -2
- package/dist/controllers/WagmiButton.d.ts.map +1 -1
- package/dist/controllers/WagmiButton.js +6 -2
- package/dist/controllers/index.d.ts +6 -1
- package/dist/controllers/index.d.ts.map +1 -1
- package/dist/controllers/index.js +6 -1
- package/dist/controllers/loadStellarBalance.d.ts +7 -0
- package/dist/controllers/loadStellarBalance.d.ts.map +1 -0
- package/dist/controllers/loadStellarBalance.js +23 -0
- package/dist/css/UI_Comp/styles.module.css +193 -44
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/package.json +16 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/wagmi__providers.d.ts +12 -1
- package/dist/wagmi__providers.d.ts.map +1 -1
- package/dist/wagmi__providers.js +52 -3
- package/package.json +16 -4
- package/dist/controllers/Get_Sessions.d.ts +0 -2
- package/dist/controllers/Get_Sessions.d.ts.map +0 -1
- package/dist/controllers/Get_Sessions.js +0 -2
|
@@ -1,18 +1,69 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { getTokenBalance, loadStellarBalance } from "../controllers";
|
|
4
|
+
import { useWalletModal, useStellarWallet } from "../wagmi__providers";
|
|
5
|
+
import { useAccount } from "wagmi";
|
|
6
|
+
import { useEffect, useState } from "react";
|
|
7
|
+
const ACTIVE_WALLET_SESSION_KEY = "cordy_minikit_active_wallet_session";
|
|
8
|
+
const STELLAR_BALANCE_REFRESH_EVENT = "cordy:stellar-balance-updated";
|
|
6
9
|
export default function ConnectWalletBT({ className, }) {
|
|
7
10
|
const { openModal } = useWalletModal();
|
|
11
|
+
const { stellarWallet, setStellarWallet } = useStellarWallet();
|
|
8
12
|
const { isConnected, address } = useAccount();
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const [balance, setBalance] = useState("");
|
|
14
|
+
const [symbol, setSymbol] = useState("");
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (isConnected && address) {
|
|
17
|
+
void Get_Balance();
|
|
18
|
+
}
|
|
19
|
+
}, [isConnected, address]);
|
|
20
|
+
const Get_Balance = async () => {
|
|
21
|
+
if (!address)
|
|
22
|
+
return;
|
|
23
|
+
const { balance, symbol } = await getTokenBalance(address);
|
|
24
|
+
setBalance(balance);
|
|
25
|
+
setSymbol(symbol);
|
|
26
|
+
};
|
|
27
|
+
const handleLoadStellarBalance = async (accountId) => {
|
|
28
|
+
try {
|
|
29
|
+
const result = await loadStellarBalance(accountId);
|
|
30
|
+
setStellarWallet((current) => ({
|
|
31
|
+
...current,
|
|
32
|
+
address: result.address,
|
|
33
|
+
network: result.network,
|
|
34
|
+
balance: result.balance,
|
|
35
|
+
}));
|
|
36
|
+
if (typeof window !== "undefined") {
|
|
37
|
+
window.localStorage.setItem(ACTIVE_WALLET_SESSION_KEY, "stellar");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
console.error("Failed to load Stellar balance:", err);
|
|
42
|
+
setStellarWallet((current) => ({
|
|
43
|
+
...current,
|
|
44
|
+
balance: "0",
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (stellarWallet.address) {
|
|
50
|
+
void handleLoadStellarBalance(stellarWallet.address);
|
|
51
|
+
}
|
|
52
|
+
}, [stellarWallet.address]);
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
const handler = () => {
|
|
55
|
+
if (stellarWallet.address) {
|
|
56
|
+
void handleLoadStellarBalance(stellarWallet.address);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
window.addEventListener(STELLAR_BALANCE_REFRESH_EVENT, handler);
|
|
60
|
+
return () => {
|
|
61
|
+
window.removeEventListener(STELLAR_BALANCE_REFRESH_EVENT, handler);
|
|
62
|
+
};
|
|
63
|
+
}, [stellarWallet.address]);
|
|
15
64
|
return (_jsx("button", { className: className, onClick: openModal, children: isConnected
|
|
16
|
-
? `BAL ${
|
|
17
|
-
:
|
|
65
|
+
? `BAL ${balance} ${symbol ?? ""}`
|
|
66
|
+
: stellarWallet.address
|
|
67
|
+
? `BAL ${stellarWallet.balance ?? "0"} XLM`
|
|
68
|
+
: "Connect Wallet" }));
|
|
18
69
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UI_Comp.d.ts","sourceRoot":"","sources":["../../components/UI_Comp.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"UI_Comp.d.ts","sourceRoot":"","sources":["../../components/UI_Comp.tsx"],"names":[],"mappings":"AAWA,MAAM,CAAC,OAAO,UAAU,OAAO,gCA+N9B"}
|
|
@@ -1,24 +1,37 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { UI_Comp__css } from "../css";
|
|
4
|
-
import { WalletButton, getTokenBalance } from "../controllers";
|
|
5
|
-
import { useWalletModal } from "../wagmi__providers";
|
|
6
|
-
import { useAccount
|
|
4
|
+
import { WalletButton, getTokenBalance, StellarWalletButton, loadStellarBalance, useDisconnectWallets } from "../controllers";
|
|
5
|
+
import { useWalletModal, useStellarWallet } from "../wagmi__providers";
|
|
6
|
+
import { useAccount } from "wagmi";
|
|
7
7
|
import { FaUser } from 'react-icons/fa';
|
|
8
8
|
import { useState, useEffect } from "react";
|
|
9
9
|
import pkg from "../package.json";
|
|
10
10
|
import links from "../config/links.json";
|
|
11
|
+
const ACTIVE_WALLET_SESSION_KEY = "cordy_minikit_active_wallet_session";
|
|
11
12
|
export default function UI_Comp() {
|
|
12
13
|
const { closeModal } = useWalletModal();
|
|
14
|
+
const { stellarWallet, setStellarWallet } = useStellarWallet();
|
|
13
15
|
const { isConnected, address, chain } = useAccount();
|
|
14
|
-
const { disconnect } = useDisconnect();
|
|
15
16
|
const [loading, setLoading] = useState(false);
|
|
16
17
|
const [errorMsg, setErrorMsg] = useState();
|
|
17
18
|
const [balance, setBalance] = useState("");
|
|
18
19
|
const [symbol, setSymbol] = useState("");
|
|
20
|
+
const [stellarLoading, setStellarLoading] = useState(false);
|
|
21
|
+
const [stellarError, setStellarError] = useState();
|
|
22
|
+
const { disconnectEVM, disconnectStellar,
|
|
23
|
+
// disconnectAll,
|
|
24
|
+
} = useDisconnectWallets();
|
|
19
25
|
useEffect(() => {
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
if (isConnected && address) {
|
|
27
|
+
Get_Balance();
|
|
28
|
+
}
|
|
29
|
+
}, [isConnected, address]);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (stellarWallet.address) {
|
|
32
|
+
void loadStellarBalance(stellarWallet.address);
|
|
33
|
+
}
|
|
34
|
+
}, [stellarWallet.address]);
|
|
22
35
|
const Get_Balance = async () => {
|
|
23
36
|
if (!address)
|
|
24
37
|
return;
|
|
@@ -27,17 +40,66 @@ export default function UI_Comp() {
|
|
|
27
40
|
setSymbol(symbol);
|
|
28
41
|
return;
|
|
29
42
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
43
|
+
const handleLoadStellarBalance = async (accountId) => {
|
|
44
|
+
setStellarError(undefined);
|
|
45
|
+
try {
|
|
46
|
+
const result = await loadStellarBalance(accountId);
|
|
47
|
+
setStellarWallet((current) => ({
|
|
48
|
+
...current,
|
|
49
|
+
address: result.address,
|
|
50
|
+
network: result.network,
|
|
51
|
+
balance: result.balance,
|
|
52
|
+
}));
|
|
53
|
+
if (typeof window !== "undefined") {
|
|
54
|
+
window.localStorage.setItem(ACTIVE_WALLET_SESSION_KEY, "stellar");
|
|
55
|
+
}
|
|
33
56
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
57
|
+
catch (err) {
|
|
58
|
+
const message = err instanceof Error ? err.message : "Failed to load Stellar balance";
|
|
59
|
+
console.error("Failed to load Stellar balance:", err);
|
|
60
|
+
setStellarError(message);
|
|
61
|
+
setStellarWallet((current) => ({
|
|
62
|
+
...current,
|
|
63
|
+
balance: "0",
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const truncateAddress = (value, head = 8, tail = 4) => {
|
|
68
|
+
if (!value)
|
|
69
|
+
return "";
|
|
70
|
+
if (value.length <= head + tail + 3)
|
|
71
|
+
return value;
|
|
72
|
+
return `${value.slice(0, head)}...${value.slice(-tail)}`;
|
|
73
|
+
};
|
|
74
|
+
// EVM
|
|
75
|
+
if (isConnected) {
|
|
76
|
+
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("h2", { children: "Wallet Status" }), _jsxs("div", { className: UI_Comp__css.split_layout, children: [_jsxs("div", { className: UI_Comp__css.left_column, children: [_jsx("h3", { children: "EVM Wallet" }), _jsx("div", { className: UI_Comp__css.icon_wrap, children: _jsx(FaUser, { size: 70 }) })] }), _jsxs("div", { className: UI_Comp__css.right_column, children: [_jsx("h3", { children: "Status" }), balance ? (_jsx("div", { className: UI_Comp__css.info, children: _jsxs("div", { className: UI_Comp__css.status_stack, children: [_jsx("p", { style: { color: "#0f0" }, children: "Connected" }), _jsxs("p", { style: { color: "#2f9" }, children: ["Network: ", chain?.name || "Unknown"] }), _jsxs("p", { style: { color: "#0ff" }, children: ["Balance: ", Number(balance).toFixed(2), " ", symbol] }), _jsx("p", { className: UI_Comp__css.address, style: { color: "#ff0" }, title: address || "", children: truncateAddress(address) })] }) })) : (_jsxs("span", { className: UI_Comp__css.blockchain_loader, children: [_jsx("span", { className: UI_Comp__css.node }), _jsx("span", { className: UI_Comp__css.node }), _jsx("span", { className: UI_Comp__css.node })] }))] })] }), _jsx("button", { style: { width: "230px" }, onClick: async () => {
|
|
77
|
+
const success = await disconnectEVM();
|
|
78
|
+
console.log("EVM disconnect:", success);
|
|
79
|
+
}, children: "DisConnect" }), _jsxs("a", { style: { marginTop: "2rem" }, href: links.NPM_Pack_links, children: ["Powered By CordyStackX | Version ", pkg.version] })] }) }));
|
|
80
|
+
}
|
|
81
|
+
//Non - EVM
|
|
82
|
+
if (stellarWallet.address) {
|
|
83
|
+
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("h2", { children: "Wallet Status" }), _jsxs("div", { className: UI_Comp__css.split_layout, children: [_jsxs("div", { className: UI_Comp__css.left_column, children: [_jsx("h3", { children: "Stellar Wallet" }), _jsx("div", { className: UI_Comp__css.icon_wrap, children: _jsx(FaUser, { size: 70 }) })] }), _jsxs("div", { className: UI_Comp__css.right_column, children: [_jsx("h3", { children: "Status" }), stellarWallet.balance ? (_jsxs("div", { className: UI_Comp__css.status_stack, children: [_jsx("p", { style: { color: "#0f0" }, children: "Connected" }), _jsxs("p", { style: { color: "#2f9" }, children: ["Network: ", stellarWallet.network || "Stellar"] }), _jsxs("p", { style: { color: "#0ff" }, children: ["Balance: ", stellarWallet.balance ?? "0", " XLM"] }), _jsx("p", { className: UI_Comp__css.address, style: { color: "#ff0" }, title: stellarWallet.address || "", children: truncateAddress(stellarWallet.address) }), stellarError ? _jsx("p", { style: { color: "#f55" }, children: stellarError }) : null] })) : (_jsxs("span", { className: UI_Comp__css.blockchain_loader, children: [_jsx("span", { className: UI_Comp__css.node }), _jsx("span", { className: UI_Comp__css.node }), _jsx("span", { className: UI_Comp__css.node })] }))] })] }), _jsx("button", { style: { width: "230px" }, onClick: async () => {
|
|
84
|
+
const success = await disconnectStellar();
|
|
85
|
+
console.log("EVM disconnect:", success);
|
|
86
|
+
}, children: "DisConnect" }), _jsxs("a", { style: { marginTop: "2rem" }, href: links.NPM_Pack_links, children: ["Powered By CordyStackX | Version ", pkg.version] })] }) }));
|
|
38
87
|
}
|
|
39
|
-
return (_jsx("div", { className: UI_Comp__css.container, children: _jsxs("div", { className: UI_Comp__css.connector, children: [
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
88
|
+
return (_jsx("div", { className: UI_Comp__css.container, children: _jsxs("div", { className: UI_Comp__css.connector, children: [loading || stellarLoading ? (_jsxs("span", { className: UI_Comp__css.blockchain_loader, children: [_jsx("span", { className: UI_Comp__css.node }), _jsx("span", { className: UI_Comp__css.node }), _jsx("span", { className: UI_Comp__css.node })] })) : null, _jsx("p", { className: UI_Comp__css.closed, onClick: closeModal, children: "\u2715" }), _jsx("h2", { children: "Connect Your Wallet" }), _jsxs("div", { className: UI_Comp__css.split_layout, children: [_jsxs("div", { className: UI_Comp__css.left_column, children: [_jsx("h3", { children: "EVM Wallets" }), _jsx(WalletButton, { onStatusChange: ({ isPending, error }) => {
|
|
89
|
+
setLoading(isPending);
|
|
90
|
+
setErrorMsg(error);
|
|
91
|
+
} })] }), _jsxs("div", { className: UI_Comp__css.right_column, children: [_jsx("h3", { children: "Non - EVM Wallets" }), _jsx(StellarWalletButton, { onConnect: (address) => {
|
|
92
|
+
setStellarWallet((current) => ({ ...current, address }));
|
|
93
|
+
void handleLoadStellarBalance(address);
|
|
94
|
+
}, onStatusChange: ({ isPending, error, address, network }) => {
|
|
95
|
+
setStellarLoading(isPending);
|
|
96
|
+
setStellarError(error);
|
|
97
|
+
if (address)
|
|
98
|
+
setStellarWallet((current) => ({ ...current, address }));
|
|
99
|
+
if (network) {
|
|
100
|
+
setStellarWallet((current) => ({ ...current, network }));
|
|
101
|
+
}
|
|
102
|
+
if (address)
|
|
103
|
+
void handleLoadStellarBalance(address);
|
|
104
|
+
} })] })] }), _jsx("p", { style: { color: "#f00" }, children: errorMsg }), _jsx("p", { style: { color: "#f00" }, children: stellarError }), _jsxs("a", { style: { marginTop: "2rem" }, href: links.NPM_Pack_links, children: ["Powered By CordyStackX | Version ", pkg.version] })] }) }));
|
|
43
105
|
}
|
package/dist/config/Image.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"logo": "https://cordy-stack-x.vercel.app/logo.svg",
|
|
3
|
-
"
|
|
3
|
+
"Coinbase Wallet": "https://raw.githubusercontent.com/cordyStackX/cordy_minikit_official/main/assets/coinbased.svg",
|
|
4
4
|
"MetaMask": "https://raw.githubusercontent.com/cordyStackX/cordy_minikit_official/main/assets/metamask.png",
|
|
5
|
-
"WalletConnect": "https://raw.githubusercontent.com/cordyStackX/cordy_minikit_official/
|
|
6
|
-
"Trust Wallet": "https://raw.githubusercontent.com/cordyStackX/cordy_minikit_official/refs/heads/main/assets/trust-wallet-icon.png"
|
|
5
|
+
"WalletConnect": "https://raw.githubusercontent.com/cordyStackX/cordy_minikit_official/5086ee7de9e94e331f9b595e17ec5d022f5b8674/assets/WalletConnect.svg",
|
|
6
|
+
"Trust Wallet": "https://raw.githubusercontent.com/cordyStackX/cordy_minikit_official/refs/heads/main/assets/trust-wallet-icon.png",
|
|
7
|
+
"Freighter": "https://raw.githubusercontent.com/cordyStackX/cordy_minikit_official/refs/heads/main/assets/freighter.jpeg"
|
|
7
8
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DisConnect.d.ts","sourceRoot":"","sources":["../../controllers/DisConnect.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,OAAO,UAAU,oBAAoB;yBAWV,OAAO,CAAC,OAAO,CAAC;6BAYZ,OAAO,CAAC,OAAO,CAAC;yBAYpB,OAAO,CAAC,OAAO,CAAC;EAkBjD"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useDisconnect } from "wagmi";
|
|
3
|
+
import { useWalletModal, useStellarWallet } from "../wagmi__providers";
|
|
4
|
+
const ACTIVE_WALLET_SESSION_KEY = "***";
|
|
5
|
+
export default function useDisconnectWallets() {
|
|
6
|
+
const { disconnectAsync } = useDisconnect();
|
|
7
|
+
const { closeModal } = useWalletModal();
|
|
8
|
+
const { clearStellarWallet } = useStellarWallet();
|
|
9
|
+
const clearSession = () => {
|
|
10
|
+
if (typeof window !== "undefined") {
|
|
11
|
+
window.localStorage.removeItem(ACTIVE_WALLET_SESSION_KEY);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const disconnectEVM = async () => {
|
|
15
|
+
try {
|
|
16
|
+
await disconnectAsync();
|
|
17
|
+
clearSession();
|
|
18
|
+
closeModal();
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
console.error("Failed to disconnect EVM wallet:", err);
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const disconnectStellar = async () => {
|
|
27
|
+
try {
|
|
28
|
+
clearStellarWallet();
|
|
29
|
+
clearSession();
|
|
30
|
+
closeModal();
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
console.error("Failed to disconnect Stellar wallet:", err);
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const disconnectAll = async () => {
|
|
39
|
+
try {
|
|
40
|
+
await disconnectAsync();
|
|
41
|
+
clearStellarWallet();
|
|
42
|
+
clearSession();
|
|
43
|
+
closeModal();
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
console.error("Failed to disconnect wallets:", err);
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
disconnectEVM,
|
|
53
|
+
disconnectStellar,
|
|
54
|
+
disconnectAll,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type WalletContext = "EVM" | "Non_EVM" | "MULTI" | "NONE";
|
|
2
|
+
export default function useWalletStatus(): {
|
|
3
|
+
context: string;
|
|
4
|
+
evm: {
|
|
5
|
+
isConnected: boolean;
|
|
6
|
+
address: `0x${string}` | undefined;
|
|
7
|
+
chain: import("viem").Chain | undefined;
|
|
8
|
+
balance: string;
|
|
9
|
+
symbol: string;
|
|
10
|
+
error: string | undefined;
|
|
11
|
+
};
|
|
12
|
+
stellar: {
|
|
13
|
+
isConnected: boolean;
|
|
14
|
+
address: string | null;
|
|
15
|
+
network: string | undefined;
|
|
16
|
+
balance: string | undefined;
|
|
17
|
+
error: string | undefined;
|
|
18
|
+
};
|
|
19
|
+
refreshEvmBalance: () => Promise<boolean>;
|
|
20
|
+
refreshStellarBalance: (accountId?: string) => Promise<boolean>;
|
|
21
|
+
refreshBalances: () => Promise<boolean>;
|
|
22
|
+
disconnectEVM: () => Promise<boolean>;
|
|
23
|
+
disconnectStellar: () => Promise<boolean>;
|
|
24
|
+
disconnectAll: () => Promise<boolean>;
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=Get_Account_Info.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Get_Account_Info.d.ts","sourceRoot":"","sources":["../../controllers/Get_Account_Info.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;AAGjE,MAAM,CAAC,OAAO,UAAU,eAAe;;;;;;;;;;;;;;;;;6BAsBW,OAAO,CAAC,OAAO,CAAC;wCAwB3C,MAAM,KAAG,OAAO,CAAC,OAAO,CAAC;2BAuCA,OAAO,CAAC,OAAO,CAAC;yBAS9B,OAAO,CAAC,OAAO,CAAC;6BAmBZ,OAAO,CAAC,OAAO,CAAC;yBAgBpB,OAAO,CAAC,OAAO,CAAC;EA4DjD"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useState } from "react";
|
|
3
|
+
import { useAccount, useDisconnect } from "wagmi";
|
|
4
|
+
import { useWalletModal, useStellarWallet } from "../wagmi__providers";
|
|
5
|
+
import getTokenBalance from "./Get_Balance";
|
|
6
|
+
import loadStellarBalance from "./loadStellarBalance";
|
|
7
|
+
const ACTIVE_WALLET_SESSION_KEY = "cordy_minikit_active_wallet_session";
|
|
8
|
+
export default function useWalletStatus() {
|
|
9
|
+
const { closeModal } = useWalletModal();
|
|
10
|
+
const { stellarWallet, setStellarWallet, clearStellarWallet } = useStellarWallet();
|
|
11
|
+
const { isConnected, address: evmAddress, chain } = useAccount();
|
|
12
|
+
const { disconnectAsync } = useDisconnect();
|
|
13
|
+
const [evmBalance, setEvmBalance] = useState("");
|
|
14
|
+
const [evmSymbol, setEvmSymbol] = useState("");
|
|
15
|
+
const [stellarError, setStellarError] = useState();
|
|
16
|
+
const [evmError, setEvmError] = useState();
|
|
17
|
+
const walletContext = isConnected && stellarWallet.address
|
|
18
|
+
? "MULTI"
|
|
19
|
+
: isConnected
|
|
20
|
+
? "EVM"
|
|
21
|
+
: stellarWallet.address
|
|
22
|
+
? "Non-EVM"
|
|
23
|
+
: "NONE";
|
|
24
|
+
const refreshEvmBalance = useCallback(async () => {
|
|
25
|
+
if (!evmAddress)
|
|
26
|
+
return false;
|
|
27
|
+
try {
|
|
28
|
+
setEvmError(undefined);
|
|
29
|
+
const result = await getTokenBalance(evmAddress);
|
|
30
|
+
setEvmBalance(result.balance);
|
|
31
|
+
setEvmSymbol(result.symbol);
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
const message = err instanceof Error ? err.message : "Failed to load EVM balance";
|
|
36
|
+
console.error("Failed to load EVM balance:", err);
|
|
37
|
+
setEvmError(message);
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}, [evmAddress]);
|
|
41
|
+
const refreshStellarBalance = useCallback(async (accountId) => {
|
|
42
|
+
const stellarAddress = accountId || stellarWallet.address;
|
|
43
|
+
if (!stellarAddress)
|
|
44
|
+
return false;
|
|
45
|
+
try {
|
|
46
|
+
setStellarError(undefined);
|
|
47
|
+
const result = await loadStellarBalance(stellarAddress);
|
|
48
|
+
setStellarWallet((current) => ({
|
|
49
|
+
...current,
|
|
50
|
+
address: result.address,
|
|
51
|
+
network: result.network,
|
|
52
|
+
balance: result.balance,
|
|
53
|
+
}));
|
|
54
|
+
if (typeof window !== "undefined") {
|
|
55
|
+
window.localStorage.setItem(ACTIVE_WALLET_SESSION_KEY, "stellar");
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
const message = err instanceof Error ? err.message : "Failed to load Stellar balance";
|
|
61
|
+
console.error("Failed to load Stellar balance:", err);
|
|
62
|
+
setStellarError(message);
|
|
63
|
+
setStellarWallet((current) => ({
|
|
64
|
+
...current,
|
|
65
|
+
balance: "0",
|
|
66
|
+
}));
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}, [stellarWallet.address, setStellarWallet]);
|
|
70
|
+
const refreshBalances = useCallback(async () => {
|
|
71
|
+
const results = await Promise.all([
|
|
72
|
+
refreshEvmBalance(),
|
|
73
|
+
refreshStellarBalance(),
|
|
74
|
+
]);
|
|
75
|
+
return results.some(Boolean);
|
|
76
|
+
}, [refreshEvmBalance, refreshStellarBalance]);
|
|
77
|
+
const disconnectEVM = async () => {
|
|
78
|
+
try {
|
|
79
|
+
await disconnectAsync();
|
|
80
|
+
setEvmBalance("");
|
|
81
|
+
setEvmSymbol("");
|
|
82
|
+
if (typeof window !== "undefined") {
|
|
83
|
+
window.localStorage.removeItem(ACTIVE_WALLET_SESSION_KEY);
|
|
84
|
+
}
|
|
85
|
+
closeModal();
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
console.error("Failed to disconnect EVM wallet:", err);
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const disconnectStellar = async () => {
|
|
94
|
+
try {
|
|
95
|
+
clearStellarWallet();
|
|
96
|
+
if (typeof window !== "undefined") {
|
|
97
|
+
window.localStorage.removeItem(ACTIVE_WALLET_SESSION_KEY);
|
|
98
|
+
}
|
|
99
|
+
closeModal();
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
console.error("Failed to disconnect Stellar wallet:", err);
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const disconnectAll = async () => {
|
|
108
|
+
try {
|
|
109
|
+
await disconnectAsync();
|
|
110
|
+
clearStellarWallet();
|
|
111
|
+
setEvmBalance("");
|
|
112
|
+
setEvmSymbol("");
|
|
113
|
+
if (typeof window !== "undefined") {
|
|
114
|
+
window.localStorage.removeItem(ACTIVE_WALLET_SESSION_KEY);
|
|
115
|
+
}
|
|
116
|
+
closeModal();
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
console.error("Failed to disconnect wallets:", err);
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
useEffect(() => {
|
|
125
|
+
if (isConnected && evmAddress) {
|
|
126
|
+
void refreshEvmBalance();
|
|
127
|
+
}
|
|
128
|
+
}, [isConnected, evmAddress, refreshEvmBalance]);
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
if (stellarWallet.address) {
|
|
131
|
+
void refreshStellarBalance(stellarWallet.address);
|
|
132
|
+
}
|
|
133
|
+
}, [stellarWallet.address, refreshStellarBalance]);
|
|
134
|
+
return {
|
|
135
|
+
context: walletContext,
|
|
136
|
+
evm: {
|
|
137
|
+
isConnected,
|
|
138
|
+
address: evmAddress,
|
|
139
|
+
chain,
|
|
140
|
+
balance: evmBalance,
|
|
141
|
+
symbol: evmSymbol,
|
|
142
|
+
error: evmError,
|
|
143
|
+
},
|
|
144
|
+
stellar: {
|
|
145
|
+
isConnected: Boolean(stellarWallet.address),
|
|
146
|
+
address: stellarWallet.address,
|
|
147
|
+
network: stellarWallet.network,
|
|
148
|
+
balance: stellarWallet.balance,
|
|
149
|
+
error: stellarError,
|
|
150
|
+
},
|
|
151
|
+
refreshEvmBalance,
|
|
152
|
+
refreshStellarBalance,
|
|
153
|
+
refreshBalances,
|
|
154
|
+
disconnectEVM,
|
|
155
|
+
disconnectStellar,
|
|
156
|
+
disconnectAll,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
@@ -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,QAAQ,GAAE,MAAW,GACpB,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"Get_Balance.d.ts","sourceRoot":"","sources":["../../controllers/Get_Balance.tsx"],"names":[],"mappings":"AAGA,wBAA8B,eAAe,CAC3C,OAAO,EAAE,MAAM,EACf,QAAQ,GAAE,MAAW,GACpB,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CA2C9C"}
|
|
@@ -2,10 +2,23 @@ import { ethers } from "ethers";
|
|
|
2
2
|
import ERC20_ABI from "../config/ERC20_ABI.json";
|
|
3
3
|
export default async function getTokenBalance(address, decimals = 18) {
|
|
4
4
|
try {
|
|
5
|
-
|
|
5
|
+
const tokenAddress = process.env.NEXT_PUBLIC_TOKENADDRESS;
|
|
6
|
+
const rpcEndpoint = process.env.NEXT_PUBLIC_RPC_ENDPOINT;
|
|
7
|
+
if (!tokenAddress) {
|
|
8
|
+
console.error("NEXT_PUBLIC_TOKENADDRESS is not configured");
|
|
6
9
|
return { balance: "0", symbol: "" };
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
}
|
|
11
|
+
if (!rpcEndpoint) {
|
|
12
|
+
console.error("NEXT_PUBLIC_RPC_ENDPOINT is not configured");
|
|
13
|
+
return { balance: "0", symbol: "" };
|
|
14
|
+
}
|
|
15
|
+
const provider = new ethers.JsonRpcProvider(rpcEndpoint);
|
|
16
|
+
const code = await provider.getCode(tokenAddress);
|
|
17
|
+
if (!code || code === "0x") {
|
|
18
|
+
console.error(`No contract bytecode found at ${tokenAddress} on ${rpcEndpoint}`);
|
|
19
|
+
return { balance: "0", symbol: "" };
|
|
20
|
+
}
|
|
21
|
+
const contract = new ethers.Contract(tokenAddress, ERC20_ABI, provider);
|
|
9
22
|
// Fetch balance
|
|
10
23
|
const balance = await contract.balanceOf(address);
|
|
11
24
|
const formattedBalance = ethers.formatUnits(balance, decimals);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export default function StellarWalletButton({ onConnect, onStatusChange, }: {
|
|
2
|
+
onConnect?: (address: string) => void;
|
|
3
|
+
onStatusChange?: (status: {
|
|
4
|
+
isPending: boolean;
|
|
5
|
+
error?: string;
|
|
6
|
+
address?: string;
|
|
7
|
+
network?: string;
|
|
8
|
+
}) => void;
|
|
9
|
+
}): import("react").JSX.Element;
|
|
10
|
+
//# sourceMappingURL=StellarButton.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StellarButton.d.ts","sourceRoot":"","sources":["../../controllers/StellarButton.tsx"],"names":[],"mappings":"AAMA,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,EAC1C,SAAS,EACT,cAAc,GACf,EAAE;IACD,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE;QACxB,SAAS,EAAE,OAAO,CAAC;QACnB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,KAAK,IAAI,CAAC;CACZ,+BAqDA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { requestAccess, getNetworkDetails } from "@stellar/freighter-api";
|
|
5
|
+
import img_src from "../config/Image.json";
|
|
6
|
+
export default function StellarWalletButton({ onConnect, onStatusChange, }) {
|
|
7
|
+
const [address, setAddress] = useState(null);
|
|
8
|
+
const [isPending, setIsPending] = useState(false);
|
|
9
|
+
const [errorMsg, setErrorMsg] = useState();
|
|
10
|
+
const [network, setNetwork] = useState();
|
|
11
|
+
const connect = async () => {
|
|
12
|
+
setIsPending(true);
|
|
13
|
+
setErrorMsg(undefined);
|
|
14
|
+
onStatusChange?.({ isPending: true });
|
|
15
|
+
try {
|
|
16
|
+
const access = await requestAccess();
|
|
17
|
+
const publicKey = access.address;
|
|
18
|
+
setAddress(publicKey);
|
|
19
|
+
const networkDetails = await getNetworkDetails();
|
|
20
|
+
setNetwork(networkDetails.network || "Unknown");
|
|
21
|
+
onConnect?.(publicKey);
|
|
22
|
+
onStatusChange?.({
|
|
23
|
+
isPending: false,
|
|
24
|
+
address: publicKey,
|
|
25
|
+
network: networkDetails.network || "Unknown",
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
const message = err instanceof Error ? err.message : "Freighter connection failed";
|
|
30
|
+
console.error("Freighter error:", err);
|
|
31
|
+
setErrorMsg(message);
|
|
32
|
+
onStatusChange?.({ isPending: false, error: message });
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
setIsPending(false);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
return (_jsxs("button", { onClick: connect, disabled: isPending, children: [_jsx("img", { src: img_src.Freighter, alt: "Freighter", title: "Freighter", width: 18, height: 18 }), isPending
|
|
39
|
+
? "Connecting..."
|
|
40
|
+
: address
|
|
41
|
+
? `Connected: ${address.slice(0, 6)}...`
|
|
42
|
+
: "Freighter", network ? ` • ${network}` : "", errorMsg ? ` • ${errorMsg}` : ""] }));
|
|
43
|
+
}
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
type CordyStackStellarTransOptions = {
|
|
2
|
+
memo?: string;
|
|
3
|
+
source?: string;
|
|
4
|
+
};
|
|
1
5
|
export default function CordyStackTrans(address: string, cost: number): Promise<boolean>;
|
|
6
|
+
export declare function CordyStackTransStellar(address: string, cost: number, options?: CordyStackStellarTransOptions): Promise<boolean>;
|
|
7
|
+
export {};
|
|
2
8
|
//# sourceMappingURL=Transactions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transactions.d.ts","sourceRoot":"","sources":["../../controllers/Transactions.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Transactions.d.ts","sourceRoot":"","sources":["../../controllers/Transactions.tsx"],"names":[],"mappings":"AAWA,KAAK,6BAA6B,GAAG;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,wBAA8B,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,oBAqD1E;AAED,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,6BAAkC,oBAoF5C"}
|