-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
68aa7b5
commit 026aead
Showing
25 changed files
with
467 additions
and
153 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
packages/common/src/store/ui/modals/add-funds-modal/index.ts
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { createModal } from '../createModal' | ||
|
||
export type AddFundsModalState = { | ||
isOpen: boolean | ||
} | ||
|
||
const AddFundsModal = createModal<AddFundsModalState>({ | ||
reducerPath: 'AddFundsModal', | ||
initialState: { | ||
isOpen: false | ||
}, | ||
sliceSelector: (state) => state.ui.modals | ||
}) | ||
|
||
export const { hook: useAddFundsModal, reducer: addFundsModalReducer } = | ||
AddFundsModal |
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
13 changes: 13 additions & 0 deletions
13
packages/web/src/components/add-funds-modal/AddFundsModal.module.css
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.modal { | ||
width: 720px; | ||
} | ||
|
||
.modalHeader { | ||
text-align: center; | ||
} | ||
|
||
.modalHeader.mobile { | ||
margin: 0; | ||
padding: 0; | ||
border: none; | ||
} |
80 changes: 80 additions & 0 deletions
80
packages/web/src/components/add-funds-modal/AddFundsModal.tsx
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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { useCallback, useState } from 'react' | ||
|
||
import { useAddFundsModal } from '@audius/common' | ||
import { ModalContent, ModalHeader } from '@audius/stems' | ||
import cn from 'classnames' | ||
|
||
import { AddFunds, Method } from 'components/add-funds/AddFunds' | ||
import { Text } from 'components/typography' | ||
import { USDCManualTransfer } from 'components/usdc-manual-transfer/USDCManualTransfer' | ||
import ModalDrawer from 'pages/audio-rewards-page/components/modals/ModalDrawer' | ||
import { isMobile } from 'utils/clientUtil' | ||
import zIndex from 'utils/zIndex' | ||
|
||
import styles from './AddFundsModal.module.css' | ||
|
||
const messages = { | ||
addFunds: 'Add Funds', | ||
cryptoTransfer: 'Crypto Transfer' | ||
} | ||
|
||
type Page = 'add-funds' | 'crypto-transfer' | ||
|
||
export const AddFundsModal = () => { | ||
const { isOpen, onClose } = useAddFundsModal() | ||
const mobile = isMobile() | ||
|
||
const [page, setPage] = useState<Page>('add-funds') | ||
|
||
const handleClose = useCallback(() => { | ||
onClose() | ||
}, [onClose]) | ||
|
||
const handleClosed = useCallback(() => { | ||
setPage('add-funds') | ||
}, [setPage]) | ||
|
||
const handleContinue = useCallback( | ||
(method: Method) => { | ||
setPage('crypto-transfer') | ||
}, | ||
[setPage] | ||
) | ||
|
||
return ( | ||
<ModalDrawer | ||
zIndex={zIndex.ADD_FUNDS_MODAL} | ||
size={'small'} | ||
onClose={handleClose} | ||
isOpen={isOpen} | ||
onClosed={handleClosed} | ||
bodyClassName={styles.modal} | ||
useGradientTitle={false} | ||
dismissOnClickOutside | ||
isFullscreen={false} | ||
> | ||
<ModalHeader | ||
className={cn(styles.modalHeader, { [styles.mobile]: mobile })} | ||
onClose={onClose} | ||
showDismissButton={!mobile} | ||
> | ||
<Text | ||
variant='label' | ||
color='neutralLight2' | ||
size='xLarge' | ||
strength='strong' | ||
className={styles.title} | ||
> | ||
{page === 'add-funds' ? messages.addFunds : messages.cryptoTransfer} | ||
</Text> | ||
</ModalHeader> | ||
<ModalContent> | ||
{page === 'add-funds' ? ( | ||
<AddFunds onContinue={handleContinue} /> | ||
) : ( | ||
<USDCManualTransfer onClose={handleClose} /> | ||
)} | ||
</ModalContent> | ||
</ModalDrawer> | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.root { | ||
display: flex; | ||
flex-direction: column; | ||
gap: var(--unit-6); | ||
} | ||
|
||
.buttonContainer { | ||
display: flex; | ||
flex-direction: row; | ||
gap: var(--unit-2); | ||
} | ||
|
||
.buttonContainer.mobile { | ||
flex-direction: column; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import { ChangeEvent, useCallback, useState } from 'react' | ||
|
||
import { | ||
BNUSDC, | ||
decimalIntegerToHumanReadable, | ||
formatUSDCWeiToFloorCentsNumber, | ||
useCreateUserbankIfNeeded, | ||
useUSDCBalance | ||
} from '@audius/common' | ||
import { | ||
Box, | ||
Button, | ||
ButtonType, | ||
Flex, | ||
Text, | ||
IconLogoCircleUSDC, | ||
IconCreditCard, | ||
IconTransaction, | ||
FilterButton, | ||
FilterButtonType | ||
} from '@audius/harmony' | ||
import { BN } from 'bn.js' | ||
import cn from 'classnames' | ||
|
||
import { SummaryTable, SummaryTableItem } from 'components/summary-table' | ||
import { track } from 'services/analytics' | ||
import { audiusBackendInstance } from 'services/audius-backend/audius-backend-instance' | ||
import { isMobile } from 'utils/clientUtil' | ||
|
||
import styles from './AddFunds.module.css' | ||
|
||
const messages = { | ||
usdcBalance: 'USDC Balance', | ||
paymentMethod: 'Payment Method', | ||
withCard: 'Add funds with Card', | ||
withCrypto: 'Add funds with crypto transfer', | ||
continue: 'Continue' | ||
} | ||
|
||
export type Method = 'card' | 'crypto' | ||
|
||
export const AddFunds = ({ | ||
onContinue | ||
}: { | ||
onContinue: (method: Method) => void | ||
}) => { | ||
useCreateUserbankIfNeeded({ | ||
recordAnalytics: track, | ||
audiusBackendInstance, | ||
mint: 'usdc' | ||
}) | ||
const [selectedMethod, setSelectedMethod] = useState<Method>('card') | ||
const mobile = isMobile() | ||
const { data: balance } = useUSDCBalance() | ||
const balanceNumber = formatUSDCWeiToFloorCentsNumber( | ||
(balance ?? new BN(0)) as BNUSDC | ||
) | ||
const balanceFormatted = decimalIntegerToHumanReadable(balanceNumber) | ||
|
||
const items: SummaryTableItem[] = [ | ||
{ | ||
id: 'card', | ||
label: messages.withCard, | ||
icon: IconCreditCard, | ||
value: ( | ||
<FilterButton | ||
initialSelectionIndex={0} | ||
variant={FilterButtonType.REPLACE_LABEL} | ||
options={[{ label: 'Stripe' }]} | ||
/> | ||
) | ||
}, | ||
{ | ||
id: 'crypto', | ||
label: messages.withCrypto, | ||
icon: IconTransaction | ||
} | ||
] | ||
|
||
const handleChangeOption = useCallback( | ||
(e: ChangeEvent<HTMLInputElement>) => { | ||
setSelectedMethod(e.target.value as Method) | ||
}, | ||
[setSelectedMethod] | ||
) | ||
|
||
return ( | ||
<div className={styles.root}> | ||
<div | ||
className={cn(styles.buttonContainer, { | ||
[styles.mobile]: mobile | ||
})} | ||
> | ||
<Flex direction='column' w='100%' gap='xl'> | ||
<Box h='unit6' border='strong' p='m'> | ||
<Flex alignItems='center' justifyContent='space-between'> | ||
<Flex alignItems='center'> | ||
<IconLogoCircleUSDC /> | ||
<Box pl='s'> | ||
<Text variant='title' size='m'> | ||
{messages.usdcBalance} | ||
</Text> | ||
</Box> | ||
</Flex> | ||
<Text variant='title' size='l' strength='strong'> | ||
{`$${balanceFormatted}`} | ||
</Text> | ||
</Flex> | ||
</Box> | ||
<SummaryTable | ||
title={messages.paymentMethod} | ||
items={items} | ||
withRadioOptions | ||
onRadioChange={handleChangeOption} | ||
selectedRadioOption={selectedMethod} | ||
/> | ||
<Button | ||
variant={ButtonType.PRIMARY} | ||
fullWidth | ||
onClick={() => onContinue(selectedMethod)} | ||
> | ||
{messages.continue} | ||
</Button> | ||
</Flex> | ||
</div> | ||
</div> | ||
) | ||
} |
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 |
---|---|---|
|
@@ -29,3 +29,7 @@ | |
.rowGrayBackground { | ||
background: var(--background-surface-1); | ||
} | ||
|
||
.radioGroup { | ||
width: 100%; | ||
} |
Oops, something went wrong.