Skip to content

Commit

Permalink
[PAY-2779] Fix validation for albumTrackPrice (#8302)
Browse files Browse the repository at this point in the history
  • Loading branch information
amendelsohn committed May 2, 2024
1 parent 963bec4 commit 722e933
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
18 changes: 12 additions & 6 deletions packages/web/src/pages/upload-page/fields/AccessAndSaleField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ export const AccessAndSaleFormSchema = (
// Check for albumTrackPrice price >= min price (if applicable)
.refine(
(values) =>
isAlbum && isUpload
isAlbum &&
isUpload &&
values[STREAM_CONDITIONS]?.usdc_purchase?.albumTrackPrice
? refineMinPrice('albumTrackPrice', minContentPriceCents)(values)
: true,
{
Expand All @@ -187,7 +189,9 @@ export const AccessAndSaleFormSchema = (
})
.refine(
(values) =>
isAlbum && isUpload
isAlbum &&
isUpload &&
values[STREAM_CONDITIONS]?.usdc_purchase?.albumTrackPrice
? refineMaxPrice('albumTrackPrice', maxContentPriceCents)(values)
: true,
{
Expand Down Expand Up @@ -413,15 +417,17 @@ export const AccessAndSaleField = (props: AccessAndSaleFieldProps) => {
switch (availabilityType) {
case StreamTrackAvailabilityType.USDC_PURCHASE: {
// type cast because the object is fully formed in saga (validated + added splits)
const albumTrackPriceValue = (
streamConditions as USDCPurchaseConditions
).usdc_purchase.albumTrackPrice
const conditions = {
usdc_purchase: {
price: Math.round(
(streamConditions as USDCPurchaseConditions).usdc_purchase.price
),
albumTrackPrice: Math.round(
(streamConditions as USDCPurchaseConditions).usdc_purchase
.albumTrackPrice || 0
)
albumTrackPrice: albumTrackPriceValue
? Math.round(albumTrackPriceValue)
: null
}
} as USDCPurchaseConditions
setIsStreamGated(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,23 @@ const PreviewField = (props: TrackAvailabilityFieldsProps) => {

const PriceField = (props: PriceFieldProps) => {
const { disabled, messaging, fieldName } = props
const [{ value }, , { setValue: setPrice }] = useField<number>(fieldName)
const [{ value }, , { setValue: setPrice }] = useField<number | null>(
fieldName
)
const [humanizedValue, setHumanizedValue] = useState(
value ? decimalIntegerToHumanReadable(value) : null
)

const handlePriceChange: ChangeEventHandler<HTMLInputElement> = useCallback(
(e) => {
const { human, value } = filterDecimalString(e.target.value)
setHumanizedValue(human)
setPrice(value)
if (value === 0) {
setHumanizedValue(null)
setPrice(null)
} else {
setHumanizedValue(human)
setPrice(value)
}
},
[setPrice, setHumanizedValue]
)
Expand Down

0 comments on commit 722e933

Please sign in to comment.