Skip to content

Commit 1cad9d2

Browse files
authored
feat(checkout-widgets): Make swap widget headers customisable (#2711)
1 parent c54c770 commit 1cad9d2

10 files changed

Lines changed: 50 additions & 25 deletions

File tree

.editorconfig

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ root = true
22

33
# https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties
44

5-
[*.{yml,yaml}]
5+
6+
[*]
7+
insert_final_newline = true
8+
trim_trailing_whitespace = true
69
indent_style = space
710
indent_size = 2
8-
quote_type = double
11+
quote_type = double
12+
13+
[*.{ts,tsx}]
14+
max_line_length = 120

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ import { WidgetConfiguration } from './widget';
44
* Swap Widget Configuration represents the configuration options for the Swap Widget.
55
*/
66
export type SwapWidgetConfiguration = {
7+
customTitle?: string;
8+
customSubTitle?: string;
79
} & WidgetConfiguration;

packages/checkout/widgets-lib/.eslintrc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,6 @@ module.exports = {
7070
"jsx-a11y/control-has-associated-label": "off",
7171
"react/jsx-props-no-spreading": "off",
7272
"implicit-arrow-linebreak": "off",
73+
"operator-linebreak": "off",
7374
}
7475
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ export default function CommerceWidget(props: CommerceWidgetInputs) {
315315
{view.type === CommerceFlowType.SWAP && (
316316
<SwapWidget
317317
config={widgetsConfig}
318+
swapConfig={view.data.config}
318319
{...(view.data.params || {})}
319-
{...(view.data.config || {})}
320320
showBackButton={showBackButton}
321321
/>
322322
)}

packages/checkout/widgets-lib/src/widgets/sale/components/FundingRouteExecute/FundingRouteExecute.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ export function FundingRouteExecute({
319319
<BridgeWidget {...bridgeParams!} config={config} checkout={checkout!} />
320320
)}
321321
{view === FundingRouteExecuteViews.EXECUTE_SWAP && (
322-
<SwapWidget {...swapParams!} config={config} />
322+
<SwapWidget {...swapParams!} config={config} swapConfig={{}} />
323323
)}
324324
{view === FundingRouteExecuteViews.EXECUTE_ON_RAMP && (
325325
<OnRampWidget config={config} {...onRampParams} />

packages/checkout/widgets-lib/src/widgets/swap/SwapWidget.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
TokenFilterTypes, IMTBLWidgetEvents, SwapWidgetParams,
1111
SwapDirection,
1212
WalletProviderName,
13+
SwapWidgetConfiguration,
1314
} from '@imtbl/checkout-sdk';
1415
import { useTranslation } from 'react-i18next';
1516
import { SwapCoins } from './views/SwapCoins';
@@ -59,6 +60,7 @@ import { GeoblockLoader } from './GeoblockLoader';
5960

6061
export type SwapWidgetInputs = SwapWidgetParams & {
6162
config: StrongCheckoutWidgetsConfig;
63+
swapConfig: SwapWidgetConfiguration;
6264
};
6365

6466
export default function SwapWidget({
@@ -69,6 +71,7 @@ export default function SwapWidget({
6971
autoProceed,
7072
direction,
7173
showBackButton,
74+
swapConfig: { customTitle, customSubTitle },
7275
walletProviderName,
7376
}: SwapWidgetInputs) {
7477
const { t } = useTranslation();
@@ -257,6 +260,8 @@ export default function SwapWidget({
257260
fromTokenAddress={viewState.view.data?.fromTokenAddress ?? fromTokenAddress}
258261
toTokenAddress={viewState.view.data?.toTokenAddress ?? toTokenAddress}
259262
showBackButton={showBackButton}
263+
title={customTitle ?? t('views.SWAP.header.title')}
264+
subTitle={customSubTitle ?? t('views.SWAP.content.title')}
260265
/>
261266
)}
262267
{viewState.view.type === SwapWidgetViews.IN_PROGRESS && (

packages/checkout/widgets-lib/src/widgets/swap/SwapWidgetRoot.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ export class Swap extends Base<WidgetType.SWAP> {
106106
direction={this.parameters.direction ?? SwapDirection.FROM}
107107
showBackButton={this.parameters.showBackButton}
108108
walletProviderName={this.parameters.walletProviderName}
109+
swapConfig={{
110+
customTitle: this.properties.config?.customTitle,
111+
customSubTitle: this.properties.config?.customSubTitle,
112+
}}
109113
/>
110114
</Suspense>
111115
</ConnectLoader>

packages/checkout/widgets-lib/src/widgets/swap/components/SwapForm.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export interface SwapFromProps {
7878
data?: SwapFormData;
7979
theme: WidgetTheme;
8080
cancelAutoProceed: () => void;
81+
subTitle: string;
8182
}
8283

8384
class PriceImpactError extends Error {
@@ -87,7 +88,9 @@ class PriceImpactError extends Error {
8788
}
8889
}
8990

90-
export function SwapForm({ data, theme, cancelAutoProceed }: SwapFromProps) {
91+
export function SwapForm({
92+
data, theme, cancelAutoProceed, subTitle,
93+
}: SwapFromProps) {
9194
const { t } = useTranslation();
9295
const {
9396
swapState: {
@@ -106,7 +109,6 @@ export function SwapForm({ data, theme, cancelAutoProceed }: SwapFromProps) {
106109
? NATIVE
107110
: `${symbol.toLowerCase()}-${address!.toLowerCase()}`), []);
108111

109-
// const { cryptoFiatState, cryptoFiatDispatch } = useContext(CryptoFiatContext);
110112
const { conversions: usdConversions } = useCryptoUSDConversion(checkout?.config.environment);
111113
const { viewDispatch } = useContext(ViewContext);
112114

@@ -939,13 +941,15 @@ export function SwapForm({ data, theme, cancelAutoProceed }: SwapFromProps) {
939941
marginBottom: 'base.spacing.x2',
940942
}}
941943
>
942-
<Heading
943-
size="small"
944-
weight="regular"
945-
sx={{ paddingBottom: 'base.spacing.x4' }}
946-
>
947-
{t('views.SWAP.content.title')}
948-
</Heading>
944+
{subTitle !== '' ? (
945+
<Heading
946+
size="small"
947+
weight="regular"
948+
sx={{ paddingBottom: 'base.spacing.x4' }}
949+
>
950+
{subTitle}
951+
</Heading>
952+
) : null}
949953
<Box
950954
sx={{
951955
display: 'flex',

packages/checkout/widgets-lib/src/widgets/swap/views/SwapCoins.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export interface SwapCoinsProps {
3232
fromTokenAddress?: string;
3333
toTokenAddress?: string;
3434
showBackButton?: boolean;
35+
title: string;
36+
subTitle: string;
3537
}
3638

3739
export function SwapCoins({
@@ -42,6 +44,8 @@ export function SwapCoins({
4244
fromTokenAddress,
4345
toTokenAddress,
4446
showBackButton,
47+
title,
48+
subTitle,
4549
}: SwapCoinsProps) {
4650
const { t } = useTranslation();
4751
const { viewDispatch } = useContext(ViewContext);
@@ -88,7 +92,7 @@ export function SwapCoins({
8892
<SimpleLayout
8993
header={!autoProceed ? (
9094
<HeaderNavigation
91-
title={t('views.SWAP.header.title')}
95+
title={title}
9296
onCloseButtonClick={() => sendSwapWidgetCloseEvent(eventTarget)}
9397
showBack={showBackButton}
9498
onBackButtonClick={() => {
@@ -119,6 +123,7 @@ export function SwapCoins({
119123
toTokenAddress,
120124
}}
121125
theme={theme}
126+
subTitle={subTitle}
122127
/>
123128
<NotEnoughImx
124129
environment={checkout?.config.environment ?? Environment.PRODUCTION}

packages/checkout/widgets-sample-app/src/components/ui/checkout/checkout.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ function CheckoutUI() {
198198
amount: "10",
199199
fromTokenAddress: "native",
200200
toTokenAddress: "0x3B2d8A1931736Fc321C24864BceEe981B11c3c57",
201+
showBackButton: true,
201202
},
202203
WALLET: {
203204
flow: CommerceFlowType.WALLET,
@@ -286,17 +287,15 @@ function CheckoutUI() {
286287
config: {
287288
theme,
288289
language,
289-
// SWAP: {},
290-
// BRIDGE: {},
291-
// CONNECT: {},
292-
// ONRAMP: {},
293-
SALE: {
294-
hideExcludedPaymentTypes: true,
295-
waitFulfillmentSettlements: false,
290+
SWAP: {
296291
},
297-
WALLET: {
298-
showDisconnectButton: true,
299-
showNetworkMenu: true,
292+
// TRANSFER: {
293+
// showTitle: false,
294+
// showSubTitle: false,
295+
// },
296+
ONRAMP: {
297+
// showTitle: false,
298+
// showSubTitle: false,
300299
},
301300
},
302301
});
@@ -397,7 +396,6 @@ function CheckoutUI() {
397396
const params = new URLSearchParams(window.location.search);
398397
params.set("environment", environment);
399398
window.location.href = `${window.location.href}?${params.toString()}`;
400-
401399
}
402400
}, [environment, prevEnvironment]);
403401

0 commit comments

Comments
 (0)