Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Wallet): Vertical Slide #449

Merged
merged 20 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions public/images/Wallet/VerticalSlide/bracket-left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/images/Wallet/VerticalSlide/bracket-right.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions public/images/Wallet/VerticalSlide/multiple-keys.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions public/images/Wallet/VerticalSlide/recovery.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions public/images/Wallet/VerticalSlide/scan.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 84 additions & 0 deletions src/components/Wallet/VerticalSlide/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { useEffect, useState } from 'react'
import { ButtonBase, Container, Grid, Typography } from '@mui/material'
import type { BaseBlock } from '@/components/Home/types'
import BracketLeft from '@/public/images/Wallet/VerticalSlide/bracket-left.svg'
import RecoveryIcon from '@/public/images/Wallet/VerticalSlide/recovery.svg'
import ScanIcon from '@/public/images/Wallet/VerticalSlide/scan.svg'
import MultipleKeysIcon from '@/public/images/Wallet/VerticalSlide/multiple-keys.svg'
import BracketRight from '@/public/images/Wallet/VerticalSlide/bracket-right.svg'
import layoutCss from '@/components/common/styles.module.css'
import css from './styles.module.css'

const VerticalSlide = ({ title, items = [] }: BaseBlock) => {
const [selectedIndex, setSelectedIndex] = useState(0)

const itemsImages = items.map((item) => item.image)
const icons = [<RecoveryIcon key="recovery" />, <ScanIcon key="scan" />, <MultipleKeysIcon key="multiple-keys" />]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: we can move this outside of the component.


const handleCardClick = (index: number) => {
setSelectedIndex(index)
}
Comment on lines +20 to +22
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this is somewhat neglible. You can just call setSelectedIndex directly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to leave the click handler


// Change index every 5 seconds
useEffect(() => {
const interval = setInterval(() => {
setSelectedIndex((prevIndex) => (prevIndex + 1) % items?.length)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will return NaN if items is undefined.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initiate items to 0 in the received props

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which case, we don't need the optional chaining.

}, 5000)

return () => clearInterval(interval) // Cleanup interval on component unmount
}, [items.length])

return (
<Container className={layoutCss.containerShort}>
<Typography variant="h2" className={css.title}>
{title}
</Typography>

<Grid container spacing="40px" justifyContent="flex-end">
<Grid item md={7} className={css.imageItem}>
<div className={css.showInMd}>
<BracketLeft />
{icons.map((icon, index) => (
<span key={index} className={index === selectedIndex ? css.selected : undefined}>
{icon}
</span>
))}
<BracketRight />
</div>

{itemsImages[selectedIndex] ? (
<img src={itemsImages[selectedIndex].src} alt={itemsImages[selectedIndex].alt} className={css.image} />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can extract itemsImages[selectedIndex] to a variable to simplify this.

) : null}
</Grid>

<Grid item xs={12} md={5}>
<div className={css.cardWrapper}>
{items.map((item, index) => {
const { title, text } = item

return (
<Grid item key={index} xs={12}>
<ButtonBase
onClick={() => handleCardClick(index)}
disableRipple
className={`${css.card} ${index === selectedIndex ? css.selected : ''}`}
>
<Typography variant="h5">{title}</Typography>

{text && (
<Typography color="primary.light" component="div">
{text}
</Typography>
)}
</ButtonBase>
</Grid>
)
})}
</div>
</Grid>
</Grid>
</Container>
)
}

export default VerticalSlide
65 changes: 65 additions & 0 deletions src/components/Wallet/VerticalSlide/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
.title {
text-align: center;
max-width: 650px;
margin-bottom: 48px;
}

.image {
height: 300px;
object-fit: contain;
}

.showInMd {
display: none;
}

.cardWrapper {
border-radius: 6px;
border: 1px solid var(--mui-palette-border-light);
overflow: hidden;
}

.card {
border-bottom: 1px solid var(--mui-palette-border-light);
margin-bottom: -1px;
display: flex;
flex-direction: column;
align-items: flex-start;
padding: 48px 40px;
text-align: left;
}

.card.selected::before {
content: '';
position: absolute;
top: 0;
left: 0;
bottom: 0;
width: 4px;
background-color: var(--mui-palette-primary-main);
}

.selected {
color: var(--mui-palette-primary-main);
}

@media (min-width: 900px) {
.title {
margin-bottom: 80px;
}

.imageItem {
display: flex;
flex-direction: column;
align-items: center;
gap: 40px;
}

.image {
height: 450px;
}

.showInMd {
display: block;
}
}
30 changes: 30 additions & 0 deletions src/content/wallet.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,36 @@
],
"component": "common/TitleSlidingIcons"
},
{
"component": "Wallet/VerticalSlide",
"title": "Defend assets with <b>multi-signature</b> security",
"items": [
{
"title": "Eliminate single points of failure",
"text": "Distribute control across multiple owners and require for enhanced security.",
"image": {
"src": "/images/Wallet/VerticalSlide/eliminate-single-pof.png",
"alt": "Execute multisig"
}
},
{
"title": "Simulate and scan transactions",
"text": "Transact with confidence with risk scanning and transaction simulation before executing.",
"image": {
"src": "/images/Wallet/VerticalSlide/simulate-scan-tx.png",
"alt": "Simulate and scan transactions"
}
},
{
"title": "Restore access to your account",
"text": "Never lose access to your account. Restore account control easily with secure recovery mechanisms.",
"image": {
"src": "/images/Wallet/VerticalSlide/restore-access.png",
"alt": "Activate recovery"
}
}
]
},
{
"items": [
{
Expand Down
Loading