-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
20 changed files
with
387 additions
and
125 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
36 changes: 36 additions & 0 deletions
36
packages/common/src/hooks/purchaseContent/usePurchaseContentErrorMessage.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 { BuyUSDCErrorCode } from 'store/index' | ||
import { | ||
PurchaseContentErrorCode, | ||
PurchaseErrorCode | ||
} from 'store/purchase-content' | ||
import { formatPrice } from 'utils/formatUtil' | ||
|
||
import { RemoteVarHook } from '../useRemoteVar' | ||
|
||
import { useUSDCPurchaseConfig } from './useUSDCPurchaseConfig' | ||
|
||
const messages = { | ||
generic: 'Your purchase was unsuccessful.', | ||
minimumPurchase: (minAmount: number) => | ||
`Total purchase amount must be at least $${formatPrice(minAmount)}.`, | ||
maximumPurchase: (maxAmount: number) => | ||
`Total purchase amount may not exceed $${formatPrice(maxAmount)}.` | ||
} | ||
|
||
export const usePurchaseContentErrorMessage = ( | ||
errorCode: PurchaseContentErrorCode, | ||
useRemoteVar: RemoteVarHook | ||
) => { | ||
const { minUSDCPurchaseAmountCents, maxUSDCPurchaseAmountCents } = | ||
useUSDCPurchaseConfig(useRemoteVar) | ||
|
||
switch (errorCode) { | ||
case BuyUSDCErrorCode.MinAmountNotMet: | ||
return messages.minimumPurchase(minUSDCPurchaseAmountCents) | ||
case BuyUSDCErrorCode.MaxAmountExceeded: | ||
return messages.maximumPurchase(maxUSDCPurchaseAmountCents) | ||
case BuyUSDCErrorCode.OnrampError: | ||
case PurchaseErrorCode.Unknown: | ||
return messages.generic | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
packages/common/src/hooks/purchaseContent/useUSDCPurchaseConfig.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 { useMemo } from 'react' | ||
|
||
import { IntKeys } from 'services/remote-config' | ||
|
||
import { RemoteVarHook } from '../useRemoteVar' | ||
|
||
import { USDCPurchaseConfig } from './types' | ||
|
||
/** Fetches the USDC/purchase content remote config values */ | ||
export const useUSDCPurchaseConfig = ( | ||
useRemoteVar: RemoteVarHook | ||
): USDCPurchaseConfig => { | ||
const minContentPriceCents = useRemoteVar(IntKeys.MIN_CONTENT_PRICE_CENTS) | ||
const maxContentPriceCents = useRemoteVar(IntKeys.MAX_CONTENT_PRICE_CENTS) | ||
const minUSDCPurchaseAmountCents = useRemoteVar( | ||
IntKeys.MIN_USDC_PURCHASE_AMOUNT_CENTS | ||
) | ||
const maxUSDCPurchaseAmountCents = useRemoteVar( | ||
IntKeys.MAX_USDC_PURCHASE_AMOUNT_CENTS | ||
) | ||
|
||
return useMemo( | ||
() => ({ | ||
minContentPriceCents, | ||
maxContentPriceCents, | ||
minUSDCPurchaseAmountCents, | ||
maxUSDCPurchaseAmountCents | ||
}), | ||
[ | ||
minContentPriceCents, | ||
maxContentPriceCents, | ||
minUSDCPurchaseAmountCents, | ||
maxUSDCPurchaseAmountCents | ||
] | ||
) | ||
} |
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
Oops, something went wrong.