-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: add swaps card to safe apps list (#3786)
- Loading branch information
Showing
11 changed files
with
197 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/components/safe-apps/NativeSwapsCard/index.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
import NativeSwapsCard from './index' | ||
import { Box } from '@mui/material' | ||
import { StoreDecorator } from '@/stories/storeDecorator' | ||
|
||
const meta = { | ||
component: NativeSwapsCard, | ||
parameters: { | ||
componentSubtitle: 'Renders a promo card for native swaps', | ||
}, | ||
|
||
decorators: [ | ||
(Story) => { | ||
return ( | ||
<StoreDecorator initialState={{ chains: { data: [{ chainId: '11155111', features: ['NATIVE_SWAPS'] }] } }}> | ||
<Box sx={{ maxWidth: '500px' }}> | ||
<Story /> | ||
</Box> | ||
</StoreDecorator> | ||
) | ||
}, | ||
], | ||
tags: ['autodocs'], | ||
} satisfies Meta<typeof NativeSwapsCard> | ||
|
||
export default meta | ||
type Story = StoryObj<typeof meta> | ||
|
||
export const Default: Story = { | ||
args: {}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import CardHeader from '@mui/material/CardHeader' | ||
import CardContent from '@mui/material/CardContent' | ||
import Typography from '@mui/material/Typography' | ||
import { Button, Paper, Stack } from '@mui/material' | ||
import SafeAppIconCard from '../SafeAppIconCard' | ||
import css from './styles.module.css' | ||
import { SWAP_EVENTS, SWAP_LABELS } from '@/services/analytics/events/swaps' | ||
import Track from '@/components/common/Track' | ||
import Link from 'next/link' | ||
import { AppRoutes } from '@/config/routes' | ||
import { useRouter } from 'next/router' | ||
import useLocalStorage from '@/services/local-storage/useLocalStorage' | ||
import { useHasFeature } from '@/hooks/useChains' | ||
import { FEATURES } from '@/utils/chains' | ||
|
||
const SWAPS_APP_CARD_STORAGE_KEY = 'showSwapsAppCard' | ||
|
||
const NativeSwapsCard = () => { | ||
const router = useRouter() | ||
const isSwapFeatureEnabled = useHasFeature(FEATURES.NATIVE_SWAPS) | ||
const [isSwapsCardVisible = true, setIsSwapsCardVisible] = useLocalStorage<boolean>(SWAPS_APP_CARD_STORAGE_KEY) | ||
if (!isSwapFeatureEnabled || !isSwapsCardVisible) return null | ||
|
||
return ( | ||
<Paper className={css.container}> | ||
<CardHeader | ||
className={css.header} | ||
avatar={ | ||
<div className={css.iconContainer}> | ||
<SafeAppIconCard src="/images/common/swap.svg" alt="Swap Icon" width={24} height={24} /> | ||
</div> | ||
} | ||
/> | ||
|
||
<CardContent className={css.content}> | ||
<Typography className={css.title} variant="h5"> | ||
Native swaps are here! | ||
</Typography> | ||
|
||
<Typography className={css.description} variant="body2" color="text.secondary"> | ||
Experience seamless trading with better decoding and security in native swaps. | ||
</Typography> | ||
|
||
<Stack direction="row" gap={2} className={css.buttons}> | ||
<Track {...SWAP_EVENTS.OPEN_SWAPS} label={SWAP_LABELS.safeAppsPromoWidget}> | ||
<Link href={{ pathname: AppRoutes.swap, query: { safe: router.query.safe } }} passHref legacyBehavior> | ||
<Button variant="contained" size="small"> | ||
Try now | ||
</Button> | ||
</Link> | ||
</Track> | ||
<Button onClick={() => setIsSwapsCardVisible(false)} size="small" variant="text" sx={{ px: '16px' }}> | ||
Don't show | ||
</Button> | ||
</Stack> | ||
</CardContent> | ||
</Paper> | ||
) | ||
} | ||
|
||
export default NativeSwapsCard |
50 changes: 50 additions & 0 deletions
50
src/components/safe-apps/NativeSwapsCard/styles.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
.container { | ||
transition: background-color 0.3s ease-in-out, border 0.3s ease-in-out; | ||
border: 1px solid transparent; | ||
height: 100%; | ||
} | ||
|
||
.container:hover { | ||
background-color: var(--color-background-light); | ||
border: 1px solid var(--color-secondary-light); | ||
} | ||
|
||
.header { | ||
padding: var(--space-3) var(--space-2) var(--space-1) var(--space-2); | ||
} | ||
|
||
.content { | ||
padding: var(--space-2); | ||
} | ||
|
||
.iconContainer { | ||
position: relative; | ||
background: var(--color-secondary-light); | ||
border-radius: 50%; | ||
display: flex; | ||
padding: var(--space-1); | ||
} | ||
|
||
.title { | ||
line-height: 175%; | ||
margin: 0; | ||
|
||
flex-grow: 1; | ||
|
||
white-space: nowrap; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
} | ||
|
||
.description { | ||
/* Truncate Safe App Description (3 lines) */ | ||
display: -webkit-box; | ||
-webkit-line-clamp: 3; | ||
-webkit-box-orient: vertical; | ||
overflow: hidden; | ||
} | ||
|
||
.buttons { | ||
padding-top: var(--space-2); | ||
white-space: nowrap; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters