diff --git a/apps/cross-chain-accounts/components/AccountBlobs.tsx b/apps/cross-chain-accounts/components/AccountBlobs.tsx
index 6baa24d..6a6c041 100644
--- a/apps/cross-chain-accounts/components/AccountBlobs.tsx
+++ b/apps/cross-chain-accounts/components/AccountBlobs.tsx
@@ -11,23 +11,42 @@ interface AccountBlobsProps {
export const AccountBlobs = ({ refreshTrigger }: AccountBlobsProps) => {
const { account } = useWallet();
const [blobs, setBlobs] = useState([]);
+ const [isLoading, setIsLoading] = useState(false);
+ const [error, setError] = useState(null);
useEffect(() => {
if (!account) {
setBlobs([]);
+ setError(null);
return;
}
- const getBlobs = async (): Promise => {
- const blobs = await getShelbyClient().coordination.getAccountBlobs({
- account: account.address,
- });
- return blobs;
+
+ let cancelled = false;
+ const getBlobs = async (): Promise => {
+ setIsLoading(true);
+ setError(null);
+ try {
+ const fetched = await getShelbyClient().coordination.getAccountBlobs({
+ account: account.address,
+ });
+ if (!cancelled) setBlobs(fetched);
+ } catch (err) {
+ if (!cancelled) {
+ const message =
+ err instanceof Error ? err.message : "Failed to fetch blobs";
+ setError(message);
+ setBlobs([]);
+ }
+ } finally {
+ if (!cancelled) setIsLoading(false);
+ }
};
- getBlobs().then((blobs) => {
- setBlobs(blobs);
- refreshTrigger;
- });
+ getBlobs();
+
+ return () => {
+ cancelled = true;
+ };
}, [account, refreshTrigger]);
const extractFileName = (blobName: string): string => {
@@ -49,7 +68,17 @@ export const AccountBlobs = ({ refreshTrigger }: AccountBlobsProps) => {
)}
- {account && blobs.length === 0 && (
+ {account && isLoading && (
+
+ )}
+ {account && error && !isLoading && (
+
+ )}
+ {account && !isLoading && !error && blobs.length === 0 && (
No blobs found for this account. Upload a file to get started!