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
724a54b0
Commit
724a54b0
authored
Nov 30, 2022
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add token balances
parent
41d6b89f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
4 deletions
+57
-4
token-balances.ts
pages/api/addresses/[id]/token-balances.ts
+11
-0
address.ts
types/api/address.ts
+6
-0
queries.ts
types/client/queries.ts
+1
-0
AddressDetails.tsx
ui/address/AddressDetails.tsx
+39
-4
No files found.
pages/api/addresses/[id]/token-balances.ts
0 → 100644
View file @
724a54b0
import
type
{
NextApiRequest
}
from
'
next
'
;
import
handler
from
'
lib/api/handler
'
;
const
getUrl
=
(
req
:
NextApiRequest
)
=>
{
return
`/v2/addresses/
${
req
.
query
.
id
}
/token-balances`
;
};
const
requestHandler
=
handler
(
getUrl
,
[
'
GET
'
]);
export
default
requestHandler
;
types/api/address.ts
View file @
724a54b0
...
@@ -25,3 +25,9 @@ export interface AddressCounters {
...
@@ -25,3 +25,9 @@ export interface AddressCounters {
gas_usage_count
:
string
;
gas_usage_count
:
string
;
validation_count
:
string
|
null
;
validation_count
:
string
|
null
;
}
}
export
interface
AddressTokenBalance
{
token
:
TokenInfo
;
token_id
:
string
|
null
;
value
:
string
;
}
types/client/queries.ts
View file @
724a54b0
...
@@ -19,4 +19,5 @@ export enum QueryKeys {
...
@@ -19,4 +19,5 @@ export enum QueryKeys {
jsonRpcUrl
=
'
json-rpc-url
'
,
jsonRpcUrl
=
'
json-rpc-url
'
,
address
=
'
address
'
,
address
=
'
address
'
,
addressCounters
=
'
address-counters
'
,
addressCounters
=
'
address-counters
'
,
addressTokenBalances
=
'
address-token-balances
'
,
}
}
ui/address/AddressDetails.tsx
View file @
724a54b0
import
{
Box
,
Flex
,
Text
,
Icon
,
Button
,
Grid
}
from
'
@chakra-ui/react
'
;
import
{
Box
,
Flex
,
Text
,
Icon
,
Button
,
Grid
,
Select
}
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
{
useQuery
}
from
'
@tanstack/react-query
'
;
import
BigNumber
from
'
bignumber.js
'
;
import
BigNumber
from
'
bignumber.js
'
;
import
{
useRouter
}
from
'
next/router
'
;
import
{
useRouter
}
from
'
next/router
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
type
{
Address
as
TAddress
,
AddressCounters
}
from
'
types/api/address
'
;
import
type
{
Address
as
TAddress
,
AddressCounters
,
AddressTokenBalance
}
from
'
types/api/address
'
;
import
{
QueryKeys
}
from
'
types/client/queries
'
;
import
{
QueryKeys
}
from
'
types/client/queries
'
;
import
appConfig
from
'
configs/app/config
'
;
import
appConfig
from
'
configs/app/config
'
;
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
walletIcon
from
'
icons/wallet.svg
'
;
import
useFetch
from
'
lib/hooks/useFetch
'
;
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
'
;
...
@@ -34,11 +35,19 @@ const AddressDetails = ({ addressQuery }: Props) => {
...
@@ -34,11 +35,19 @@ const AddressDetails = ({ addressQuery }: Props) => {
},
},
);
);
if
(
countersQuery
.
isLoading
||
addressQuery
.
isLoading
)
{
const
tokenBalancesQuery
=
useQuery
<
unknown
,
unknown
,
Array
<
AddressTokenBalance
>>
(
[
QueryKeys
.
addressTokenBalances
,
router
.
query
.
id
],
async
()
=>
await
fetch
(
`/node-api/addresses/
${
router
.
query
.
id
}
/token-balances`
),
{
enabled
:
Boolean
(
router
.
query
.
id
)
&&
Boolean
(
addressQuery
.
data
),
},
);
if
(
countersQuery
.
isLoading
||
addressQuery
.
isLoading
||
tokenBalancesQuery
.
isLoading
)
{
return
<
Box
>
loading
</
Box
>;
return
<
Box
>
loading
</
Box
>;
}
}
if
(
countersQuery
.
isError
||
addressQuery
.
isError
)
{
if
(
countersQuery
.
isError
||
addressQuery
.
isError
||
tokenBalancesQuery
.
isError
)
{
return
<
Box
>
error
</
Box
>;
return
<
Box
>
error
</
Box
>;
}
}
...
@@ -73,6 +82,32 @@ const AddressDetails = ({ addressQuery }: Props) => {
...
@@ -73,6 +82,32 @@ const AddressDetails = ({ addressQuery }: Props) => {
rowGap=
{
{
base
:
3
,
lg
:
3
}
}
rowGap=
{
{
base
:
3
,
lg
:
3
}
}
templateColumns=
{
{
base
:
'
minmax(0, 1fr)
'
,
lg
:
'
auto minmax(0, 1fr)
'
}
}
overflow=
"hidden"
templateColumns=
{
{
base
:
'
minmax(0, 1fr)
'
,
lg
:
'
auto minmax(0, 1fr)
'
}
}
overflow=
"hidden"
>
>
<
DetailsInfoItem
title=
"Tokens"
hint=
"All tokens in the account and total value."
alignSelf=
"center"
>
{
tokenBalancesQuery
.
data
.
length
>
0
?
(
<>
{
/* TODO will be fixed later when we implement select with custom menu */
}
<
Select
size=
"sm"
borderRadius=
"base"
focusBorderColor=
"none"
display=
"inline-block"
w=
"auto"
>
{
tokenBalancesQuery
.
data
.
map
((
token
)
=>
<
option
key=
{
token
.
token
.
address
}
value=
{
token
.
token
.
address
}
>
{
token
.
token
.
symbol
}
</
option
>)
}
</
Select
>
<
Button
variant=
"outline"
size=
"sm"
ml=
{
3
}
>
<
Icon
as=
{
walletIcon
}
boxSize=
{
5
}
/>
</
Button
>
</>
)
:
(
'
-
'
)
}
</
DetailsInfoItem
>
<
DetailsInfoItem
<
DetailsInfoItem
title=
"Transactions"
title=
"Transactions"
hint=
"Number of transactions related to this address."
hint=
"Number of transactions related to this address."
...
...
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