Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
73cad84f
Commit
73cad84f
authored
Feb 28, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor Sort
parent
dab03ebf
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
94 additions
and
143 deletions
+94
-143
VerifiedContracts.tsx
ui/pages/VerifiedContracts.tsx
+18
-53
Sort.tsx
ui/shared/sort/Sort.tsx
+12
-17
SortButton.tsx
ui/shared/sort/SortButton.tsx
+0
-0
TxsHeaderMobile.tsx
ui/txs/TxsHeaderMobile.tsx
+17
-8
TxsSorting.tsx
ui/txs/TxsSorting.tsx
+0
-62
useTxsSort.tsx
ui/txs/useTxsSort.tsx
+2
-2
utils.ts
ui/verifiedContracts/utils.ts
+45
-1
No files found.
ui/pages/VerifiedContracts.tsx
View file @
73cad84f
...
@@ -2,9 +2,8 @@ import { Box, Flex, Hide, Show, Text } from '@chakra-ui/react';
...
@@ -2,9 +2,8 @@ import { Box, Flex, Hide, Show, Text } from '@chakra-ui/react';
import
{
useRouter
}
from
'
next/router
'
;
import
{
useRouter
}
from
'
next/router
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
type
{
VerifiedContract
,
VerifiedContract
sFilters
}
from
'
types/api/contracts
'
;
import
type
{
VerifiedContractsFilters
}
from
'
types/api/contracts
'
;
import
compareBns
from
'
lib/bigint/compareBns
'
;
import
useDebounce
from
'
lib/hooks/useDebounce
'
;
import
useDebounce
from
'
lib/hooks/useDebounce
'
;
import
useQueryWithPages
from
'
lib/hooks/useQueryWithPages
'
;
import
useQueryWithPages
from
'
lib/hooks/useQueryWithPages
'
;
import
{
apos
}
from
'
lib/html-entities
'
;
import
{
apos
}
from
'
lib/html-entities
'
;
...
@@ -17,56 +16,18 @@ import PageTitle from 'ui/shared/Page/PageTitle';
...
@@ -17,56 +16,18 @@ import PageTitle from 'ui/shared/Page/PageTitle';
import
Pagination
from
'
ui/shared/Pagination
'
;
import
Pagination
from
'
ui/shared/Pagination
'
;
import
SkeletonList
from
'
ui/shared/skeletons/SkeletonList
'
;
import
SkeletonList
from
'
ui/shared/skeletons/SkeletonList
'
;
import
SkeletonTable
from
'
ui/shared/skeletons/SkeletonTable
'
;
import
SkeletonTable
from
'
ui/shared/skeletons/SkeletonTable
'
;
import
type
{
Sort
,
SortField
}
from
'
ui/verifiedContracts/utils
'
;
import
Sort
from
'
ui/shared/sort/Sort
'
;
import
type
{
SortField
,
Sort
as
TSort
}
from
'
ui/verifiedContracts/utils
'
;
import
{
SORT_OPTIONS
,
sortFn
,
getNextSortValue
}
from
'
ui/verifiedContracts/utils
'
;
import
VerifiedContractsFilter
from
'
ui/verifiedContracts/VerifiedContractsFilter
'
;
import
VerifiedContractsFilter
from
'
ui/verifiedContracts/VerifiedContractsFilter
'
;
import
VerifiedContractsList
from
'
ui/verifiedContracts/VerifiedContractsList
'
;
import
VerifiedContractsList
from
'
ui/verifiedContracts/VerifiedContractsList
'
;
import
VerifiedContractsSort
from
'
ui/verifiedContracts/VerifiedContractsSort
'
;
import
VerifiedContractsTable
from
'
ui/verifiedContracts/VerifiedContractsTable
'
;
import
VerifiedContractsTable
from
'
ui/verifiedContracts/VerifiedContractsTable
'
;
const
SORT_SEQUENCE
:
Record
<
SortField
,
Array
<
Sort
|
undefined
>>
=
{
balance
:
[
'
balance-desc
'
,
'
balance-asc
'
,
undefined
],
txs
:
[
'
txs-desc
'
,
'
txs-asc
'
,
undefined
],
};
const
getNextSortValue
=
(
field
:
SortField
)
=>
(
prevValue
:
Sort
|
undefined
)
=>
{
const
sequence
=
SORT_SEQUENCE
[
field
];
const
curIndex
=
sequence
.
findIndex
((
sort
)
=>
sort
===
prevValue
);
const
nextIndex
=
curIndex
+
1
>
sequence
.
length
-
1
?
0
:
curIndex
+
1
;
return
sequence
[
nextIndex
];
};
const
sortFn
=
(
sort
:
Sort
|
undefined
)
=>
(
a
:
VerifiedContract
,
b
:
VerifiedContract
)
=>
{
switch
(
sort
)
{
case
'
balance-desc
'
:
{
const
result
=
compareBns
(
b
.
coin_balance
,
a
.
coin_balance
);
return
a
.
coin_balance
===
b
.
coin_balance
?
0
:
result
;
}
case
'
balance-asc
'
:
{
const
result
=
compareBns
(
a
.
coin_balance
,
b
.
coin_balance
);
return
a
.
coin_balance
===
b
.
coin_balance
?
0
:
result
;
}
case
'
txs-desc
'
:
{
const
result
=
(
a
.
tx_count
||
0
)
>
(
b
.
tx_count
||
0
)
?
-
1
:
1
;
return
a
.
tx_count
===
b
.
tx_count
?
0
:
result
;
}
case
'
txs-asc
'
:
{
const
result
=
(
a
.
tx_count
||
0
)
>
(
b
.
tx_count
||
0
)
?
1
:
-
1
;
return
a
.
tx_count
===
b
.
tx_count
?
0
:
result
;
}
default
:
return
0
;
}
};
const
VerifiedContracts
=
()
=>
{
const
VerifiedContracts
=
()
=>
{
const
router
=
useRouter
();
const
router
=
useRouter
();
const
[
searchTerm
,
setSearchTerm
]
=
React
.
useState
(
getQueryParamString
(
router
.
query
.
q
)
||
undefined
);
const
[
searchTerm
,
setSearchTerm
]
=
React
.
useState
(
getQueryParamString
(
router
.
query
.
q
)
||
undefined
);
const
[
type
,
setType
]
=
React
.
useState
(
getQueryParamString
(
router
.
query
.
filter
)
as
VerifiedContractsFilters
[
'
filter
'
]
||
undefined
);
const
[
type
,
setType
]
=
React
.
useState
(
getQueryParamString
(
router
.
query
.
filter
)
as
VerifiedContractsFilters
[
'
filter
'
]
||
undefined
);
const
[
sort
,
setSort
]
=
React
.
useState
<
Sort
>
();
const
[
sort
,
setSort
]
=
React
.
useState
<
T
Sort
>
();
const
debouncedSearchTerm
=
useDebounce
(
searchTerm
||
''
,
300
);
const
debouncedSearchTerm
=
useDebounce
(
searchTerm
||
''
,
300
);
...
@@ -114,25 +75,29 @@ const VerifiedContracts = () => {
...
@@ -114,25 +75,29 @@ const VerifiedContracts = () => {
);
);
const
sortButton
=
(
const
sortButton
=
(
<
VerifiedContractsSort
<
Sort
options=
{
SORT_OPTIONS
}
sort=
{
sort
}
sort=
{
sort
}
setSort=
{
setSort
}
setSort=
{
setSort
}
isActive=
{
Boolean
(
sort
)
}
/>
/>
);
);
const
bar
=
(
const
bar
=
(
<>
<>
<
Flex
columnGap=
{
3
}
mb=
{
6
}
display=
{
{
base
:
'
flex
'
,
lg
:
'
none
'
}
}
>
<
Show
below=
"lg"
ssr=
{
false
}
>
<
Flex
columnGap=
{
3
}
mb=
{
6
}
>
{
typeFilter
}
{
typeFilter
}
{
sortButton
}
{
sortButton
}
{
filterInput
}
{
filterInput
}
</
Flex
>
</
Flex
>
</
Show
>
<
ActionBar
mt=
{
-
6
}
>
<
ActionBar
mt=
{
-
6
}
>
<
Flex
columnGap=
{
3
}
display=
{
{
base
:
'
none
'
,
lg
:
'
flex
'
}
}
>
<
Hide
below=
"lg"
ssr=
{
false
}
>
<
Flex
columnGap=
{
3
}
>
{
typeFilter
}
{
typeFilter
}
{
filterInput
}
{
filterInput
}
</
Flex
>
</
Flex
>
</
Hide
>
{
isPaginationVisible
&&
<
Pagination
ml=
"auto"
{
...
pagination
}
/>
}
{
isPaginationVisible
&&
<
Pagination
ml=
"auto"
{
...
pagination
}
/>
}
</
ActionBar
>
</
ActionBar
>
</>
</>
...
...
ui/
verifiedContracts/VerifiedContracts
Sort.tsx
→
ui/
shared/sort/
Sort.tsx
View file @
73cad84f
...
@@ -9,25 +9,20 @@ import {
...
@@ -9,25 +9,20 @@ import {
}
from
'
@chakra-ui/react
'
;
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
SortButton
from
'
ui/shared
/SortButton
'
;
import
SortButton
from
'
.
/SortButton
'
;
import
type
{
Sort
}
from
'
./utils
'
;
export
interface
Option
<
Sort
extends
string
>
{
title
:
string
;
id
:
Sort
|
undefined
;
}
interface
Props
{
interface
Props
<
Sort
extends
string
>
{
isActive
:
boolean
;
options
:
Array
<
Option
<
Sort
>>
;
sort
:
Sort
|
undefined
;
sort
:
Sort
|
undefined
;
setSort
:
(
val
:
Sort
|
undefined
)
=>
void
;
setSort
:
(
val
ue
:
Sort
|
undefined
)
=>
void
;
}
}
const
SORT_OPTIONS
=
[
const
Sort
=
<
Sort
extends
string
>
(
{
sort
,
setSort
,
options
}
: Props
<
Sort
>
) =
>
{
{
title
:
'
Default
'
,
id
:
undefined
},
{
title
:
'
Balance ascending
'
,
id
:
'
balance-asc
'
},
{
title
:
'
Balance descending
'
,
id
:
'
balance-desc
'
},
{
title
:
'
Txs count ascending
'
,
id
:
'
txs-asc
'
},
{
title
:
'
Txs count descending
'
,
id
:
'
txs-desc
'
},
];
const
VerifiedContractSorting
=
({
isActive
,
sort
,
setSort
}:
Props
)
=>
{
const
{
isOpen
,
onToggle
}
=
useDisclosure
();
const
{
isOpen
,
onToggle
}
=
useDisclosure
();
const
setSortingFromMenu
=
React
.
useCallback
((
val
:
string
|
Array
<
string
>
)
=>
{
const
setSortingFromMenu
=
React
.
useCallback
((
val
:
string
|
Array
<
string
>
)
=>
{
...
@@ -39,13 +34,13 @@ const VerifiedContractSorting = ({ isActive, sort, setSort }: Props) => {
...
@@ -39,13 +34,13 @@ const VerifiedContractSorting = ({ isActive, sort, setSort }: Props) => {
<
Menu
>
<
Menu
>
<
MenuButton
>
<
MenuButton
>
<
SortButton
<
SortButton
isActive=
{
isOpen
||
isActive
}
isActive=
{
isOpen
||
Boolean
(
sort
)
}
onClick=
{
onToggle
}
onClick=
{
onToggle
}
/>
/>
</
MenuButton
>
</
MenuButton
>
<
MenuList
minWidth=
"240px"
zIndex=
"popover"
>
<
MenuList
minWidth=
"240px"
zIndex=
"popover"
>
<
MenuOptionGroup
value=
{
sort
}
title=
"Sort by"
type=
"radio"
onChange=
{
setSortingFromMenu
}
>
<
MenuOptionGroup
value=
{
sort
}
title=
"Sort by"
type=
"radio"
onChange=
{
setSortingFromMenu
}
>
{
SORT_OPTIONS
.
map
((
option
)
=>
(
{
options
.
map
((
option
)
=>
(
<
MenuItemOption
<
MenuItemOption
key=
{
option
.
id
||
'
default
'
}
key=
{
option
.
id
||
'
default
'
}
value=
{
option
.
id
}
value=
{
option
.
id
}
...
@@ -59,4 +54,4 @@ const VerifiedContractSorting = ({ isActive, sort, setSort }: Props) => {
...
@@ -59,4 +54,4 @@ const VerifiedContractSorting = ({ isActive, sort, setSort }: Props) => {
);
);
}
;
}
;
export
default
React
.
memo
(
chakra
(
VerifiedContractSorting
))
;
export default React.memo(chakra(
Sort)) as typeof Sort
;
ui/shared/SortButton.tsx
→
ui/shared/
sort/
SortButton.tsx
View file @
73cad84f
File moved
ui/txs/TxsHeaderMobile.tsx
View file @
73cad84f
import
{
HStack
,
chakra
}
from
'
@chakra-ui/react
'
;
import
{
HStack
,
chakra
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
type
{
Sort
}
from
'
types/client/txs-sort
'
;
import
type
{
Sort
as
TSort
}
from
'
types/client/txs-sort
'
;
// import FilterInput from 'ui/shared/filters/FilterInput';
// import FilterInput from 'ui/shared/filters/FilterInput';
import
ActionBar
from
'
ui/shared/ActionBar
'
;
import
ActionBar
from
'
ui/shared/ActionBar
'
;
import
Pagination
from
'
ui/shared/Pagination
'
;
import
Pagination
from
'
ui/shared/Pagination
'
;
import
type
{
Props
as
PaginationProps
}
from
'
ui/shared/Pagination
'
;
import
type
{
Props
as
PaginationProps
}
from
'
ui/shared/Pagination
'
;
import
TxsSorting
from
'
ui/txs/TxsSorting
'
;
import
type
{
Option
}
from
'
ui/shared/sort/Sort
'
;
import
Sort
from
'
ui/shared/sort/Sort
'
;
// import TxsFilters from './TxsFilters';
// import TxsFilters from './TxsFilters';
const
SORT_OPTIONS
:
Array
<
Option
<
TSort
>>
=
[
{
title
:
'
Default
'
,
id
:
undefined
},
{
title
:
'
Value ascending
'
,
id
:
'
val-asc
'
},
{
title
:
'
Value descending
'
,
id
:
'
val-desc
'
},
{
title
:
'
Fee ascending
'
,
id
:
'
fee-asc
'
},
{
title
:
'
Fee descending
'
,
id
:
'
fee-desc
'
},
];
type
Props
=
{
type
Props
=
{
sorting
:
Sort
;
sorting
:
T
Sort
;
setSorting
:
(
val
:
Sort
)
=>
void
;
setSorting
:
(
val
:
TSort
|
undefined
)
=>
void
;
paginationProps
:
PaginationProps
;
paginationProps
:
PaginationProps
;
className
?:
string
;
className
?:
string
;
showPagination
?:
boolean
;
showPagination
?:
boolean
;
...
@@ -26,10 +35,10 @@ const TxsHeaderMobile = ({ filterComponent, sorting, setSorting, paginationProps
...
@@ -26,10 +35,10 @@ const TxsHeaderMobile = ({ filterComponent, sorting, setSorting, paginationProps
<
ActionBar
className=
{
className
}
>
<
ActionBar
className=
{
className
}
>
<
HStack
>
<
HStack
>
{
filterComponent
}
{
filterComponent
}
<
TxsSorting
<
Sort
isActive=
{
Boolean
(
sorting
)
}
options=
{
SORT_OPTIONS
}
setSort
ing
=
{
setSorting
}
setSort=
{
setSorting
}
sort
ing
=
{
sorting
}
sort=
{
sorting
}
/>
/>
{
/* api is not implemented */
}
{
/* api is not implemented */
}
{
/* <FilterInput
{
/* <FilterInput
...
...
ui/txs/TxsSorting.tsx
deleted
100644 → 0
View file @
dab03ebf
import
{
chakra
,
Menu
,
MenuButton
,
MenuList
,
MenuOptionGroup
,
MenuItemOption
,
useDisclosure
,
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
type
{
Sort
}
from
'
types/client/txs-sort
'
;
import
SortButton
from
'
ui/shared/SortButton
'
;
interface
Props
{
isActive
:
boolean
;
sorting
:
Sort
;
setSorting
:
(
val
:
Sort
)
=>
void
;
}
const
SORT_OPTIONS
=
[
{
title
:
'
Default
'
,
id
:
''
},
{
title
:
'
Value ascending
'
,
id
:
'
val-asc
'
},
{
title
:
'
Value descending
'
,
id
:
'
val-desc
'
},
{
title
:
'
Fee ascending
'
,
id
:
'
fee-asc
'
},
{
title
:
'
Fee descending
'
,
id
:
'
fee-desc
'
},
];
const
TxsSorting
=
({
isActive
,
sorting
,
setSorting
}:
Props
)
=>
{
const
{
isOpen
,
onToggle
}
=
useDisclosure
();
const
setSortingFromMenu
=
React
.
useCallback
((
val
:
string
|
Array
<
string
>
)
=>
{
const
value
=
val
as
Sort
|
Array
<
Sort
>
;
setSorting
(
Array
.
isArray
(
value
)
?
value
[
0
]
:
value
);
},
[
setSorting
]);
return
(
<
Menu
>
<
MenuButton
>
<
SortButton
isActive=
{
isOpen
||
isActive
}
onClick=
{
onToggle
}
/>
</
MenuButton
>
<
MenuList
minWidth=
"240px"
>
<
MenuOptionGroup
value=
{
sorting
}
title=
"Sort by"
type=
"radio"
onChange=
{
setSortingFromMenu
}
>
{
SORT_OPTIONS
.
map
((
option
)
=>
(
<
MenuItemOption
key=
{
option
.
id
}
value=
{
option
.
id
}
>
{
option
.
title
}
</
MenuItemOption
>
))
}
</
MenuOptionGroup
>
</
MenuList
>
</
Menu
>
);
};
export
default
chakra
(
TxsSorting
);
ui/txs/useTxsSort.tsx
View file @
73cad84f
...
@@ -10,7 +10,7 @@ import sortTxs from 'lib/tx/sortTxs';
...
@@ -10,7 +10,7 @@ import sortTxs from 'lib/tx/sortTxs';
type
HookResult
=
UseQueryResult
<
TxsResponse
>
&
{
type
HookResult
=
UseQueryResult
<
TxsResponse
>
&
{
sorting
:
Sort
;
sorting
:
Sort
;
setSortByField
:
(
field
:
'
val
'
|
'
fee
'
)
=>
()
=>
void
;
setSortByField
:
(
field
:
'
val
'
|
'
fee
'
)
=>
()
=>
void
;
setSortByValue
:
(
value
:
Sort
)
=>
void
;
setSortByValue
:
(
value
:
Sort
|
undefined
)
=>
void
;
}
}
export
default
function
useTxsSort
(
export
default
function
useTxsSort
(
...
@@ -45,7 +45,7 @@ export default function useTxsSort(
...
@@ -45,7 +45,7 @@ export default function useTxsSort(
});
});
},
[
]);
},
[
]);
const
setSortByValue
=
React
.
useCallback
((
value
:
Sort
)
=>
{
const
setSortByValue
=
React
.
useCallback
((
value
:
Sort
|
undefined
)
=>
{
setSorting
((
prevVal
:
Sort
)
=>
{
setSorting
((
prevVal
:
Sort
)
=>
{
let
newVal
:
Sort
=
''
;
let
newVal
:
Sort
=
''
;
if
(
value
!==
prevVal
)
{
if
(
value
!==
prevVal
)
{
...
...
ui/verifiedContracts/utils.ts
View file @
73cad84f
export
type
Sort
=
'
balance-asc
'
|
'
balance-desc
'
|
'
txs-asc
'
|
'
txs-desc
'
;
import
type
{
VerifiedContract
}
from
'
types/api/contracts
'
;
import
compareBns
from
'
lib/bigint/compareBns
'
;
import
type
{
Option
}
from
'
ui/shared/sort/Sort
'
;
export
type
SortField
=
'
balance
'
|
'
txs
'
;
export
type
SortField
=
'
balance
'
|
'
txs
'
;
export
type
Sort
=
`
${
SortField
}
-asc`
|
`
${
SortField
}
-desc`
;
export
const
SORT_OPTIONS
:
Array
<
Option
<
Sort
>>
=
[
{
title
:
'
Default
'
,
id
:
undefined
},
{
title
:
'
Balance descending
'
,
id
:
'
balance-desc
'
},
{
title
:
'
Balance ascending
'
,
id
:
'
balance-asc
'
},
{
title
:
'
Txs count descending
'
,
id
:
'
txs-desc
'
},
{
title
:
'
Txs count ascending
'
,
id
:
'
txs-asc
'
},
];
const
SORT_SEQUENCE
:
Record
<
SortField
,
Array
<
Sort
|
undefined
>>
=
{
balance
:
[
'
balance-desc
'
,
'
balance-asc
'
,
undefined
],
txs
:
[
'
txs-desc
'
,
'
txs-asc
'
,
undefined
],
};
export
const
getNextSortValue
=
(
field
:
SortField
)
=>
(
prevValue
:
Sort
|
undefined
)
=>
{
const
sequence
=
SORT_SEQUENCE
[
field
];
const
curIndex
=
sequence
.
findIndex
((
sort
)
=>
sort
===
prevValue
);
const
nextIndex
=
curIndex
+
1
>
sequence
.
length
-
1
?
0
:
curIndex
+
1
;
return
sequence
[
nextIndex
];
};
export
const
sortFn
=
(
sort
:
Sort
|
undefined
)
=>
(
a
:
VerifiedContract
,
b
:
VerifiedContract
)
=>
{
switch
(
sort
)
{
case
'
balance-asc
'
:
case
'
balance-desc
'
:
{
const
result
=
compareBns
(
b
.
coin_balance
,
a
.
coin_balance
)
*
(
sort
.
includes
(
'
desc
'
)
?
1
:
-
1
);
return
a
.
coin_balance
===
b
.
coin_balance
?
0
:
result
;
}
case
'
txs-asc
'
:
case
'
txs-desc
'
:
{
const
result
=
((
a
.
tx_count
||
0
)
>
(
b
.
tx_count
||
0
)
?
-
1
:
1
)
*
(
sort
.
includes
(
'
desc
'
)
?
1
:
-
1
);
return
a
.
tx_count
===
b
.
tx_count
?
0
:
result
;
}
default
:
return
0
;
}
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment