diff --git a/src/components/ClaimableBalanceCard.tsx b/src/components/ClaimableBalanceCard.tsx index 1ee8e2e..e6d7601 100644 --- a/src/components/ClaimableBalanceCard.tsx +++ b/src/components/ClaimableBalanceCard.tsx @@ -1,10 +1,9 @@ import { useEffect, useState } from "react"; - import { Badge } from "@/components/ui/Badge"; import { Button } from "@/components/ui/Button"; import { useSorokit } from "@/context/useSorokit"; import type { ClaimableBalance } from "@/lib/client"; -import { getClient } from "@/lib/client"; +import { getClient, hasClient } from "@/lib/client"; import { truncateAddress } from "@/lib/utils"; function BalanceRow({ cb }: { cb: ClaimableBalance }) { @@ -19,6 +18,7 @@ function BalanceRow({ cb }: { cb: ClaimableBalance }) { setClaiming(true); setClaimError(null); try { + if (!hasClient()) { setClaimError("[sorokit-ui] Client not initialized."); return; } const { error } = await getClient().account.claimBalance(cb.id); if (!error) { setClaimed(true); @@ -87,6 +87,7 @@ export function ClaimableBalanceCard() { let active = true; const timerId = window.setTimeout(() => { setLoading(true); + if (!hasClient()) { setError("[sorokit-ui] Client not initialized."); return; } getClient() .account.getClaimableBalances(address) .then(({ data, error: err }) => { diff --git a/src/components/SorobanInvokeButton.tsx b/src/components/SorobanInvokeButton.tsx index a021689..252bc1b 100644 --- a/src/components/SorobanInvokeButton.tsx +++ b/src/components/SorobanInvokeButton.tsx @@ -1,10 +1,9 @@ import { useRef, useState } from "react"; - import { Badge } from "@/components/ui/Badge"; import { Button } from "@/components/ui/Button"; import { useSorokit } from "@/context/useSorokit"; import type { InvokeParams } from "@/lib/client"; -import { getClient } from "@/lib/client"; +import { getClient, hasClient } from "@/lib/client"; import { cn, friendlyError } from "@/lib/utils"; type InvokeState = "idle" | "loading" | "success" | "error"; @@ -50,6 +49,7 @@ export function SorobanInvokeButton({ setError(null); try { + if (!hasClient()) { setError("[sorokit-ui] Client not initialized."); return; } const { data, error: err } = await getClient().soroban.invokeContract(params); if (err) { diff --git a/src/components/TransactionHistory.tsx b/src/components/TransactionHistory.tsx index b59589f..b1e623f 100644 --- a/src/components/TransactionHistory.tsx +++ b/src/components/TransactionHistory.tsx @@ -11,7 +11,7 @@ import { Badge } from "@/components/ui/Badge"; import { Button } from "@/components/ui/Button"; import { useSorokit } from "@/context/useSorokit"; import type { Transaction } from "@/lib/client"; -import { getClient } from "@/lib/client"; +import { getClient, hasClient } from "@/lib/client"; import { truncateAddress } from "@/lib/utils"; const PAGE_SIZE = 10; @@ -94,6 +94,7 @@ export function TransactionHistory() { let active = true; const timerId = window.setTimeout(() => { setLoading(true); + if (!hasClient()) { setError("[sorokit-ui] Client not initialized."); return; } getClient() .transaction.getHistory(address, page, PAGE_SIZE) .then(({ data, error: err, total: t }) => { diff --git a/src/components/ui/Input.tsx b/src/components/ui/Input.tsx index 160f5e2..01b7e48 100644 --- a/src/components/ui/Input.tsx +++ b/src/components/ui/Input.tsx @@ -11,7 +11,7 @@ interface InputProps extends React.InputHTMLAttributes { export const Input = forwardRef( ({ label, error, hint, className, id, ...props }, ref) => { const generatedId = useId(); - const inputId = id ?? label?.toLowerCase().replace(/\s+/g, "-") ?? generatedId; + const inputId = id ?? `${generatedId}-${label?.toLowerCase().replace(/\s+/g, "-")}`; const [lastError, setLastError] = useState(error); const [lastHint, setLastHint] = useState(hint); diff --git a/src/lib/client.ts b/src/lib/client.ts index af4fe48..74fe2a4 100644 --- a/src/lib/client.ts +++ b/src/lib/client.ts @@ -148,10 +148,8 @@ export type NetworkInfo = { horizonUrl: string; }; -let _client: SorokitClient | null = null; - -export function initClient(client: SorokitClient): void { - _client = client; +export function hasClient(): boolean { + return _client !== null; } export function hasClient(): boolean {