Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PAY-2503] Fix mobile crypto transfer purchase flow #7620

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 52 additions & 48 deletions packages/common/src/store/purchase-content/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,55 +479,59 @@ function* doStartPurchaseContentFlow({
usdcConfig.minUSDCPurchaseAmountCents
)

if (purchaseMethod === PurchaseMethod.BALANCE && balanceNeeded.lten(0)) {
// No balance needed, perform the purchase right away
yield* call(purchaseContent, audiusBackendInstance, {
id: contentId,
blocknumber,
extraAmount: extraAmountBN,
splits,
type: 'track',
purchaserUserId,
purchaseAccess
})
} else {
// We need to acquire USDC before the purchase can continue
// Invariant: The user must be checking out with a card
if (purchaseMethod !== PurchaseMethod.CARD) {
throw new PurchaseContentError(
PurchaseErrorCode.InsufficientBalance,
'Unexpected insufficient balance to complete purchase'
)
switch (purchaseMethod) {
case PurchaseMethod.BALANCE:
case PurchaseMethod.CRYPTO: {
// Invariant: The user must have enough funds
if (balanceNeeded.gtn(0)) {
throw new PurchaseContentError(
PurchaseErrorCode.InsufficientBalance,
'Unexpected insufficient balance to complete purchase'
)
}
// No balance needed, perform the purchase right away
yield* call(purchaseContent, audiusBackendInstance, {
id: contentId,
blocknumber,
extraAmount: extraAmountBN,
splits,
type: 'track',
purchaserUserId,
purchaseAccess
})
break
}

const purchaseAmount = (price + (extraAmount ?? 0)) / 100.0
switch (purchaseVendor) {
case PurchaseVendor.COINFLOW:
// Purchase with coinflow, funding and completing the purchase in one step.
yield* call(purchaseWithCoinflow, {
blocknumber,
extraAmount,
splits,
contentId,
contentType,
purchaserUserId,
price: purchaseAmount,
purchaseAccess
})
break
case PurchaseVendor.STRIPE:
// Buy USDC with Stripe. Once funded, continue with purchase.
yield* call(purchaseUSDCWithStripe, { amount: purchaseAmount })
yield* call(purchaseContent, audiusBackendInstance, {
id: contentId,
blocknumber,
extraAmount: extraAmountBN,
splits,
type: 'track',
purchaserUserId,
purchaseAccess
})
break
case PurchaseMethod.CARD: {
const purchaseAmount = (price + (extraAmount ?? 0)) / 100.0
switch (purchaseVendor) {
case PurchaseVendor.COINFLOW:
// Purchase with coinflow, funding and completing the purchase in one step.
yield* call(purchaseWithCoinflow, {
blocknumber,
extraAmount,
splits,
contentId,
contentType,
purchaserUserId,
price: purchaseAmount,
purchaseAccess
})
break
case PurchaseVendor.STRIPE:
// Buy USDC with Stripe. Once funded, continue with purchase.
yield* call(purchaseUSDCWithStripe, { amount: purchaseAmount })
yield* call(purchaseContent, audiusBackendInstance, {
id: contentId,
blocknumber,
extraAmount: extraAmountBN,
splits,
type: 'track',
purchaserUserId,
purchaseAccess
})
break
}
break
}
}

Expand Down