Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from 'react';
import React, { useEffect, useRef, useState } from 'react';
import { useLocalStorage, useReadLocalStorage } from 'usehooks-ts';
import { useActiveWalletAccount, useAllWalletAccounts, useAuthorize, useWalletAccountsList } from '@deriv/api';
import Joyride, { ACTIONS, CallBackProps } from '@deriv/react-joyride';
Expand All @@ -15,22 +15,40 @@ import './WalletTourGuide.scss';

const WalletTourGuide = () => {
const [walletsOnboarding, setWalletsOnboarding] = useLocalStorage(key, useReadLocalStorage(key));
const [addMoreWalletsTransformValue, setAddMoreWalletsTransformValue] = useState('');
const { isMobile } = useDevice();

const { isFetching, isLoading, isSuccess, switchAccount } = useAuthorize();
const { data: wallets } = useWalletAccountsList();
const { data: activeWallet } = useActiveWalletAccount();
const { data: availableWallets } = useAllWalletAccounts();

const addMoreWalletRef = useRef<HTMLElement | null>(document.getElementById('wallets_add_more_carousel_wrapper'));

const fiatWalletLoginId = getFiatWalletLoginId(wallets);
const walletIndex = getWalletIndexForTarget(fiatWalletLoginId, wallets);
const activeWalletLoginId = activeWallet?.loginid;

const isDemoWallet = Boolean(activeWallet?.is_virtual);
const hasMT5Account = Boolean(activeWallet?.linked_to?.some(account => account.platform === 'mt5'));
const hasDerivAppsTradingAccount = Boolean(activeWallet?.dtrade_loginid);
const isAllWalletsAlreadyAdded = Boolean(availableWallets?.every(wallet => wallet.is_added));

const callbackHandle = (data: CallBackProps) => {
const { action } = data;
const { action, index, lifecycle } = data;

if (index === 0 && !isAllWalletsAlreadyAdded) {
if (addMoreWalletRef.current && lifecycle === 'init' && action === 'start') {
setAddMoreWalletsTransformValue(addMoreWalletRef.current.style.transform);
addMoreWalletRef.current.style.transform = 'translate3d(0px, 0px, 0px)';
}
}

if (action === ACTIONS.RESET) {
setWalletsOnboarding('');
if (!isAllWalletsAlreadyAdded && addMoreWalletRef.current) {
addMoreWalletRef.current.style.transform = addMoreWalletsTransformValue;
}
}
};

Expand All @@ -47,10 +65,11 @@ const WalletTourGuide = () => {
}
}, [activeWalletLoginId, fiatWalletLoginId, switchAccount, walletsOnboarding]);

const isDemoWallet = Boolean(activeWallet?.is_virtual);
const hasMT5Account = Boolean(activeWallet?.linked_to?.some(account => account.platform === 'mt5'));
const hasDerivAppsTradingAccount = Boolean(activeWallet?.dtrade_loginid);
const isAllWalletsAlreadyAdded = Boolean(availableWallets?.every(wallet => wallet.is_added));
useEffect(() => {
if (!addMoreWalletRef.current) {
addMoreWalletRef.current = document.getElementById('wallets_add_more_carousel_wrapper');
}
}, []);

if (isMobile) return null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const WalletsAddMoreCarousel: React.FC = () => {
</WalletText>
</div>
<div className='wallets-add-more__carousel' data-testid='dt-wallets-add-more' ref={walletsAddMoreEmblaRef}>
<div className='wallets-add-more__carousel-wrapper'>
<div className='wallets-add-more__carousel-wrapper' id='wallets_add_more_carousel_wrapper'>
{(isLoading || isAuthorizeLoading) &&
Array.from({ length: 8 }).map((_, idx) => (
<WalletsAddMoreLoader key={`wallets-add-more-loader-${idx}`} />
Expand Down