Skip to content

Commit

Permalink
Fix account abstraction factories table crash (#4629)
Browse files Browse the repository at this point in the history
## Problem solved

Short description of the bug fixed or feature added

<!-- start pr-codex -->

---

## PR-Codex overview
The focus of this PR is to refactor the `useFactories` function in `AccountFactories/index.tsx`.

### Detailed summary
- Refactored the `useFactories` function to improve readability and maintainability
- Updated how factories are filtered and returned
- Updated the `contracts` prop passed to `FactoryContracts` component

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}`

<!-- end pr-codex -->
  • Loading branch information
MananTank committed Sep 16, 2024
1 parent c373ea5 commit 85ddb17
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { TrackedLinkTW } from "@/components/ui/tracked-link";
import { useLoggedInUser } from "@3rdweb-sdk/react/hooks/useLoggedInUser";
import { useMultiChainRegContractList } from "@3rdweb-sdk/react/hooks/useRegistry";
import { useQuery } from "@tanstack/react-query";
import type { BasicContract } from "contract-ui/types/types";
import { PlusIcon } from "lucide-react";
import { defineChain, getContract } from "thirdweb";
import { getCompilerMetadata } from "thirdweb/contract";
Expand All @@ -23,7 +22,7 @@ const useFactories = () => {
"factories",
],
queryFn: async () => {
return await Promise.all(
const factories = await Promise.all(
(contractListQuery.data || []).map(async (c) => {
const contract = getContract({
// eslint-disable-next-line no-restricted-syntax
Expand All @@ -35,6 +34,8 @@ const useFactories = () => {
return m.name.indexOf("AccountFactory") > -1 ? c : null;
}),
);

return factories.filter((f) => f !== null);
},
enabled: !!user?.address && isLoggedIn && !!contractListQuery.data?.length,
});
Expand Down Expand Up @@ -70,7 +71,7 @@ export const AccountFactories: React.FC<AccountFactoriesProps> = ({
</div>

<FactoryContracts
contracts={(factories.data || []) as BasicContract[]}
contracts={factories.data || []}
isLoading={factories.isLoading}
isFetched={factories.isFetched}
/>
Expand Down

0 comments on commit 85ddb17

Please sign in to comment.