-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tooling-dashboard): style selected stake
- Loading branch information
1 parent
d64f686
commit c19bc2a
Showing
9 changed files
with
234 additions
and
22 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
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,73 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { useState } from 'react'; | ||
import cn from 'clsx'; | ||
|
||
export enum ImageIconSize { | ||
Small = 'w-5 h-5', | ||
Medium = 'w-8 h-8', | ||
Large = 'w-10 h-10', | ||
Full = 'w-full h-full', | ||
} | ||
|
||
export interface ImageIconProps { | ||
src: string | null | undefined; | ||
label: string; | ||
fallback: string; | ||
alt?: string; | ||
rounded?: boolean; | ||
size?: ImageIconSize; | ||
} | ||
|
||
function FallBackAvatar({ | ||
str, | ||
rounded, | ||
size = ImageIconSize.Large, | ||
}: { | ||
str: string; | ||
rounded?: boolean; | ||
size?: ImageIconSize; | ||
}) { | ||
function generateTextSize(size: ImageIconSize) { | ||
switch (size) { | ||
case ImageIconSize.Small: | ||
return 'text-label-sm'; | ||
case ImageIconSize.Medium: | ||
return 'text-label-md'; | ||
case ImageIconSize.Large: | ||
return 'text-title-md'; | ||
case ImageIconSize.Full: | ||
return 'text-title-lg'; | ||
} | ||
} | ||
return ( | ||
<div | ||
className={cn( | ||
'flex h-full w-full items-center justify-center bg-neutral-96 bg-gradient-to-r capitalize text-neutral-10 dark:bg-neutral-92 dark:text-primary-100', | ||
{ 'rounded-full': rounded }, | ||
generateTextSize(size), | ||
)} | ||
> | ||
{str?.slice(0, 2)} | ||
</div> | ||
); | ||
} | ||
|
||
export function ImageIcon({ src, label, alt = label, fallback, rounded, size }: ImageIconProps) { | ||
const [error, setError] = useState(false); | ||
return ( | ||
<div role="img" aria-label={label} className={size}> | ||
{error || !src ? ( | ||
<FallBackAvatar rounded={rounded} str={fallback} size={size} /> | ||
) : ( | ||
<img | ||
src={src} | ||
alt={alt} | ||
className="flex h-full w-full items-center justify-center rounded-full object-cover" | ||
onError={() => setError(true)} | ||
/> | ||
)} | ||
</div> | ||
); | ||
} |
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
107 changes: 107 additions & 0 deletions
107
apps/wallet-dashboard/components/Dialogs/StakedDetails/StakedDetailsDialog.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,107 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import React from 'react'; | ||
import { ExtendedDelegatedStake, ImageIcon, ImageIconSize } from '@iota/core'; | ||
import { | ||
Dialog, | ||
DialogBody, | ||
DialogContent, | ||
DialogPosition, | ||
Header, | ||
Button, | ||
ButtonType, | ||
// Badge, | ||
// BadgeType, | ||
Card, | ||
// CardAction, | ||
// CardActionType, | ||
CardBody, | ||
CardImage, | ||
CardType, | ||
// ImageShape, | ||
Panel, | ||
KeyValueInfo, | ||
} from '@iota/apps-ui-kit'; | ||
import { formatAddress } from '@iota/iota-sdk/utils'; | ||
interface StakeDialogProps { | ||
stakedDetails: ExtendedDelegatedStake; | ||
handleClose: () => void; | ||
} | ||
|
||
export function StakedDetailsDialog({ handleClose, stakedDetails }: StakeDialogProps): JSX.Element { | ||
console.log(stakedDetails); | ||
|
||
function handleUnstake() { | ||
console.log('Unstake'); | ||
} | ||
|
||
function handleAddNewStake() { | ||
console.log('Stake'); | ||
} | ||
|
||
return ( | ||
<Dialog open onOpenChange={handleClose}> | ||
<DialogContent containerId="overlay-portal-container" position={DialogPosition.Right}> | ||
<div className="flex min-h-full flex-col"> | ||
<Header | ||
title="Validator" | ||
onClose={handleClose} | ||
onBack={handleClose} | ||
titleCentered | ||
/> | ||
<div className="flex w-full flex-1 [&_>div]:flex [&_>div]:w-full [&_>div]:flex-col [&_>div]:justify-between"> | ||
<DialogBody> | ||
<div className="flex w-full flex-col gap-md"> | ||
<Card type={CardType.Filled}> | ||
<CardImage> | ||
<ImageIcon | ||
rounded={true} | ||
src={null} | ||
label={stakedDetails.validatorAddress} | ||
fallback={stakedDetails.validatorAddress} | ||
size={ImageIconSize.Large} | ||
/> | ||
</CardImage> | ||
<CardBody | ||
// TODO add validator name | ||
title={stakedDetails.validatorAddress} | ||
subtitle={formatAddress(stakedDetails.validatorAddress)} | ||
isTextTruncated | ||
/> | ||
</Card> | ||
<Panel hasBorder> | ||
<div className="flex flex-col gap-y-sm p-md"> | ||
<KeyValueInfo | ||
keyText="Your Stake" | ||
value={'f'} | ||
supportingLabel={'f'} | ||
fullwidth | ||
/> | ||
</div> | ||
</Panel> | ||
</div> | ||
<div> | ||
<div className="my-3.75 flex w-full gap-2.5"> | ||
<Button | ||
type={ButtonType.Secondary} | ||
onClick={handleUnstake} | ||
text="Unstake" | ||
fullWidth | ||
/> | ||
<Button | ||
type={ButtonType.Primary} | ||
text="Stake" | ||
onClick={handleAddNewStake} | ||
disabled={true} // TODO add condition | ||
fullWidth | ||
/> | ||
</div> | ||
</div> | ||
</DialogBody> | ||
</div> | ||
</div> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
} |
4 changes: 4 additions & 0 deletions
4
apps/wallet-dashboard/components/Dialogs/StakedDetails/index.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,4 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from './StakedDetailsDialog'; |
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from './Staking'; | ||
export * from './StakedDetails'; |
Oops, something went wrong.