Skip to content

Commit

Permalink
fix: query tx's by timestamp and add additional JS sorting logic
Browse files Browse the repository at this point in the history
  • Loading branch information
chalabi2 committed Dec 24, 2024
1 parent b239f68 commit e2890d3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 22 deletions.
26 changes: 14 additions & 12 deletions components/groups/components/groupControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export default function GroupProposals({
<ArrowRightIcon className="text-primary" />
</button>
<h1 className="text-2xl font-bold text-primary-content truncate">{groupName}</h1>
<div className="hidden sm:block">
<div className="">
<ProfileAvatar walletAddress={policyAddress} size={40} />
</div>
</div>
Expand Down Expand Up @@ -322,7 +322,7 @@ export default function GroupProposals({
</div>
) : filteredProposals.length > 0 ? (
<table
className="table w-full border-separate border-spacing-y-3"
className="table w-full border-separate border-spacing-y-3 -mt-6"
aria-label="Group proposals"
>
<thead>
Expand Down Expand Up @@ -471,16 +471,18 @@ export default function GroupProposals({
)}

{activeTab === 'tokens' && (
<DenomList
denoms={denoms}
isLoading={isLoading}
refetchDenoms={refetchDenoms}
refetchProposals={refetchProposals}
address={address ?? ''}
admin={policyAddress}
pageSize={pageSize}
isGroup={true}
/>
<div className="h-full w-full -mt-7">
<DenomList
denoms={denoms}
isLoading={isLoading}
refetchDenoms={refetchDenoms}
refetchProposals={refetchProposals}
address={address ?? ''}
admin={policyAddress}
pageSize={pageSize}
isGroup={true}
/>
</div>
)}
</div>
{selectedProposal && (
Expand Down
4 changes: 2 additions & 2 deletions components/groups/components/myGroups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export function YourGroups({
const [currentPageGroupInfo, setCurrentPageGroupInfo] = useState(1);

const pageSizeGroupInfo = isMobile ? 4 : 7;
const pageSizeHistory = isMobile ? 4 : 7;
const pageSizeHistory = isMobile ? 4 : 6;
const skeletonGroupCount = 1;
const skeletonTxCount = isMobile ? 4 : 7;

Expand Down Expand Up @@ -224,7 +224,7 @@ export function YourGroups({

const [activeInfoModalId, setActiveInfoModalId] = useState<string | null>(null);
const [activeMemberModalId, setActiveMemberModalId] = useState<string | null>(null);

console.log(sendTxs);
return (
<div className="relative w-full h-screen overflow-x-hidden scrollbar-hide ">
<div
Expand Down
10 changes: 5 additions & 5 deletions components/react/addressCopy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ export const TruncatedAddressWithCopy = ({
const iconSize = size === 'small' ? 10 : 16;

return (
<div
<span
className="flex items-center hover:text-primary dark:hover:text-primary space-x-2 text-[#00000099] dark:text-[#FFFFFF99]"
onClick={handleCopy}
style={{ cursor: 'pointer' }}
>
<span className="truncate ">{truncatedAddress}</span>
{copied ? <FiCheck size={iconSize} /> : <FiCopy size={iconSize} />}
</div>
</span>
);
};

Expand All @@ -67,13 +67,13 @@ export const AddressWithCopy = ({ address }: { address: string }) => {
};

return (
<div
className="flex items-center space-x-2"
<span
className="flex items-center space-x-2"
onClick={handleCopy}
style={{ cursor: 'pointer' }}
>
<span className="hover:text-primary">{address}</span>
{copied ? <FiCheck size="16" /> : <FiCopy size="16" />}
</div>
</span>
);
};
16 changes: 13 additions & 3 deletions hooks/useQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -871,11 +871,12 @@ export const useGetFilteredTxAndSuccessfulProposals = (
const fetchTransactions = async () => {
const baseUrl = `${indexerUrl}/rpc/get_address_filtered_transactions_and_successful_proposals?address=${address}`;

// Add pagination parameters
// Update order parameter to sort by timestamp instead of height
const offset = (page - 1) * pageSize;
const paginationParams = `&limit=${pageSize}&offset=${offset}`;
const orderParam = `&order=data->txResponse->timestamp.desc`; // Changed from height to timestamp

const finalUrl = `${baseUrl}&order=data->txResponse->height.desc${paginationParams}`;
const finalUrl = `${baseUrl}${orderParam}${paginationParams}`;

try {
// First, get the total count
Expand All @@ -901,7 +902,16 @@ export const useGetFilteredTxAndSuccessfulProposals = (

const transactions = dataResponse.data
.flatMap((tx: any) => transformTransactions(tx, address))
.filter((tx: any) => tx !== null);
.filter((tx: any) => tx !== null)
// Add secondary sort in JavaScript to ensure consistent ordering
.sort((a: any, b: any) => {
// Sort by timestamp descending (newest first)
const dateComparison =
new Date(b.formatted_date).getTime() - new Date(a.formatted_date).getTime();
if (dateComparison !== 0) return dateComparison;
// If timestamps are equal, sort by block number descending
return b.block_number - a.block_number;
});

return {
transactions,
Expand Down

0 comments on commit e2890d3

Please sign in to comment.