Skip to content

Commit

Permalink
Chore/refactor smart swap modal (#20239)
Browse files Browse the repository at this point in the history
* Add story for smart tx popover

* Use tsx for smart tx popover story and add btn to open it

* Refactor smart tx popover component to tsx and style

* Fix modal not triggering

* Remove bold from bullet points

* Adjust margins
  • Loading branch information
infiniteflower authored Aug 1, 2023
1 parent 2ad2827 commit 10ffc1e
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 171 deletions.
16 changes: 8 additions & 8 deletions ui/pages/swaps/build-quote/build-quote.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,14 +563,14 @@ export default function BuildQuote({
return (
<div className="build-quote">
<div className="build-quote__content">
{showSmartTransactionsOptInPopover && (
<SmartTransactionsPopover
onEnableSmartTransactionsClick={onEnableSmartTransactionsClick}
onCloseSmartTransactionsOptInPopover={
onCloseSmartTransactionsOptInPopover
}
/>
)}
<SmartTransactionsPopover
onEnableSmartTransactionsClick={onEnableSmartTransactionsClick}
onCloseSmartTransactionsOptInPopover={
onCloseSmartTransactionsOptInPopover
}
isOpen={showSmartTransactionsOptInPopover}
/>

<div className="build-quote__dropdown-input-pair-header">
<div className="build-quote__input-label">{t('swapSwapFrom')}</div>
{!isSwapsDefaultTokenSymbol(fromTokenSymbol, chainId) && (
Expand Down
34 changes: 0 additions & 34 deletions ui/pages/swaps/prepare-swap-page/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -368,37 +368,3 @@
@keyframes slide-in {
100% { transform: translateY(0%); }
}

.smart-transactions-popover {
transform: translateY(-100%);
animation: slide-in 0.5s forwards;

&__content {
flex-direction: column;

ul {
list-style: inside;
}

a {
color: var(--color-primary-default);
cursor: pointer;
}
}

&__footer {
flex-direction: column;
flex: 1;
align-items: center;
border-top: 0;

button {
border-radius: 50px;
}

a {
font-size: inherit;
padding-bottom: 0;
}
}
}
17 changes: 9 additions & 8 deletions ui/pages/swaps/prepare-swap-page/prepare-swap-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -846,14 +846,15 @@ export default function PrepareSwapPage({
</Box>
</ModalContent>
</Modal>
{showSmartTransactionsOptInPopover && (
<SmartTransactionsPopover
onEnableSmartTransactionsClick={onEnableSmartTransactionsClick}
onCloseSmartTransactionsOptInPopover={
onCloseSmartTransactionsOptInPopover
}
/>
)}

<SmartTransactionsPopover
onEnableSmartTransactionsClick={onEnableSmartTransactionsClick}
onCloseSmartTransactionsOptInPopover={
onCloseSmartTransactionsOptInPopover
}
isOpen={showSmartTransactionsOptInPopover}
/>

<div className="prepare-swap-page__swap-from-content">
<Box
display={DISPLAY.FLEX}
Expand Down
121 changes: 0 additions & 121 deletions ui/pages/swaps/prepare-swap-page/smart-transactions-popover.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react';
import { StoryFn, Meta } from '@storybook/react';
import { useArgs } from '@storybook/client-api';
import { BUTTON_VARIANT, Button } from '../../../components/component-library';
import SmartTransactionPopover from './smart-transactions-popover';

export default {
title: 'Pages/Swaps/SmartTransactionsPopover',
component: SmartTransactionPopover,
argTypes: {
isShowingModal: {
control: 'boolean',
},
},
} as Meta<typeof SmartTransactionPopover>;

export const DefaultStory: StoryFn<typeof SmartTransactionPopover> = () => {
const [{ isShowingModal }, updateArgs] = useArgs();
const toggleModal = () => updateArgs({ isShowingModal: !isShowingModal });

return (
<>
<Button variant={BUTTON_VARIANT.PRIMARY} onClick={toggleModal}>
Open modal
</Button>
{isShowingModal && (
<SmartTransactionPopover
isOpen={isShowingModal}
onEnableSmartTransactionsClick={() => {
console.log('onEnableSmartTransactionsClick');
}}
onCloseSmartTransactionsOptInPopover={toggleModal}
/>
)}
</>
);
};

DefaultStory.storyName = 'Default';
102 changes: 102 additions & 0 deletions ui/pages/swaps/prepare-swap-page/smart-transactions-popover.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import React, { useContext } from 'react';

import { I18nContext } from '../../../contexts/i18n';
import {
TextColor,
Display,
FlexDirection,
FontWeight,
BlockSize,
} from '../../../helpers/constants/design-system';
import {
Modal,
ModalContent,
ModalHeader,
ModalOverlay,
Text,
Box,
Button,
BUTTON_VARIANT,
} from '../../../components/component-library';

interface Props {
onEnableSmartTransactionsClick: () => void;
onCloseSmartTransactionsOptInPopover: () => void;
isOpen: boolean;
}

export default function SmartTransactionsPopover({
onEnableSmartTransactionsClick,
onCloseSmartTransactionsOptInPopover,
isOpen,
}: Props) {
const t = useContext(I18nContext);
return (
<Modal isOpen={isOpen} onClose={onCloseSmartTransactionsOptInPopover}>
<ModalOverlay />
<ModalContent>
<ModalHeader onClose={onCloseSmartTransactionsOptInPopover}>
{t('smartSwapsAreHere')}
</ModalHeader>

<Box
display={Display.Flex}
flexDirection={FlexDirection.Column}
gap={4}
marginTop={4}
>
<Box display={Display.Flex} flexDirection={FlexDirection.Column}>
<img
src="./images/logo/smart-transactions-header.png"
alt={t('swapSwapSwitch')}
/>
</Box>
<Text>{t('smartSwapsDescription')}</Text>
<Text
as="ul"
marginTop={3}
marginBottom={3}
style={{ listStyle: 'inside' }}
>
<li>{t('stxBenefit1')}</li>
<li>{t('stxBenefit2')}</li>
<li>{t('stxBenefit3')}</li>
<li>
{t('stxBenefit4')}
<Text as="span" fontWeight={FontWeight.Normal}>
{' *'}
</Text>
</li>
</Text>
<Text color={TextColor.textAlternative}>
{t('smartSwapsSubDescription')}&nbsp;
<Text
as="span"
fontWeight={FontWeight.Bold}
color={TextColor.textAlternative}
>
{t('stxYouCanOptOut')}&nbsp;
</Text>
</Text>

<Button
variant={BUTTON_VARIANT.PRIMARY}
onClick={onEnableSmartTransactionsClick}
width={BlockSize.Full}
>
{t('enableSmartSwaps')}
</Button>

<Button
type="link"
variant={BUTTON_VARIANT.LINK}
onClick={onCloseSmartTransactionsOptInPopover}
width={BlockSize.Full}
>
{t('noThanksVariant2')}
</Button>
</Box>
</ModalContent>
</Modal>
);
}

0 comments on commit 10ffc1e

Please sign in to comment.