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
d6f80acd
Commit
d6f80acd
authored
Nov 30, 2022
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
address counters
parent
4523797f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
17 deletions
+91
-17
counters.ts
pages/api/addresses/[id]/counters.ts
+11
-0
address.ts
types/api/address.ts
+7
-0
queries.ts
types/client/queries.ts
+3
-1
AddressDetails.tsx
ui/address/AddressDetails.tsx
+63
-10
Address.tsx
ui/pages/Address.tsx
+7
-6
No files found.
pages/api/addresses/[id]/counters.ts
0 → 100644
View file @
d6f80acd
import
type
{
NextApiRequest
}
from
'
next
'
;
import
handler
from
'
lib/api/handler
'
;
const
getUrl
=
(
req
:
NextApiRequest
)
=>
{
return
`/v2/addresses/
${
req
.
query
.
id
}
/counters`
;
};
const
requestHandler
=
handler
(
getUrl
,
[
'
GET
'
]);
export
default
requestHandler
;
types/api/address.ts
View file @
d6f80acd
...
@@ -18,3 +18,10 @@ export interface Address {
...
@@ -18,3 +18,10 @@ export interface Address {
tokenInfo
:
TokenInfo
|
null
;
tokenInfo
:
TokenInfo
|
null
;
watchlist_names
:
Array
<
WatchlistName
>
|
null
;
watchlist_names
:
Array
<
WatchlistName
>
|
null
;
}
}
export
interface
AddressCounters
{
transaction_count
:
string
;
token_transfer_count
:
string
;
gas_usage_count
:
string
;
validation_count
:
string
|
null
;
}
types/client/queries.ts
View file @
d6f80acd
...
@@ -16,5 +16,7 @@ export enum QueryKeys {
...
@@ -16,5 +16,7 @@ export enum QueryKeys {
chartsMarket
=
'
charts-market
'
,
chartsMarket
=
'
charts-market
'
,
indexBlocks
=
'
indexBlocks
'
,
indexBlocks
=
'
indexBlocks
'
,
indexTxs
=
'
indexTxs
'
,
indexTxs
=
'
indexTxs
'
,
jsonRpcUrl
=
'
json-rpc-url
'
jsonRpcUrl
=
'
json-rpc-url
'
,
address
=
'
address
'
,
addressCounters
=
'
address-counters
'
,
}
}
ui/address/AddressDetails.tsx
View file @
d6f80acd
import
{
Box
,
Flex
,
Text
,
Icon
,
Button
}
from
'
@chakra-ui/react
'
;
import
{
Box
,
Flex
,
Text
,
Icon
,
Button
,
Grid
}
from
'
@chakra-ui/react
'
;
import
type
{
UseQueryResult
}
from
'
@tanstack/react-query
'
;
import
type
{
UseQueryResult
}
from
'
@tanstack/react-query
'
;
import
{
useQuery
}
from
'
@tanstack/react-query
'
;
import
BigNumber
from
'
bignumber.js
'
;
import
{
useRouter
}
from
'
next/router
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
type
{
Address
as
TAddress
}
from
'
types/api/address
'
;
import
type
{
Address
as
TAddress
,
AddressCounters
}
from
'
types/api/address
'
;
import
{
QueryKeys
}
from
'
types/client/queries
'
;
import
metamaskIcon
from
'
icons/metamask.svg
'
;
import
metamaskIcon
from
'
icons/metamask.svg
'
;
import
qrCodeIcon
from
'
icons/qr_code.svg
'
;
import
qrCodeIcon
from
'
icons/qr_code.svg
'
;
import
starOutlineIcon
from
'
icons/star_outline.svg
'
;
import
starOutlineIcon
from
'
icons/star_outline.svg
'
;
import
useFetch
from
'
lib/hooks/useFetch
'
;
import
AddressIcon
from
'
ui/shared/address/AddressIcon
'
;
import
AddressIcon
from
'
ui/shared/address/AddressIcon
'
;
import
CopyToClipboard
from
'
ui/shared/CopyToClipboard
'
;
import
CopyToClipboard
from
'
ui/shared/CopyToClipboard
'
;
import
DetailsInfoItem
from
'
ui/shared/DetailsInfoItem
'
;
interface
Props
{
interface
Props
{
address
Info
:
UseQueryResult
<
TAddress
>
;
address
Query
:
UseQueryResult
<
TAddress
>
;
}
}
const
AddressDetails
=
({
addressInfo
}:
Props
)
=>
{
const
AddressDetails
=
({
addressQuery
}:
Props
)
=>
{
const
{
data
,
isError
,
isLoading
}
=
addressInfo
;
const
router
=
useRouter
();
if
(
isError
||
isLoading
)
{
const
fetch
=
useFetch
();
return
null
;
const
countersQuery
=
useQuery
<
unknown
,
unknown
,
AddressCounters
>
(
[
QueryKeys
.
addressCounters
,
router
.
query
.
id
],
async
()
=>
await
fetch
(
`/node-api/addresses/
${
router
.
query
.
id
}
/counters`
),
{
enabled
:
Boolean
(
router
.
query
.
id
)
&&
Boolean
(
addressQuery
.
data
),
},
);
if
(
countersQuery
.
isLoading
||
addressQuery
.
isLoading
)
{
return
<
Box
>
loading
</
Box
>;
}
if
(
countersQuery
.
isError
||
addressQuery
.
isError
)
{
return
<
Box
>
error
</
Box
>;
}
}
return
(
return
(
<
Box
>
<
Box
>
<
Flex
alignItems=
"center"
>
<
Flex
alignItems=
"center"
>
<
AddressIcon
hash=
{
data
.
hash
}
/>
<
AddressIcon
hash=
{
addressQuery
.
data
.
hash
}
/>
<
Text
ml=
{
2
}
fontFamily=
"heading"
fontWeight=
{
500
}
>
{
data
.
hash
}
</
Text
>
<
Text
ml=
{
2
}
fontFamily=
"heading"
fontWeight=
{
500
}
>
{
addressQuery
.
data
.
hash
}
</
Text
>
<
CopyToClipboard
text=
{
data
.
hash
}
/>
<
CopyToClipboard
text=
{
addressQuery
.
data
.
hash
}
/>
<
Icon
as=
{
metamaskIcon
}
boxSize=
{
6
}
ml=
{
2
}
/>
<
Icon
as=
{
metamaskIcon
}
boxSize=
{
6
}
ml=
{
2
}
/>
<
Button
variant=
"outline"
size=
"sm"
ml=
{
3
}
>
<
Button
variant=
"outline"
size=
"sm"
ml=
{
3
}
>
<
Icon
as=
{
starOutlineIcon
}
boxSize=
{
5
}
/>
<
Icon
as=
{
starOutlineIcon
}
boxSize=
{
5
}
/>
...
@@ -34,6 +54,39 @@ const AddressDetails = ({ addressInfo }: Props) => {
...
@@ -34,6 +54,39 @@ const AddressDetails = ({ addressInfo }: Props) => {
<
Icon
as=
{
qrCodeIcon
}
boxSize=
{
5
}
/>
<
Icon
as=
{
qrCodeIcon
}
boxSize=
{
5
}
/>
</
Button
>
</
Button
>
</
Flex
>
</
Flex
>
<
Grid
mt=
{
8
}
columnGap=
{
8
}
rowGap=
{
{
base
:
3
,
lg
:
3
}
}
templateColumns=
{
{
base
:
'
minmax(0, 1fr)
'
,
lg
:
'
auto minmax(0, 1fr)
'
}
}
overflow=
"hidden"
>
<
DetailsInfoItem
title=
"Transactions"
hint=
"Number of transactions related to this address."
>
{
Number
(
countersQuery
.
data
.
transaction_count
).
toLocaleString
()
}
</
DetailsInfoItem
>
<
DetailsInfoItem
title=
"Transfers"
hint=
"Number of transfers to/from this address."
>
{
Number
(
countersQuery
.
data
.
token_transfer_count
).
toLocaleString
()
}
</
DetailsInfoItem
>
<
DetailsInfoItem
title=
"Gas used"
hint=
"Gas used by the address."
>
{
BigNumber
(
countersQuery
.
data
.
gas_usage_count
).
toFormat
()
}
</
DetailsInfoItem
>
{
countersQuery
.
data
.
validation_count
&&
(
<
DetailsInfoItem
title=
"Blocks validated"
hint=
"Number of blocks validated by this validator."
>
{
Number
(
countersQuery
.
data
.
validation_count
).
toLocaleString
()
}
</
DetailsInfoItem
>
)
}
</
Grid
>
</
Box
>
</
Box
>
);
);
};
};
...
...
ui/pages/Address.tsx
View file @
d6f80acd
...
@@ -4,6 +4,7 @@ import { useRouter } from 'next/router';
...
@@ -4,6 +4,7 @@ import { useRouter } from 'next/router';
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
type
{
Address
}
from
'
types/api/address
'
;
import
type
{
Address
}
from
'
types/api/address
'
;
import
{
QueryKeys
}
from
'
types/client/queries
'
;
import
useFetch
from
'
lib/hooks/useFetch
'
;
import
useFetch
from
'
lib/hooks/useFetch
'
;
import
AddressDetails
from
'
ui/address/AddressDetails
'
;
import
AddressDetails
from
'
ui/address/AddressDetails
'
;
...
@@ -14,8 +15,8 @@ const AddressPageContent = () => {
...
@@ -14,8 +15,8 @@ const AddressPageContent = () => {
const
router
=
useRouter
();
const
router
=
useRouter
();
const
fetch
=
useFetch
();
const
fetch
=
useFetch
();
const
address
Info
=
useQuery
<
unknown
,
unknown
,
Address
>
(
const
address
Query
=
useQuery
<
unknown
,
unknown
,
Address
>
(
[
'
address
'
,
router
.
query
.
id
],
[
QueryKeys
.
address
,
router
.
query
.
id
],
async
()
=>
await
fetch
(
`/node-api/addresses/
${
router
.
query
.
id
}
`
),
async
()
=>
await
fetch
(
`/node-api/addresses/
${
router
.
query
.
id
}
`
),
{
{
enabled
:
Boolean
(
router
.
query
.
id
),
enabled
:
Boolean
(
router
.
query
.
id
),
...
@@ -23,9 +24,9 @@ const AddressPageContent = () => {
...
@@ -23,9 +24,9 @@ const AddressPageContent = () => {
);
);
const
tags
=
[
const
tags
=
[
...(
address
Info
.
data
?.
private_tags
||
[]),
...(
address
Query
.
data
?.
private_tags
||
[]),
...(
address
Info
.
data
?.
public_tags
||
[]),
...(
address
Query
.
data
?.
public_tags
||
[]),
...(
address
Info
.
data
?.
watchlist_names
||
[]),
...(
address
Query
.
data
?.
watchlist_names
||
[]),
].
map
((
tag
)
=>
<
Tag
key=
{
tag
.
label
}
>
{
tag
.
display_name
}
</
Tag
>);
].
map
((
tag
)
=>
<
Tag
key=
{
tag
.
label
}
>
{
tag
.
display_name
}
</
Tag
>);
return
(
return
(
...
@@ -38,7 +39,7 @@ const AddressPageContent = () => {
...
@@ -38,7 +39,7 @@ const AddressPageContent = () => {
</
Flex
>
</
Flex
>
)
}
)
}
</
Flex
>
</
Flex
>
<
AddressDetails
address
Info=
{
addressInfo
}
/>
<
AddressDetails
address
Query=
{
addressQuery
}
/>
</
Page
>
</
Page
>
);
);
};
};
...
...
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