Skip to content

Commit

Permalink
feat(tooling-dashboard): style selected stake
Browse files Browse the repository at this point in the history
  • Loading branch information
panteleymonchuk committed Oct 31, 2024
1 parent d64f686 commit c19bc2a
Show file tree
Hide file tree
Showing 9 changed files with 234 additions and 22 deletions.
1 change: 1 addition & 0 deletions apps/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@sentry/react": "^7.59.2",
"@tanstack/react-query": "^5.50.1",
"bignumber.js": "^9.1.1",
"clsx": "^2.1.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-hook-form": "^7.45.2",
Expand Down
73 changes: 73 additions & 0 deletions apps/core/src/components/IconImage/IconImage.tsx
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>
);
}
1 change: 1 addition & 0 deletions apps/core/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
// SPDX-License-Identifier: Apache-2.0

export * from './KioskClientProvider';
export * from './IconImage/IconImage';
29 changes: 25 additions & 4 deletions apps/wallet-dashboard/app/(protected)/staking/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@

'use client';

import { AmountBox, Box, StakeCard, StakeDialog, StakeDetailsPopup, Button } from '@/components';
import { usePopups } from '@/hooks';
import {
AmountBox,
Box,
StakeCard,
StakeDialog,
// StakeDetailsPopup,
Button,
StakedDetailsDialog,
} from '@/components';
// import { usePopups } from '@/hooks';
import {
ExtendedDelegatedStake,
formatDelegatedStake,
Expand All @@ -21,9 +29,11 @@ import { useState } from 'react';

function StakingDashboardPage(): JSX.Element {
const account = useCurrentAccount();
console.log(account);
const [isDialogStakeOpen, setIsDialogStakeOpen] = useState(false);
const [stakedDetails, setStakedDetails] = useState<ExtendedDelegatedStake | null>(null);

const { openPopup, closePopup } = usePopups();
// const { openPopup, closePopup } = usePopups();
const { data: delegatedStakeData } = useGetDelegatedStake({
address: account?.address || '',
staleTime: DELEGATED_STAKES_QUERY_STALE_TIME,
Expand All @@ -43,8 +53,13 @@ function StakingDashboardPage(): JSX.Element {
);

const viewStakeDetails = (extendedStake: ExtendedDelegatedStake) => {
openPopup(<StakeDetailsPopup extendedStake={extendedStake} onClose={closePopup} />);
setStakedDetails(extendedStake);
// openPopup(<StakeDetailsPopup extendedStake={extendedStake} onClose={closePopup} />);
};
function handleCloseStakedDetails() {
setStakedDetails(null);
}

function handleNewStake() {
setIsDialogStakeOpen(true);
}
Expand Down Expand Up @@ -79,6 +94,12 @@ function StakingDashboardPage(): JSX.Element {
<Button onClick={handleNewStake}>New Stake</Button>
</div>
<StakeDialog isOpen={isDialogStakeOpen} setOpen={setIsDialogStakeOpen} />;
{!!stakedDetails && (
<StakedDetailsDialog
stakedDetails={stakedDetails}
handleClose={handleCloseStakedDetails}
/>
)}
</>
);
}
Expand Down
1 change: 1 addition & 0 deletions apps/wallet-dashboard/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default function RootLayout({
<QueryClientProvider client={queryClient}>
<IotaClientProvider networks={allNetworks} defaultNetwork={defaultNetwork}>
<WalletProvider
autoConnect
theme={[
{
variables: lightTheme,
Expand Down
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>
);
}
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';
1 change: 1 addition & 0 deletions apps/wallet-dashboard/components/Dialogs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
// SPDX-License-Identifier: Apache-2.0

export * from './Staking';
export * from './StakedDetails';
Loading

0 comments on commit c19bc2a

Please sign in to comment.