Skip to content

Commit

Permalink
Feature/cm 933 AddFunds onboarding drawer (#2293)
Browse files Browse the repository at this point in the history
  • Loading branch information
glomotion authored Oct 11, 2024
1 parent 93a71b0 commit 5268661
Show file tree
Hide file tree
Showing 23 changed files with 2,501 additions and 165 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Box, BoxProps } from '@biom3/react';
import merge from 'ts-deepmerge';
import {
simpleLayoutStyle,
headerStyle,
Expand All @@ -18,40 +19,42 @@ export interface SimpleLayoutProps {
floatHeader?: boolean;
footerBackgroundColor?: string;
bodyStyleOverrides?: BoxProps['sx'];
containerSx?: BoxProps['sx'];
}

export function SimpleLayout({
header,
footer,
children,
heroContent,
testId,
testId = 'container',
floatHeader = false,
footerBackgroundColor,
bodyStyleOverrides,
containerSx = {},
}: SimpleLayoutProps) {
return (
<Box sx={responsiveStyles}>
<Box testId={testId} sx={simpleLayoutStyle}>
<Box sx={responsiveStyles} testId="simpleLayout">
<Box testId={testId} sx={merge(simpleLayoutStyle, containerSx)}>
{header && (
<Box sx={headerStyle(floatHeader)}>
<Box sx={headerStyle(floatHeader)} testId="header">
{header}
</Box>
)}
<Box sx={contentStyle}>
<Box sx={contentStyle} testId="main">
{heroContent && (
<Box sx={heroContentStyle}>
{heroContent}
</Box>
)}
{children && (
<Box sx={{ ...bodyStyle, ...bodyStyleOverrides }}>
<Box sx={{ ...bodyStyle, ...bodyStyleOverrides }} testId="children">
{children}
</Box>
)}
</Box>
{footer && (
<Box sx={footerStyle(footerBackgroundColor)}>
<Box sx={footerStyle(footerBackgroundColor)} testId="footer">
{footer}
</Box>
)}
Expand Down
17 changes: 17 additions & 0 deletions packages/checkout/widgets-lib/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,23 @@
}
},
"ADD_FUNDS": {
"onboarding": {
"screen1": {
"title": "Payments on Immutable\nhave evolved",
"caption": "listen up",
"buttonText": "Next"
},
"screen2": {
"title": "Deliver tokens to Passport\n& pay from any wallet",
"caption": "whats evolved",
"buttonText": "Next"
},
"screen3": {
"title": "Pay with tokens on other chains,\nwe'll find you the best option",
"caption": "evolution",
"buttonText": "Choose the Wallet to Pay with"
}
},
"drawer": {
"options": {
"swap": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
AddFundsWidgetParams,
} from '@imtbl/checkout-sdk';
import React, { Suspense } from 'react';
import { CloudImage, Stack } from '@biom3/react';
import { Base } from '../BaseWidgetRoot';
import { CustomAnalyticsProvider } from '../../context/analytics-provider/CustomAnalyticsProvider';
import { HandoverProvider } from '../../context/handover-context/HandoverProvider';
Expand All @@ -20,7 +21,11 @@ import {
} from '../../components/ConnectLoader/ConnectLoader';
import { getL1ChainId, getL2ChainId } from '../../lib';
import { sendAddFundsCloseEvent } from './AddFundsWidgetEvents';
import { isValidAddress, isValidAmount } from '../../lib/validations/widgetValidators';
import {
isValidAddress,
isValidAmount,
} from '../../lib/validations/widgetValidators';
import { getRemoteImage } from '../../lib/utils';

const AddFundsWidget = React.lazy(() => import('./AddFundsWidget'));

Expand Down Expand Up @@ -79,14 +84,15 @@ export class AddFunds extends Base<WidgetType.ADD_FUNDS> {
],
isCheckNetworkEnabled: false,
};
const config = this.strongConfig();

this.reactRoot.render(
<React.StrictMode>
<CustomAnalyticsProvider checkout={this.checkout}>
<ThemeProvider id="add-funds-container" config={this.strongConfig()}>
<ThemeProvider id="add-funds-container" config={config}>
<HandoverProvider>
<ConnectLoader
widgetConfig={this.strongConfig()}
widgetConfig={config}
params={connectLoaderParams}
closeEvent={() => sendAddFundsCloseEvent(window)}
>
Expand All @@ -95,17 +101,37 @@ export class AddFunds extends Base<WidgetType.ADD_FUNDS> {
<LoadingView loadingText={t('views.LOADING_VIEW.text')} />
}
>
<AddFundsWidget
config={this.strongConfig()}
checkout={this.checkout}
web3Provider={this.web3Provider}
showBridgeOption={this.parameters.showBridgeOption}
showSwapOption={this.parameters.showSwapOption}
showOnrampOption={this.parameters.showOnrampOption}
toTokenAddress={this.parameters.toTokenAddress}
toAmount={this.parameters.toAmount}
showBackButton={this.parameters.showBackButton}
/>
<Stack sx={{ pos: 'relative' }}>
<CloudImage
use={(
<img
src={getRemoteImage(
config.environment,
'/add-funds-bg-texture.webp',
)}
alt="blurry bg texture"
/>
)}
sx={{
pos: 'absolute',
h: '100%',
w: '100%',
objectFit: 'cover',
objectPosition: 'center',
}}
/>
<AddFundsWidget
config={config}
checkout={this.checkout}
web3Provider={this.web3Provider}
showBridgeOption={this.parameters.showBridgeOption}
showSwapOption={this.parameters.showSwapOption}
showOnrampOption={this.parameters.showOnrampOption}
toTokenAddress={this.parameters.toTokenAddress}
toAmount={this.parameters.toAmount}
showBackButton={this.parameters.showBackButton}
/>
</Stack>
</Suspense>
</ConnectLoader>
</HandoverProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,26 @@ import { AddFundsWidgetParams, Checkout } from '@imtbl/checkout-sdk';
import { sendAddFundsCloseEvent } from './AddFundsWidgetEvents';
import { EventTargetContext } from '../../context/event-target-context/EventTargetContext';
import {
AddFundsActions, AddFundsContext, addFundsReducer, initialAddFundsState,
AddFundsActions,
AddFundsContext,
addFundsReducer,
initialAddFundsState,
} from './context/AddFundsContext';
import { AddFundsWidgetViews } from '../../context/view-context/AddFundsViewContextTypes';
import {
initialViewState,
SharedViews, ViewActions,
SharedViews,
ViewActions,
ViewContext,
viewReducer,
} from '../../context/view-context/ViewContext';
import { AddFunds } from './views/AddFunds';
import { ErrorView } from '../../views/error/ErrorView';
import { useSquid } from './hooks/useSquid';
import { useAnalytics, UserJourney } from '../../context/analytics-provider/SegmentAnalyticsProvider';
import {
useAnalytics,
UserJourney,
} from '../../context/analytics-provider/SegmentAnalyticsProvider';
import { fetchChains } from './functions/fetchChains';
import { StrongCheckoutWidgetsConfig } from '../../lib/withDefaultWidgetConfig';
import { Review } from './views/Review';
Expand Down Expand Up @@ -60,11 +67,12 @@ export default function AddFundsWidget({
[viewState, viewReducer],
);

const [addFundsState, addFundsDispatch] = useReducer(addFundsReducer, initialAddFundsState);
const [addFundsState, addFundsDispatch] = useReducer(
addFundsReducer,
initialAddFundsState,
);

const {
squid, provider, chains,
} = addFundsState;
const { squid, provider, chains } = addFundsState;

const addFundsReducerValues = useMemo(
() => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { ReactElement } from 'react';
import { useTranslation } from 'react-i18next';
import { FiatOptionType } from '../types';

export interface FiatOptionProps<RC extends ReactElement | undefined = undefined> {
export interface FiatOptionProps<
RC extends ReactElement | undefined = undefined,
> {
rc?: RC;
type: FiatOptionType;
onClick?: (type: FiatOptionType) => void;
Expand Down Expand Up @@ -55,7 +57,7 @@ export function FiatOption<RC extends ReactElement | undefined = undefined>({
</MenuItem.Label>
{!disabled && <MenuItem.IntentIcon />}
<MenuItem.Caption>
{ t(
{t(
`views.ADD_FUNDS.drawer.options.${type}.${
disabled ? 'disabledCaption' : 'caption'
}`,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import {
Button,
Divider,
Drawer,
Heading,
OnboardingPagination,
vFlex,
} from '@biom3/react';
import {
useCallback, useEffect, useMemo, useState,
} from 'react';
import { useTranslation } from 'react-i18next';
import {
getCacheItem,
SEEN_ONBOARDING_KEY,
setCacheItem,
} from '../../functions/onboardingState';
import { OnboardingIllustration1 } from './OnboardingIllustration1';
import { OnboardingIllustration2 } from './OnboardingIllustration2';
import { OnboardingIllustration3 } from './OnboardingIllustration3';

const HERO_IMAGES = [
OnboardingIllustration1,
OnboardingIllustration2,
OnboardingIllustration3,
];

export function OnboardingDrawer() {
const { t } = useTranslation();
const [visible, setVisible] = useState(false);
const [screenIndex, setScreenIndex] = useState<1 | 2 | 3>(1);

useEffect(() => {
async function checkToInitialiseDrawer() {
const cachedValue = await getCacheItem(SEEN_ONBOARDING_KEY);
return cachedValue ? setVisible(false) : setVisible(true);
}

checkToInitialiseDrawer();
}, []);

const handleCtaOnClick = useCallback(() => {
switch (screenIndex) {
case 2: {
// @NOTE: once they have "seen" the final slide, mark it as such
// in the cache so that we don't show this to users again
setCacheItem(SEEN_ONBOARDING_KEY, true);
return setScreenIndex(3);
}
case 3:
// @NOTE: they have "seen" all slides - so this drawer can be closed
return setVisible(false);

case 1:
default:
return setScreenIndex(2);
}
}, [screenIndex]);

const ScreenHeroImage = useMemo(
() => HERO_IMAGES[screenIndex - 1],
[screenIndex],
);

return (
<Drawer size="threeQuarter" visible={visible} showHeaderBar={false}>
<Drawer.Content
sx={{
...vFlex,
alignItems: 'center',
textAlign: 'center',
px: 'base.spacing.x6',
}}
>
<ScreenHeroImage />
<Divider
size="xSmall"
textAlign="center"
sx={{ mt: 'base.spacing.x6', mb: 'base.spacing.x4' }}
>
{t(`views.ADD_FUNDS.onboarding.screen${screenIndex}.caption`)}
</Divider>
<Heading
size="small"
sx={{
// @NOTE: this preserves newlines inside any strings, which
// come out of the translation layer
whiteSpace: 'pre-line',
}}
>
{t(`views.ADD_FUNDS.onboarding.screen${screenIndex}.title`)}
</Heading>
<OnboardingPagination
disabled
size="small"
currentPage={screenIndex}
totalPages={3}
sx={{ mt: 'base.spacing.x11', mb: 'base.spacing.x8' }}
/>
<Button
variant={screenIndex === 3 ? 'primary' : 'tertiary'}
onClick={handleCtaOnClick}
size="large"
sx={{ alignSelf: 'stretch' }}
>
{t(`views.ADD_FUNDS.onboarding.screen${screenIndex}.buttonText`)}
</Button>
</Drawer.Content>
</Drawer>
);
}
Loading

0 comments on commit 5268661

Please sign in to comment.