Skip to content

Commit

Permalink
fix(website): CAN-590 (#1480)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosampler authored Oct 17, 2024
1 parent 2a0a23b commit 01fb765
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 20 deletions.
1 change: 1 addition & 0 deletions packages/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"react-feather": "^2.0.10",
"react-github-btn": "^1.4.0",
"react-icons": "^4.11.0",
"react-infinite-scroll-component": "^6.1.0",
"react-markdown": "^8.0.7",
"react-scroll": "^1.9.0",
"react-syntax-highlighter": "^15.5.0",
Expand Down
87 changes: 67 additions & 20 deletions packages/website/src/features/Deploy/SignTransactionsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { useStore } from '@/helpers/store';
import { useSafeTransactions } from '@/hooks/backend';
import { useExecutedTransactions } from '@/hooks/safe';
import { useInMemoryPagination } from '@/hooks/useInMemoryPagination';
import {
Box,
Checkbox,
Expand All @@ -13,8 +14,9 @@ import {
Skeleton,
Text,
} from '@chakra-ui/react';
import { useState } from 'react';
import React, { useState } from 'react';
import { Transaction } from './Transaction';
import InfiniteScroll from 'react-infinite-scroll-component';

export default function SignTransactionsPage() {
return <SignTransactions />;
Expand All @@ -29,7 +31,19 @@ function SignTransactions() {
const { data: history } = useExecutedTransactions(currentSafe);
const [isChecked, setIsChecked] = useState(true);

const handleCheckboxChange = (e: any) => {
const {
paginatedData: paginatedStagedTxs,
hasMore: hasMoreStagedTxs,
fetchMoreData: fetchMoreStagedTxs,
} = useInMemoryPagination(staged, 5);

const {
paginatedData: paginatedExecutedTxs,
hasMore: hasMoreExecutedTxs,
fetchMoreData: fetchMoreExecutedTxs,
} = useInMemoryPagination(history.results, 5);

const handleCheckboxChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setIsChecked(e.target.checked);
};

Expand All @@ -41,7 +55,7 @@ function SignTransactions() {
Sign & Execute Transactions
</Heading>
<Text color="gray.300">
Make sure youre using the same{' '}
Make sure you&apos;re using the same{' '}
<Link href="/settings">Safe Signature Collection Service</Link> as
other signers.
</Text>
Expand Down Expand Up @@ -70,15 +84,29 @@ function SignTransactions() {
There are no transactions queued on the selected safe.
</Text>
) : (
staged.map((tx) => (
<Transaction
key={JSON.stringify(tx.txn)}
safe={currentSafe}
tx={tx.txn}
hideExternal={false}
isStaged
/>
))
<Box
id="staged-transactions-container"
maxHeight="350px"
overflowY="auto"
>
<InfiniteScroll
dataLength={paginatedStagedTxs.length}
next={fetchMoreStagedTxs}
hasMore={hasMoreStagedTxs}
loader={<Skeleton height="60px" my={2} />}
scrollableTarget="staged-transactions-container"
>
{paginatedStagedTxs.map((tx) => (
<Transaction
key={JSON.stringify(tx.txn)}
safe={currentSafe}
tx={tx.txn}
hideExternal={false}
isStaged
/>
))}
</InfiniteScroll>
</Box>
))
)}
</Box>
Expand Down Expand Up @@ -110,14 +138,33 @@ function SignTransactions() {
Show Cannon transactions only
</Checkbox>
</Flex>
{history.results.map((tx: any) => (
<Transaction
key={tx.safeTxHash}
safe={currentSafe}
tx={tx}
hideExternal={isChecked}
/>
))}
<Box
id="executed-transactions-container"
maxHeight="300"
overflowY="scroll"
>
<InfiniteScroll
dataLength={paginatedExecutedTxs.length}
next={fetchMoreExecutedTxs}
hasMore={hasMoreExecutedTxs}
loader={<div>aaaa...</div>}
scrollableTarget="executed-transactions-container"
endMessage={
<Text color="gray.300" textAlign="center" mt={4}>
No more transactions to load.
</Text>
}
>
{paginatedExecutedTxs.map((tx) => (
<Transaction
key={tx.safeTxHash}
safe={currentSafe}
tx={tx}
hideExternal={isChecked}
/>
))}
</InfiniteScroll>
</Box>
</Box>
)}
</Container>
Expand Down
26 changes: 26 additions & 0 deletions packages/website/src/hooks/useInMemoryPagination.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useState, useMemo, useCallback } from 'react';

interface PaginationResult<T> {
paginatedData: T[];
hasMore: boolean;
fetchMoreData: () => void;
}

export function useInMemoryPagination<T>(data: T[], itemsPerPage: number): PaginationResult<T> {
const [displayedItems, setDisplayedItems] = useState(itemsPerPage);

const paginatedData = useMemo(() => {
// Return all data up to the current number of displayed items
return data.slice(0, displayedItems);
}, [data, displayedItems]);

const hasMore = useMemo(() => {
return displayedItems < data.length;
}, [data.length, displayedItems]);

const fetchMoreData = useCallback(() => {
setDisplayedItems((prevItems) => Math.min(prevItems + itemsPerPage, data.length));
}, [itemsPerPage, data.length]);

return { paginatedData, hasMore, fetchMoreData };
}
20 changes: 20 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 01fb765

Please sign in to comment.