1
1
import React , { useEffect , useMemo , useState } from 'react' ;
2
2
import { useNavigate } from 'react-router-dom' ;
3
3
import { useTranslation } from 'react-i18next' ;
4
- import { AccountAddress } from '@concordium/web-sdk' ;
4
+ import { AccountAddress , Ratio } from '@concordium/web-sdk' ;
5
5
import { absoluteRoutes , sendFundsRoute } from '@popup/popupX/constants/routes' ;
6
6
import Page from '@popup/popupX/shared/Page' ;
7
7
import Text from '@popup/popupX/shared/Text' ;
@@ -16,6 +16,8 @@ import Clock from '@assets/svgX/clock.svg';
16
16
import Percent from '@assets/svgX/percent.svg' ;
17
17
import ConcordiumLogo from '@assets/svgX/concordium-logo.svg' ;
18
18
import { TokenPickerVariant } from '@popup/popupX/shared/Form/TokenAmount/View' ;
19
+ import { displayCcdAsEur } from '@popup/popupX/shared/utils/helpers' ;
20
+ import { useBlockChainParameters } from '@popup/shared/BlockChainParametersProvider' ;
19
21
20
22
const zeroBalance : Omit < PublicAccountAmounts , 'scheduled' > = {
21
23
total : 0n ,
@@ -43,6 +45,7 @@ function useCcdInfo(credential: WalletCredential) {
43
45
atDisposal : displayAsCcd ( balances . atDisposal , false , true ) ,
44
46
staked : displayAsCcd ( balances . staked , false , true ) ,
45
47
cooldown : displayAsCcd ( balances . cooldown , false , true ) ,
48
+ microCcdAmount : balances . total ,
46
49
} ;
47
50
}
48
51
return { total : null , atDisposal : null } ;
@@ -51,11 +54,24 @@ function useCcdInfo(credential: WalletCredential) {
51
54
return tokenDetails ;
52
55
}
53
56
57
+ function TokenExchange ( { microCcdPerEur, balanceBase } : { microCcdPerEur ?: Ratio ; balanceBase ?: bigint } ) {
58
+ const isNoExchange = microCcdPerEur === undefined || balanceBase === undefined ;
59
+
60
+ return isNoExchange ? null : (
61
+ < div className = "token-balance__exchange-rate" >
62
+ < Text . Capture > { displayCcdAsEur ( microCcdPerEur , balanceBase , 2 ) } </ Text . Capture >
63
+ </ div >
64
+ ) ;
65
+ }
66
+
54
67
function TokenDetailsCcd ( { credential } : { credential : WalletCredential } ) {
55
68
const { t } = useTranslation ( 'x' , { keyPrefix : 'tokenDetails' } ) ;
56
69
57
70
const tokenDetails = useCcdInfo ( credential ) ;
58
71
72
+ const chainParameters = useBlockChainParameters ( ) ;
73
+ const microCcdPerEur = chainParameters ?. microGTUPerEuro ;
74
+
59
75
const nav = useNavigate ( ) ;
60
76
const navToSend = ( ) =>
61
77
nav ( sendFundsRoute ( AccountAddress . fromBase58 ( credential . address ) ) , {
@@ -72,6 +88,7 @@ function TokenDetailsCcd({ credential }: { credential: WalletCredential }) {
72
88
< Text . DynamicSize baseFontSize = { 32 } baseTextLength = { 17 } className = "heading_big" >
73
89
{ tokenDetails . total }
74
90
</ Text . DynamicSize >
91
+ < TokenExchange microCcdPerEur = { microCcdPerEur } balanceBase = { tokenDetails . microCcdAmount } />
75
92
< div className = "token-details-x__stake" >
76
93
< div className = "token-details-x__stake_group" >
77
94
< Text . Capture > { t ( 'earning' ) } </ Text . Capture >
0 commit comments