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
288fa1ef
Commit
288fa1ef
authored
Jan 05, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
separate loader for address counters
parent
95bd3e72
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
15 deletions
+43
-15
address.ts
types/api/address.ts
+1
-0
AddressDetails.tsx
ui/address/AddressDetails.tsx
+8
-15
AddressCounterItem.tsx
ui/address/details/AddressCounterItem.tsx
+34
-0
No files found.
types/api/address.ts
View file @
288fa1ef
...
...
@@ -13,6 +13,7 @@ export interface Address {
creation_tx_hash
:
string
|
null
;
exchange_rate
:
string
|
null
;
hash
:
string
;
has_validated_blocks
:
boolean
;
implementation_address
:
string
|
null
;
implementation_name
:
string
|
null
;
is_contract
:
boolean
;
...
...
ui/address/AddressDetails.tsx
View file @
288fa1ef
import
{
Box
,
Flex
,
Text
,
Icon
,
Grid
,
Link
}
from
'
@chakra-ui/react
'
;
import
type
{
UseQueryResult
}
from
'
@tanstack/react-query
'
;
import
BigNumber
from
'
bignumber.js
'
;
import
{
useRouter
}
from
'
next/router
'
;
import
React
from
'
react
'
;
...
...
@@ -11,6 +10,7 @@ import blockIcon from 'icons/block.svg';
import
useApiQuery
from
'
lib/api/useApiQuery
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
link
from
'
lib/link/link
'
;
import
AddressCounterItem
from
'
ui/address/details/AddressCounterItem
'
;
import
AddressIcon
from
'
ui/shared/address/AddressIcon
'
;
import
AddressLink
from
'
ui/shared/address/AddressLink
'
;
import
CopyToClipboard
from
'
ui/shared/CopyToClipboard
'
;
...
...
@@ -41,27 +41,20 @@ const AddressDetails = ({ addressQuery }: Props) => {
enabled
:
Boolean
(
router
.
query
.
id
)
&&
Boolean
(
addressQuery
.
data
),
},
});
const
tokenBalancesQuery
=
useApiQuery
(
'
address_token_balances
'
,
{
pathParams
:
{
id
:
router
.
query
.
id
?.
toString
()
},
queryOptions
:
{
enabled
:
Boolean
(
router
.
query
.
id
)
&&
Boolean
(
addressQuery
.
data
),
},
});
if
(
addressQuery
.
isError
)
{
throw
Error
(
'
Address fetch error
'
,
{
cause
:
addressQuery
.
error
as
unknown
as
Error
});
}
if
(
countersQuery
.
isLoading
||
addressQuery
.
isLoading
||
tokenBalance
sQuery
.
isLoading
)
{
if
(
addres
sQuery
.
isLoading
)
{
return
<
AddressDetailsSkeleton
/>;
}
if
(
countersQuery
.
isError
||
addressQuery
.
isError
||
tokenBalance
sQuery
.
isError
)
{
if
(
addres
sQuery
.
isError
)
{
return
<
DataFetchAlert
/>;
}
const
explorers
=
appConfig
.
network
.
explorers
.
filter
(({
paths
})
=>
paths
.
address
);
const
validationsCount
=
Number
(
countersQuery
.
data
.
validations_count
);
return
(
<
Box
>
...
...
@@ -116,26 +109,26 @@ const AddressDetails = ({ addressQuery }: Props) => {
title=
"Transactions"
hint=
"Number of transactions related to this address."
>
{
Number
(
countersQuery
.
data
.
transactions_count
).
toLocaleString
()
}
<
AddressCounterItem
prop=
"transactions_count"
query=
{
countersQuery
}
/>
</
DetailsInfoItem
>
<
DetailsInfoItem
title=
"Transfers"
hint=
"Number of transfers to/from this address."
>
{
Number
(
countersQuery
.
data
.
token_transfers_count
).
toLocaleString
()
}
<
AddressCounterItem
prop=
"token_transfers_count"
query=
{
countersQuery
}
/>
</
DetailsInfoItem
>
<
DetailsInfoItem
title=
"Gas used"
hint=
"Gas used by the address."
>
{
BigNumber
(
countersQuery
.
data
.
gas_usage_count
).
toFormat
()
}
<
AddressCounterItem
prop=
"gas_usage_count"
query=
{
countersQuery
}
/>
</
DetailsInfoItem
>
{
!
Object
.
is
(
validationsCount
,
NaN
)
&&
validationsCount
>
0
&&
(
{
addressQuery
.
data
.
has_validated_blocks
&&
(
<
DetailsInfoItem
title=
"Blocks validated"
hint=
"Number of blocks validated by this validator."
>
{
validationsCount
.
toLocaleString
()
}
<
AddressCounterItem
prop=
"validations_count"
query=
{
countersQuery
}
/>
</
DetailsInfoItem
>
)
}
{
addressQuery
.
data
.
block_number_balance_updated_at
&&
(
...
...
ui/address/details/AddressCounterItem.tsx
0 → 100644
View file @
288fa1ef
import
{
Skeleton
}
from
'
@chakra-ui/react
'
;
import
type
{
UseQueryResult
}
from
'
@tanstack/react-query
'
;
import
BigNumber
from
'
bignumber.js
'
;
import
React
from
'
react
'
;
import
type
{
AddressCounters
}
from
'
types/api/address
'
;
interface
Props
{
prop
:
keyof
AddressCounters
;
query
:
UseQueryResult
<
AddressCounters
>
;
}
const
AddressCounterItem
=
({
prop
,
query
}:
Props
)
=>
{
if
(
query
.
isLoading
)
{
return
<
Skeleton
h=
{
5
}
w=
"80px"
borderRadius=
"full"
/>;
}
const
data
=
query
.
data
?.[
prop
];
if
(
query
.
isError
||
data
===
null
||
data
===
undefined
)
{
return
<
span
>
no data
</
span
>;
}
switch
(
prop
)
{
case
'
gas_usage_count
'
:
return
<
span
>
{
BigNumber
(
data
).
toFormat
()
}
</
span
>;
case
'
transactions_count
'
:
case
'
token_transfers_count
'
:
case
'
validations_count
'
:
return
<
span
>
{
Number
(
data
).
toLocaleString
()
}
</
span
>;
}
};
export
default
React
.
memo
(
AddressCounterItem
);
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