diff --git a/src/components/Molecules/Address/NFTApproval/NFTApprovals.tsx b/src/components/Molecules/Address/NFTApproval/NFTApprovals.tsx deleted file mode 100644 index 69a8add2..00000000 --- a/src/components/Molecules/Address/NFTApproval/NFTApprovals.tsx +++ /dev/null @@ -1,51 +0,0 @@ -import { type Option, None, Some } from "@/utils/option"; -import type { NftApprovalsItem } from "@covalenthq/client-sdk"; -import { type TokensApprovalItem } from "@covalenthq/client-sdk"; -import { useEffect, useState } from "react"; -import { type NFTApprovalsProps } from "@/utils/types/molecules.types"; -import { useGoldRush } from "@/utils/store"; -import { type CovalentAPIError } from "@/utils/types/shared.types"; -import { defaultErrorMessage } from "@/utils/constants/shared.constants"; -import { NFTApprovalsTable } from "@/components/Shared/NFTTokenApprovals"; - -export const NFTApprovals: React.FC = ({ - chain_name, - address, - ...props -}) => { - const { covalentClient } = useGoldRush(); - - const [maybeResult, setMaybeResult] = - useState>(None); - const [errorMessage, setErrorMessage] = useState(null); - - useEffect(() => { - (async () => { - setMaybeResult(None); - setErrorMessage(null); - try { - const { data, ...error } = - await covalentClient.SecurityService.getNftApprovals( - chain_name, - address.trim() - ); - if (error.error) { - throw error; - } - setMaybeResult(new Some(data.items)); - } catch (error: CovalentAPIError | any) { - setErrorMessage(error?.error_message ?? defaultErrorMessage); - setMaybeResult(new Some(null)); - console.error(error); - } - })(); - }, [chain_name, address]); - - return ( - - ); -}; diff --git a/src/components/Molecules/Address/NFTApproval/NFTApprovals.stories.tsx b/src/components/Molecules/Address/NFTApprovalList/NFTApprovalList.stories.tsx similarity index 97% rename from src/components/Molecules/Address/NFTApproval/NFTApprovals.stories.tsx rename to src/components/Molecules/Address/NFTApprovalList/NFTApprovalList.stories.tsx index 9236137c..8a4a4091 100644 --- a/src/components/Molecules/Address/NFTApproval/NFTApprovals.stories.tsx +++ b/src/components/Molecules/Address/NFTApprovalList/NFTApprovalList.stories.tsx @@ -1,5 +1,5 @@ import { type Meta, type StoryObj } from "@storybook/react"; -import { NFTApprovals as NFTApprovalsComponent } from "./NFTApprovals"; +import { NFTApprovals as NFTApprovalsComponent } from "./NFTApprovalList"; type Story = StoryObj; diff --git a/src/components/Shared/NFTTokenApprovals.tsx b/src/components/Molecules/Address/NFTApprovalList/NFTApprovalList.tsx similarity index 72% rename from src/components/Shared/NFTTokenApprovals.tsx rename to src/components/Molecules/Address/NFTApprovalList/NFTApprovalList.tsx index d11f7141..50c45fbf 100644 --- a/src/components/Shared/NFTTokenApprovals.tsx +++ b/src/components/Molecules/Address/NFTApprovalList/NFTApprovalList.tsx @@ -1,13 +1,47 @@ -import { type NftApprovalsItem } from "@covalenthq/client-sdk"; -import { type ColumnDef } from "@tanstack/react-table"; -import { TableHeaderSorting, TableList } from "."; -import { type NFTApprovalsTableProps } from "@/utils/types/shared.types"; +import { type Option, None, Some } from "@/utils/option"; +import type { NftApprovalsItem } from "@covalenthq/client-sdk"; +import { useEffect, useState } from "react"; +import { type NFTApprovalListProps } from "@/utils/types/molecules.types"; +import { useGoldRush } from "@/utils/store"; +import { type CovalentAPIError } from "@/utils/types/shared.types"; +import { defaultErrorMessage } from "@/utils/constants/shared.constants"; +import { TableHeaderSorting, TableList } from "@/components/Shared"; +import { ColumnDef } from "@tanstack/react-table"; import { Address } from "@/components/Atoms"; -export const NFTApprovalsTable: React.FC = ({ - errorMessage, - maybeResult, +export const NFTApprovalList: React.FC = ({ + chain_name, + address, + ...props }) => { + const { covalentClient } = useGoldRush(); + + const [maybeResult, setMaybeResult] = + useState>(None); + const [errorMessage, setErrorMessage] = useState(null); + + useEffect(() => { + (async () => { + setMaybeResult(None); + setErrorMessage(null); + try { + const { data, ...error } = + await covalentClient.SecurityService.getNftApprovals( + chain_name, + address.trim() + ); + if (error.error) { + throw error; + } + setMaybeResult(new Some(data.items)); + } catch (error: CovalentAPIError | any) { + setErrorMessage(error?.error_message ?? defaultErrorMessage); + setMaybeResult(new Some(null)); + console.error(error); + } + })(); + }, [chain_name, address]); + const columns: ColumnDef[] = [ { id: "token_details", diff --git a/src/components/Molecules/Address/TokenApproval/TokenApprovals.tsx b/src/components/Molecules/Address/TokenApproval/TokenApprovals.tsx deleted file mode 100644 index 71009dc7..00000000 --- a/src/components/Molecules/Address/TokenApproval/TokenApprovals.tsx +++ /dev/null @@ -1,50 +0,0 @@ -import { type Option, None, Some } from "@/utils/option"; -import { type TokensApprovalItem } from "@covalenthq/client-sdk"; -import { useEffect, useState } from "react"; -import { type TokenApprovalsProps } from "@/utils/types/molecules.types"; -import { useGoldRush } from "@/utils/store"; -import { type CovalentAPIError } from "@/utils/types/shared.types"; -import { defaultErrorMessage } from "@/utils/constants/shared.constants"; -import { TokenApprovalsTable } from "@/components/Shared/TokenApprovalsTable"; - -export const TokenApprovals: React.FC = ({ - chain_name, - address, - ...props -}) => { - const { covalentClient } = useGoldRush(); - - const [maybeResult, setMaybeResult] = - useState>(None); - const [errorMessage, setErrorMessage] = useState(null); - - useEffect(() => { - (async () => { - setMaybeResult(None); - setErrorMessage(null); - try { - const { data, ...error } = - await covalentClient.SecurityService.getApprovals( - chain_name, - address.trim() - ); - if (error.error) { - throw error; - } - setMaybeResult(new Some(data.items)); - } catch (error: CovalentAPIError | any) { - setErrorMessage(error?.error_message ?? defaultErrorMessage); - setMaybeResult(new Some(null)); - console.error(error); - } - })(); - }, [chain_name, address]); - - return ( - - ); -}; diff --git a/src/components/Molecules/Address/TokenApproval/TokenApprovals.stories.tsx b/src/components/Molecules/Address/TokenApprovalList/TokenApprovalList.stories.tsx similarity index 96% rename from src/components/Molecules/Address/TokenApproval/TokenApprovals.stories.tsx rename to src/components/Molecules/Address/TokenApprovalList/TokenApprovalList.stories.tsx index d69be12a..cf231e3d 100644 --- a/src/components/Molecules/Address/TokenApproval/TokenApprovals.stories.tsx +++ b/src/components/Molecules/Address/TokenApprovalList/TokenApprovalList.stories.tsx @@ -1,5 +1,5 @@ import { type Meta, type StoryObj } from "@storybook/react"; -import { TokenApprovals as TokenApprovalsComponent } from "./TokenApprovals"; +import { TokenApprovals as TokenApprovalsComponent } from "./TokenApprovalList"; type Story = StoryObj; diff --git a/src/components/Shared/TokenApprovalsTable.tsx b/src/components/Molecules/Address/TokenApprovalList/TokenApprovalList.tsx similarity index 77% rename from src/components/Shared/TokenApprovalsTable.tsx rename to src/components/Molecules/Address/TokenApprovalList/TokenApprovalList.tsx index c06ce44d..e9cdbc5b 100644 --- a/src/components/Shared/TokenApprovalsTable.tsx +++ b/src/components/Molecules/Address/TokenApprovalList/TokenApprovalList.tsx @@ -1,13 +1,47 @@ +import { type Option, None, Some } from "@/utils/option"; import { type TokensApprovalItem } from "@covalenthq/client-sdk"; -import { type ColumnDef } from "@tanstack/react-table"; -import { TableHeaderSorting, TableList } from "."; -import { type TokenApprovalsTableProps } from "@/utils/types/shared.types"; +import { useEffect, useState } from "react"; +import { type TokenApprovalListProps } from "@/utils/types/molecules.types"; +import { useGoldRush } from "@/utils/store"; +import { type CovalentAPIError } from "@/utils/types/shared.types"; +import { defaultErrorMessage } from "@/utils/constants/shared.constants"; +import { TableHeaderSorting, TableList } from "@/components/Shared"; +import { ColumnDef } from "@tanstack/react-table"; import { Address } from "@/components/Atoms"; -export const TokenApprovalsTable: React.FC = ({ - errorMessage, - maybeResult, +export const TokenApprovalList: React.FC = ({ + chain_name, + address, + ...props }) => { + const { covalentClient } = useGoldRush(); + + const [maybeResult, setMaybeResult] = + useState>(None); + const [errorMessage, setErrorMessage] = useState(null); + + useEffect(() => { + (async () => { + setMaybeResult(None); + setErrorMessage(null); + try { + const { data, ...error } = + await covalentClient.SecurityService.getApprovals( + chain_name, + address.trim() + ); + if (error.error) { + throw error; + } + setMaybeResult(new Some(data.items)); + } catch (error: CovalentAPIError | any) { + setErrorMessage(error?.error_message ?? defaultErrorMessage); + setMaybeResult(new Some(null)); + console.error(error); + } + })(); + }, [chain_name, address]); + const columns: ColumnDef[] = [ { id: "token_details", diff --git a/src/components/Molecules/index.ts b/src/components/Molecules/index.ts index ce223eec..44ee0f43 100644 --- a/src/components/Molecules/index.ts +++ b/src/components/Molecules/index.ts @@ -8,7 +8,8 @@ export { LatestBlocks } from "./Block/LatestBlocks/LatestBlocks"; export { ChainSelector } from "./ChainSelector/ChainSelector"; export { GasCard } from "./GasCard/GasCard"; export { LatestPrice } from "./LatestPrice/LatestPrice"; -export { TokenApprovals } from "./Address/TokenApproval/TokenApprovals"; +export { TokenApprovalList } from "./Address/TokenApprovalList/TokenApprovalList"; +export { NFTApprovalList } from "./Address/NFTApprovalList/NFTApprovalList"; export { NFTCollectionDetails } from "./NFT/NFTCollectionDetails/NFTCollectionDetails"; export { NFTCollectionTokensList } from "./NFT/NFTCollectionTokensList/NFTCollectionTokensList"; export { NFTFloorPrice } from "./NFT/NFTFloorPrice/NFTFloorPrice"; diff --git a/src/utils/types/molecules.types.ts b/src/utils/types/molecules.types.ts index e6cb07d3..b789abc0 100644 --- a/src/utils/types/molecules.types.ts +++ b/src/utils/types/molecules.types.ts @@ -30,12 +30,12 @@ export interface AddressActivityListProps { errorMessage?: string | null; } -export interface NFTApprovalsProps { +export interface NFTApprovalListProps { chain_name: Chain; address: string; } -export interface TokenApprovalsProps { +export interface TokenApprovalListProps { chain_name: Chain; address: string; }