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
22fba855
Commit
22fba855
authored
Jan 04, 2023
by
isstuev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
address tokens balances
parent
90ad298f
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
119 additions
and
10 deletions
+119
-10
AddressTokens.tsx
ui/address/AddressTokens.tsx
+9
-0
TokenSelectButton.tsx
ui/address/tokenSelect/TokenSelectButton.tsx
+3
-4
TokenSelectItem.tsx
ui/address/tokenSelect/TokenSelectItem.tsx
+1
-1
TokenSelectMenu.tsx
ui/address/tokenSelect/TokenSelectMenu.tsx
+2
-2
useTokenSelect.ts
ui/address/tokenSelect/useTokenSelect.ts
+2
-2
TokenBalances.tsx
ui/address/tokens/TokenBalances.tsx
+94
-0
tokenUtils.ts
ui/address/utils/tokenUtils.ts
+6
-0
Address.tsx
ui/pages/Address.tsx
+2
-1
No files found.
ui/address/AddressTokens.tsx
0 → 100644
View file @
22fba855
import
React
from
'
react
'
;
import
TokenBalances
from
'
./tokens/TokenBalances
'
;
const
AddressTokens
=
()
=>
{
return
<
TokenBalances
/>;
};
export
default
AddressTokens
;
ui/address/tokenSelect/TokenSelectButton.tsx
View file @
22fba855
import
{
Box
,
Button
,
Icon
,
Skeleton
,
Text
,
useColorModeValue
}
from
'
@chakra-ui/react
'
;
import
{
Box
,
Button
,
Icon
,
Skeleton
,
Text
,
useColorModeValue
}
from
'
@chakra-ui/react
'
;
import
BigNumber
from
'
bignumber.js
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
arrowIcon
from
'
icons/arrows/east-mini.svg
'
;
import
arrowIcon
from
'
icons/arrows/east-mini.svg
'
;
import
tokensIcon
from
'
icons/tokens.svg
'
;
import
tokensIcon
from
'
icons/tokens.svg
'
;
import
{
ZERO
}
from
'
lib/consts
'
;
import
type
{
EnhancedData
}
from
'
./utils
'
;
import
type
{
EnhancedData
}
from
'
../utils/tokenUtils
'
;
import
{
getTokenBalanceTotal
}
from
'
../utils/tokenUtils
'
;
interface
Props
{
interface
Props
{
isOpen
:
boolean
;
isOpen
:
boolean
;
...
@@ -16,7 +15,7 @@ interface Props {
...
@@ -16,7 +15,7 @@ interface Props {
}
}
const
TokenSelectButton
=
({
isOpen
,
isLoading
,
onClick
,
data
}:
Props
,
ref
:
React
.
ForwardedRef
<
HTMLButtonElement
>
)
=>
{
const
TokenSelectButton
=
({
isOpen
,
isLoading
,
onClick
,
data
}:
Props
,
ref
:
React
.
ForwardedRef
<
HTMLButtonElement
>
)
=>
{
const
totalBn
=
data
.
reduce
((
result
,
item
)
=>
!
item
.
usd
?
result
:
result
.
plus
(
BigNumber
(
item
.
usd
)),
ZERO
);
const
totalBn
=
getTokenBalanceTotal
(
data
);
const
skeletonBgColor
=
useColorModeValue
(
'
white
'
,
'
black
'
);
const
skeletonBgColor
=
useColorModeValue
(
'
white
'
,
'
black
'
);
const
handleClick
=
React
.
useCallback
(()
=>
{
const
handleClick
=
React
.
useCallback
(()
=>
{
...
...
ui/address/tokenSelect/TokenSelectItem.tsx
View file @
22fba855
...
@@ -6,7 +6,7 @@ import link from 'lib/link/link';
...
@@ -6,7 +6,7 @@ import link from 'lib/link/link';
import
HashStringShorten
from
'
ui/shared/HashStringShorten
'
;
import
HashStringShorten
from
'
ui/shared/HashStringShorten
'
;
import
TokenLogo
from
'
ui/shared/TokenLogo
'
;
import
TokenLogo
from
'
ui/shared/TokenLogo
'
;
import
type
{
EnhancedData
}
from
'
.
/u
tils
'
;
import
type
{
EnhancedData
}
from
'
.
./utils/tokenU
tils
'
;
interface
Props
{
interface
Props
{
data
:
EnhancedData
;
data
:
EnhancedData
;
...
...
ui/address/tokenSelect/TokenSelectMenu.tsx
View file @
22fba855
...
@@ -8,9 +8,9 @@ import type { TokenType } from 'types/api/tokenInfo';
...
@@ -8,9 +8,9 @@ import type { TokenType } from 'types/api/tokenInfo';
import
arrowIcon
from
'
icons/arrows/east.svg
'
;
import
arrowIcon
from
'
icons/arrows/east.svg
'
;
import
searchIcon
from
'
icons/search.svg
'
;
import
searchIcon
from
'
icons/search.svg
'
;
import
type
{
Sort
,
EnhancedData
}
from
'
../utils/tokenUtils
'
;
import
{
sortTokenGroups
,
sortingFns
}
from
'
../utils/tokenUtils
'
;
import
TokenSelectItem
from
'
./TokenSelectItem
'
;
import
TokenSelectItem
from
'
./TokenSelectItem
'
;
import
type
{
Sort
,
EnhancedData
}
from
'
./utils
'
;
import
{
sortTokenGroups
,
sortingFns
}
from
'
./utils
'
;
interface
Props
{
interface
Props
{
searchTerm
:
string
;
searchTerm
:
string
;
...
...
ui/address/tokenSelect/useTokenSelect.ts
View file @
22fba855
...
@@ -4,8 +4,8 @@ import React from 'react';
...
@@ -4,8 +4,8 @@ import React from 'react';
import
type
{
AddressTokenBalance
}
from
'
types/api/address
'
;
import
type
{
AddressTokenBalance
}
from
'
types/api/address
'
;
import
type
{
Sort
}
from
'
.
/u
tils
'
;
import
type
{
Sort
}
from
'
.
./utils/tokenU
tils
'
;
import
{
calculateUsdValue
,
filterTokens
}
from
'
.
/u
tils
'
;
import
{
calculateUsdValue
,
filterTokens
}
from
'
.
./utils/tokenU
tils
'
;
export
default
function
useData
(
data
:
Array
<
AddressTokenBalance
>
)
{
export
default
function
useData
(
data
:
Array
<
AddressTokenBalance
>
)
{
const
[
searchTerm
,
setSearchTerm
]
=
React
.
useState
(
''
);
const
[
searchTerm
,
setSearchTerm
]
=
React
.
useState
(
''
);
...
...
ui/address/tokens/TokenBalances.tsx
0 → 100644
View file @
22fba855
import
{
Box
,
Flex
,
Icon
,
Skeleton
,
Text
,
useColorModeValue
}
from
'
@chakra-ui/react
'
;
import
BigNumber
from
'
bignumber.js
'
;
import
{
useRouter
}
from
'
next/router
'
;
import
React
from
'
react
'
;
import
appConfig
from
'
configs/app/config
'
;
import
walletIcon
from
'
icons/wallet.svg
'
;
import
useApiQuery
from
'
lib/api/useApiQuery
'
;
import
getCurrencyValue
from
'
lib/getCurrencyValue
'
;
import
DataFetchAlert
from
'
ui/shared/DataFetchAlert
'
;
import
{
getTokenBalanceTotal
,
calculateUsdValue
}
from
'
../utils/tokenUtils
'
;
const
TokenBalances
=
()
=>
{
const
router
=
useRouter
();
const
addressQuery
=
useApiQuery
(
'
address
'
,
{
pathParams
:
{
id
:
router
.
query
.
id
?.
toString
()
},
queryOptions
:
{
enabled
:
Boolean
(
router
.
query
.
id
)
},
});
const
balancesQuery
=
useApiQuery
(
'
address_token_balances
'
,
{
pathParams
:
{
id
:
addressQuery
.
data
?.
hash
},
queryOptions
:
{
enabled
:
Boolean
(
addressQuery
.
data
)
},
});
const
bgColor
=
useColorModeValue
(
'
blackAlpha.50
'
,
'
whiteAlpha.50
'
);
if
(
addressQuery
.
isError
||
balancesQuery
.
isError
)
{
return
<
DataFetchAlert
/>;
}
if
(
addressQuery
.
isLoading
||
balancesQuery
.
isLoading
)
{
const
item
=
<
Skeleton
w=
{
{
base
:
'
100%
'
,
lg
:
'
240px
'
}
}
h=
"82px"
borderRadius=
"16px"
/>;
return
(
<
Flex
columnGap=
{
3
}
rowGap=
{
3
}
mt=
{
{
base
:
'
6px
'
,
lg
:
0
}
}
flexDirection=
{
{
base
:
'
column
'
,
lg
:
'
row
'
}
}
>
{
item
}
{
item
}
{
item
}
</
Flex
>
);
}
const
addressData
=
addressQuery
.
data
;
const
{
valueStr
:
nativeValue
,
usd
:
nativeUsd
}
=
getCurrencyValue
({
value
:
addressData
.
coin_balance
||
'
0
'
,
accuracy
:
8
,
accuracyUsd
:
2
,
exchangeRate
:
addressData
.
exchange_rate
,
decimals
:
String
(
appConfig
.
network
.
currency
.
decimals
),
});
const
tokenBalanceBn
=
getTokenBalanceTotal
(
balancesQuery
.
data
.
map
(
calculateUsdValue
)).
toFixed
(
2
);
const
totalUsd
=
nativeUsd
?
BigNumber
(
nativeUsd
).
toNumber
()
+
BigNumber
(
tokenBalanceBn
).
toNumber
()
:
undefined
;
const
itemProps
=
{
p
:
5
,
bgColor
,
borderRadius
:
'
16px
'
,
alignItems
:
'
center
'
,
};
return
(
<
Flex
columnGap=
{
3
}
rowGap=
{
3
}
mt=
{
{
base
:
'
6px
'
,
lg
:
0
}
}
flexDirection=
{
{
base
:
'
column
'
,
lg
:
'
row
'
}
}
>
<
Flex
{
...
itemProps
}
>
<
Icon
as=
{
walletIcon
}
boxSize=
"30px"
mr=
{
3
}
/>
<
Box
>
<
Text
variant=
"secondary"
fontSize=
"xs"
>
Net Worth
</
Text
>
<
Text
fontWeight=
"500"
>
{
totalUsd
?
`$${ totalUsd } USD`
:
'
N/A
'
}
</
Text
>
</
Box
>
</
Flex
>
<
Flex
{
...
itemProps
}
>
<
Icon
as=
{
walletIcon
}
boxSize=
"30px"
mr=
{
3
}
/>
<
Box
>
<
Text
variant=
"secondary"
fontSize=
"xs"
>
{
`${ appConfig.network.currency.symbol } Balance`
}
</
Text
>
<
Text
fontWeight=
"500"
>
{
nativeUsd
&&
`$${ nativeUsd } USD | `
}
{
`${ nativeValue } ${ appConfig.network.currency.symbol }`
}
</
Text
>
</
Box
>
</
Flex
>
<
Flex
{
...
itemProps
}
>
<
Icon
as=
{
walletIcon
}
boxSize=
"30px"
mr=
{
3
}
/>
<
Box
>
<
Text
variant=
"secondary"
fontSize=
"xs"
>
Tokens
</
Text
>
<
Text
fontWeight=
"500"
>
{
`$${ tokenBalanceBn } USD `
}
{
Boolean
(
balancesQuery
.
data
.
length
)
&&
` | ${ balancesQuery.data.length } ${ balancesQuery.data.length === 1 ? 'token' : 'tokens' }`
}
</
Text
>
</
Box
>
</
Flex
>
</
Flex
>
);
};
export
default
React
.
memo
(
TokenBalances
);
ui/address/
tokenSelect/u
tils.ts
→
ui/address/
utils/tokenU
tils.ts
View file @
22fba855
...
@@ -3,6 +3,8 @@ import BigNumber from 'bignumber.js';
...
@@ -3,6 +3,8 @@ import BigNumber from 'bignumber.js';
import
type
{
AddressTokenBalance
}
from
'
types/api/address
'
;
import
type
{
AddressTokenBalance
}
from
'
types/api/address
'
;
import
type
{
TokenType
}
from
'
types/api/tokenInfo
'
;
import
type
{
TokenType
}
from
'
types/api/tokenInfo
'
;
import
{
ZERO
}
from
'
lib/consts
'
;
export
type
EnhancedData
=
AddressTokenBalance
&
{
export
type
EnhancedData
=
AddressTokenBalance
&
{
usd
?:
BigNumber
;
usd
?:
BigNumber
;
}
}
...
@@ -77,3 +79,7 @@ export const calculateUsdValue = (data: AddressTokenBalance): EnhancedData => {
...
@@ -77,3 +79,7 @@ export const calculateUsdValue = (data: AddressTokenBalance): EnhancedData => {
usd
:
BigNumber
(
data
.
value
).
div
(
BigNumber
(
10
**
decimals
)).
multipliedBy
(
BigNumber
(
exchangeRate
)),
usd
:
BigNumber
(
data
.
value
).
div
(
BigNumber
(
10
**
decimals
)).
multipliedBy
(
BigNumber
(
exchangeRate
)),
};
};
};
};
export
const
getTokenBalanceTotal
=
(
data
:
Array
<
EnhancedData
>
)
=>
{
return
data
.
reduce
((
result
,
item
)
=>
!
item
.
usd
?
result
:
result
.
plus
(
BigNumber
(
item
.
usd
)),
ZERO
);
};
ui/pages/Address.tsx
View file @
22fba855
...
@@ -12,6 +12,7 @@ import AddressContract from 'ui/address/AddressContract';
...
@@ -12,6 +12,7 @@ import AddressContract from 'ui/address/AddressContract';
import
AddressDetails
from
'
ui/address/AddressDetails
'
;
import
AddressDetails
from
'
ui/address/AddressDetails
'
;
import
AddressInternalTxs
from
'
ui/address/AddressInternalTxs
'
;
import
AddressInternalTxs
from
'
ui/address/AddressInternalTxs
'
;
import
AddressLogs
from
'
ui/address/AddressLogs
'
;
import
AddressLogs
from
'
ui/address/AddressLogs
'
;
import
AddressTokens
from
'
ui/address/AddressTokens
'
;
import
AddressTokenTransfers
from
'
ui/address/AddressTokenTransfers
'
;
import
AddressTokenTransfers
from
'
ui/address/AddressTokenTransfers
'
;
import
AddressTxs
from
'
ui/address/AddressTxs
'
;
import
AddressTxs
from
'
ui/address/AddressTxs
'
;
import
ContractCode
from
'
ui/address/contract/ContractCode
'
;
import
ContractCode
from
'
ui/address/contract/ContractCode
'
;
...
@@ -72,7 +73,7 @@ const AddressPageContent = () => {
...
@@ -72,7 +73,7 @@ const AddressPageContent = () => {
addressQuery
.
data
?.
has_token_transfers
?
addressQuery
.
data
?.
has_token_transfers
?
{
id
:
'
token_transfers
'
,
title
:
'
Token transfers
'
,
component
:
<
AddressTokenTransfers
scrollRef=
{
tabsScrollRef
}
/>
}
:
{
id
:
'
token_transfers
'
,
title
:
'
Token transfers
'
,
component
:
<
AddressTokenTransfers
scrollRef=
{
tabsScrollRef
}
/>
}
:
undefined
,
undefined
,
addressQuery
.
data
?.
has_tokens
?
{
id
:
'
tokens
'
,
title
:
'
Tokens
'
,
component
:
null
}
:
undefined
,
addressQuery
.
data
?.
has_tokens
?
{
id
:
'
tokens
'
,
title
:
'
Tokens
'
,
component
:
<
AddressTokens
/>
}
:
undefined
,
{
id
:
'
internal_txns
'
,
title
:
'
Internal txns
'
,
component
:
<
AddressInternalTxs
scrollRef=
{
tabsScrollRef
}
/>
},
{
id
:
'
internal_txns
'
,
title
:
'
Internal txns
'
,
component
:
<
AddressInternalTxs
scrollRef=
{
tabsScrollRef
}
/>
},
{
id
:
'
coin_balance_history
'
,
title
:
'
Coin balance history
'
,
component
:
<
AddressCoinBalance
/>
},
{
id
:
'
coin_balance_history
'
,
title
:
'
Coin balance history
'
,
component
:
<
AddressCoinBalance
/>
},
addressQuery
.
data
?.
has_validated_blocks
?
addressQuery
.
data
?.
has_validated_blocks
?
...
...
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