Skip to content

Commit f2a96ee

Browse files
committed
fix: sorting by ascending order of creation date
1 parent cc55c59 commit f2a96ee

4 files changed

Lines changed: 34 additions & 6 deletions

File tree

src/components/MonitoringAccounts/MonitoringAccountList.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
1-
import React, { useState } from 'react';
1+
import React, { useMemo, useState } from 'react';
22
import { Legend } from '../Legend';
33
import { MonitoringAccountItem } from './MonitoringAccountItem';
44
import type { MonitoringAccount } from './types';
55
import { ReactComponent as IconExpand } from '../../assets/icon-expand.svg';
66
import cn from 'classnames';
77
import { useFetch } from '../../hooks/useFetch';
88
import { useAuthContext } from '../../containers/AuthContainer';
9+
import { sortByField } from '../../utils/helpers';
910

1011
export function MonitoringAccountList() {
1112
const { stateRefreshed } = useAuthContext();
12-
const { data: items, loading } = useFetch<MonitoringAccount[]>(
13+
const { data, loading } = useFetch<MonitoringAccount[]>(
1314
'wallet/monitor',
1415
stateRefreshed,
1516
);
1617
const [isListVisible, setIsListVisible] = useState<boolean>(true);
1718
const toggleListVisibility = () => {
1819
setIsListVisible(!isListVisible);
1920
};
21+
22+
const items = useMemo(
23+
() => (data || []).sort(sortByField<MonitoringAccount>('createdAt', 'asc')),
24+
[data],
25+
);
26+
2027
return (
2128
<>
2229
<Legend

src/components/ViewableAccounts/ViewableAccountsList.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import React, { useState } from 'react';
1+
import React, { useMemo, useState } from 'react';
22
import { ViewableAccountItem } from './ViewableAccountItem';
33
import { Legend } from '../Legend';
44
import cn from 'classnames';
55
import { ReactComponent as IconExpand } from '../../assets/icon-expand.svg';
66
import { useFetch } from '../../hooks/useFetch';
77
import { ViewableAccount } from './types';
88
import { useAuthContext } from '../../containers/AuthContainer';
9+
import { sortByField } from '../../utils/helpers';
910

1011
export function ViewableAccountsList() {
1112
const { stateRefreshed } = useAuthContext();
12-
const { data: items, loading } = useFetch<ViewableAccount[]>(
13+
const { data, loading } = useFetch<ViewableAccount[]>(
1314
'wallet/view',
1415
stateRefreshed,
1516
);
@@ -18,6 +19,12 @@ export function ViewableAccountsList() {
1819
const toggleListVisibility = () => {
1920
setIsListVisible(!isListVisible);
2021
};
22+
23+
const items = useMemo(
24+
() => (data || []).sort(sortByField<ViewableAccount>('createdAt', 'asc')),
25+
[data],
26+
);
27+
2128
return (
2229
<>
2330
<Legend

src/containers/NewProposalContainer/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,6 @@ export function NewProposalContainer() {
202202
/>
203203
</div>
204204

205-
{step}
206-
207205
{step === 1 && (
208206
<>
209207
<h2 className="text-lg font-semibold mb-4">Account Info</h2>

src/utils/helpers.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,19 @@ export const chainIdToNetworkName = (chainId: number) =>
4747

4848
export const ifGenesisThen = (value: string, fallback: string) =>
4949
value.toLowerCase() === ZERO_ADDRESS ? fallback : value;
50+
51+
type Sort = 'asc' | 'desc';
52+
53+
export const sortByField =
54+
<T = object>(
55+
field: keyof T,
56+
order: Sort = 'asc',
57+
fn: (value: any) => any = value => value,
58+
) =>
59+
(a: T, b: T) => {
60+
if (order === 'asc') {
61+
return fn(a[field]) < fn(b[field]) ? -1 : 1;
62+
} else {
63+
return fn(a[field]) < fn(b[field]) ? 1 : -1;
64+
}
65+
};

0 commit comments

Comments
 (0)