Commit 14b02eda authored by Jack Short's avatar Jack Short Committed by GitHub

feat: initial pay with any token setup (#5823)

* feat: initial pay with any token ui setup

* reordering

* refactoring

* refactoring
parent 60bc2a16
...@@ -6,16 +6,19 @@ import { BrowserEvent, InterfaceElementName, NFTEventName } from '@uniswap/analy ...@@ -6,16 +6,19 @@ import { BrowserEvent, InterfaceElementName, NFTEventName } from '@uniswap/analy
import { useWeb3React } from '@web3-react/core' import { useWeb3React } from '@web3-react/core'
import Column from 'components/Column' import Column from 'components/Column'
import Loader from 'components/Loader' import Loader from 'components/Loader'
import CurrencyLogo from 'components/Logo/CurrencyLogo'
import Row from 'components/Row' import Row from 'components/Row'
import { SupportedChainId } from 'constants/chains' import { SupportedChainId } from 'constants/chains'
import { PayWithAnyTokenVariant, usePayWithAnyTokenFlag } from 'featureFlags/flags/payWithAnyToken'
import { useCurrency } from 'hooks/Tokens'
import { useBag } from 'nft/hooks/useBag' import { useBag } from 'nft/hooks/useBag'
import { useWalletBalance } from 'nft/hooks/useWalletBalance' import { useWalletBalance } from 'nft/hooks/useWalletBalance'
import { BagStatus } from 'nft/types' import { BagStatus } from 'nft/types'
import { ethNumberStandardFormatter, formatWeiToDecimal } from 'nft/utils' import { ethNumberStandardFormatter, formatWeiToDecimal } from 'nft/utils'
import { PropsWithChildren, useMemo } from 'react' import { PropsWithChildren, useMemo } from 'react'
import { AlertTriangle } from 'react-feather' import { AlertTriangle, ChevronDown } from 'react-feather'
import { useToggleWalletModal } from 'state/application/hooks' import { useToggleWalletModal } from 'state/application/hooks'
import styled from 'styled-components/macro' import styled, { useTheme } from 'styled-components/macro'
import { ThemedText } from 'theme' import { ThemedText } from 'theme'
import { switchChain } from 'utils/switchChain' import { switchChain } from 'utils/switchChain'
...@@ -39,6 +42,17 @@ const FooterHeader = styled(Column)<{ warningText?: boolean }>` ...@@ -39,6 +42,17 @@ const FooterHeader = styled(Column)<{ warningText?: boolean }>`
padding-bottom: ${({ warningText }) => (warningText ? '8px' : '20px')}; padding-bottom: ${({ warningText }) => (warningText ? '8px' : '20px')};
` `
const CurrencyRow = styled(Row)<{ warningText?: boolean }>`
padding-top: 4px;
padding-bottom: ${({ warningText }) => (warningText ? '8px' : '20px')};
justify-content: space-between;
align-items: start;
`
const TotalColumn = styled(Column)`
text-align: end;
`
const WarningIcon = styled(AlertTriangle)` const WarningIcon = styled(AlertTriangle)`
width: 14px; width: 14px;
margin-right: 4px; margin-right: 4px;
...@@ -53,6 +67,11 @@ const WarningText = styled(ThemedText.BodyPrimary)` ...@@ -53,6 +67,11 @@ const WarningText = styled(ThemedText.BodyPrimary)`
text-align: center; text-align: center;
` `
const CurrencyInput = styled(Row)`
gap: 8px;
cursor: pointer;
`
const PayButton = styled(Row)<{ disabled?: boolean }>` const PayButton = styled(Row)<{ disabled?: boolean }>`
background: ${({ theme }) => theme.accentAction}; background: ${({ theme }) => theme.accentAction};
color: ${({ theme }) => theme.accentTextLightPrimary}; color: ${({ theme }) => theme.accentTextLightPrimary};
...@@ -116,8 +135,11 @@ export const BagFooter = ({ ...@@ -116,8 +135,11 @@ export const BagFooter = ({
eventProperties, eventProperties,
}: BagFooterProps) => { }: BagFooterProps) => {
const toggleWalletModal = useToggleWalletModal() const toggleWalletModal = useToggleWalletModal()
const theme = useTheme()
const { account, chainId, connector } = useWeb3React() const { account, chainId, connector } = useWeb3React()
const connected = Boolean(account && chainId) const connected = Boolean(account && chainId)
const shouldUsePayWithAnyToken = usePayWithAnyTokenFlag() === PayWithAnyTokenVariant.Enabled
const inputCurrency = useCurrency('ETH')
const setBagExpanded = useBag((state) => state.setBagExpanded) const setBagExpanded = useBag((state) => state.setBagExpanded)
...@@ -172,24 +194,54 @@ export const BagFooter = ({ ...@@ -172,24 +194,54 @@ export const BagFooter = ({
return ( return (
<FooterContainer> <FooterContainer>
<Footer> <Footer>
<FooterHeader gap="xs" warningText={!!warningText}> {shouldUsePayWithAnyToken && (
<Row justify="space-between"> <CurrencyRow>
<div> <Column gap="xs">
<ThemedText.HeadlineSmall>Total</ThemedText.HeadlineSmall> <ThemedText.SubHeaderSmall>
</div> <Trans>Pay with</Trans>
<div> </ThemedText.SubHeaderSmall>
<CurrencyInput>
<CurrencyLogo currency={inputCurrency} size="24px" />
<ThemedText.HeadlineSmall fontWeight={500} lineHeight="24px">
{inputCurrency?.symbol}
</ThemedText.HeadlineSmall>
<ChevronDown size={20} color={theme.textSecondary} />
</CurrencyInput>
</Column>
<TotalColumn gap="xs">
<ThemedText.SubHeaderSmall marginBottom="4px">
<Trans>Total</Trans>
</ThemedText.SubHeaderSmall>
<ThemedText.HeadlineSmall> <ThemedText.HeadlineSmall>
{formatWeiToDecimal(totalEthPrice.toString())}&nbsp;ETH {formatWeiToDecimal(totalEthPrice.toString())}&nbsp;ETH
</ThemedText.HeadlineSmall> </ThemedText.HeadlineSmall>
</div> <ThemedText.BodySmall color="textSecondary" lineHeight="20px">{`${ethNumberStandardFormatter(
</Row> totalUsdPrice,
<Row justify="flex-end"> true
<ThemedText.BodySmall color="textSecondary" lineHeight="20px">{`${ethNumberStandardFormatter( )}`}</ThemedText.BodySmall>
totalUsdPrice, </TotalColumn>
true </CurrencyRow>
)}`}</ThemedText.BodySmall> )}
</Row> {!shouldUsePayWithAnyToken && (
</FooterHeader> <FooterHeader gap="xs" warningText={!!warningText}>
<Row justify="space-between">
<div>
<ThemedText.HeadlineSmall>Total</ThemedText.HeadlineSmall>
</div>
<div>
<ThemedText.HeadlineSmall>
{formatWeiToDecimal(totalEthPrice.toString())}&nbsp;ETH
</ThemedText.HeadlineSmall>
</div>
</Row>
<Row justify="flex-end">
<ThemedText.BodySmall color="textSecondary" lineHeight="20px">{`${ethNumberStandardFormatter(
totalUsdPrice,
true
)}`}</ThemedText.BodySmall>
</Row>
</FooterHeader>
)}
<TraceEvent <TraceEvent
events={[BrowserEvent.onClick]} events={[BrowserEvent.onClick]}
name={NFTEventName.NFT_BUY_BAG_PAY} name={NFTEventName.NFT_BUY_BAG_PAY}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment