forked from austintgriffith/burner-wallet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request austintgriffith#218 from MaxStalker/feature/210-di…
…splay-tokens Display amount of tokens in advanced mode
- Loading branch information
Showing
2 changed files
with
50 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,69 @@ | ||
import React from 'react'; | ||
import { Flex, Text, Image } from "rimble-ui"; | ||
import styled from 'styled-components' | ||
|
||
export default ({icon, text, amount, currencyDisplay}) => { | ||
const expertMode = localStorage.getItem("expertMode") === "true" | ||
// Right now "expertMode" is enabled by default. To disable it by default, remove the following line. | ||
|| localStorage.getItem("expertMode") === null; | ||
const Fiat = styled(Text).attrs(()=>({ | ||
fontSize: 4, | ||
fontWeight: 4 | ||
}))``; | ||
|
||
let opacity = 1 | ||
const Token = styled(Text).attrs(()=>({ | ||
fontSize: 1, | ||
}))` | ||
color: var(--secondary-btn-text-color) | ||
`; | ||
|
||
const Amount = styled(Flex)` | ||
flex-direction: column; | ||
align-items: flex-end; | ||
`; | ||
|
||
const tokenDisplay = (amount, symbol = "", maximumFractionDigits = 2) => { | ||
const locale = localStorage.getItem('i18nextLng') | ||
const formatter = new Intl.NumberFormat(locale, { | ||
minimumFractionDigits: 2, | ||
maximumFractionDigits: maximumFractionDigits, | ||
}); | ||
return `${formatter.format(amount)} ${symbol}` | ||
}; | ||
|
||
const valuableTokens = ["ETH"] | ||
|
||
export default ({icon, text, amount, tokenAmount, currencyDisplay}) => { | ||
let opacity; | ||
let fiatValue; | ||
let tokenValue; | ||
const floatNumbers = valuableTokens.includes(text) ? 5 : 2 | ||
|
||
if(isNaN(amount)){ | ||
opacity = 0.25 | ||
opacity = 0.25; | ||
|
||
/* NOTE: Sometimes the exchangeRate to fiat wasn't loaded yet and hence | ||
* amount can become NaN. In this case, we simply pass 0 to currencyDisplay | ||
*/ | ||
|
||
fiatValue = currencyDisplay(0); | ||
tokenValue = tokenDisplay(0); | ||
}else{ | ||
opacity = 1; | ||
fiatValue = currencyDisplay(amount); | ||
tokenValue = tokenDisplay(tokenAmount || amount, text, floatNumbers); | ||
} | ||
|
||
return ( | ||
<Flex opacity={opacity} justifyContent={"space-between"} alignItems={"center"} borderBottom={1} borderColor={"#DFDFDF"} mb={3} pb={3}> | ||
{expertMode ? ( | ||
<Flex alignItems={"center"}> | ||
<Image src={icon} height={"50px"} width={"50px"} mr={3} bg="transparent" /> | ||
<Text> | ||
{text} | ||
</Text> | ||
</Flex> | ||
) : ( | ||
<Text> | ||
Your balance | ||
</Text> | ||
)} | ||
|
||
<Text fontSize={4}> | ||
<Amount> | ||
<Fiat>{fiatValue}</Fiat> | ||
<Token>{tokenValue}</Token> | ||
</Amount> | ||
|
||
{/* NOTE: Sometimes the exchangeRate to fiat wasn't loaded yet and hence | ||
* amount can become NaN. In this case, we simply pass 0 to | ||
* currencyDisplay.*/} | ||
{isNaN(amount) ? currencyDisplay(0) : currencyDisplay(amount)} | ||
</Text> | ||
</Flex> | ||
) | ||
}; |