Compare commits

..
Author SHA1 Message Date
Aleka Cheung b0946688b1 add more controlled pagination to table 2024-02-05 18:48:09 -05:00
5 changed files with 26 additions and 25 deletions
+18 -7
View File
@@ -95,7 +95,10 @@ export type ElementProps<TableRowData extends object | CustomRowConfig, TableRow
selectionBehavior?: 'replace' | 'toggle';
onRowAction?: (key: TableRowKey, row: TableRowData) => void;
slotEmpty?: React.ReactNode;
initialNumRowsToShow?: number;
viewMoreConfig?: {
initialNumRowsToShow: number;
numRowsPerPage?: number;
};
// collection: TableCollection<string>;
// children: React.ReactNode;
};
@@ -125,7 +128,7 @@ export const Table = <TableRowData extends object, TableRowKey extends Key>({
selectionMode = 'single',
selectionBehavior = 'toggle',
slotEmpty,
initialNumRowsToShow,
viewMoreConfig,
// shouldRowRender,
// collection,
@@ -141,8 +144,18 @@ export const Table = <TableRowData extends object, TableRowKey extends Key>({
style,
}: ElementProps<TableRowData, TableRowKey> & StyleProps) => {
const [selectedKeys, setSelectedKeys] = useState(new Set<TableRowKey>());
const [numRowsToShow, setNumRowsToShow] = useState(initialNumRowsToShow);
const enableViewMore = numRowsToShow !== undefined;
const [numRowsToShow, setNumRowsToShow] = useState(viewMoreConfig?.initialNumRowsToShow);
const enableViewMore = viewMoreConfig !== undefined;
const onViewMoreClick = () => {
if (!viewMoreConfig) return;
const { numRowsPerPage } = viewMoreConfig;
if (numRowsPerPage) {
setNumRowsToShow((prev) => (prev ?? 0) + numRowsPerPage);
} else {
setNumRowsToShow(data.length);
}
};
const currentBreakpoints = useBreakpoints();
const shownColumns = columns.filter(
@@ -218,9 +231,7 @@ export const Table = <TableRowData extends object, TableRowKey extends Key>({
}
numColumns={shownColumns.length}
onViewMoreClick={
enableViewMore && numRowsToShow < data.length
? () => setNumRowsToShow(data.length)
: undefined
enableViewMore && numRowsToShow! < data.length ? onViewMoreClick : undefined
}
// shouldRowRender={shouldRowRender}
hideHeader={hideHeader}
-2
View File
@@ -173,5 +173,3 @@ export type AnalyticsEventData<T extends AnalyticsEvent> =
validatorUrl: string;
}
: never;
export const DEFAULT_TRANSACTION_MEMO = 'dYdX Frontend (web)';
+1 -3
View File
@@ -16,7 +16,6 @@ import {
import type { ResolutionString } from 'public/tradingview/charting_library';
import type { ConnectNetworkEvent, NetworkConfig } from '@/constants/abacus';
import { DEFAULT_TRANSACTION_MEMO } from '@/constants/analytics';
import { type Candle, RESOLUTION_MAP } from '@/constants/candles';
import { ENVIRONMENT_CONFIG_MAP } from '@/constants/networks';
import { DydxChainAsset } from '@/constants/wallets';
@@ -84,8 +83,7 @@ const useDydxClientContext = () => {
{
broadcastPollIntervalMs: 3_000,
broadcastTimeoutMs: 60_000,
},
DEFAULT_TRANSACTION_MEMO
}
)
)
);
+6 -12
View File
@@ -31,7 +31,6 @@ import {
type HumanReadableTransferPayload,
} from '@/constants/abacus';
import { DEFAULT_TRANSACTION_MEMO } from '@/constants/analytics';
import { DialogTypes } from '@/constants/dialogs';
import { UNCOMMITTED_ORDER_TIMEOUT_MS } from '@/constants/trade';
import { ENVIRONMENT_CONFIG_MAP, DydxNetwork, isTestnet } from '@/constants/networks';
@@ -116,8 +115,7 @@ class DydxChainTransactions implements AbacusDYDXChainTransactionsProtocol {
{
broadcastPollIntervalMs: 3_000,
broadcastTimeoutMs: 60_000,
},
DEFAULT_TRANSACTION_MEMO
}
)
)
);
@@ -372,8 +370,8 @@ class DydxChainTransactions implements AbacusDYDXChainTransactionsProtocol {
value: {
...params.msg,
timeoutTimestamp: params.msg.timeoutTimestamp
? // Squid returns timeoutTimestamp as Long, but the signer expects BigInt
BigInt(Long.fromValue(params.msg.timeoutTimestamp).toString())
// Squid returns timeoutTimestamp as Long, but the signer expects BigInt
? BigInt(Long.fromValue(params.msg.timeoutTimestamp).toString())
: undefined,
},
};
@@ -389,11 +387,7 @@ class DydxChainTransactions implements AbacusDYDXChainTransactionsProtocol {
}
ibcMsg.value.token.amount = amount.toString();
const tx = await this.nobleClient.send(
[ibcMsg],
undefined,
`${DEFAULT_TRANSACTION_MEMO} | ${this.nobleWallet?.address}`
);
const tx = await this.nobleClient.send([ibcMsg]);
const parsedTx = this.parseToPrimitives(tx);
@@ -432,8 +426,8 @@ class DydxChainTransactions implements AbacusDYDXChainTransactionsProtocol {
value: {
...parsedIbcPayload.msg,
timeoutTimestamp: parsedIbcPayload.msg.timeoutTimestamp
? // Squid returns timeoutTimestamp as Long, but the signer expects BigInt
BigInt(Long.fromValue(parsedIbcPayload.msg.timeoutTimestamp).toString())
// Squid returns timeoutTimestamp as Long, but the signer expects BigInt
? BigInt(Long.fromValue(parsedIbcPayload.msg.timeoutTimestamp).toString())
: undefined,
},
};
@@ -121,7 +121,7 @@ export const TradingRewardHistoryTable = ({
selectionBehavior="replace"
withOuterBorder={withOuterBorder}
withInnerBorders={withInnerBorders}
initialNumRowsToShow={5}
viewMoreConfig={{ initialNumRowsToShow: 5, numRowsPerPage: 10 }}
withScrollSnapColumns
withScrollSnapRows
/>