Skip to content

Commit

Permalink
[PAY-2472] Make USDCManualTransfer modal buy button actually buy (#7571)
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondjacobson authored Feb 13, 2024
1 parent 8ebc8cb commit 030ce6a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import {
usePayExtraPresets,
isTrackStreamPurchaseable,
isTrackDownloadPurchaseable,
PurchaseableTrackMetadata
PurchaseableTrackMetadata,
PURCHASE_METHOD
} from '@audius/common/hooks'
import {
PurchaseMethod,
PurchaseVendor,
Track,
USDCPurchaseConditions
Expand All @@ -28,7 +30,7 @@ import { USDC } from '@audius/fixed-decimal'
import { Flex, IconCart } from '@audius/harmony'
import { ModalContentPages, ModalFooter, ModalHeader } from '@audius/stems'
import cn from 'classnames'
import { Formik, useFormikContext } from 'formik'
import { Formik, useField, useFormikContext } from 'formik'
import { useDispatch, useSelector } from 'react-redux'
import { toFormikValidationSchema } from 'zod-formik-adapter'

Expand Down Expand Up @@ -89,9 +91,10 @@ const RenderForm = ({
} = purchaseConditions
const { error, isUnlocking, purchaseSummaryValues, stage, page } =
usePurchaseContentFormState({ price })
const [, , { setValue: setPurchaseMethod }] = useField(PURCHASE_METHOD)
const currentPageIndex = pageToPageIndex(page)

const { resetForm } = useFormikContext()
const { submitForm, resetForm } = useFormikContext()
const { history } = useHistoryContext()

// Reset form on track change
Expand All @@ -104,10 +107,15 @@ const RenderForm = ({
}
}, [stage, permalink, dispatch, history])

const handleClose = useCallback(() => {
const handleUSDCManualTransferClose = useCallback(() => {
dispatch(setPurchasePage({ page: PurchaseContentPage.PURCHASE }))
}, [dispatch])

const handleUSDCManualTransferPurchase = useCallback(() => {
setPurchaseMethod(PurchaseMethod.BALANCE)
submitForm()
}, [submitForm, setPurchaseMethod])

return (
<ModalForm className={cn(styles.modalRoot, { [styles.mobile]: isMobile })}>
<ModalHeader
Expand Down Expand Up @@ -156,7 +164,11 @@ const RenderForm = ({
</Flex>
</Flex>
</>
<USDCManualTransfer onClose={handleClose} amountInCents={price} />
<USDCManualTransfer
onClose={handleUSDCManualTransferClose}
amountInCents={price}
onPurchase={handleUSDCManualTransferPurchase}
/>
</ModalContentPages>
<ModalFooter className={styles.footer}>
{page === PurchaseContentPage.PURCHASE ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ const messages = {

export const USDCManualTransfer = ({
onClose,
amountInCents
amountInCents,
onPurchase
}: {
onClose: () => void
amountInCents?: number
onPurchase?: () => void
}) => {
const stage = useSelector(getPurchaseContentFlowStage)
const error = useSelector(getPurchaseContentError)
Expand Down Expand Up @@ -130,6 +132,7 @@ export const USDCManualTransfer = ({
color='lightGreen'
disabled={isBuyButtonDisabled}
type='submit'
onClick={onPurchase}
>
{messages.buy(
USDC(amount).toLocaleString('en-us', {
Expand Down

0 comments on commit 030ce6a

Please sign in to comment.