-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(devwallet): change profile (#2651)
- Loading branch information
1 parent
b28d165
commit 65c30e4
Showing
13 changed files
with
467 additions
and
228 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
--- |
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
97 changes: 97 additions & 0 deletions
97
packages/apps/dev-wallet/src/Components/ProfileChanger/ProfileChanger.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,97 @@ | ||
import { useWallet } from '@/modules/wallet/wallet.hook'; | ||
import { IProfilePicked, unlockWithWebAuthn } from '@/utils/unlockWithWebAuthn'; | ||
import { MonoMoreHoriz } from '@kadena/kode-icons/system'; | ||
import { | ||
Button, | ||
ContextMenu, | ||
ContextMenuDivider, | ||
ContextMenuItem, | ||
Stack, | ||
} from '@kadena/kode-ui'; | ||
import { FC } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { Profile } from './components/Profile'; | ||
import { profileClass, profileListClass } from './components/style.css'; | ||
|
||
const getInitial = (name: string): string => { | ||
return name.at(0)?.toUpperCase() ?? '-'; | ||
}; | ||
|
||
export const ProfileChanger: FC = () => { | ||
const { | ||
profileList, | ||
profile: currentProfile, | ||
unlockProfile, | ||
lockProfile, | ||
} = useWallet(); | ||
const navigate = useNavigate(); | ||
|
||
const handleSelect = async (profile: IProfilePicked) => { | ||
if (profile.options.authMode === 'WEB_AUTHN') { | ||
await unlockWithWebAuthn(profile, unlockProfile); | ||
} else { | ||
navigate(`/unlock-profile/${profile.uuid}`); | ||
} | ||
}; | ||
|
||
const filteredProfile = profileList.filter( | ||
(p) => p.uuid !== currentProfile?.uuid, | ||
)[0]; | ||
|
||
const hasMoreOptions = profileList.length > 2; | ||
|
||
return ( | ||
<Stack as="section" className={profileListClass}> | ||
{hasMoreOptions && ( | ||
<ContextMenu | ||
placement="bottom start" | ||
trigger={ | ||
<Button className={profileClass()}> | ||
<MonoMoreHoriz /> | ||
</Button> | ||
} | ||
> | ||
{profileList.map((profile) => { | ||
return ( | ||
<ContextMenuItem | ||
key={profile.uuid} | ||
label={profile.name} | ||
onClick={() => { | ||
handleSelect(profile); | ||
}} | ||
/> | ||
); | ||
})} | ||
<ContextMenuDivider /> | ||
<ContextMenuItem label="logout" onClick={lockProfile} /> | ||
</ContextMenu> | ||
)} | ||
|
||
{filteredProfile && ( | ||
<Profile | ||
key={filteredProfile.uuid} | ||
color={filteredProfile.accentColor} | ||
idx={hasMoreOptions ? 1 : 0} | ||
hasMoreOptions={hasMoreOptions} | ||
isActive={currentProfile?.uuid === filteredProfile.uuid} | ||
onClick={() => handleSelect(filteredProfile)} | ||
> | ||
{getInitial(filteredProfile.name)} | ||
</Profile> | ||
)} | ||
|
||
{currentProfile && ( | ||
<Profile | ||
key={currentProfile.uuid} | ||
color={currentProfile.accentColor} | ||
idx={hasMoreOptions ? 2 : 0} | ||
hasMoreOptions={hasMoreOptions} | ||
isActive={currentProfile?.uuid === currentProfile.uuid} | ||
onClick={() => handleSelect(currentProfile)} | ||
> | ||
{getInitial(currentProfile.name)} | ||
</Profile> | ||
)} | ||
</Stack> | ||
); | ||
}; |
39 changes: 39 additions & 0 deletions
39
packages/apps/dev-wallet/src/Components/ProfileChanger/components/Profile.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,39 @@ | ||
import { Stack } from '@kadena/kode-ui'; | ||
import { FC, PropsWithChildren } from 'react'; | ||
import { profileClass } from './style.css'; | ||
|
||
interface IProps extends PropsWithChildren { | ||
idx?: number; | ||
color: string; | ||
isActive: boolean; | ||
onClick: () => void; | ||
hasMoreOptions: boolean; | ||
} | ||
|
||
export const Profile: FC<IProps> = ({ | ||
children, | ||
color, | ||
idx, | ||
isActive, | ||
onClick, | ||
hasMoreOptions, | ||
}) => { | ||
return ( | ||
<Stack | ||
as="button" | ||
data-hasMoreOptions={hasMoreOptions} | ||
onClick={() => onClick()} | ||
className={profileClass({ isActive })} | ||
style={{ | ||
backgroundColor: color, | ||
zIndex: idx ?? 0 + 1, | ||
transform: | ||
idx && hasMoreOptions | ||
? `translateX(-${90 * idx}%)` | ||
: `translateX(-100%)`, | ||
}} | ||
> | ||
{children} | ||
</Stack> | ||
); | ||
}; |
71 changes: 71 additions & 0 deletions
71
packages/apps/dev-wallet/src/Components/ProfileChanger/components/style.css.ts
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,71 @@ | ||
import { | ||
atoms, | ||
globalStyle, | ||
recipe, | ||
style, | ||
token, | ||
} from '@kadena/kode-ui/styles'; | ||
|
||
export const profileClass = recipe({ | ||
base: { | ||
borderRadius: token('radius.round'), | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
cursor: 'pointer', | ||
fontWeight: token('typography.weight.primaryFont.medium'), | ||
|
||
border: 0, | ||
width: '32px', | ||
height: '32px', | ||
aspectRatio: '1/1', | ||
color: token('color.background.base.default'), | ||
willChange: 'transform', | ||
transition: 'transform .4s ease', | ||
selectors: { | ||
'&:hover': { | ||
opacity: '.8', | ||
}, | ||
}, | ||
}, | ||
variants: { | ||
isActive: { | ||
true: { | ||
selectors: { | ||
'&:after': { | ||
content: '', | ||
position: 'absolute', | ||
backgroundColor: token( | ||
'color.background.accent.primary.inverse.default', | ||
), | ||
borderRadius: '50%', | ||
width: '10px', | ||
height: '10px', | ||
bottom: 0, | ||
right: 0, | ||
}, | ||
}, | ||
}, | ||
false: {}, | ||
}, | ||
}, | ||
}); | ||
|
||
export const profileListClass = style([ | ||
atoms({ | ||
position: 'relative', | ||
padding: 'no', | ||
margin: 'no', | ||
listStyleType: 'none', | ||
alignItems: 'center', | ||
cursor: 'pointer', | ||
gap: 'xs', | ||
}), | ||
]); | ||
|
||
globalStyle( | ||
`${profileListClass}:hover ${profileClass()}[data-hasMoreOptions="true"]`, | ||
{ | ||
background: 'green', | ||
transform: 'translateX(0)!important', | ||
}, | ||
); |
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
Oops, something went wrong.