Skip to content

Commit

Permalink
Revert "[PAY-2276] Selectable amounts for coinflow add funds web (#69… (
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondjacobson committed Dec 18, 2023
1 parent 53d3802 commit 56704b8
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 243 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { useRemoteVar } from '../useRemoteVar'
import { PayExtraAmountPresetValues, PayExtraPreset } from './types'

/** Extracts and parses the Pay Extra presets from remote config */
export const usePayExtraPresets = (key: StringKeys) => {
const configValue = useRemoteVar(key)
export const usePayExtraPresets = () => {
const configValue = useRemoteVar(StringKeys.PAY_EXTRA_PRESET_CENT_AMOUNTS)
return useMemo<PayExtraAmountPresetValues>(() => {
const [low, medium, high] = parseIntList(configValue)
return {
Expand Down
1 change: 0 additions & 1 deletion packages/common/src/services/remote-config/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ export const remoteConfigStringDefaults: {
[StringKeys.STRIPE_ALLOWED_COUNTRIES_2_LETTER]: '',
[StringKeys.AUDIO_FEATURES_DEGRADED_TEXT]: null,
[StringKeys.PAY_EXTRA_PRESET_CENT_AMOUNTS]: '200,500,1000',
[StringKeys.COINFLOW_ADD_FUNDS_PRESET_CENT_AMOUNTS]: '200,500,1000',
[StringKeys.EXPLORE_PREMIUM_DENIED_USERS]: ''
}

Expand Down
5 changes: 1 addition & 4 deletions packages/common/src/services/remote-config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,7 @@ export enum StringKeys {
PAY_EXTRA_PRESET_CENT_AMOUNTS = 'PAY_EXTRA_PRESET_CENT_AMOUNTS',

/** Denylist of user ids for explore premium tracks page */
EXPLORE_PREMIUM_DENIED_USERS = 'EXPLORE_PREMIUM_DENIED_USERS',

/** Add funds preset amounts for Coinflow */
COINFLOW_ADD_FUNDS_PRESET_CENT_AMOUNTS = 'COINFLOW_ADD_FUNDS_PRESET_CENT_AMOUNTS'
EXPLORE_PREMIUM_DENIED_USERS = 'EXPLORE_PREMIUM_DENIED_USERS'
}

export type AllRemoteConfigKeys =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import {
usePurchaseContentFormConfiguration,
usePurchaseMethod,
useUSDCBalance,
PURCHASE_VENDOR,
StringKeys
PURCHASE_VENDOR
} from '@audius/common'
import { Formik, useField, useFormikContext } from 'formik'
import {
Expand Down Expand Up @@ -235,9 +234,7 @@ const RenderForm = ({
const styles = useStyles()
const dispatch = useDispatch()
const { specialLightGreen, primary } = useThemeColors()
const presetValues = usePayExtraPresets(
StringKeys.PAY_EXTRA_PRESET_CENT_AMOUNTS
)
const presetValues = usePayExtraPresets()
const { isEnabled: isIOSUSDCPurchaseEnabled } = useFeatureFlag(
FeatureFlags.IOS_USDC_PURCHASE_ENABLED
)
Expand Down Expand Up @@ -401,10 +398,7 @@ export const PremiumTrackPurchaseDrawer = () => {
const styles = useStyles()
const dispatch = useDispatch()
const isUSDCEnabled = useIsUSDCEnabled()
const presetValues = usePayExtraPresets(
StringKeys.PAY_EXTRA_PRESET_CENT_AMOUNTS
)

const presetValues = usePayExtraPresets()
const {
data: { contentId: trackId },
isOpen,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import {
getPurchaseSummaryValues,
PayExtraPreset,
usePayExtraPresets,
useUSDCPurchaseConfig,
StringKeys
useUSDCPurchaseConfig
} from '@audius/common'
import { useField } from 'formik'

Expand All @@ -20,9 +19,7 @@ export const usePurchaseSummaryValues = ({
}) => {
const [{ value: customAmount }] = useField(CUSTOM_AMOUNT)
const [{ value: amountPreset }] = useField(AMOUNT_PRESET)
const presetValues = usePayExtraPresets(
StringKeys.PAY_EXTRA_PRESET_CENT_AMOUNTS
)
const presetValues = usePayExtraPresets()
const { minUSDCPurchaseAmountCents } = useUSDCPurchaseConfig()

const extraAmount = getExtraAmount({
Expand Down
47 changes: 5 additions & 42 deletions packages/web/src/components/add-funds-modal/AddFundsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@ import {
buyUSDCActions,
PurchaseMethod,
DEFAULT_PURCHASE_AMOUNT_CENTS,
PurchaseVendor,
PayExtraPreset,
getExtraAmount,
StringKeys,
usePayExtraPresets
PurchaseVendor
} from '@audius/common'
import { ModalContent, ModalHeader } from '@audius/stems'
import cn from 'classnames'
import { Formik } from 'formik'
import { useDispatch } from 'react-redux'
import { toFormikValidationSchema } from 'zod-formik-adapter'

import { AddFunds } from 'components/add-funds/AddFunds'
import { Text } from 'components/typography'
Expand All @@ -25,7 +19,6 @@ import { isMobile } from 'utils/clientUtil'
import zIndex from 'utils/zIndex'

import styles from './AddFundsModal.module.css'
import { AddFundsSchema } from './validation'

const messages = {
addFunds: 'Add Funds',
Expand All @@ -40,30 +33,13 @@ export const AddFundsModal = () => {
const mobile = isMobile()

const [page, setPage] = useState<Page>('add-funds')
const presetValues = usePayExtraPresets(
StringKeys.COINFLOW_ADD_FUNDS_PRESET_CENT_AMOUNTS
)
const initialValues = {
AMOUNT_PRESET: PayExtraPreset.NONE,
CUSTOM_AMOUNT: undefined
}

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

const handleContinue = useCallback(
({
purchaseMethod,
purchaseVendor,
amountPreset = PayExtraPreset.NONE,
customAmount
}: {
purchaseMethod: PurchaseMethod
purchaseVendor?: PurchaseVendor
amountPreset?: PayExtraPreset
customAmount?: number
}) => {
(purchaseMethod: PurchaseMethod, purchaseVendor?: PurchaseVendor) => {
switch (purchaseMethod) {
case PurchaseMethod.CRYPTO:
setPage('crypto-transfer')
Expand All @@ -73,14 +49,7 @@ export const AddFundsModal = () => {
buyUSDCActions.onrampOpened({
vendor: purchaseVendor || PurchaseVendor.STRIPE,
purchaseInfo: {
desiredAmount:
amountPreset !== PayExtraPreset.NONE
? getExtraAmount({
amountPreset,
presetValues,
customAmount
})
: DEFAULT_PURCHASE_AMOUNT_CENTS
desiredAmount: DEFAULT_PURCHASE_AMOUNT_CENTS
}
})
)
Expand All @@ -90,7 +59,7 @@ export const AddFundsModal = () => {
throw new Error('Add funds not supported with existing balance')
}
},
[dispatch, presetValues]
[setPage, dispatch]
)

return (
Expand Down Expand Up @@ -122,13 +91,7 @@ export const AddFundsModal = () => {
</ModalHeader>
<ModalContent className={styles.noPadding}>
{page === 'add-funds' ? (
<Formik
initialValues={initialValues}
validationSchema={toFormikValidationSchema(AddFundsSchema)}
onSubmit={() => undefined} // Not using formik for submit
>
<AddFunds onContinue={handleContinue} />
</Formik>
<AddFunds onContinue={handleContinue} />
) : (
<USDCManualTransfer onClose={() => setPage('add-funds')} />
)}
Expand Down
9 changes: 0 additions & 9 deletions packages/web/src/components/add-funds-modal/constants.ts

This file was deleted.

14 changes: 0 additions & 14 deletions packages/web/src/components/add-funds-modal/types.ts

This file was deleted.

40 changes: 0 additions & 40 deletions packages/web/src/components/add-funds-modal/validation.ts

This file was deleted.

30 changes: 5 additions & 25 deletions packages/web/src/components/add-funds/AddFunds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import {
PurchaseMethod,
PurchaseVendor,
useCreateUserbankIfNeeded,
useUSDCBalance,
PayExtraPreset,
CUSTOM_AMOUNT
useUSDCBalance
} from '@audius/common'
import { USDC } from '@audius/fixed-decimal'
import {
Expand All @@ -19,9 +17,7 @@ import {
} from '@audius/harmony'
import { BN } from 'bn.js'
import cn from 'classnames'
import { useField } from 'formik'

import { AMOUNT_PRESET } from 'components/add-funds-modal/constants'
import { PaymentMethod } from 'components/payment-method/PaymentMethod'
import { track } from 'services/analytics'
import { audiusBackendInstance } from 'services/audius-backend/audius-backend-instance'
Expand All @@ -37,17 +33,10 @@ const messages = {
export const AddFunds = ({
onContinue
}: {
onContinue: ({
purchaseMethod,
purchaseVendor,
amountPreset,
customAmount
}: {
purchaseMethod: PurchaseMethod
onContinue: (
purchaseMethod: PurchaseMethod,
purchaseVendor?: PurchaseVendor
amountPreset?: PayExtraPreset
customAmount?: number
}) => void
) => void
}) => {
useCreateUserbankIfNeeded({
recordAnalytics: track,
Expand All @@ -59,8 +48,6 @@ export const AddFunds = ({
const [selectedPurchaseVendor, setSelectedPurchaseVendor] = useState<
PurchaseVendor | undefined
>(undefined)
const [{ value: amountPreset }, ,] = useField(AMOUNT_PRESET)
const [{ value: customAmount }, ,] = useField<number>(CUSTOM_AMOUNT)

const mobile = isMobile()
const { data: balanceBN } = useUSDCBalance({ isPolling: true })
Expand Down Expand Up @@ -95,21 +82,14 @@ export const AddFunds = ({
</Box>
<PaymentMethod
selectedMethod={selectedPurchaseMethod}
selectedVendor={selectedPurchaseVendor}
setSelectedMethod={setSelectedPurchaseMethod}
setSelectedVendor={setSelectedPurchaseVendor}
showCoinflowAmounts={true}
/>
<Button
variant={ButtonType.PRIMARY}
fullWidth
onClick={() =>
onContinue({
purchaseMethod: selectedPurchaseMethod,
purchaseVendor: selectedPurchaseVendor,
amountPreset,
customAmount
})
onContinue(selectedPurchaseMethod, selectedPurchaseVendor)
}
>
{messages.continue}
Expand Down
Loading

0 comments on commit 56704b8

Please sign in to comment.