From ea9aacf54864f7430791d52ba73a54f1717450ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=A3=20de=20Souza?= Date: Wed, 3 Jul 2024 10:59:30 +1000 Subject: [PATCH] feat: CM-735 - Add parameter to disable fiat currencies on primary sales card payments (#1958) --- .../sdk/src/widgets/definitions/parameters/sale.ts | 2 ++ .../widgets-lib/src/components/Transak/TransakIframe.tsx | 2 ++ .../src/components/Transak/useTransakIframe.ts | 6 ++++++ .../checkout/widgets-lib/src/widgets/sale/SaleWidget.tsx | 4 +++- .../widgets-lib/src/widgets/sale/SaleWidgetRoot.tsx | 1 + .../widgets-lib/src/widgets/sale/components/WithCard.tsx | 2 ++ .../src/widgets/sale/context/SaleContextProvider.tsx | 4 ++++ packages/checkout/widgets-sample-app/src/App.tsx | 2 +- .../widgets-sample-app/src/components/ui/sale/sale.tsx | 8 ++++++-- 9 files changed, 27 insertions(+), 4 deletions(-) diff --git a/packages/checkout/sdk/src/widgets/definitions/parameters/sale.ts b/packages/checkout/sdk/src/widgets/definitions/parameters/sale.ts index d90e504cdb..9a721ba740 100644 --- a/packages/checkout/sdk/src/widgets/definitions/parameters/sale.ts +++ b/packages/checkout/sdk/src/widgets/definitions/parameters/sale.ts @@ -24,6 +24,8 @@ export type SaleWidgetParams = { language?: WidgetLanguage; /** The disabled payment types */ excludePaymentTypes?: SalePaymentTypes[]; + /** Fiat currencies excluded from on-ramp */ + excludeFiatCurrencies?: string[]; /** Preferred currency, replacing the backend's base currency */ preferredCurrency?: string; }; diff --git a/packages/checkout/widgets-lib/src/components/Transak/TransakIframe.tsx b/packages/checkout/widgets-lib/src/components/Transak/TransakIframe.tsx index 9753e9d2a7..74d2a37eba 100644 --- a/packages/checkout/widgets-lib/src/components/Transak/TransakIframe.tsx +++ b/packages/checkout/widgets-lib/src/components/Transak/TransakIframe.tsx @@ -33,6 +33,7 @@ export function TransakIframe(props: TransakIframeProps) { estimatedGasLimit, exchangeScreenTitle, partnerOrderId, + excludeFiatCurrencies, onOpen, onInit, onOrderCreated, @@ -74,6 +75,7 @@ export function TransakIframe(props: TransakIframeProps) { email, walletAddress, partnerOrderId, + excludeFiatCurrencies, }, onError: onFailedToLoad, }); diff --git a/packages/checkout/widgets-lib/src/components/Transak/useTransakIframe.ts b/packages/checkout/widgets-lib/src/components/Transak/useTransakIframe.ts index faa77ea9a1..84a43c0421 100644 --- a/packages/checkout/widgets-lib/src/components/Transak/useTransakIframe.ts +++ b/packages/checkout/widgets-lib/src/components/Transak/useTransakIframe.ts @@ -15,6 +15,7 @@ export type TransakNFTCheckoutParams = { walletAddress: string; email: string; partnerOrderId?: string; + excludeFiatCurrencies?: string[]; }; type UseTransakIframeProps = { @@ -62,6 +63,7 @@ export const useTransakIframe = (props: UseTransakIframeProps) => { nftData: nfts, estimatedGasLimit, cryptoCurrencyCode, + excludeFiatCurrencies, ...restWidgetParams } = transakParams; @@ -112,6 +114,10 @@ export const useTransakIframe = (props: UseTransakIframeProps) => { ...restWidgetParams, }); + if (excludeFiatCurrencies) { + queryParams.append('excludeFiatCurrencies', excludeFiatCurrencies.join(',')); + } + return `${baseWidgetUrl}${queryParams.toString()}`; } catch { onError?.(); diff --git a/packages/checkout/widgets-lib/src/widgets/sale/SaleWidget.tsx b/packages/checkout/widgets-lib/src/widgets/sale/SaleWidget.tsx index bd70b5ffd3..ebb1ae8820 100644 --- a/packages/checkout/widgets-lib/src/widgets/sale/SaleWidget.tsx +++ b/packages/checkout/widgets-lib/src/widgets/sale/SaleWidget.tsx @@ -39,7 +39,7 @@ import { EventTargetContext } from '../../context/event-target-context/EventTarg import { OrderSummary } from './views/OrderSummary'; import { CreditCardWarningDrawer } from './components/CreditCardWarningDrawer'; -type OptionalWidgetParams = Pick; +type OptionalWidgetParams = Pick; type RequiredWidgetParams = Required< Omit >; @@ -61,6 +61,7 @@ export default function SaleWidget(props: SaleWidgetProps) { environmentId, collectionName, excludePaymentTypes, + excludeFiatCurrencies, preferredCurrency, hideExcludedPaymentTypes, waitFulfillmentSettlements = true, @@ -128,6 +129,7 @@ export default function SaleWidget(props: SaleWidgetProps) { passport: checkout?.passport, collectionName, excludePaymentTypes, + excludeFiatCurrencies, preferredCurrency, waitFulfillmentSettlements, hideExcludedPaymentTypes, diff --git a/packages/checkout/widgets-lib/src/widgets/sale/SaleWidgetRoot.tsx b/packages/checkout/widgets-lib/src/widgets/sale/SaleWidgetRoot.tsx index 842cab4e2a..c797b17ffd 100644 --- a/packages/checkout/widgets-lib/src/widgets/sale/SaleWidgetRoot.tsx +++ b/packages/checkout/widgets-lib/src/widgets/sale/SaleWidgetRoot.tsx @@ -131,6 +131,7 @@ export class Sale extends Base { environmentId={this.parameters.environmentId!} collectionName={this.parameters.collectionName!} excludePaymentTypes={this.parameters.excludePaymentTypes!} + excludeFiatCurrencies={this.parameters.excludeFiatCurrencies!} preferredCurrency={this.parameters.preferredCurrency!} hideExcludedPaymentTypes={ this.properties?.config?.hideExcludedPaymentTypes ?? false diff --git a/packages/checkout/widgets-lib/src/widgets/sale/components/WithCard.tsx b/packages/checkout/widgets-lib/src/widgets/sale/components/WithCard.tsx index 75f508fa97..7c15d9caf0 100644 --- a/packages/checkout/widgets-lib/src/widgets/sale/components/WithCard.tsx +++ b/packages/checkout/widgets-lib/src/widgets/sale/components/WithCard.tsx @@ -32,6 +32,7 @@ export function WithCard(props: WithCardProps) { goToErrorView, environment, orderQuote, + excludeFiatCurrencies, } = useSaleContext(); const executeTxn = signResponse?.transactions.find((txn) => txn.methodCall.startsWith('execute')); @@ -69,6 +70,7 @@ export function WithCard(props: WithCardProps) { cryptoCurrencyCode={signResponse.order.currency.name} estimatedGasLimit={executeTxn.gasEstimate} partnerOrderId={executeTxn.params.reference} + excludeFiatCurrencies={excludeFiatCurrencies} onInit={onInit} onOpen={onOpen} onOrderCreated={onOrderCreated} diff --git a/packages/checkout/widgets-lib/src/widgets/sale/context/SaleContextProvider.tsx b/packages/checkout/widgets-lib/src/widgets/sale/context/SaleContextProvider.tsx index bb22784416..128126e864 100644 --- a/packages/checkout/widgets-lib/src/widgets/sale/context/SaleContextProvider.tsx +++ b/packages/checkout/widgets-lib/src/widgets/sale/context/SaleContextProvider.tsx @@ -46,6 +46,7 @@ type SaleContextProps = { checkout: ConnectLoaderState['checkout']; passport?: Passport; excludePaymentTypes: SalePaymentTypes[]; + excludeFiatCurrencies?: string[]; preferredCurrency?: string; waitFulfillmentSettlements: boolean; hideExcludedPaymentTypes: boolean; @@ -157,6 +158,7 @@ export function SaleContextProvider(props: { passport, collectionName, excludePaymentTypes, + excludeFiatCurrencies, preferredCurrency, waitFulfillmentSettlements, hideExcludedPaymentTypes, @@ -380,6 +382,7 @@ export function SaleContextProvider(props: { orderQuote, signTokenIds: tokenIds, excludePaymentTypes, + excludeFiatCurrencies, selectedCurrency, waitFulfillmentSettlements, hideExcludedPaymentTypes, @@ -413,6 +416,7 @@ export function SaleContextProvider(props: { orderQuote, tokenIds, excludePaymentTypes, + excludeFiatCurrencies, selectedCurrency, waitFulfillmentSettlements, hideExcludedPaymentTypes, diff --git a/packages/checkout/widgets-sample-app/src/App.tsx b/packages/checkout/widgets-sample-app/src/App.tsx index 8f0db5b930..f8091a47cd 100644 --- a/packages/checkout/widgets-sample-app/src/App.tsx +++ b/packages/checkout/widgets-sample-app/src/App.tsx @@ -30,7 +30,7 @@ function App() {
Sale Widget diff --git a/packages/checkout/widgets-sample-app/src/components/ui/sale/sale.tsx b/packages/checkout/widgets-sample-app/src/components/ui/sale/sale.tsx index 57d2b2ef73..d92c858974 100644 --- a/packages/checkout/widgets-sample-app/src/components/ui/sale/sale.tsx +++ b/packages/checkout/widgets-sample-app/src/components/ui/sale/sale.tsx @@ -78,8 +78,8 @@ const useParams = () => { .get("excludePaymentTypes") ?.split(",") as SalePaymentTypes[]; - const preferredCurrency = - (urlParams.get("preferredCurrency") as string) ?? undefined; + const preferredCurrency = (urlParams.get("preferredCurrency") as string) ?? undefined; + const excludeFiatCurrencies = (urlParams.get("excludeFiatCurrencies") as string) ?? undefined; const hideExcludedPaymentTypes = Boolean( urlParams.get("hideExcludedPaymentTypes") ); @@ -91,6 +91,7 @@ const useParams = () => { excludePaymentTypes, preferredCurrency, hideExcludedPaymentTypes, + excludeFiatCurrencies: excludeFiatCurrencies?.split(","), }; }; @@ -131,6 +132,7 @@ export function SaleUI() { excludePaymentTypes, preferredCurrency, hideExcludedPaymentTypes, + excludeFiatCurrencies, } = params; const [passportConfig, setPassportConfig] = useState( JSON.stringify(defaultPassportConfig, null, 2) @@ -199,6 +201,7 @@ export function SaleUI() { collectionName, items: defaultItems, excludePaymentTypes, + excludeFiatCurrencies, preferredCurrency, }); saleWidget.addListener(SaleEventType.CLOSE_WIDGET, () => { @@ -302,6 +305,7 @@ export function SaleUI() { items: defaultItems, excludePaymentTypes, preferredCurrency, + excludeFiatCurrencies, }) } >