This repository has been archived by the owner on Oct 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into pay-1631-post-purchas…
…e-page * origin/main: [PAY-1720] Implements PlainButton (#3897) Fix minor bugs for multi-track upload demo (#3854) Limit lines in Leaving Audius Modal (#3896) [C-2681, C-2682, C-2683] Add new upload finish page (#3890) [C-2914] USDC purchase options for new upload UI (web) (#3888) Minor UI fixes for leaving audius modal (#3895) Fix OAuth login page width (#3894) Fix playlist form from crashing after double save (#3893) Update seo h1 to be accessibly hidden vs visually hidden (#3892) Move setCollectionPermalink within fetchCollectionSucceeded action (#3867) [plat-1055] revert legacy playlist route formatting in embed player to use permalink (#3824) [PAY-1717] Make sign in/sign up page overlap banner (#3886) [PAY-1658] Artist pick, hidden track tile tags moved to mid-left (#3889) [C-2957] Add h1 tag for SEO (#3887) [C-2685 C-2686] Implement collection upload form (#3870) [PAY-1702] Use existing chats as default user list when sharing to DMs (#3877) [PAY-1701] Fix "Share to DMs" on mobile to go through InboxUnavailable modal (#3878) [PAY-1700] Replace navigation if coming from ChatUserListScreen (#3879) [PAY-1588] Use existing balance in purchase flow on mobile (#3885)
- Loading branch information
Showing
91 changed files
with
2,174 additions
and
600 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,50 @@ | ||
import BN from 'bn.js' | ||
|
||
import { BNUSDC } from 'models/Wallet' | ||
import { BN_USDC_CENT_WEI, ceilingBNUSDCToNearestCent } from 'utils/wallet' | ||
|
||
import { PurchaseContentStage } from './types' | ||
|
||
export const zeroBalance = () => new BN(0) as BNUSDC | ||
|
||
export const isContentPurchaseInProgress = (stage: PurchaseContentStage) => { | ||
return [ | ||
PurchaseContentStage.BUY_USDC, | ||
PurchaseContentStage.PURCHASING, | ||
PurchaseContentStage.CONFIRMING_PURCHASE | ||
].includes(stage) | ||
} | ||
|
||
type PurchaseSummaryValues = { | ||
amountDue: number | ||
existingBalance: number | undefined | ||
basePrice: number | ||
artistCut: number | ||
} | ||
|
||
export const getPurchaseSummaryValues = ( | ||
price: number, | ||
currentBalance: BNUSDC = zeroBalance() | ||
): PurchaseSummaryValues => { | ||
let amountDue = price | ||
let existingBalance | ||
const priceBN = new BN(price).mul(BN_USDC_CENT_WEI) | ||
|
||
if (currentBalance.gte(priceBN)) { | ||
amountDue = 0 | ||
existingBalance = price | ||
} | ||
// Only count the balance if it's greater than 1 cent | ||
else if (currentBalance.gt(BN_USDC_CENT_WEI)) { | ||
// Note: Rounding amount due *up* to nearest cent for cases where the balance | ||
// is between cents so that we aren't advertising *lower* than what the user | ||
// will have to pay. | ||
const diff = priceBN.sub(currentBalance) | ||
amountDue = ceilingBNUSDCToNearestCent(diff as BNUSDC) | ||
.div(BN_USDC_CENT_WEI) | ||
.toNumber() | ||
existingBalance = price - amountDue | ||
} | ||
|
||
return { amountDue, existingBalance, basePrice: price, artistCut: price } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.