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
f2d6d338
Commit
f2d6d338
authored
Oct 21, 2022
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
api for block txs
parent
f1122f41
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
46 additions
and
20 deletions
+46
-20
transactions.ts
pages/api/blocks/[id]/transactions.ts
+11
-0
block.ts
types/api/block.ts
+10
-0
queries.ts
types/client/queries.ts
+1
-0
BlockDetails.tsx
ui/block/BlockDetails.tsx
+1
-1
BlockTxs.tsx
ui/block/BlockTxs.tsx
+10
-13
TxsContent.tsx
ui/txs/TxsContent.tsx
+6
-3
TxsTab.tsx
ui/txs/TxsTab.tsx
+1
-0
useQueryWithPages.ts
ui/txs/useQueryWithPages.ts
+6
-3
No files found.
pages/api/blocks/[id]/transactions.ts
0 → 100644
View file @
f2d6d338
import
type
{
NextApiRequest
}
from
'
next
'
;
import
handler
from
'
lib/api/handler
'
;
const
getUrl
=
(
req
:
NextApiRequest
)
=>
{
return
`/v2/blocks/
${
req
.
query
.
id
}
/transactions`
;
};
const
requestHandler
=
handler
(
getUrl
,
[
'
GET
'
]);
export
default
requestHandler
;
types/api/block.ts
View file @
f2d6d338
import
type
{
AddressParam
}
from
'
types/api/addressParams
'
;
import
type
{
AddressParam
}
from
'
types/api/addressParams
'
;
import
type
{
Reward
}
from
'
types/api/reward
'
;
import
type
{
Reward
}
from
'
types/api/reward
'
;
import
type
{
Transaction
}
from
'
types/api/transaction
'
;
export
type
BlockType
=
'
block
'
|
'
reorg
'
|
'
uncle
'
;
export
type
BlockType
=
'
block
'
|
'
reorg
'
|
'
uncle
'
;
...
@@ -37,3 +38,12 @@ export interface BlocksResponse {
...
@@ -37,3 +38,12 @@ export interface BlocksResponse {
items_count
:
number
;
items_count
:
number
;
};
};
}
}
export
interface
BlockTransactionsResponse
{
items
:
Array
<
Transaction
>
;
next_page_params
:
{
block_number
:
number
;
index
:
number
;
items_count
:
number
;
}
|
null
;
}
types/client/queries.ts
View file @
f2d6d338
...
@@ -7,4 +7,5 @@ export enum QueryKeys {
...
@@ -7,4 +7,5 @@ export enum QueryKeys {
txInternals
=
'
tx-internals
'
,
txInternals
=
'
tx-internals
'
,
txLog
=
'
tx-log
'
,
txLog
=
'
tx-log
'
,
txRawTrace
=
'
tx-raw-trace
'
,
txRawTrace
=
'
tx-raw-trace
'
,
blockTxs
=
'
block-transactions
'
,
}
}
ui/block/BlockDetails.tsx
View file @
f2d6d338
...
@@ -109,7 +109,7 @@ const BlockDetails = () => {
...
@@ -109,7 +109,7 @@ const BlockDetails = () => {
title=
"Transactions"
title=
"Transactions"
hint=
"The number of transactions in the block."
hint=
"The number of transactions in the block."
>
>
<
Link
href=
{
link
(
'
block
'
,
{
id
:
router
.
query
.
id
},
{
tab
:
'
t
ransaction
s
'
})
}
>
<
Link
href=
{
link
(
'
block
'
,
{
id
:
router
.
query
.
id
},
{
tab
:
'
t
x
s
'
})
}
>
{
data
.
tx_count
}
transactions
{
data
.
tx_count
}
transactions
</
Link
>
</
Link
>
</
DetailsInfoItem
>
</
DetailsInfoItem
>
...
...
ui/block/BlockTxs.tsx
View file @
f2d6d338
import
{
useRouter
}
from
'
next/router
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
TxsWithSort
from
'
ui/txs/TxsWithSort
'
;
import
{
QueryKeys
}
from
'
types/client/queries
'
;
import
TxsContent
from
'
ui/txs/TxsContent
'
;
const
BlockTxs
=
()
=>
{
const
BlockTxs
=
()
=>
{
const
router
=
useRouter
();
return
(
return
(
// <TxsContent
<
TxsContent
// showDescription={ false }
queryName=
{
QueryKeys
.
blockTxs
}
// showSortButton={ false }
apiPath=
{
`/api/blocks/${ router.query.id }/transactions`
}
// txs={ [] }
/>
// page={ 1 }
// // eslint-disable-next-line react/jsx-no-bind
// onNextPageClick={ () => {} }
// // eslint-disable-next-line react/jsx-no-bind
// onPrevPageClick={ () => {} }
// />
// eslint-disable-next-line react/jsx-no-bind
<
TxsWithSort
txs=
{
[]
}
sort=
{
()
=>
()
=>
{}
}
/>
);
);
};
};
...
...
ui/txs/TxsContent.tsx
View file @
f2d6d338
import
{
Alert
,
Box
,
HStack
,
Show
,
Button
}
from
'
@chakra-ui/react
'
;
import
{
Alert
,
Box
,
HStack
,
Show
,
Button
}
from
'
@chakra-ui/react
'
;
import
React
,
{
useState
,
useCallback
}
from
'
react
'
;
import
React
,
{
useState
,
useCallback
}
from
'
react
'
;
import
type
{
QueryKeys
}
from
'
types/client/queries
'
;
import
type
{
Sort
}
from
'
types/client/txs-sort
'
;
import
type
{
Sort
}
from
'
types/client/txs-sort
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
...
@@ -16,15 +17,17 @@ import TxsWithSort from './TxsWithSort';
...
@@ -16,15 +17,17 @@ import TxsWithSort from './TxsWithSort';
import
useQueryWithPages
from
'
./useQueryWithPages
'
;
import
useQueryWithPages
from
'
./useQueryWithPages
'
;
type
Props
=
{
type
Props
=
{
queryName
:
string
;
queryName
:
QueryKeys
;
showDescription
?:
boolean
;
showDescription
?:
boolean
;
stateFilter
:
'
validated
'
|
'
pending
'
;
stateFilter
?:
'
validated
'
|
'
pending
'
;
apiPath
:
string
;
}
}
const
TxsContent
=
({
const
TxsContent
=
({
showDescription
,
showDescription
,
queryName
,
queryName
,
stateFilter
,
stateFilter
,
apiPath
,
}:
Props
)
=>
{
}:
Props
)
=>
{
const
[
sorting
,
setSorting
]
=
useState
<
Sort
>
();
const
[
sorting
,
setSorting
]
=
useState
<
Sort
>
();
...
@@ -62,7 +65,7 @@ const TxsContent = ({
...
@@ -62,7 +65,7 @@ const TxsContent = ({
onNextPageClick
,
onNextPageClick
,
hasPagination
,
hasPagination
,
resetPage
,
resetPage
,
}
=
useQueryWithPages
(
queryName
,
stateFilter
);
}
=
useQueryWithPages
(
queryName
,
stateFilter
,
apiPath
);
const
isMobile
=
useIsMobile
(
false
);
const
isMobile
=
useIsMobile
(
false
);
...
...
ui/txs/TxsTab.tsx
View file @
f2d6d338
...
@@ -14,6 +14,7 @@ const TxsTab = ({ tab }: Props) => {
...
@@ -14,6 +14,7 @@ const TxsTab = ({ tab }: Props) => {
queryName=
{
tab
===
'
validated
'
?
QueryKeys
.
transactionsValidated
:
QueryKeys
.
transactionsPending
}
queryName=
{
tab
===
'
validated
'
?
QueryKeys
.
transactionsValidated
:
QueryKeys
.
transactionsPending
}
showDescription=
{
tab
===
'
validated
'
}
showDescription=
{
tab
===
'
validated
'
}
stateFilter=
{
tab
}
stateFilter=
{
tab
}
apiPath=
"/api/transactions"
/>
/>
);
);
};
};
...
...
ui/txs/useQueryWithPages.ts
View file @
f2d6d338
...
@@ -10,7 +10,7 @@ import useFetch from 'lib/hooks/useFetch';
...
@@ -10,7 +10,7 @@ import useFetch from 'lib/hooks/useFetch';
const
PAGINATION_FIELDS
=
[
'
block_number
'
,
'
index
'
,
'
items_count
'
];
const
PAGINATION_FIELDS
=
[
'
block_number
'
,
'
index
'
,
'
items_count
'
];
export
default
function
useQueryWithPages
(
queryName
:
string
,
filter
:
string
)
{
export
default
function
useQueryWithPages
(
queryName
:
string
,
filter
:
string
|
undefined
,
apiPath
:
string
)
{
const
queryClient
=
useQueryClient
();
const
queryClient
=
useQueryClient
();
const
router
=
useRouter
();
const
router
=
useRouter
();
const
[
page
,
setPage
]
=
React
.
useState
(
1
);
const
[
page
,
setPage
]
=
React
.
useState
(
1
);
...
@@ -23,9 +23,12 @@ export default function useQueryWithPages(queryName: string, filter: string) {
...
@@ -23,9 +23,12 @@ export default function useQueryWithPages(queryName: string, filter: string) {
async
()
=>
{
async
()
=>
{
const
params
:
Array
<
string
>
=
[];
const
params
:
Array
<
string
>
=
[];
Object
.
entries
(
currPageParams
).
forEach
(([
key
,
val
])
=>
params
.
push
(
`
${
key
}
=
${
val
}
`
));
Object
.
entries
({
...
currPageParams
,
filter
,
}).
forEach
(([
key
,
val
])
=>
val
&&
params
.
push
(
`
${
key
}
=
${
val
}
`
));
return
fetch
(
`
/api/transactions?filter=
${
filter
}${
params
.
length
?
'
&
'
+
params
.
join
(
'
&
'
)
:
''
}
`
);
return
fetch
(
`
${
apiPath
}${
params
.
length
?
'
?
'
+
params
.
join
(
'
&
'
)
:
''
}
`
);
},
},
{
staleTime
:
Infinity
},
{
staleTime
:
Infinity
},
);
);
...
...
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