Skip to content

Commit

Permalink
feat: CM-735 - Add parameter to disable fiat currencies on primary sa…
Browse files Browse the repository at this point in the history
…les card payments (#1958)
  • Loading branch information
luads authored Jul 3, 2024
1 parent 8e8d8d4 commit ea9aacf
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export function TransakIframe(props: TransakIframeProps) {
estimatedGasLimit,
exchangeScreenTitle,
partnerOrderId,
excludeFiatCurrencies,
onOpen,
onInit,
onOrderCreated,
Expand Down Expand Up @@ -74,6 +75,7 @@ export function TransakIframe(props: TransakIframeProps) {
email,
walletAddress,
partnerOrderId,
excludeFiatCurrencies,
},
onError: onFailedToLoad,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type TransakNFTCheckoutParams = {
walletAddress: string;
email: string;
partnerOrderId?: string;
excludeFiatCurrencies?: string[];
};

type UseTransakIframeProps = {
Expand Down Expand Up @@ -62,6 +63,7 @@ export const useTransakIframe = (props: UseTransakIframeProps) => {
nftData: nfts,
estimatedGasLimit,
cryptoCurrencyCode,
excludeFiatCurrencies,
...restWidgetParams
} = transakParams;

Expand Down Expand Up @@ -112,6 +114,10 @@ export const useTransakIframe = (props: UseTransakIframeProps) => {
...restWidgetParams,
});

if (excludeFiatCurrencies) {
queryParams.append('excludeFiatCurrencies', excludeFiatCurrencies.join(','));
}

return `${baseWidgetUrl}${queryParams.toString()}`;
} catch {
onError?.();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SaleWidgetParams, 'excludePaymentTypes'>;
type OptionalWidgetParams = Pick<SaleWidgetParams, 'excludePaymentTypes' | 'excludeFiatCurrencies'>;
type RequiredWidgetParams = Required<
Omit<SaleWidgetParams, 'walletProviderName'>
>;
Expand All @@ -61,6 +61,7 @@ export default function SaleWidget(props: SaleWidgetProps) {
environmentId,
collectionName,
excludePaymentTypes,
excludeFiatCurrencies,
preferredCurrency,
hideExcludedPaymentTypes,
waitFulfillmentSettlements = true,
Expand Down Expand Up @@ -128,6 +129,7 @@ export default function SaleWidget(props: SaleWidgetProps) {
passport: checkout?.passport,
collectionName,
excludePaymentTypes,
excludeFiatCurrencies,
preferredCurrency,
waitFulfillmentSettlements,
hideExcludedPaymentTypes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export class Sale extends Base<WidgetType.SALE> {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function WithCard(props: WithCardProps) {
goToErrorView,
environment,
orderQuote,
excludeFiatCurrencies,
} = useSaleContext();
const executeTxn = signResponse?.transactions.find((txn) => txn.methodCall.startsWith('execute'));

Expand Down Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type SaleContextProps = {
checkout: ConnectLoaderState['checkout'];
passport?: Passport;
excludePaymentTypes: SalePaymentTypes[];
excludeFiatCurrencies?: string[];
preferredCurrency?: string;
waitFulfillmentSettlements: boolean;
hideExcludedPaymentTypes: boolean;
Expand Down Expand Up @@ -157,6 +158,7 @@ export function SaleContextProvider(props: {
passport,
collectionName,
excludePaymentTypes,
excludeFiatCurrencies,
preferredCurrency,
waitFulfillmentSettlements,
hideExcludedPaymentTypes,
Expand Down Expand Up @@ -380,6 +382,7 @@ export function SaleContextProvider(props: {
orderQuote,
signTokenIds: tokenIds,
excludePaymentTypes,
excludeFiatCurrencies,
selectedCurrency,
waitFulfillmentSettlements,
hideExcludedPaymentTypes,
Expand Down Expand Up @@ -413,6 +416,7 @@ export function SaleContextProvider(props: {
orderQuote,
tokenIds,
excludePaymentTypes,
excludeFiatCurrencies,
selectedCurrency,
waitFulfillmentSettlements,
hideExcludedPaymentTypes,
Expand Down
2 changes: 1 addition & 1 deletion packages/checkout/widgets-sample-app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function App() {
<div>
<a
href={
"/sale?environmentId=249d9b0b-ee16-4dd5-91ee-96bece3b0473&collectionName=Iguanas&excludePaymentTypes=credit&multicurrency=true"
"/sale?environmentId=249d9b0b-ee16-4dd5-91ee-96bece3b0473&collectionName=Iguanas&excludePaymentTypes=credit"
}
>
Sale Widget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
);
Expand All @@ -91,6 +91,7 @@ const useParams = () => {
excludePaymentTypes,
preferredCurrency,
hideExcludedPaymentTypes,
excludeFiatCurrencies: excludeFiatCurrencies?.split(","),
};
};

Expand Down Expand Up @@ -131,6 +132,7 @@ export function SaleUI() {
excludePaymentTypes,
preferredCurrency,
hideExcludedPaymentTypes,
excludeFiatCurrencies,
} = params;
const [passportConfig, setPassportConfig] = useState(
JSON.stringify(defaultPassportConfig, null, 2)
Expand Down Expand Up @@ -199,6 +201,7 @@ export function SaleUI() {
collectionName,
items: defaultItems,
excludePaymentTypes,
excludeFiatCurrencies,
preferredCurrency,
});
saleWidget.addListener(SaleEventType.CLOSE_WIDGET, () => {
Expand Down Expand Up @@ -302,6 +305,7 @@ export function SaleUI() {
items: defaultItems,
excludePaymentTypes,
preferredCurrency,
excludeFiatCurrencies,
})
}
>
Expand Down

0 comments on commit ea9aacf

Please sign in to comment.