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

henry/wall-1655/feat: add more wallets carousel #9916

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion packages/api/src/hooks/useVerifyEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type TPayload = Parameters<ReturnType<typeof useRequest<'verify_email'>>['mutate
/** A custom hook for verifying email address */
const useVerifyEmail = () => {
const { mutate: _mutate, ...rest } = useRequest('verify_email');

const mutate = useCallback((payload: TPayload) => _mutate({ payload }), [_mutate]);

return {
Expand Down
6 changes: 5 additions & 1 deletion packages/wallets/src/AppContent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import WalletsAddMore from './components/WalletsAddMoreCarousel';
import useDevice from './hooks/useDevice';
import { DesktopWalletsList, WalletsCarousel } from './components';
import './AppContent.scss';
Expand All @@ -8,7 +9,10 @@ const AppContent: React.FC = () => {

return (
<div className='wallets-app'>
<div className='wallets-app__content'>{is_mobile ? <WalletsCarousel /> : <DesktopWalletsList />}</div>
<div className='wallets-app__content'>
{is_mobile ? <WalletsCarousel /> : <DesktopWalletsList />}
<WalletsAddMore />
</div>
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
.wallets-add-more {
display: flex;
flex-direction: column;
width: 100%;
padding-top: 2.4rem;

@media (max-width: 375px) {
padding-top: 0;
gap: 0.8rem;
}

&__header {
font-size: 3.2rem;
font-weight: 700;
margin-bottom: 1.6rem;

@media (max-width: 375px) {
font-size: 2.8rem;
padding-left: 1.6rem;
margin-bottom: 0;
}
}
&__carousel {
overflow: hidden;
background-color: #fff;
padding: 3.2rem 0 3.2rem 1.6rem;
border-radius: 0.8rem;
position: relative;
border: 0.1rem solid #d6dadb;
height: 100%;

@media (max-width: 375px) {
padding: 1.6rem 0 2.4rem 1.6rem;
border-radius: unset;
}

&-wrapper {
height: 100%;
display: flex;
align-items: center;
justify-content: flex-start;
gap: 2.4rem;

@media (max-width: 375px) {
gap: 1.6rem;
}
}

&-btn {
z-index: 1;
position: absolute;
height: 4rem;
width: 4rem;
border-radius: 50%;
cursor: pointer;
top: 45%;

&--prev {
left: 1.6rem;
}
&--next {
right: 1.6rem;
}
&:disabled {
opacity: 0.3;
display: none;
}
}
}
&__card {
width: 23.2rem;
height: 28.2rem;
border-radius: 1.6rem;
flex-shrink: 0;
border: 0.1rem solid #d6dadb;

@media (max-width: 375px) {
height: 29.2rem;
width: 19.2rem;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import React, { useCallback, useEffect, useState } from 'react';
import useEmblaCarousel, { EmblaCarouselType, EmblaOptionsType } from 'embla-carousel-react';
import { useAvailableWallets } from '@deriv/api';
import useDevice from '../../hooks/useDevice';

const WalletsAddMoreCarousel = () => {
const { is_mobile } = useDevice();
const { data } = useAvailableWallets();
const options: EmblaOptionsType = {
align: 0,
containScroll: 'trimSnaps',
};

const [WalletsAddMoreRef, emblaApi] = useEmblaCarousel(options);
const [is_hovered, setIsHovered] = useState(is_mobile);
const [prev_btn_enabled, setPrevBtnEnabled] = useState(false);
const [next_btn_enabled, setNextBtnEnabled] = useState(false);

const scrollPrev = useCallback(() => emblaApi?.scrollPrev(), [emblaApi]);
const scrollNext = useCallback(() => emblaApi?.scrollNext(), [emblaApi]);

useEffect(() => {
if (!emblaApi) return;

const onSelect = (embla_api: EmblaCarouselType) => {
setPrevBtnEnabled(embla_api.canScrollPrev());
setNextBtnEnabled(embla_api.canScrollNext());
};

onSelect(emblaApi);
emblaApi.on('reInit', onSelect);
emblaApi.reInit({ watchDrag: is_mobile });
emblaApi.on('select', onSelect);
}, [emblaApi, is_mobile]);

return (
<React.Fragment>
<div className='wallets-add-more'>
<h2 className='wallets-add-more__header'>Add more Wallets</h2>
<div
className='wallets-add-more__carousel'
data-testid='dt-wallets-add-more'
ref={WalletsAddMoreRef}
onMouseEnter={() => !is_mobile && setIsHovered(true)}
onMouseLeave={() => !is_mobile && setIsHovered(false)}
>
<div className='wallets-add-more__carousel-wrapper'>
{data?.map(item => (
<div className='wallets-add-more__card' key={item.currency}>
{item.currency}
</div>
))}
</div>
{!is_mobile && is_hovered && (
<React.Fragment>
<button
className='wallets-add-more__carousel-btn wallets-add-more__carousel-btn--prev'
onClick={scrollPrev}
disabled={!prev_btn_enabled}
>
a
</button>
<button
className='wallets-add-more__carousel-btn wallets-add-more__carousel-btn--next'
onClick={scrollNext}
disabled={!next_btn_enabled}
>
b
</button>
</React.Fragment>
)}
</div>
</div>
</React.Fragment>
);
};

export default WalletsAddMoreCarousel;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import WalletsAddMoreCarousel from './WalletsAddMoreCarousel';
import './WalletsAddMoreCarousel.scss';

export default WalletsAddMoreCarousel;
2 changes: 1 addition & 1 deletion packages/wallets/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import './index.scss';

const App: React.FC = () => (
<APIProvider>
<AppContent />;
<AppContent />
</APIProvider>
);

Expand Down