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
70506bec
Unverified
Commit
70506bec
authored
Oct 31, 2022
by
Igor Stuev
Committed by
GitHub
Oct 31, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #283 from blockscout/txs-sorting-cookie
txs sorting cookie
parents
2721c160
30e223aa
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
53 additions
and
39 deletions
+53
-39
cookies.ts
lib/cookies.ts
+1
-0
sortTxs.ts
lib/tx/sortTxs.ts
+26
-0
txs-sort.ts
types/client/txs-sort.ts
+1
-1
TxsContent.tsx
ui/txs/TxsContent.tsx
+21
-19
TxsTable.tsx
ui/txs/TxsTable.tsx
+1
-1
TxsWithSort.tsx
ui/txs/TxsWithSort.tsx
+3
-18
No files found.
lib/cookies.ts
View file @
70506bec
...
@@ -6,6 +6,7 @@ import isBrowser from './isBrowser';
...
@@ -6,6 +6,7 @@ import isBrowser from './isBrowser';
export
enum
NAMES
{
export
enum
NAMES
{
NAV_BAR_COLLAPSED
=
'
nav_bar_collapsed
'
,
NAV_BAR_COLLAPSED
=
'
nav_bar_collapsed
'
,
API_TOKEN
=
'
_explorer_key
'
,
API_TOKEN
=
'
_explorer_key
'
,
TXS_SORT
=
'
txs_sort
'
,
}
}
export
function
get
(
name
?:
string
|
undefined
|
null
)
{
export
function
get
(
name
?:
string
|
undefined
|
null
)
{
...
...
lib/tx/sortTxs.ts
0 → 100644
View file @
70506bec
import
type
{
TransactionsResponse
}
from
'
types/api/transaction
'
;
import
type
{
Sort
}
from
'
types/client/txs-sort
'
;
import
compareBns
from
'
lib/bigint/compareBns
'
;
export
default
function
sortTxs
(
txs
:
TransactionsResponse
[
'
items
'
],
sorting
?:
Sort
)
{
let
sortedTxs
;
switch
(
sorting
)
{
case
'
val-desc
'
:
sortedTxs
=
[
...
txs
].
sort
((
tx1
,
tx2
)
=>
compareBns
(
tx1
.
value
,
tx2
.
value
));
break
;
case
'
val-asc
'
:
sortedTxs
=
[
...
txs
].
sort
((
tx1
,
tx2
)
=>
compareBns
(
tx2
.
value
,
tx1
.
value
));
break
;
case
'
fee-desc
'
:
sortedTxs
=
[
...
txs
].
sort
((
tx1
,
tx2
)
=>
compareBns
(
tx1
.
fee
.
value
,
tx2
.
fee
.
value
));
break
;
case
'
fee-asc
'
:
sortedTxs
=
[
...
txs
].
sort
((
tx1
,
tx2
)
=>
compareBns
(
tx2
.
fee
.
value
,
tx1
.
fee
.
value
));
break
;
default
:
sortedTxs
=
txs
;
}
return
sortedTxs
;
}
types/client/txs-sort.ts
View file @
70506bec
export
type
Sort
=
'
val-desc
'
|
'
val-asc
'
|
'
fee-desc
'
|
'
fee-asc
'
|
undefined
;
export
type
Sort
=
'
val-desc
'
|
'
val-asc
'
|
'
fee-desc
'
|
'
fee-asc
'
|
''
;
ui/txs/TxsContent.tsx
View file @
70506bec
...
@@ -5,6 +5,7 @@ import type { TTxsFilters } from 'types/api/txsFilters';
...
@@ -5,6 +5,7 @@ import type { TTxsFilters } from 'types/api/txsFilters';
import
type
{
QueryKeys
}
from
'
types/client/queries
'
;
import
type
{
QueryKeys
}
from
'
types/client/queries
'
;
import
type
{
Sort
}
from
'
types/client/txs-sort
'
;
import
type
{
Sort
}
from
'
types/client/txs-sort
'
;
import
*
as
cookies
from
'
lib/cookies
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
DataFetchAlert
from
'
ui/shared/DataFetchAlert
'
;
import
DataFetchAlert
from
'
ui/shared/DataFetchAlert
'
;
// import FilterInput from 'ui/shared/FilterInput';
// import FilterInput from 'ui/shared/FilterInput';
...
@@ -30,32 +31,33 @@ const TxsContent = ({
...
@@ -30,32 +31,33 @@ const TxsContent = ({
stateFilter
,
stateFilter
,
apiPath
,
apiPath
,
}:
Props
)
=>
{
}:
Props
)
=>
{
const
[
sorting
,
setSorting
]
=
useState
<
Sort
>
();
const
[
sorting
,
setSorting
]
=
useState
<
Sort
>
(
cookies
.
get
(
cookies
.
NAMES
.
TXS_SORT
)
as
Sort
||
''
);
// const [ filters, setFilters ] = useState<Partial<TTxsFilters>>({ type: [], method: [] });
// const [ filters, setFilters ] = useState<Partial<TTxsFilters>>({ type: [], method: [] });
const
sort
=
useCallback
((
field
:
'
val
'
|
'
fee
'
)
=>
()
=>
{
const
sort
=
useCallback
((
field
:
'
val
'
|
'
fee
'
)
=>
()
=>
{
if
(
field
===
'
val
'
)
{
setSorting
((
prevVal
)
=>
{
setSorting
((
prevVal
=>
{
let
newVal
:
Sort
=
''
;
if
(
field
===
'
val
'
)
{
if
(
prevVal
===
'
val-asc
'
)
{
if
(
prevVal
===
'
val-asc
'
)
{
return
undefined
;
newVal
=
''
;
}
else
if
(
prevVal
===
'
val-desc
'
)
{
newVal
=
'
val-asc
'
;
}
else
{
newVal
=
'
val-desc
'
;
}
}
if
(
prevVal
===
'
val-desc
'
)
{
}
return
'
val-asc
'
;
if
(
field
===
'
fee
'
)
{
}
return
'
val-desc
'
;
}));
}
if
(
field
===
'
fee
'
)
{
setSorting
((
prevVal
=>
{
if
(
prevVal
===
'
fee-asc
'
)
{
if
(
prevVal
===
'
fee-asc
'
)
{
return
undefined
;
newVal
=
''
;
}
}
else
if
(
prevVal
===
'
fee-desc
'
)
{
if
(
prevVal
===
'
fee-desc
'
)
{
newVal
=
'
fee-asc
'
;
return
'
fee-asc
'
;
}
else
{
newVal
=
'
fee-desc
'
;
}
}
return
'
fee-desc
'
;
}
}));
cookies
.
set
(
cookies
.
NAMES
.
TXS_SORT
,
newVal
||
''
);
}
return
newVal
;
});
},
[
setSorting
]);
},
[
setSorting
]);
const
{
const
{
...
...
ui/txs/TxsTable.tsx
View file @
70506bec
...
@@ -12,7 +12,7 @@ import TxsTableItem from './TxsTableItem';
...
@@ -12,7 +12,7 @@ import TxsTableItem from './TxsTableItem';
type
Props
=
{
type
Props
=
{
txs
:
Array
<
Transaction
>
;
txs
:
Array
<
Transaction
>
;
sort
:
(
field
:
'
val
'
|
'
fee
'
)
=>
()
=>
void
;
sort
:
(
field
:
'
val
'
|
'
fee
'
)
=>
()
=>
void
;
sorting
:
Sort
;
sorting
?
:
Sort
;
}
}
const
TxsTable
=
({
txs
,
sort
,
sorting
}:
Props
)
=>
{
const
TxsTable
=
({
txs
,
sort
,
sorting
}:
Props
)
=>
{
...
...
ui/txs/TxsWithSort.tsx
View file @
70506bec
...
@@ -4,7 +4,7 @@ import React, { useEffect, useState } from 'react';
...
@@ -4,7 +4,7 @@ import React, { useEffect, useState } from 'react';
import
type
{
TransactionsResponse
}
from
'
types/api/transaction
'
;
import
type
{
TransactionsResponse
}
from
'
types/api/transaction
'
;
import
type
{
Sort
}
from
'
types/client/txs-sort
'
;
import
type
{
Sort
}
from
'
types/client/txs-sort
'
;
import
compareBns
from
'
lib/bigint/compareBn
s
'
;
import
sortTxs
from
'
lib/tx/sortTx
s
'
;
import
TxsListItem
from
'
./TxsListItem
'
;
import
TxsListItem
from
'
./TxsListItem
'
;
import
TxsTable
from
'
./TxsTable
'
;
import
TxsTable
from
'
./TxsTable
'
;
...
@@ -20,25 +20,10 @@ const TxsWithSort = ({
...
@@ -20,25 +20,10 @@ const TxsWithSort = ({
sorting
,
sorting
,
sort
,
sort
,
}:
Props
)
=>
{
}:
Props
)
=>
{
const
[
sortedTxs
,
setSortedTxs
]
=
useState
(
txs
);
const
[
sortedTxs
,
setSortedTxs
]
=
useState
<
TransactionsResponse
[
'
items
'
]
>
(
sortTxs
(
txs
,
sorting
)
);
useEffect
(()
=>
{
useEffect
(()
=>
{
switch
(
sorting
)
{
setSortedTxs
(
sortTxs
(
txs
,
sorting
));
case
'
val-desc
'
:
setSortedTxs
([
...
txs
].
sort
((
tx1
,
tx2
)
=>
compareBns
(
tx1
.
value
,
tx2
.
value
)));
break
;
case
'
val-asc
'
:
setSortedTxs
([
...
txs
].
sort
((
tx1
,
tx2
)
=>
compareBns
(
tx2
.
value
,
tx1
.
value
)));
break
;
case
'
fee-desc
'
:
setSortedTxs
([
...
txs
].
sort
((
tx1
,
tx2
)
=>
compareBns
(
tx1
.
fee
.
value
,
tx2
.
fee
.
value
)));
break
;
case
'
fee-asc
'
:
setSortedTxs
([
...
txs
].
sort
((
tx1
,
tx2
)
=>
compareBns
(
tx2
.
fee
.
value
,
tx1
.
fee
.
value
)));
break
;
default
:
setSortedTxs
(
txs
);
}
},
[
sorting
,
txs
]);
},
[
sorting
,
txs
]);
return
(
return
(
...
...
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