-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PAY-1707] Implements usage of existing balance during content purcha…
…ses (#3883)
- Loading branch information
Showing
11 changed files
with
226 additions
and
34 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
36 changes: 36 additions & 0 deletions
36
apps/audius-client/packages/common/src/hooks/useUSDCBalance.ts
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { useEffect, useState } from 'react' | ||
|
||
import BN from 'bn.js' | ||
|
||
import { Status } from 'models/Status' | ||
import { BNUSDC } from 'models/Wallet' | ||
import { getUserbankAccountInfo } from 'services/index' | ||
import { useAppContext } from 'src/context/appContext' | ||
|
||
/** | ||
* On mount, fetches the USDC balance for the current user | ||
*/ | ||
export const useUSDCBalance = () => { | ||
const { audiusBackend } = useAppContext() | ||
const [status, setStatus] = useState(Status.IDLE) | ||
const [data, setData] = useState<BNUSDC>() | ||
|
||
useEffect(() => { | ||
const fetch = async () => { | ||
setStatus(Status.LOADING) | ||
try { | ||
const account = await getUserbankAccountInfo(audiusBackend, { | ||
mint: 'usdc' | ||
}) | ||
const balance = (account?.amount ?? new BN(0)) as BNUSDC | ||
setData(balance) | ||
setStatus(Status.SUCCESS) | ||
} catch (e) { | ||
setStatus(Status.ERROR) | ||
} | ||
} | ||
fetch() | ||
}, [audiusBackend]) | ||
|
||
return { status, data } | ||
} |
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
9 changes: 9 additions & 0 deletions
9
...kages/web/src/components/premium-content-purchase-modal/components/FormatPrice.module.css
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.container { | ||
display: inline-flex; | ||
align-items: center; | ||
gap: var(--unit-2); | ||
} | ||
|
||
.existingBalance { | ||
text-decoration: none; | ||
} |
31 changes: 31 additions & 0 deletions
31
...ent/packages/web/src/components/premium-content-purchase-modal/components/FormatPrice.tsx
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { formatPrice } from '@audius/common' | ||
import cn from 'classnames' | ||
|
||
import styles from './FormatPrice.module.css' | ||
|
||
type FormatPriceProps = { | ||
amountDue: number | ||
basePrice: number | ||
className?: string | ||
} | ||
|
||
export const FormatPrice = ({ | ||
amountDue, | ||
basePrice, | ||
className | ||
}: FormatPriceProps) => { | ||
if (basePrice === amountDue) | ||
return ( | ||
<span className={cn(styles.container, className)}>{`$${formatPrice( | ||
amountDue | ||
)}`}</span> | ||
) | ||
return ( | ||
<span className={cn(styles.container, className)}> | ||
<del>{`$${formatPrice(basePrice)}`}</del> | ||
<ins className={styles.existingBalance}>{`$${ | ||
amountDue === 0 ? '0' : formatPrice(amountDue) | ||
}`}</ins> | ||
</span> | ||
) | ||
} |
Oops, something went wrong.