diff --git a/apps/ui-kit/src/lib/components/organisms/dialog/Dialog.tsx b/apps/ui-kit/src/lib/components/organisms/dialog/Dialog.tsx index ddd77e87df7..53971681633 100644 --- a/apps/ui-kit/src/lib/components/organisms/dialog/Dialog.tsx +++ b/apps/ui-kit/src/lib/components/organisms/dialog/Dialog.tsx @@ -21,7 +21,7 @@ const DialogOverlay = React.forwardRef< >(({ showCloseIcon, ...props }, ref) => ( @@ -70,7 +70,7 @@ const DialogContent = React.forwardRef< void; isOpen: boolean; setOpen: (bool: boolean) => void; } @@ -32,14 +32,10 @@ interface StakeDialogProps { enum Step { SelectValidator, EnterAmount, + TransactionDetails, } -function StakeDialog({ - onSuccess, - isTimelockedStaking, - isOpen, - setOpen, -}: StakeDialogProps): JSX.Element { +function StakeDialog({ isTimelockedStaking, isOpen, setOpen }: StakeDialogProps): JSX.Element { const [step, setStep] = useState(Step.SelectValidator); const [selectedValidator, setSelectedValidator] = useState(''); const [amount, setAmount] = useState(''); @@ -91,6 +87,12 @@ function StakeDialog({ } } + function resetDefaultValues(): void { + setStep(Step.SelectValidator); + setSelectedValidator(''); + setAmount(''); + } + function handleStake(): void { if (isTimelockedStaking && groupedTimelockObjects.length === 0) { addNotification('Invalid stake amount. Please try again.', NotificationType.Error); @@ -105,10 +107,8 @@ function StakeDialog({ transaction: newStakeData?.transaction, }, { - onSuccess: (tx) => { - if (onSuccess) { - onSuccess(tx.digest); - } + onSuccess: () => { + setStep(Step.TransactionDetails); }, }, ) @@ -120,20 +120,26 @@ function StakeDialog({ }); } - const title = { + const title: Record = { [Step.SelectValidator]: 'Select Validator', [Step.EnterAmount]: 'Enter Amount', + [Step.TransactionDetails]: 'Transaction', }; + function handleClose(): void { + setOpen(false); + resetDefaultValues(); + } + return (
setOpen(false)} - titleCentered - onBack={handleBack} + onClose={handleClose} + titleCentered={step !== Step.TransactionDetails} + onBack={step === Step.EnterAmount ? handleBack : undefined} />
@@ -155,6 +161,15 @@ function StakeDialog({ onStake={handleStake} /> )} + {step === Step.TransactionDetails && ( + + )}
diff --git a/apps/wallet-dashboard/components/Dialogs/Staking/views/ConfirmAndExit.tsx b/apps/wallet-dashboard/components/Dialogs/Staking/views/ConfirmAndExit.tsx new file mode 100644 index 00000000000..345e549cf78 --- /dev/null +++ b/apps/wallet-dashboard/components/Dialogs/Staking/views/ConfirmAndExit.tsx @@ -0,0 +1,65 @@ +// Copyright (c) 2024 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +import { + Button, + ButtonType, + Card, + CardBody, + CardImage, + CardType, + ImageShape, + ImageType, +} from '@iota/apps-ui-kit'; +import { useValidatorInfo } from '@iota/core'; +import { StakingTransactionDetails } from './StakingTransactionDetails'; +import { Validator } from './Validator'; +import { IotaLogoMark } from '@iota/ui-icons'; + +interface SuccessScreenViewProps { + validatorAddress: string; + gasBudget: string | number | null | undefined; + onConfirm: () => void; + amount: string; + symbol: string | undefined; +} + +export function SuccessScreenView({ + validatorAddress, + gasBudget, + onConfirm, + amount, + symbol, +}: SuccessScreenViewProps): React.JSX.Element { + const { apy } = useValidatorInfo({ + validatorAddress, + }); + + return ( +
+
+
+ + + + + + + + + + +
+
+ +
+
+
+ ); +} diff --git a/apps/wallet-dashboard/components/Dialogs/Staking/views/EnterAmountView.tsx b/apps/wallet-dashboard/components/Dialogs/Staking/views/EnterAmountView.tsx index c01cdd6d9ed..25677b80510 100644 --- a/apps/wallet-dashboard/components/Dialogs/Staking/views/EnterAmountView.tsx +++ b/apps/wallet-dashboard/components/Dialogs/Staking/views/EnterAmountView.tsx @@ -4,19 +4,11 @@ import React from 'react'; import { useFormatCoin, useBalance, CoinFormat } from '@iota/core'; import { IOTA_TYPE_ARG } from '@iota/iota-sdk/utils'; -import { - Button, - ButtonType, - KeyValueInfo, - Panel, - Divider, - Input, - InputType, -} from '@iota/apps-ui-kit'; -import { useStakeTxnInfo } from '../hooks'; -import { useCurrentAccount, useIotaClientQuery } from '@iota/dapp-kit'; +import { Button, ButtonType, Input, InputType } from '@iota/apps-ui-kit'; +import { useCurrentAccount } from '@iota/dapp-kit'; import { Validator } from './Validator'; import { StakedInfo } from './StakedInfo'; +import { StakingTransactionDetails } from './StakingTransactionDetails'; interface EnterAmountViewProps { selectedValidator: string; @@ -40,7 +32,6 @@ function EnterAmountView({ const account = useCurrentAccount(); const accountAddress = account?.address; - const { data: system } = useIotaClientQuery('getLatestIotaSystemState'); const { data: iotaBalance } = useBalance(accountAddress!); const coinBalance = BigInt(iotaBalance?.totalBalance || 0); @@ -50,10 +41,6 @@ function EnterAmountView({ IOTA_TYPE_ARG, CoinFormat.FULL, ); - const [gas, symbol] = useFormatCoin(gasBudget, IOTA_TYPE_ARG); - const { stakedRewardsStartEpoch, timeBeforeStakeRewardsRedeemableAgoDisplay } = useStakeTxnInfo( - system?.epoch, - ); return (
@@ -73,28 +60,7 @@ function EnterAmountView({ caption={`${maxTokenFormatted} ${maxTokenFormattedSymbol} Available`} />
- - -
- - - - -
-
+
diff --git a/apps/wallet-dashboard/components/Dialogs/Staking/views/StakingTransactionDetails.tsx b/apps/wallet-dashboard/components/Dialogs/Staking/views/StakingTransactionDetails.tsx new file mode 100644 index 00000000000..53a79c6e803 --- /dev/null +++ b/apps/wallet-dashboard/components/Dialogs/Staking/views/StakingTransactionDetails.tsx @@ -0,0 +1,53 @@ +// Copyright (c) 2024 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +import { Divider, KeyValueInfo, Panel } from '@iota/apps-ui-kit'; +import { useFormatCoin } from '@iota/core'; +import { useIotaClientQuery } from '@iota/dapp-kit'; +import { IOTA_TYPE_ARG } from '@iota/iota-sdk/utils'; +import { useStakeTxnInfo } from '../hooks'; + +interface StakingTransactionDetailsProps { + gasBudget: string | number | null | undefined; + apy?: number | null; +} + +export function StakingTransactionDetails({ + gasBudget, + apy, +}: StakingTransactionDetailsProps): React.JSX.Element { + const [gas, gasSymbol] = useFormatCoin(gasBudget, IOTA_TYPE_ARG); + const { data: system } = useIotaClientQuery('getLatestIotaSystemState'); + + const { stakedRewardsStartEpoch, timeBeforeStakeRewardsRedeemableAgoDisplay } = useStakeTxnInfo( + system?.epoch, + ); + + return ( + +
+ {apy !== null && apy !== undefined ? ( + + ) : null} + + + + + +
+
+ ); +} diff --git a/apps/wallet-dashboard/components/Dialogs/Staking/views/index.ts b/apps/wallet-dashboard/components/Dialogs/Staking/views/index.ts index 2e8d1f59b5e..917bae35f85 100644 --- a/apps/wallet-dashboard/components/Dialogs/Staking/views/index.ts +++ b/apps/wallet-dashboard/components/Dialogs/Staking/views/index.ts @@ -3,3 +3,4 @@ export { default as EnterAmountView } from './EnterAmountView'; export { default as SelectValidatorView } from './SelectValidatorView'; +export * from './StakingTransactionDetails';