File tree Expand file tree Collapse file tree
containers/NewProposalContainer Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import React , { useState } from 'react' ;
1+ import React , { useMemo , useState } from 'react' ;
22import { Legend } from '../Legend' ;
33import { MonitoringAccountItem } from './MonitoringAccountItem' ;
44import type { MonitoringAccount } from './types' ;
55import { ReactComponent as IconExpand } from '../../assets/icon-expand.svg' ;
66import cn from 'classnames' ;
77import { useFetch } from '../../hooks/useFetch' ;
88import { useAuthContext } from '../../containers/AuthContainer' ;
9+ import { sortByField } from '../../utils/helpers' ;
910
1011export 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
Original file line number Diff line number Diff line change 1- import React , { useState } from 'react' ;
1+ import React , { useMemo , useState } from 'react' ;
22import { ViewableAccountItem } from './ViewableAccountItem' ;
33import { Legend } from '../Legend' ;
44import cn from 'classnames' ;
55import { ReactComponent as IconExpand } from '../../assets/icon-expand.svg' ;
66import { useFetch } from '../../hooks/useFetch' ;
77import { ViewableAccount } from './types' ;
88import { useAuthContext } from '../../containers/AuthContainer' ;
9+ import { sortByField } from '../../utils/helpers' ;
910
1011export 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
Original file line number Diff line number Diff 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 >
Original file line number Diff line number Diff line change @@ -47,3 +47,19 @@ export const chainIdToNetworkName = (chainId: number) =>
4747
4848export 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+ } ;
You can’t perform that action at this time.
0 commit comments