Skip to content

Commit

Permalink
fix (multi): various small bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vblackwhale committed Dec 18, 2024
1 parent e4854c6 commit 6b778a2
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 62 deletions.
116 changes: 57 additions & 59 deletions src/components/app/dashboard/AppDashboardActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ const CancelButton: FC<{
<TxButton
variant="destructive"
size="small"
preparation={preparation as UseSimulateContractReturnType}
preparation={
preparation as unknown as UseSimulateContractReturnType
}
>
Cancel this request
</TxButton>
Expand All @@ -147,49 +149,43 @@ export const AppDashboardActivity: React.PropsWithoutRef<typeof Card> = ({
]);
const columnHelper = createColumnHelper<Activity>();
const [activityData, setActivityData] = useState<Activity[]>([]);
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);
}
};

Expand Down Expand Up @@ -294,7 +290,7 @@ export const AppDashboardActivity: React.PropsWithoutRef<typeof Card> = ({
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,
Expand Down Expand Up @@ -360,38 +356,40 @@ export const AppDashboardActivity: React.PropsWithoutRef<typeof Card> = ({
);
})}
{(() => {
const tableRows = table.getRowModel().rows;

if (isLoading)
if (isLoading) {
return (
<div className="my-10 flex col-span-5 w-full items-center justify-center">
<Spinner />
</div>
);
else if (tableRows.length === 0)
}

const tableRows = table.getRowModel().rows;

if (!tableRows?.length) {
return (
<p className="my-10 col-span-5 w-full block text-center text-lg font-semibold text-fg/60">
No activity yet.
</p>
);
else {
return tableRows.map((row, rowIndex) =>
row.getVisibleCells().map((cell, cellIndex) => (
<div
key={cell.id}
style={{
gridColumnStart: cellIndex + 1,
}}
className={clsx(
"inline-flex items-center justify-center py-3 border-b border-b-fg/20 font-medium text-fg/90 text-[0.9rem]",
rowIndex == tableRows.length - 1 && "border-b-0",
)}
>
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</div>
)),
);
}

return tableRows.map((row, rowIndex) =>
row.getVisibleCells().map((cell, cellIndex) => (
<div
key={cell.id}
style={{
gridColumnStart: cellIndex + 1,
}}
className={clsx(
"inline-flex items-center justify-center py-3 border-b border-b-fg/20 font-medium text-fg/90 text-[0.9rem]",
rowIndex == tableRows.length - 1 && "border-b-0",
)}
>
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</div>
)),
);
})()}
</div>
<div className="flex justify-center items-center gap-3 py-4">
Expand Down
4 changes: 3 additions & 1 deletion src/components/app/invest/AppInvestHoldersCount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ export const AppInvestHoldersCount: FC<Props> = (props) => {
};

useEffect(() => {
computeHoldersCount();
computeHoldersCount().catch((e) => {
setIsLoading(false);
});
}, []);

return <div {...props}>{(isLoading && <Spinner />) || holdersCount}</div>;
Expand Down
3 changes: 3 additions & 0 deletions src/hooks/useRestricted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
22 changes: 20 additions & 2 deletions src/lib/dapp/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
lineaTestnet,
linea,
Chain,
base,
baseSepolia,
sepolia,
} from "@wagmi/core/chains";
Expand Down Expand Up @@ -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";
Expand All @@ -82,7 +100,7 @@ const devChains: readonly [Chain, ...Chain[]] = [
hardhat,
xlayerTestnet,
lineaTestnet,
baseSepolia,
// baseSepolia,
];
export const chains: readonly [Chain, ...Chain[]] =
chainsEnv === "prod" ? prodChains : devChains;

0 comments on commit 6b778a2

Please sign in to comment.