Skip to content

Commit

Permalink
[PAY-2128] Implement general coinflow scaffolding (#6847)
Browse files Browse the repository at this point in the history
Co-authored-by: Randy Schott <1815175+schottra@users.noreply.github.com>
Co-authored-by: Dharit Tantiviramanond <dharit.tan@gmail.com>
Co-authored-by: Marcus Pasell <3690498+rickyrombo@users.noreply.github.com>
  • Loading branch information
4 people committed Dec 13, 2023
1 parent cd465c9 commit 0639cad
Show file tree
Hide file tree
Showing 56 changed files with 1,140 additions and 245 deletions.
257 changes: 253 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/common/src/hooks/purchaseContent/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const CUSTOM_AMOUNT = 'customAmount'
export const AMOUNT_PRESET = 'amountPreset'
export const PURCHASE_METHOD = 'purchaseMethod'
export const PURCHASE_VENDOR = 'purchaseVendor'
export const PAGE = 'page'

// Pay between $1 and $100 extra
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import {
AMOUNT_PRESET,
CENTS_TO_USDC_MULTIPLIER,
CUSTOM_AMOUNT,
PURCHASE_METHOD
PURCHASE_METHOD,
PURCHASE_VENDOR
} from './constants'
import { PayExtraAmountPresetValues, PayExtraPreset } from './types'
import { getExtraAmount } from './utils'
Expand Down Expand Up @@ -50,17 +51,24 @@ export const usePurchaseContentFormConfiguration = ({
const isUnlocking = !error && isContentPurchaseInProgress(stage)
const { data: balanceBN } = useUSDCBalance()
const balance = USDC(balanceBN ?? new BN(0)).value

const initialValues: PurchaseContentValues = {
[CUSTOM_AMOUNT]: undefined,
[AMOUNT_PRESET]: PayExtraPreset.NONE,
[PURCHASE_METHOD]:
balance >= BigInt(price * CENTS_TO_USDC_MULTIPLIER)
? PurchaseMethod.BALANCE
: PurchaseMethod.CARD
: PurchaseMethod.CARD,
[PURCHASE_VENDOR]: undefined
}

const onSubmit = useCallback(
({ customAmount, amountPreset, purchaseMethod }: PurchaseContentValues) => {
({
customAmount,
amountPreset,
purchaseMethod,
purchaseVendor
}: PurchaseContentValues) => {
if (isUnlocking || !track?.track_id) return

if (
Expand All @@ -77,6 +85,7 @@ export const usePurchaseContentFormConfiguration = ({
dispatch(
startPurchaseContentFlow({
purchaseMethod,
purchaseVendor,
extraAmount,
extraAmountPreset: amountPreset,
contentId: track.track_id,
Expand Down
6 changes: 4 additions & 2 deletions packages/common/src/hooks/purchaseContent/validation.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { z } from 'zod'

import { PurchaseMethod } from 'models/PurchaseContent'
import { PurchaseMethod, PurchaseVendor } from 'models/PurchaseContent'

import {
AMOUNT_PRESET,
CUSTOM_AMOUNT,
PURCHASE_VENDOR,
PURCHASE_METHOD,
maximumPayExtraAmountCents,
minimumPayExtraAmountCents
Expand All @@ -25,7 +26,8 @@ const createPurchaseContentSchema = () => {
})
.optional(),
[AMOUNT_PRESET]: z.nativeEnum(PayExtraPreset),
[PURCHASE_METHOD]: z.nativeEnum(PurchaseMethod)
[PURCHASE_METHOD]: z.nativeEnum(PurchaseMethod),
[PURCHASE_VENDOR]: z.nativeEnum(PurchaseVendor).optional()
})
.refine(
({ amountPreset, customAmount }) => {
Expand Down
Loading

0 comments on commit 0639cad

Please sign in to comment.