Skip to content
Open
Show file tree
Hide file tree
Changes from 19 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
3 changes: 3 additions & 0 deletions apps/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@
"date-fns": "4.1.0",
"motion": "12.5.0",
"react": "19.0.0",
"react-custom-scrollbars-2": "4.5.0",
"react-dom": "19.0.0",
"react-i18next": "11.18.6",
"react-icons": "5.4.0",
"react-markdown": "10.1.0",
"react-transition-group": "4.4.2",
"react-virtualized": "9.22.3",
"react-window": "1.8.11",
"zod": "3.23.8"
Expand Down
218 changes: 218 additions & 0 deletions apps/next/src/components/Header/ConciergePrompt.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
import {
Box,
getHexAlpha,
Stack,
Typography,
useTheme,
} from '@avalabs/k2-alpine';
import { useRef, useState } from 'react';
import { useHistory } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { CSSTransition, TransitionGroup } from 'react-transition-group';
import {
AnimatedButton,
PromptButtonBackground,
TextAnimation,
} from './components/styledComponents';
import { useFeatureFlagContext, useSettingsContext } from '@core/ui';
import { FeatureGates } from '@core/types';

export const ConciergePrompt = ({ isAIBackdropOpen, setIsAIBackdropOpen }) => {
const theme = useTheme();
const history = useHistory();
const { t } = useTranslation();

const [isHoverAreaHidden, setIsHoverAreaHidden] = useState(false);
const { coreAssistant } = useSettingsContext();
const { featureFlags } = useFeatureFlagContext();
const timer = useRef<NodeJS.Timeout>(null);
const hasBackdropEntered = useRef(false);

const buttonLabels = [
t('Ask Core Concierge to send crypto'),
t('Ask Core Concierge to swap tokens'),
t('Ask Core Concierge to bridge tokens'),
t('Ask Core Concierge to transfer for you'),
t('Ask Core Concierge to manage accounts'),
];

const getRandomButtonLabel = () => {
return buttonLabels[Math.floor(Math.random() * buttonLabels.length)];
};

const nodeRef = useRef(null);
const nodeRef2 = useRef(null);
const nodeRef3 = useRef(null);

if (!coreAssistant || !featureFlags[FeatureGates.CORE_ASSISTANT]) {
return null;
}

return (
<>
{/* THE BOX AREA WHERE WE WANT TO CATCH THE CURSOR */}
<Stack
className="prompt-hover-area"
sx={{
width: '100%',
height: '40px',
position: 'absolute',
top: '56px',
zIndex: isHoverAreaHidden ? 0 : theme.zIndex.tooltip - 1,
}}
onMouseEnter={() => {
timer.current = setTimeout(() => {
setIsAIBackdropOpen(true);
}, 400);
}}
onMouseLeave={() => {
if (!isAIBackdropOpen && timer.current) {
clearTimeout(timer.current);
}
}}
/>
<TransitionGroup component={null}>
<Stack>
{/* GRADIENT BACKGROUND */}
<CSSTransition
key={1}
timeout={200}
classNames="overlay"
appear
enter
exit
in={isAIBackdropOpen}
nodeRef={nodeRef2}
>
<Stack
sx={{
'.prompt-background': {
display: 'none',
opacity: 0,
transition: `opacity 400ms linear`,
},
'.overlay-enter.prompt-background': {
display: 'block',
},
'.overlay-enter-done.prompt-background': {
display: 'block',
opacity: 1,
},
'.overlay-exit.prompt-background': {
display: 'block',
opacity: 1,
},
'.overlay-exit-done.prompt-background': {
display: 'block',
opacity: 0,
},
}}
>
<PromptButtonBackground
ref={nodeRef2}
className="prompt-background"
/>
</Stack>
</CSSTransition>
{/* BACKDROP */}
<CSSTransition
key={2}
timeout={1000}
classNames="backdrop"
appear
exit
in={isAIBackdropOpen}
nodeRef={nodeRef3}
onExited={() => {
hasBackdropEntered.current = false;
}}
>
<Stack
sx={{
position: 'fixed',
top: 0,
left: 0,
right: 0,
bottom: 0,
background: '#28282ECC',
backdropFilter: 'none',
display: 'none',
transition: 'opacity 400ms linear',
opacity: 0,
zIndex: theme.zIndex.appBar - 1,
'&.backdrop-enter': {
display: 'flex',
},
'&.backdrop-enter-done': {
display: 'flex',

Choose a reason for hiding this comment

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

Please replace class name literals with constants to have a link between the selectors and the logic applying the CSS classes

opacity: 1,
},
}}
ref={nodeRef3}
onMouseMove={() => {
if (hasBackdropEntered.current) {
setIsAIBackdropOpen(false);
setIsHoverAreaHidden(false);
}
}}
/>
</CSSTransition>
{/* THE BUTTON */}
<CSSTransition
key={3}
timeout={1000}
classNames="button"
appear
exit
in={isAIBackdropOpen}
nodeRef={nodeRef}
onEntered={() => {
// it needs to be delayed (waiting for the button animation getting done) to avoid the glitch
setTimeout(() => {
setIsHoverAreaHidden(true);
hasBackdropEntered.current = true;
}, 500);
}}
>
<Stack
sx={{
position: 'absolute',
top: '56px',
width: '100%',
height: '40px',
px: 1.5,
}}
>
<AnimatedButton
variant="contained"
sx={{
borderColor: 'common.white_10',
maxWidth: '100%',
justifyContent: 'flex-start',
px: 1.5,
backgroundColor: getHexAlpha(theme.palette.text.primary, 30),
color: 'common.white',
}}
onClick={() => {
history.push('/concierge');
}}
size="large"
fullWidth
ref={nodeRef}
>
<Box component="span" sx={{ mr: 1, fontSize: 24 }}>
</Box>
<TextAnimation>
<Typography variant="subtitle3">
{isAIBackdropOpen && getRandomButtonLabel()}
</Typography>
</TextAnimation>
</AnimatedButton>
</Stack>
</CSSTransition>
</Stack>
</TransitionGroup>
</>
);
};
47 changes: 15 additions & 32 deletions apps/next/src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,23 @@
import {
getHexAlpha,
Stack,
styled,
Typography,
useTheme,
} from '@avalabs/k2-alpine';
import { getHexAlpha, Stack, Typography, useTheme } from '@avalabs/k2-alpine';
import { useAccountsContext } from '@core/ui';
import { useState } from 'react';
import { MdOutlineUnfoldMore } from 'react-icons/md';
import { useHistory } from 'react-router-dom';
import { PersonalAvatar } from '../PersonalAvatar';
import { AddressList } from './AddressList';
import { HeaderActions } from './components/HeaderActions';

const AccountInfo = styled(Stack)`
cursor: pointer;
border-radius: 10px;
padding: ${({ theme }) => theme.spacing(0.5)};
transition: ${({ theme }) =>
theme.transitions.create(['background', 'opacity'])};
flex-direction: row;
align-items: center;
& > svg {
opacity: 0;
}
`;

const AccountSelectContainer = styled(Stack)`
cursor: pointer;
position: relative;
&:hover > div:first-of-type {
background: ${({ theme }) => getHexAlpha(theme.palette.primary.main, 10)};
& > svg {
opacity: 1;
}
}
`;
import {
AccountInfo,
AccountSelectContainer,
} from './components/styledComponents';
import { ConciergePrompt } from './ConciergePrompt';

export const Header = () => {
const { accounts } = useAccountsContext();
const activeAccount = accounts.active;
const theme = useTheme();
const [isAddressAppear, setIsAddressAppear] = useState(false);
const [isAIBackdropOpen, setIsAIBackdropOpen] = useState(false);
const history = useHistory();

// TODO: fix this after the transactions will be implemented
Expand Down Expand Up @@ -69,7 +45,10 @@ export const Header = () => {
alignItems: 'center',
justifyContent: 'space-between',
px: 1,
zIndex: 1,
zIndex: theme.zIndex.tooltip + 1,
}}
onMouseEnter={() => {
setIsAIBackdropOpen(false);
}}
>
<AccountSelectContainer
Expand All @@ -95,6 +74,10 @@ export const Header = () => {
pendingTransaction={isTransactionPending}
/>
</Stack>
<ConciergePrompt
isAIBackdropOpen={isAIBackdropOpen}
setIsAIBackdropOpen={setIsAIBackdropOpen}
/>
</Stack>
);
};
Loading
Loading