fix: bag footer layout (#5003)

* fix: bag footer layout

* pr feedback

* remove balance from footer
This commit is contained in:
Jordan Frankfurt 2022-10-26 10:37:35 -05:00 committed by GitHub
parent 8a5045f635
commit b3c44f20d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 21 deletions

@ -123,11 +123,9 @@ const Bag = () => {
return { totalEthPrice, totalUsdPrice } return { totalEthPrice, totalUsdPrice }
}, [itemsInBag, fetchedPriceData]) }, [itemsInBag, fetchedPriceData])
const { balance, sufficientBalance } = useMemo(() => { const sufficientBalance = useMemo(() => {
const balance: BigNumber = parseEther(balanceInEth.toString()) const balance = parseEther(balanceInEth.toString())
const sufficientBalance = isConnected ? BigNumber.from(balance).gte(totalEthPrice) : true return isConnected ? BigNumber.from(balance).gte(totalEthPrice) : true
return { balance, sufficientBalance }
}, [balanceInEth, totalEthPrice, isConnected]) }, [balanceInEth, totalEthPrice, isConnected])
const purchaseAssets = async (routingData: RouteResponse) => { const purchaseAssets = async (routingData: RouteResponse) => {
@ -278,7 +276,6 @@ const Bag = () => {
<ScrollingIndicator show={userCanScroll && scrollProgress < 100} /> <ScrollingIndicator show={userCanScroll && scrollProgress < 100} />
{hasAssetsToShow && !isProfilePage && ( {hasAssetsToShow && !isProfilePage && (
<BagFooter <BagFooter
balance={balance}
sufficientBalance={sufficientBalance} sufficientBalance={sufficientBalance}
isConnected={isConnected} isConnected={isConnected}
totalEthPrice={totalEthPrice} totalEthPrice={totalEthPrice}

@ -1,18 +1,46 @@
import { BigNumber } from '@ethersproject/bignumber' import { BigNumber } from '@ethersproject/bignumber'
import { Trans } from '@lingui/macro'
import Loader from 'components/Loader' import Loader from 'components/Loader'
import { Box } from 'nft/components/Box' import { Box } from 'nft/components/Box'
import { Column, Row } from 'nft/components/Flex' import { Column, Row } from 'nft/components/Flex'
import { bodySmall } from 'nft/css/common.css' import { bodySmall } from 'nft/css/common.css'
import { BagStatus } from 'nft/types' import { BagStatus } from 'nft/types'
import { ethNumberStandardFormatter, formatWeiToDecimal } from 'nft/utils' import { ethNumberStandardFormatter, formatWeiToDecimal } from 'nft/utils'
import { AlertTriangle } from 'react-feather'
import { useModalIsOpen, useToggleWalletModal } from 'state/application/hooks' import { useModalIsOpen, useToggleWalletModal } from 'state/application/hooks'
import { ApplicationModal } from 'state/application/reducer' import { ApplicationModal } from 'state/application/reducer'
import styled from 'styled-components/macro'
import { ThemedText } from 'theme' import { ThemedText } from 'theme'
import * as styles from './BagFooter.css' import * as styles from './BagFooter.css'
const Footer = styled.div<{ $showWarning: boolean }>`
border-top: 1px solid ${({ theme }) => theme.backgroundOutline};
color: ${({ theme }) => theme.textPrimary};
display: flex;
flex-direction: column;
padding: 12px 16px;
border-bottom-left-radius: 12px;
border-bottom-right-radius: 12px;
border-top-left-radius: ${({ $showWarning }) => ($showWarning ? '0' : '12')}px;
border-top-right-radius: ${({ $showWarning }) => ($showWarning ? '0' : '12')}px;
`
const WarningIcon = styled(AlertTriangle)`
width: 14px;
margin-right: 4px;
color: ${({ theme }) => theme.accentWarning};
`
const WarningText = styled(ThemedText.BodyPrimary)`
align-items: center;
color: ${({ theme }) => theme.accentWarning};
display: flex;
justify-content: center;
margin: 12px 0 !important;
text-align: center;
`
interface BagFooterProps { interface BagFooterProps {
balance: BigNumber
isConnected: boolean isConnected: boolean
sufficientBalance: boolean sufficientBalance: boolean
totalEthPrice: BigNumber totalEthPrice: BigNumber
@ -30,7 +58,6 @@ const PENDING_BAG_STATUSES = [
] ]
export const BagFooter = ({ export const BagFooter = ({
balance,
isConnected, isConnected,
sufficientBalance, sufficientBalance,
totalEthPrice, totalEthPrice,
@ -49,18 +76,7 @@ export const BagFooter = ({
return ( return (
<Column className={styles.footerContainer}> <Column className={styles.footerContainer}>
{showWarning && ( <Footer $showWarning={showWarning}>
<Row className={styles.warningContainer}>
{!sufficientBalance
? `Insufficient funds (${formatWeiToDecimal(balance.toString())} ETH)`
: `Something went wrong. Please try again.`}
</Row>
)}
<Column
borderTopLeftRadius={showWarning ? '0' : '12'}
borderTopRightRadius={showWarning ? '0' : '12'}
className={styles.footer}
>
<Column gap="4" paddingTop="8" paddingBottom="20"> <Column gap="4" paddingTop="8" paddingBottom="20">
<Row justifyContent="space-between"> <Row justifyContent="space-between">
<Box> <Box>
@ -76,6 +92,16 @@ export const BagFooter = ({
{`${ethNumberStandardFormatter(totalUsdPrice, true)}`} {`${ethNumberStandardFormatter(totalUsdPrice, true)}`}
</Row> </Row>
</Column> </Column>
{showWarning && (
<WarningText fontSize="14px" lineHeight="20px">
<WarningIcon />
{!sufficientBalance ? (
<Trans>Insufficient funds</Trans>
) : (
<Trans>Something went wrong. Please try again.</Trans>
)}
</WarningText>
)}
<Row <Row
as="button" as="button"
color="explicitWhite" color="explicitWhite"
@ -98,7 +124,7 @@ export const BagFooter = ({
? 'Transaction pending' ? 'Transaction pending'
: 'Pay'} : 'Pay'}
</Row> </Row>
</Column> </Footer>
</Column> </Column>
) )
} }