Skip to content

Commit

Permalink
feat(wallet-dashboard): add unstake timelocked objects flow (#4300)
Browse files Browse the repository at this point in the history
* feat(dashboard): add unstake timelocked objects view

* refactor: improve function

* feat: add more unstaking information and rename constant

* refactor: imports

* fix: imports

* fix: remove duplication collapsible

* refactor: include both single stake and grouped in a unstake hook

* refactor: unify usntake panel

* fix: go back correctly to previous screen in staking

* refactor: cleanup

* refactor: remove popups

* refactor: remove popups

* revert "refactor: remove popups"

* refactor: remove only unnecessary popups

* refactor: divide hooks and move deeper inside components

* fix: resolve re rendering issue

* feat: remove redundant code

* fix: update conditionally showing the stake dialog

* fix(tooling-dashboard): improve stake wizard (#4454)

* fix: improve stake wizzard

* fix: add set view helper function

* fix: add check for stake details

---------

Co-authored-by: evavirseda <evirseda@boxfish.studio>

* refactor: imports / exports

* feat: add wait for transaction and refresh

* feat: improve dialogs

* feat(dashboard): minor fixes

* fix: query key for timelocked staking

* fix: revert constants changes

* fix: disable stake button if no available amount for staking

* fix: query key for timelocked staking transaction

* fix: bigint serialization

* fix: remove or check in the useNewStakeTimelockedTransaction

---------

Co-authored-by: Bran <52735957+brancoder@users.noreply.github.com>
Co-authored-by: evavirseda <evirseda@boxfish.studio>
Co-authored-by: cpl121 <100352899+cpl121@users.noreply.github.com>
Co-authored-by: cpl121 <cpeon@boxfish.studio>
Co-authored-by: Branko <brankobosnic1@gmail.com>
  • Loading branch information
6 people authored and miker83z committed Dec 20, 2024
1 parent 0947050 commit cf57cce
Show file tree
Hide file tree
Showing 39 changed files with 1,511 additions and 1,288 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ interface KeyValueProps {
* Reverse the KeyValue (optional).
*/
isReverse?: boolean;
/**
* Text shown on value hover.
*/
valueHoverTitle?: string;
}

export function KeyValueInfo({
Expand All @@ -72,6 +76,7 @@ export function KeyValueInfo({
onCopyError,
fullwidth,
isReverse = false,
valueHoverTitle,
}: KeyValueProps): React.JSX.Element {
const flexDirectionClass = isReverse ? 'flex-row-reverse' : 'flex-row';
async function handleCopyClick(event: React.MouseEvent<HTMLButtonElement>) {
Expand Down Expand Up @@ -119,6 +124,7 @@ export function KeyValueInfo({
})}
>
<span
title={valueHoverTitle}
className={cx(
'text-neutral-10 dark:text-neutral-92',
size === ValueSize.Medium ? 'text-body-lg' : 'text-body-md',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,21 @@ export interface LoadingIndicatorProps {
* The text to display next to the loading indicator.
*/
text?: string;
/**
* The 'data-testid' attribute value (used in e2e tests)
*/
testId?: string;
}

export function LoadingIndicator({
color = 'text-primary-30 dark:text-primary-80',
size = 'w-5 h-5',
text,
testId,
}: LoadingIndicatorProps): React.JSX.Element {
return (
<div className="flex items-center justify-center gap-xs">
<Loader className={cx('animate-spin', color, size)} />
<Loader className={cx('animate-spin', color, size)} data-testid={testId} />
{text && <span className={cx('text-body-sm', color)}>{text}</span>}
</div>
);
Expand Down
80 changes: 67 additions & 13 deletions apps/wallet-dashboard/app/(protected)/staking/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

'use client';

import { StartStaking } from '@/components/staking-overview/StartStaking';
import {
Button,
ButtonSize,
Expand All @@ -16,7 +15,15 @@ import {
Title,
TitleSize,
} from '@iota/apps-ui-kit';
import { StakeDialog, StakeDialogView } from '@/components';
import {
StakeDialog,
StakeDialogView,
UnstakeDialog,
useUnstakeDialog,
UnstakeDialogView,
useStakeDialog,
StartStaking,
} from '@/components';
import {
ExtendedDelegatedStake,
formatDelegatedStake,
Expand All @@ -32,8 +39,8 @@ import { useCurrentAccount, useIotaClient, useIotaClientQuery } from '@iota/dapp
import { IotaSystemStateSummary } from '@iota/iota-sdk/client';
import { Info } from '@iota/ui-icons';
import { useMemo } from 'react';
import { useStakeDialog } from '@/components/Dialogs/Staking/hooks/useStakeDialog';
import { IOTA_TYPE_ARG } from '@iota/iota-sdk/utils';
import { IotaSignAndExecuteTransactionOutput } from '@iota/wallet-standard';

function StakingDashboardPage(): React.JSX.Element {
const account = useCurrentAccount();
Expand All @@ -52,6 +59,14 @@ function StakingDashboardPage(): React.JSX.Element {
handleCloseStakeDialog,
handleNewStake,
} = useStakeDialog();
const {
isOpen: isUnstakeDialogOpen,
openUnstakeDialog,
defaultDialogProps,
handleClose: handleCloseUnstakeDialog,
setView: setUnstakeDialogView,
setTxDigest,
} = useUnstakeDialog();

const { data: delegatedStakeData, refetch: refetchDelegatedStakes } = useGetDelegatedStake({
address: account?.address || '',
Expand Down Expand Up @@ -100,6 +115,34 @@ function StakingDashboardPage(): React.JSX.Element {
.then(() => refetchDelegatedStakes());
}

function handleUnstakeClick() {
setStakeDialogView(undefined);
openUnstakeDialog();
}

function handleUnstakeDialogBack() {
setStakeDialogView(StakeDialogView.Details);
handleCloseUnstakeDialog();
}

function handleOnUnstakeBack(view: UnstakeDialogView): (() => void) | undefined {
if (view === UnstakeDialogView.Unstake) {
return handleUnstakeDialogBack;
}
}

function handleOnUnstakeSuccess(tx: IotaSignAndExecuteTransactionOutput): void {
setUnstakeDialogView(UnstakeDialogView.TransactionDetails);
iotaClient
.waitForTransaction({
digest: tx.digest,
})
.then((tx) => {
refetchDelegatedStakes();
setTxDigest(tx.digest);
});
}

return (
<div className="flex justify-center">
<div className="w-3/4">
Expand Down Expand Up @@ -171,16 +214,27 @@ function StakingDashboardPage(): React.JSX.Element {
</div>
</div>
</div>
<StakeDialog
stakedDetails={selectedStake}
onSuccess={handleOnStakeSuccess}
isOpen={isDialogStakeOpen}
handleClose={handleCloseStakeDialog}
view={stakeDialogView}
setView={setStakeDialogView}
selectedValidator={selectedValidator}
setSelectedValidator={setSelectedValidator}
/>
{isDialogStakeOpen && (
<StakeDialog
stakedDetails={selectedStake}
onSuccess={handleOnStakeSuccess}
handleClose={handleCloseStakeDialog}
view={stakeDialogView}
setView={setStakeDialogView}
selectedValidator={selectedValidator}
setSelectedValidator={setSelectedValidator}
onUnstakeClick={handleUnstakeClick}
/>
)}

{isUnstakeDialogOpen && selectedStake && (
<UnstakeDialog
extendedStake={selectedStake}
onBack={handleOnUnstakeBack}
onSuccess={handleOnUnstakeSuccess}
{...defaultDialogProps}
/>
)}
</Panel>
) : (
<div className="flex h-[270px] p-lg">
Expand Down
Loading

0 comments on commit cf57cce

Please sign in to comment.