Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: account history component style and code revamp #128

Merged
merged 10 commits into from
Oct 4, 2023
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ next-env.d.ts
/test-results/
/playwright-report/
/playwright/.cache/

localhost:3000/
10 changes: 8 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,11 @@ yarn-error.log*
*.tsbuildinfo
next-env.d.ts

logs/*
playwright-report/*
/logs/
.swc/
/test-results/
/playwright-report/
/playwright/.cache/

localhost:3000/

106 changes: 44 additions & 62 deletions src/app/components/AccountHistory.tsx
Original file line number Diff line number Diff line change
@@ -1,86 +1,68 @@
import React, { useEffect, useCallback } from "react";
import { useAppDispatch, useAppSelector } from "../hooks";
import React, { useEffect } from "react";
import { useAppDispatch, useAppSelector } from "hooks";
import {
fetchAccountHistory,
Tables,
fetchAccountHistory,
selectOpenOrders,
setSelectedTable,
selectTables,
} from "../redux/accountHistorySlice";
} from "redux/accountHistorySlice";
import { DisplayTable } from "./DisplayTable";

interface ButtonProps {
label: string;
value: Tables;
selectedValue: Tables;
onClick: (value: Tables) => void;
}
function OrdersTabs() {
const dispatch = useAppDispatch();
const { selectedTable, tables } = useAppSelector(
(state) => state.accountHistory
);
const openOrders = useAppSelector(selectOpenOrders);

function tabClass(isActive: boolean) {
return (
"tab w-max no-underline h-full py-3 tab-border-1 uppercase" +
(isActive
? " tab-active tab-bordered text-accent-focus !border-accent"
: "")
);
}

const Button: React.FC<ButtonProps> = ({
label,
value,
selectedValue,
onClick,
}) => (
<button
onClick={() => onClick(value)}
aria-label={label}
className={"btn" + (selectedValue === value ? " btn-active" : "")}
>
{label}
</button>
);
return (
<div className="m-4">
<div className="tabs min-w-fit flex flex-nowrap space-x-4">
{tables.map((tableName) => (
<div
key={tableName}
className={tabClass(selectedTable === tableName)}
onClick={() => dispatch(setSelectedTable(tableName))}
>
{tableName}{" "}
{tableName === Tables.OPEN_ORDERS && openOrders.length ? (
<span className="badge badge-xs font-bold badge-accent ml-2 p-0.5 rounded-none">
{openOrders.length}
</span>
) : null}
</div>
))}
</div>
</div>
);
}

export function AccountHistory() {
const dispatch = useAppDispatch();
const account = useAppSelector(
(state) => state.radix?.walletData.accounts[0]?.address
);
const pairAddress = useAppSelector((state) => state.pairSelector.address);
const selectedTable = useAppSelector(
(state) => state.accountHistory.selectedTable
);
const tables = useAppSelector(selectTables);

useEffect(() => {
dispatch(fetchAccountHistory());
}, [dispatch, account, pairAddress]);

const handleButtonClick = useCallback(
(table: Tables) => {
dispatch(setSelectedTable(table));
},
[dispatch]
);

return (
<div>
<div className="btn-group">
{tables.map((table) => (
<Button
key={table}
label={table}
value={table}
selectedValue={selectedTable}
onClick={handleButtonClick}
/>
))}
{/* //---COMMENTED OUT BUTTONS FOR SHOW ALL ORDERS AND EXPORT
//TO NOT CONFUSE THE TESTERS----------------------------- */}
{/* <button
<button
className="btn btn-ghost normal-case text-xl"
aria-label="Show all orders"
>
Show all orders
</button>

className="btn btn-ghost normal-case text-xl"
aria-label="Export as CSV"
>
Export as CSV
</button> */}
<OrdersTabs />
<div className="">
<DisplayTable />
</div>
<DisplayTable />
</div>
);
}
Loading