From 6b778a2b922b8564166115b976538539b6158754 Mon Sep 17 00:00:00 2001 From: "blackwhale.eth" Date: Wed, 18 Dec 2024 19:31:24 +0100 Subject: [PATCH] fix (multi): various small bug fixes --- .../app/dashboard/AppDashboardActivity.tsx | 116 +++++++++--------- .../app/invest/AppInvestHoldersCount.tsx | 4 +- src/hooks/useRestricted.ts | 3 + src/lib/dapp/chains.ts | 22 +++- 4 files changed, 83 insertions(+), 62 deletions(-) diff --git a/src/components/app/dashboard/AppDashboardActivity.tsx b/src/components/app/dashboard/AppDashboardActivity.tsx index b1609902..ced04b74 100644 --- a/src/components/app/dashboard/AppDashboardActivity.tsx +++ b/src/components/app/dashboard/AppDashboardActivity.tsx @@ -123,7 +123,9 @@ const CancelButton: FC<{ Cancel this request @@ -147,49 +149,43 @@ export const AppDashboardActivity: React.PropsWithoutRef = ({ ]); const columnHelper = createColumnHelper(); const [activityData, setActivityData] = useState([]); - const [isLoading, setIsLoading] = useState(false); + const [isLoading, setIsLoading] = useState(true); const computeActivityData = async () => { if (!isLoading) { setIsLoading(true); - if (account && account.address) { - await execute( - ` - { - c${account.chainId}_activities(where: { account: "${account.address}" }) { - id - requestId - ltoken { - symbol - decimals - } - timestamp - action - amount - amountAfterFees - status + try { + if (account && account.address) { + const result = await execute( + ` + { + c${account.chainId}_activities(where: { account: "${account.address}" }) { + id + requestId + ltoken { + symbol + decimals } + timestamp + action + amount + amountAfterFees + status } - `, - {}, - ) - .then( - // @ts-ignore - (result: { - data: { - [key: string]: Activity[]; - }; - }) => { - setActivityData(result.data[`c${account.chainId}_activities`]); - setIsLoading(false); - }, - ) - .catch((e: Error) => { - setActivityData([]); - setIsLoading(false); - }); + } + `, + {}, + ); + setActivityData(result.data[`c${account.chainId}_activities`] ?? []); + } else { + setActivityData([]); + } + } catch (e) { + console.error(e); + setActivityData([]); + } finally { + setIsLoading(false); } - setIsLoading(false); } }; @@ -294,7 +290,7 @@ export const AppDashboardActivity: React.PropsWithoutRef = ({ const sortableColumns = ["timestamp", "action", "amount", "ltoken", "status"]; const table = useReactTable({ - data: activityData, + data: activityData ?? [], // Ensure we always have at least an empty array columns: activityColumns, state: { sorting, @@ -360,38 +356,40 @@ export const AppDashboardActivity: React.PropsWithoutRef = ({ ); })} {(() => { - const tableRows = table.getRowModel().rows; - - if (isLoading) + if (isLoading) { return (
); - else if (tableRows.length === 0) + } + + const tableRows = table.getRowModel().rows; + + if (!tableRows?.length) { return (

No activity yet.

); - else { - return tableRows.map((row, rowIndex) => - row.getVisibleCells().map((cell, cellIndex) => ( -
- {flexRender(cell.column.columnDef.cell, cell.getContext())} -
- )), - ); } + + return tableRows.map((row, rowIndex) => + row.getVisibleCells().map((cell, cellIndex) => ( +
+ {flexRender(cell.column.columnDef.cell, cell.getContext())} +
+ )), + ); })()}
diff --git a/src/components/app/invest/AppInvestHoldersCount.tsx b/src/components/app/invest/AppInvestHoldersCount.tsx index 16f511dc..40253d3e 100644 --- a/src/components/app/invest/AppInvestHoldersCount.tsx +++ b/src/components/app/invest/AppInvestHoldersCount.tsx @@ -80,7 +80,9 @@ export const AppInvestHoldersCount: FC = (props) => { }; useEffect(() => { - computeHoldersCount(); + computeHoldersCount().catch((e) => { + setIsLoading(false); + }); }, []); return
{(isLoading && ) || holdersCount}
; diff --git a/src/hooks/useRestricted.ts b/src/hooks/useRestricted.ts index 1239897a..9181d260 100644 --- a/src/hooks/useRestricted.ts +++ b/src/hooks/useRestricted.ts @@ -2,6 +2,9 @@ import { useState, useEffect } from "react"; import { useAccount } from "wagmi"; const useRestricted = () => { + // @bw @dev disable aml for now + return { isRestricted: false, isLoading: false }; + const [isRestricted, setIsRestricted] = useState(false); const [isLoading, setIsLoading] = useState(true); const account = useAccount(); diff --git a/src/lib/dapp/chains.ts b/src/lib/dapp/chains.ts index 4f2e6eba..0db8d515 100644 --- a/src/lib/dapp/chains.ts +++ b/src/lib/dapp/chains.ts @@ -6,7 +6,6 @@ import { lineaTestnet, linea, Chain, - base, baseSepolia, sepolia, } from "@wagmi/core/chains"; @@ -64,6 +63,25 @@ const xlayerMainnet: Chain = { testnet: false, }; +const base: Chain = { + id: 8453, + name: "Base", + nativeCurrency: { + name: "Ether", + symbol: "ETH", + decimals: 18, + }, + rpcUrls: { + default: { + http: ["https://base-rpc.publicnode.com"], + }, + }, + blockExplorers: { + default: { name: "BaseScan", url: "https://basescan.org/" }, + }, + testnet: false, +}; + /// Figure whether we're in dev or prod environment const chainsEnv = process.env.NEXT_PUBLIC_VERCEL_ENV === "prod" ? "prod" : "dev"; @@ -82,7 +100,7 @@ const devChains: readonly [Chain, ...Chain[]] = [ hardhat, xlayerTestnet, lineaTestnet, - baseSepolia, + // baseSepolia, ]; export const chains: readonly [Chain, ...Chain[]] = chainsEnv === "prod" ? prodChains : devChains;