@cordystackx/cordy_minikit 1.3.2 → 1.4.7

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.
@@ -1 +1 @@
1
- {"version":3,"file":"UI_Comp.d.ts","sourceRoot":"","sources":["../../components/UI_Comp.tsx"],"names":[],"mappings":"AAUA,MAAM,CAAC,OAAO,UAAU,OAAO,4CAwF9B"}
1
+ {"version":3,"file":"UI_Comp.d.ts","sourceRoot":"","sources":["../../components/UI_Comp.tsx"],"names":[],"mappings":"AAUA,MAAM,CAAC,OAAO,UAAU,OAAO,4CAyF9B"}
@@ -10,7 +10,7 @@ import pkg from "../package.json";
10
10
  import links from "../config/links.json";
11
11
  export default function UI_Comp() {
12
12
  const { closeModal } = useWalletModal();
13
- const { isConnected, address } = useAccount();
13
+ const { isConnected, address, chain } = useAccount();
14
14
  const { disconnect } = useDisconnect();
15
15
  const [loading, setLoading] = useState(false);
16
16
  const [errorMsg, setErrorMsg] = useState();
@@ -31,7 +31,7 @@ export default function UI_Comp() {
31
31
  if (balance === "") {
32
32
  Get_Balance();
33
33
  }
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" }), 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: "#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("button", { onClick: () => {
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" }), 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: "#2f9" }, 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("button", { onClick: () => {
35
35
  closeModal();
36
36
  disconnect();
37
37
  }, children: "DisConnect" }), _jsxs("a", { href: links.NPM_Pack_links, children: ["Powered By CordyStackX | Version ", pkg.version] })] }) }));
@@ -0,0 +1,2 @@
1
+ export default function AirDropFuacet(address: string, cost: number): Promise<boolean>;
2
+ //# sourceMappingURL=AirDrop_Faucet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AirDrop_Faucet.d.ts","sourceRoot":"","sources":["../../controllers/AirDrop_Faucet.ts"],"names":[],"mappings":"AAUA,wBAA8B,aAAa,CACzC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,oBAsGb"}
@@ -0,0 +1,93 @@
1
+ "use server";
2
+ import { ethers, parseUnits } from 'ethers';
3
+ import tokenAbi from '../config/ERC20_ABI.json';
4
+ const tokenAddress = process.env.NEXT_PUBLIC_TOKENADDRESS || "";
5
+ const rpcUrl = process.env.NEXT_PUBLIC_RPC_ENDPOINT || "";
6
+ // Server-side environment variables (for backend/API routes)
7
+ const privateKeyFromEnv = process.env.PRIVATE_KEY || "";
8
+ export default async function AirDropFuacet(address, cost) {
9
+ if (!address) {
10
+ console.error("❌ Recipient address not found");
11
+ return false;
12
+ }
13
+ const contractAddress = tokenAddress;
14
+ if (!contractAddress) {
15
+ console.error("❌ NEXT_PUBLIC_TOKENADDRESS not configured");
16
+ return false;
17
+ }
18
+ try {
19
+ let provider;
20
+ let signer;
21
+ const privateKey = privateKeyFromEnv;
22
+ // Choose signing method
23
+ if (privateKey) {
24
+ // ⚠️ PRIVATE KEY SIGNING (Server-side or backend only)
25
+ const endpoint = rpcUrl;
26
+ if (!endpoint) {
27
+ console.error("❌ NEXT_PUBLIC_RPC_ENDPOINT required for private key signing");
28
+ return false;
29
+ }
30
+ console.log("🔐 Using private key signer (from environment)");
31
+ provider = new ethers.JsonRpcProvider(endpoint);
32
+ signer = new ethers.Wallet(privateKey, provider);
33
+ }
34
+ else {
35
+ // 👛 WALLET SIGNING (User's wallet - MetaMask, etc.)
36
+ console.log("👛 Using wallet signer");
37
+ if (!window.ethereum) {
38
+ console.error("❌ No wallet detected. Install MetaMask or similar.");
39
+ return false;
40
+ }
41
+ provider = new ethers.BrowserProvider(window.ethereum);
42
+ signer = await provider.getSigner();
43
+ }
44
+ // Get network info
45
+ const network = await provider.getNetwork();
46
+ console.log(`🌐 Network: ${network.name} (Chain ID: ${network.chainId})`);
47
+ // Create contract instance
48
+ const tokenContract = new ethers.Contract(contractAddress, tokenAbi, signer);
49
+ // Get decimals from contract
50
+ let decimals;
51
+ try {
52
+ decimals = await tokenContract.decimals();
53
+ }
54
+ catch {
55
+ console.warn("⚠️ Could not fetch decimals, using default 18");
56
+ decimals = 18;
57
+ }
58
+ const amount = parseUnits(String(cost), decimals);
59
+ // Check balance
60
+ const signerAddress = await signer.getAddress();
61
+ const balance = await tokenContract.balanceOf(signerAddress);
62
+ console.log(`💰 Balance: ${ethers.formatUnits(balance, decimals)} tokens`);
63
+ console.log(`💸 Sending: ${ethers.formatUnits(amount, decimals)} tokens`);
64
+ if (balance < amount) {
65
+ console.error("❌ Insufficient balance");
66
+ return false;
67
+ }
68
+ // Execute transfer
69
+ console.log(`🚀 Initiating transfer to ${address}...`);
70
+ const tx = await tokenContract.transfer(address, amount);
71
+ console.log(`⏳ Transaction submitted: ${tx.hash}`);
72
+ const receipt = await tx.wait();
73
+ if (receipt && receipt.status === 1) {
74
+ console.log(`✅ Transaction Complete! TX hash: ${receipt.hash}`);
75
+ return true;
76
+ }
77
+ else {
78
+ console.error("❌ Transaction Failed", receipt);
79
+ return false;
80
+ }
81
+ }
82
+ catch (err) {
83
+ console.error("❌ Transaction error:", err);
84
+ if (err.code === "INVALID_ARGUMENT") {
85
+ console.error("💡 Check your private key format or wallet connection");
86
+ }
87
+ else if (err.code === "INSUFFICIENT_FUNDS") {
88
+ console.error("💡 Not enough gas or token balance");
89
+ }
90
+ return false;
91
+ }
92
+ }
93
+ ;
@@ -1 +1 @@
1
- {"version":3,"file":"Transactions.d.ts","sourceRoot":"","sources":["../../controllers/Transactions.tsx"],"names":[],"mappings":"AAKA,wBAA8B,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,oBAmC1E"}
1
+ {"version":3,"file":"Transactions.d.ts","sourceRoot":"","sources":["../../controllers/Transactions.tsx"],"names":[],"mappings":"AAMA,wBAA8B,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,oBAqC1E"}
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { ethers, parseUnits } from 'ethers';
2
3
  import tokenAbi from '../config/ERC20_ABI.json';
3
4
  const tokenAddress = process.env.NEXT_PUBLIC_TOKENADDRESS || "";
@@ -1,4 +1,5 @@
1
1
  export { default as WalletButton } from "./WagmiButton";
2
2
  export { default as CordyStackTrans } from "./Transactions";
3
3
  export { default as getTokenBalance } from "./Get_Balance";
4
+ export { default as AirDropFuacet } from "./AirDrop_Faucet";
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../controllers/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,eAAe,CAAC;AAExD,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAE5D,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../controllers/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,eAAe,CAAC;AAExD,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAE5D,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,kBAAkB,CAAC"}
@@ -1,3 +1,4 @@
1
1
  export { default as WalletButton } from "./WagmiButton";
2
2
  export { default as CordyStackTrans } from "./Transactions";
3
3
  export { default as getTokenBalance } from "./Get_Balance";
4
+ export { default as AirDropFuacet } from "./AirDrop_Faucet";
@@ -0,0 +1,11 @@
1
+ interface UseNetworkGuardOptions {
2
+ enabled?: boolean;
3
+ onWrongNetwork?: () => void;
4
+ }
5
+ export declare function useNetworkGuard(options?: UseNetworkGuardOptions): {
6
+ isEnforcing: boolean;
7
+ requiredChainId: number | null;
8
+ isCorrectNetwork: boolean;
9
+ };
10
+ export {};
11
+ //# sourceMappingURL=useNetworkGuard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useNetworkGuard.d.ts","sourceRoot":"","sources":["../../hooks/useNetworkGuard.ts"],"names":[],"mappings":"AAKA,UAAU,sBAAsB;IAC9B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;CAC7B;AAED,wBAAgB,eAAe,CAAC,OAAO,GAAE,sBAA2B;;;;EAqDnE"}
@@ -0,0 +1,49 @@
1
+ "use client";
2
+ import { useEffect, useState } from "react";
3
+ import { useAccount } from "wagmi";
4
+ import { detectContractNetwork, enforceNetwork, setupNetworkGuard } from "../utils/networkEnforcer";
5
+ export function useNetworkGuard(options = {}) {
6
+ const { enabled = true, onWrongNetwork } = options;
7
+ const { isConnected, chainId } = useAccount();
8
+ const [isEnforcing, setIsEnforcing] = useState(false);
9
+ const [requiredChainId, setRequiredChainId] = useState(null);
10
+ useEffect(() => {
11
+ if (!enabled || !isConnected)
12
+ return;
13
+ const tokenAddress = process.env.NEXT_PUBLIC_TOKENADDRESS;
14
+ if (!tokenAddress)
15
+ return;
16
+ // Detect the required network
17
+ detectContractNetwork(tokenAddress).then((network) => {
18
+ if (network) {
19
+ setRequiredChainId(network.chainId);
20
+ // Set up continuous network monitoring
21
+ const cleanup = setupNetworkGuard(network.chainId, network, () => {
22
+ setIsEnforcing(true);
23
+ if (onWrongNetwork) {
24
+ onWrongNetwork();
25
+ }
26
+ setTimeout(() => setIsEnforcing(false), 2000);
27
+ });
28
+ // Check current network on mount
29
+ if (chainId && chainId !== network.chainId) {
30
+ console.warn("⚠️ Wrong network on mount, enforcing correct network...");
31
+ setIsEnforcing(true);
32
+ enforceNetwork(network.chainId, network)
33
+ .catch((err) => {
34
+ console.error("❌ Failed to enforce network:", err);
35
+ })
36
+ .finally(() => {
37
+ setIsEnforcing(false);
38
+ });
39
+ }
40
+ return cleanup;
41
+ }
42
+ });
43
+ }, [enabled, isConnected, chainId, onWrongNetwork]);
44
+ return {
45
+ isEnforcing,
46
+ requiredChainId,
47
+ isCorrectNetwork: requiredChainId ? chainId === requiredChainId : true,
48
+ };
49
+ }
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cordystackx/cordy_minikit",
3
- "version": "1.3.1",
3
+ "version": "1.4.6",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org/"