Skip to content

Commit

Permalink
[PAY-2152] Bring add funds up to spec (web) (#6725)
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondjacobson authored Nov 17, 2023
1 parent 48f90ca commit a2e38c2
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 95 deletions.
20 changes: 20 additions & 0 deletions packages/harmony/src/components/layout/Box/Box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ export const Box = styled.div<BoxProps>(
mr,
mb,
border,
borderTop,
borderRight,
borderBottom,
borderLeft,
borderRadius,
borderTopRightRadius,
borderBottomRightRadius,
borderBottomLeftRadius,
borderTopLeftRadius,
shadow,
flex,
alignSelf,
Expand Down Expand Up @@ -54,7 +62,19 @@ export const Box = styled.div<BoxProps>(
marginRight: marginR && spacing[marginR],
marginBottom: marginB && spacing[marginB],
border: border && `1px solid ${color.border[border]}`,
borderTop: borderTop && `1px solid ${color.border[borderTop]}`,
borderRight: borderRight && `1px solid ${color.border[borderRight]}`,
borderBottom: borderBottom && `1px solid ${color.border[borderBottom]}`,
borderLeft: borderLeft && `1px solid ${color.border[borderLeft]}`,
borderRadius: borderRadius && cornerRadius[borderRadius],
borderTopRightRadius:
borderTopRightRadius && cornerRadius[borderTopRightRadius],
borderBottomRightRadius:
borderBottomRightRadius && cornerRadius[borderBottomRightRadius],
borderBottomLeftRadius:
borderBottomLeftRadius && cornerRadius[borderBottomLeftRadius],
borderTopLeftRadius:
borderTopLeftRadius && cornerRadius[borderTopLeftRadius],
flex,
alignSelf
}
Expand Down
16 changes: 16 additions & 0 deletions packages/harmony/src/components/layout/Box/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,24 @@ export type BoxProps = {

/** Border */
border?: BorderColors
/** Border Top */
borderTop?: BorderColors
/** Border Right */
borderRight?: BorderColors
/** Border Bottom */
borderBottom?: BorderColors
/** Border Left */
borderLeft?: BorderColors
/** Border Radius */
borderRadius?: CornerRadiusOptions
/** Border Top Right Radius */
borderTopRightRadius?: CornerRadiusOptions
/** Border Bottom Right Radius */
borderBottomRightRadius?: CornerRadiusOptions
/** Border Bottom Left Radius */
borderBottomLeftRadius?: CornerRadiusOptions
/** Border Top Left Radius */
borderTopLeftRadius?: CornerRadiusOptions

/** Elevation Shadow */
shadow?: ShadowOptions
Expand Down
29 changes: 24 additions & 5 deletions packages/web/src/components/add-funds-modal/AddFundsModal.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { useCallback, useState } from 'react'

import { useAddFundsModal } from '@audius/common'
import {
useAddFundsModal,
buyUSDCActions,
USDCOnRampProvider
} from '@audius/common'
import { ModalContent, ModalHeader } from '@audius/stems'
import cn from 'classnames'
import { useDispatch } from 'react-redux'

import { AddFunds, Method } from 'components/add-funds/AddFunds'
import { Text } from 'components/typography'
Expand All @@ -20,25 +25,39 @@ const messages = {

type Page = 'add-funds' | 'crypto-transfer'

const DEFAULT_PURCHASE_AMOUNT_CENTS = 10 * 100

export const AddFundsModal = () => {
const { isOpen, onClose } = useAddFundsModal()
const dispatch = useDispatch()
const mobile = isMobile()

const [page, setPage] = useState<Page>('add-funds')

const handleClose = useCallback(() => {
onClose()
}, [onClose])
setPage('add-funds')
}, [setPage])

const handleClosed = useCallback(() => {
setPage('add-funds')
}, [setPage])

const handleContinue = useCallback(
(method: Method) => {
setPage('crypto-transfer')
if (method === 'crypto') {
setPage('crypto-transfer')
} else {
dispatch(
buyUSDCActions.onrampOpened({
provider: USDCOnRampProvider.STRIPE,
purchaseInfo: {
desiredAmount: DEFAULT_PURCHASE_AMOUNT_CENTS
}
})
)
}
},
[setPage]
[setPage, dispatch]
)

return (
Expand Down
5 changes: 5 additions & 0 deletions packages/web/src/components/add-funds/AddFunds.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@
.buttonContainer.mobile {
flex-direction: column;
}

.summaryTableRow {
flex-direction: column;
align-items: flex-start;
}
5 changes: 3 additions & 2 deletions packages/web/src/components/add-funds/AddFunds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const AddFunds = ({
})
const [selectedMethod, setSelectedMethod] = useState<Method>('card')
const mobile = isMobile()
const { data: balance } = useUSDCBalance()
const { data: balance } = useUSDCBalance({ isPolling: true })
const balanceNumber = formatUSDCWeiToFloorCentsNumber(
(balance ?? new BN(0)) as BNUSDC
)
Expand Down Expand Up @@ -92,7 +92,7 @@ export const AddFunds = ({
})}
>
<Flex direction='column' w='100%' gap='xl'>
<Box h='unit6' border='strong' p='m'>
<Box h='unit6' border='strong' p='m' borderRadius='s'>
<Flex alignItems='center' justifyContent='space-between'>
<Flex alignItems='center'>
<IconLogoCircleUSDC />
Expand All @@ -113,6 +113,7 @@ export const AddFunds = ({
withRadioOptions
onRadioChange={handleChangeOption}
selectedRadioOption={selectedMethod}
rowClassName={mobile ? styles.summaryTableRow : undefined}
/>
<Button
variant={ButtonType.PRIMARY}
Expand Down
37 changes: 0 additions & 37 deletions packages/web/src/components/address-tile/AddressTile.module.css

This file was deleted.

93 changes: 74 additions & 19 deletions packages/web/src/components/address-tile/AddressTile.tsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,104 @@
import { ReactNode, useCallback, useContext } from 'react'
import { useCallback, useContext } from 'react'

import { shortenSPLAddress } from '@audius/common'
import { Text, IconCopy, PlainButton } from '@audius/harmony'
import {
BNUSDC,
decimalIntegerToHumanReadable,
formatUSDCWeiToCeilingCentsNumber,
shortenSPLAddress,
useUSDCBalance
} from '@audius/common'
import {
Text,
IconCopy,
PlainButton,
IconComponent,
Flex,
Box,
useTheme
} from '@audius/harmony'
import { BN } from 'bn.js'

import { Icon } from 'components/Icon'
import { ToastContext } from 'components/toast/ToastContext'
import { isMobile } from 'utils/clientUtil'
import { copyToClipboard } from 'utils/clipboardUtil'

import styles from './AddressTile.module.css'

const messages = {
usdcBalance: 'USDC Balance',
copied: 'Copied to Clipboard!'
}

type AddressTileProps = {
address: string
left?: ReactNode
right?: ReactNode
iconLeft: IconComponent
iconRight?: IconComponent
}

export const AddressTile = ({ address, left, right }: AddressTileProps) => {
export const AddressTile = ({
address,
iconLeft: IconLeft,
iconRight: IconRight
}: AddressTileProps) => {
const { color } = useTheme()
const { toast } = useContext(ToastContext)
const mobile = isMobile()

const { data: balance } = useUSDCBalance({ isPolling: true })
const balanceNumber = formatUSDCWeiToCeilingCentsNumber(
(balance ?? new BN(0)) as BNUSDC
)
const balanceFormatted = decimalIntegerToHumanReadable(balanceNumber)

const handleCopyPress = useCallback(() => {
copyToClipboard(address)
toast(messages.copied)
}, [address, toast])

const defaultRight = (
<PlainButton>
<Icon icon={IconCopy} onClick={handleCopyPress} />
<PlainButton onClick={handleCopyPress}>
<IconCopy size='s' color='subdued' />
</PlainButton>
)

return (
<div className={styles.addressContainer}>
<div className={styles.leftContainer}>{left}</div>
<div className={styles.middleContainer}>
<Text variant='body' className={styles.address}>
{shortenSPLAddress(address, mobile ? 6 : 12)}
<Flex direction='column' border='default' borderRadius='s'>
<Flex p='l' alignItems='center' justifyContent='space-between'>
<Flex alignItems='center'>
<IconLeft />
<Box pl='s'>
<Text variant='title' size='m'>
{messages.usdcBalance}
</Text>
</Box>
</Flex>
<Text variant='title' size='l' strength='strong'>
{`$${balanceFormatted}`}
</Text>
</div>
<div className={styles.rightContainer}>{right ?? defaultRight}</div>
</div>
</Flex>
<Flex
css={{ backgroundColor: color.background.surface1 }}
alignItems='stretch'
justifyContent='space-between'
borderTop='default'
borderBottomLeftRadius='s'
borderBottomRightRadius='s'
>
<Box p='l' borderRadius='s'>
<Text
css={{
userSelect: 'text',
overflow: 'hidden',
textOverflow: 'ellipsis',
lineHeight: '125%'
}}
variant='body'
>
{mobile ? shortenSPLAddress(address, 20) : address}
</Text>
</Box>
<Flex alignItems='center' borderLeft='default' pr='l' pl='l'>
{IconRight ? <IconRight /> : defaultRight}
</Flex>
</Flex>
</Flex>
)
}
6 changes: 4 additions & 2 deletions packages/web/src/components/summary-table/SummaryTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export type SummaryTableProps = {
withRadioOptions?: boolean
selectedRadioOption?: string
onRadioChange?: (e: ChangeEvent<HTMLInputElement>) => void
rowClassName?: string
}

export const SummaryTable = ({
Expand All @@ -74,7 +75,8 @@ export const SummaryTable = ({
summaryValueColor = 'secondary',
withRadioOptions,
selectedRadioOption,
onRadioChange
onRadioChange,
rowClassName
}: SummaryTableProps) => {
const { color } = useTheme()
// Collapsible is collapsed by default
Expand All @@ -91,7 +93,7 @@ export const SummaryTable = ({
justifyContent='space-between'
pv='m'
ph='xl'
className={styles.row}
className={cn(styles.row, rowClassName)}
css={{ opacity: disabled ? 0.5 : 1 }}
>
<Flex alignItems='center' gap='s'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
flex-direction: column;
}

.data {
display: flex;
flex-direction: column;
gap: var(--unit-6);
}

.qr {
width: 160px;
height: 160px;
Expand All @@ -28,13 +22,3 @@
align-items: center;
justify-content: center;
}

.columns {
display: flex;
gap: var(--unit-4);
align-items: center;
}

.columns.mobile {
flex-direction: column;
}
Loading

0 comments on commit a2e38c2

Please sign in to comment.