Skip to content

Commit 9a034f7

Browse files
feat(checkout-widgets): Make on-ramp widget title and menu icon customisable (#2714)
Co-authored-by: priyaleedman <priya.leedman@gmail.com>
1 parent 3ab9b35 commit 9a034f7

File tree

8 files changed

+26
-5
lines changed

8 files changed

+26
-5
lines changed

packages/checkout/sdk/src/fiatRamp/fiatRamp.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export interface FiatRampWidgetParams {
1111
tokenSymbol?: string;
1212
email?: string;
1313
allowedTokens?: string[];
14+
showMenu?: boolean;
15+
customSubTitle?: string;
1416
}
1517

1618
export class FiatRampService {
@@ -49,9 +51,10 @@ export class FiatRampService {
4951
defaultPaymentMethod: 'credit_debit_card',
5052
disablePaymentMethods: '',
5153
productsAvailed: 'buy',
52-
exchangeScreenTitle: 'Buy',
54+
exchangeScreenTitle: params.customSubTitle === '' ? ' ' : (params.customSubTitle ?? 'Buy'),
5355
themeColor: '0D0D0D',
5456
defaultCryptoCurrency: params.tokenSymbol || 'IMX',
57+
hideMenu: !(params.showMenu ?? true),
5558
};
5659

5760
if (params.isPassport && params.email) {

packages/checkout/sdk/src/sdk.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,8 @@ export class Checkout {
669669
tokenSymbol,
670670
email,
671671
allowedTokens,
672+
showMenu: params.showMenu,
673+
customSubTitle: params.customSubTitle,
672674
} as FiatRampWidgetParams);
673675
}
674676

packages/checkout/sdk/src/types/fiatRamp.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ export interface FiatRampParams {
2626
tokenAmount?: string;
2727
tokenAddress?: string;
2828
passport?: any;
29+
showMenu?: boolean;
30+
customSubTitle?: string;
2931
}

packages/checkout/sdk/src/widgets/definitions/configurations/onramp.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ import { WidgetConfiguration } from './widget';
44
* Onramp Widget Configuration represents the configuration options for the Onramp Widget.
55
*/
66
export type OnrampWidgetConfiguration = {
7+
/** Whether to show the menu in the Transak widget (default: true) */
8+
showMenu?: boolean;
9+
/** The custom subtitle to display on the exchange screen in the Transak widget (default: 'Buy') */
10+
customSubTitle?: string;
711
} & WidgetConfiguration;

packages/checkout/widgets-lib/src/widgets/immutable-commerce/CommerceWidget.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ export default function CommerceWidget(props: CommerceWidgetInputs) {
324324
<OnRampWidget
325325
config={widgetsConfig}
326326
{...(view.data.params || {})}
327-
{...(view.data.config || {})}
327+
onrampConfig={view.data.config}
328328
showBackButton={showBackButton}
329329
/>
330330
)}

packages/checkout/widgets-lib/src/widgets/on-ramp/OnRampWidget.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
useContext, useEffect, useMemo, useReducer, useState,
33
} from 'react';
4-
import { IMTBLWidgetEvents, OnRampWidgetParams } from '@imtbl/checkout-sdk';
4+
import { IMTBLWidgetEvents, OnRampWidgetParams, OnrampWidgetConfiguration } from '@imtbl/checkout-sdk';
55
import { useTranslation } from 'react-i18next';
66
import { UserJourney } from '../../context/analytics-provider/SegmentAnalyticsProvider';
77
import { NATIVE } from '../../lib';
@@ -27,11 +27,12 @@ import { OrderInProgress } from './views/OrderInProgress';
2727
import { ServiceUnavailableErrorView } from '../../views/error/ServiceUnavailableErrorView';
2828

2929
export type OnRampWidgetInputs = OnRampWidgetParams & {
30-
config: StrongCheckoutWidgetsConfig
30+
config: StrongCheckoutWidgetsConfig;
31+
onrampConfig?: OnrampWidgetConfiguration;
3132
};
3233

3334
export default function OnRampWidget({
34-
amount, tokenAddress, config, showBackButton,
35+
amount, tokenAddress, config, showBackButton, onrampConfig,
3536
}: OnRampWidgetInputs) {
3637
const {
3738
isOnRampEnabled, isSwapEnabled, isBridgeEnabled,
@@ -139,6 +140,8 @@ export default function OnRampWidget({
139140
tknAddr ?? viewState.view.data?.tokenAddress
140141
}
141142
showBackButton={showBackButton}
143+
showMenu={onrampConfig?.showMenu}
144+
customSubTitle={onrampConfig?.customSubTitle}
142145
/>
143146
)}
144147

packages/checkout/widgets-lib/src/widgets/on-ramp/OnRampWidgetRoot.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export class OnRamp extends Base<WidgetType.ONRAMP> {
102102
amount={this.parameters.amount}
103103
config={this.strongConfig()}
104104
showBackButton={this.parameters.showBackButton}
105+
onrampConfig={this.properties.config}
105106
/>
106107
</Suspense>
107108
</ConnectLoader>

packages/checkout/widgets-lib/src/widgets/on-ramp/views/OnRampMain.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,17 @@ interface OnRampProps {
4242
tokenAddress?: string;
4343
passport?: Passport;
4444
showBackButton?: boolean;
45+
showMenu?: boolean;
46+
customSubTitle?: string;
4547
}
4648
export function OnRampMain({
4749
passport,
4850
showIframe,
4951
tokenAmount,
5052
tokenAddress,
5153
showBackButton,
54+
showMenu,
55+
customSubTitle,
5256
}: OnRampProps) {
5357
const { connectLoaderState } = useContext(ConnectLoaderContext);
5458
const { checkout, provider } = connectLoaderState;
@@ -236,6 +240,8 @@ export function OnRampMain({
236240
tokenAddress,
237241
tokenAmount,
238242
passport,
243+
showMenu,
244+
customSubTitle,
239245
};
240246

241247
setWidgetUrl(await checkout.createFiatRampUrl(params));

0 commit comments

Comments
 (0)