From 42b463855f9dcebfff7430f4269396ca5912857c Mon Sep 17 00:00:00 2001 From: Daniel Main Date: Thu, 5 Aug 2021 12:48:59 +0200 Subject: [PATCH 1/2] [DDW-703] Removed undelegation from delegation center, splitted code in smaller component --- .../delegation-center/DelegationCenter.js | 3 - .../delegation-center/DelegationCenterBody.js | 3 - .../staking/delegation-center/WalletRow.js | 16 --- .../wallet/settings/UndelegateWalletBox.js | 95 +++++++++++++++ .../UndelegateWalletConfirmationDialog.js | 82 +------------ ...legateWalletConfirmationDialog.messages.js | 91 ++++++++++++++ .../wallet/settings/WalletSettings.js | 111 +++++------------- .../settings/WalletSettings.messages.js | 89 ++++++++++++++ source/renderer/app/config/walletsConfig.js | 2 +- 9 files changed, 306 insertions(+), 186 deletions(-) create mode 100644 source/renderer/app/components/wallet/settings/UndelegateWalletBox.js create mode 100644 source/renderer/app/components/wallet/settings/UndelegateWalletConfirmationDialog.messages.js create mode 100644 source/renderer/app/components/wallet/settings/WalletSettings.messages.js diff --git a/source/renderer/app/components/staking/delegation-center/DelegationCenter.js b/source/renderer/app/components/staking/delegation-center/DelegationCenter.js index 1b3b87e7b2..8f91f8a285 100644 --- a/source/renderer/app/components/staking/delegation-center/DelegationCenter.js +++ b/source/renderer/app/components/staking/delegation-center/DelegationCenter.js @@ -15,7 +15,6 @@ type Props = { numberOfStakePools: number, numberOfRankedStakePools: number, onDelegate: Function, - onUndelegate: Function, networkTip: ?TipInfo, epochLength: ?number, nextEpoch: ?NextEpoch, @@ -40,7 +39,6 @@ export default class DelegationCenter extends Component { numberOfStakePools, numberOfRankedStakePools, onDelegate, - onUndelegate, networkTip, epochLength, nextEpoch, @@ -73,7 +71,6 @@ export default class DelegationCenter extends Component { numberOfStakePools={numberOfStakePools} numberOfRankedStakePools={numberOfRankedStakePools} onDelegate={onDelegate} - onUndelegate={onUndelegate} getStakePoolById={getStakePoolById} nextEpoch={nextEpoch} futureEpoch={futureEpoch} diff --git a/source/renderer/app/components/staking/delegation-center/DelegationCenterBody.js b/source/renderer/app/components/staking/delegation-center/DelegationCenterBody.js index 2c282ea5cd..25c81d76de 100644 --- a/source/renderer/app/components/staking/delegation-center/DelegationCenterBody.js +++ b/source/renderer/app/components/staking/delegation-center/DelegationCenterBody.js @@ -34,7 +34,6 @@ type Props = { numberOfStakePools: number, numberOfRankedStakePools: number, onDelegate: Function, - onUndelegate: Function, getStakePoolById: Function, isLoading: boolean, nextEpoch: ?NextEpoch, @@ -62,7 +61,6 @@ export default class DelegationCenterBody extends Component { numberOfStakePools, numberOfRankedStakePools, onDelegate, - onUndelegate, getStakePoolById, isLoading, nextEpoch, @@ -123,7 +121,6 @@ export default class DelegationCenterBody extends Component { numberOfStakePools={numberOfStakePools} numberOfRankedStakePools={numberOfRankedStakePools} onDelegate={() => onDelegate(wallet.id)} - onUndelegate={() => onUndelegate(wallet.id)} delegatedStakePool={getStakePoolById( wallet.delegatedStakePoolId )} diff --git a/source/renderer/app/components/staking/delegation-center/WalletRow.js b/source/renderer/app/components/staking/delegation-center/WalletRow.js index b448f6417f..5bd77063c9 100644 --- a/source/renderer/app/components/staking/delegation-center/WalletRow.js +++ b/source/renderer/app/components/staking/delegation-center/WalletRow.js @@ -84,7 +84,6 @@ type Props = { numberOfStakePools: number, numberOfRankedStakePools: number, onDelegate: Function, - onUndelegate: Function, getStakePoolById: Function, nextEpochNumber: number, futureEpochNumber: number, @@ -220,7 +219,6 @@ export default class WalletRow extends Component { numberOfRankedStakePools, getStakePoolById, onDelegate, - onUndelegate, nextEpochNumber, futureEpochNumber, currentTheme, @@ -230,12 +228,8 @@ export default class WalletRow extends Component { } = this.props; const { highlightedPoolId } = this.state; - // @TODO - remove once quit stake pool delegation is connected with rewards balance - const isUndelegateBlocked = true; - const syncingProgress = get(syncState, 'progress.quantity', ''); const notDelegatedText = intl.formatMessage(messages.notDelegated); - const removeDelegationText = intl.formatMessage(messages.removeDelegation); const delegateText = intl.formatMessage(messages.delegate); const redelegateText = intl.formatMessage(messages.redelegate); @@ -458,16 +452,6 @@ export default class WalletRow extends Component { {notDelegatedText} )} - {futurePendingDelegatedStakePoolId && !isUndelegateBlocked && ( -
- {removeDelegationText} -
- )}
{ + const messages = getWalletSettingsMessages(); + + const headerMessage = isDelegating + ? intl.formatMessage(messages.undelegateWalletHeader) + : intl.formatMessage(messages.delegateWalletHeader); + let warningMessage = null; + if (isDelegating) { + warningMessage = + isRestoring || isSyncing + ? intl.formatMessage(messages.undelegateWalletDisabledWarning) + : intl.formatMessage(messages.undelegateWalletWarning); + } else { + warningMessage = + isRestoring || isSyncing + ? intl.formatMessage(messages.delegateWalletDisabledWarning) + : intl.formatMessage(messages.delegateWalletWarning); + } + + const onUndelegateWalletClick = useCallback(async () => { + onBlockForm(); + openDialogAction({ + dialog: UndelegateWalletConfirmationDialog, + }); + updateDataForActiveDialogAction({ + data: { walletId }, + }); + }); + + return ( + <> + + {headerMessage} +
+
+

{warningMessage}

+
+ {isDelegating ? ( + + ) : ( + + )} +
+
+ {isDialogOpen(UndelegateWalletConfirmationDialog) + ? undelegateWalletDialogContainer + : false} + + ); +}; + +export default injectIntl(UndelegateWalletBox); diff --git a/source/renderer/app/components/wallet/settings/UndelegateWalletConfirmationDialog.js b/source/renderer/app/components/wallet/settings/UndelegateWalletConfirmationDialog.js index 90daec716c..f832c260eb 100644 --- a/source/renderer/app/components/wallet/settings/UndelegateWalletConfirmationDialog.js +++ b/source/renderer/app/components/wallet/settings/UndelegateWalletConfirmationDialog.js @@ -3,7 +3,7 @@ import React, { Component } from 'react'; import { observer } from 'mobx-react'; import { get } from 'lodash'; -import { defineMessages, intlShape, FormattedHTMLMessage } from 'react-intl'; +import { intlShape, FormattedHTMLMessage } from 'react-intl'; import vjf from 'mobx-react-form/lib/validators/VJF'; import classnames from 'classnames'; import { Checkbox } from 'react-polymorph/lib/components/Checkbox'; @@ -22,85 +22,9 @@ import styles from './UndelegateWalletConfirmationDialog.scss'; import globalMessages from '../../../i18n/global-messages'; import LocalizableError from '../../../i18n/LocalizableError'; import { submitOnEnter } from '../../../utils/form'; +import getUndelegateWalletConfirmationDialogMessages from './UndelegateWalletConfirmationDialog.messages'; -const messages = defineMessages({ - title: { - id: 'wallet.settings.undelegate.dialog.title', - defaultMessage: '!!!Undelegate', - description: 'Title for the "Undelegate wallet" dialog.', - }, - confirmButtonLabel: { - id: 'wallet.settings.undelegate.dialog.confirmButtonLabel', - defaultMessage: '!!!Undelegate', - description: - 'Label for the "Undelegate" button in the undelegate wallet dialog.', - }, - descriptionWithTicker: { - id: 'wallet.settings.undelegate.dialog.descriptionWithTicker', - defaultMessage: - '!!!

The stake from your wallet {walletName} is currently delegated to the [{stakePoolTicker}] {stakePoolName} stake pool.

Do you want to undelegate your stake and stop earning rewards?

', - description: - 'Description of current delegation of wallet in the "Undelegate wallet" dialog.', - }, - descriptionWithUnknownTicker: { - id: 'wallet.settings.undelegate.dialog.descriptionWithUnknownTicker', - defaultMessage: - '!!!

The stake from your wallet {walletName} is currently delegated to the {stakePoolTicker} stake pool.

Do you want to undelegate your stake and stop earning rewards?

', - description: - 'Description of current delegation of wallet in the "Undelegate wallet" dialog.', - }, - unknownStakePoolLabel: { - id: 'wallet.settings.undelegate.dialog.unknownStakePoolLabel', - defaultMessage: '!!!unknown', - description: 'unknown stake pool label in the "Undelegate wallet" dialog.', - }, - confirmUnsupportNotice: { - id: 'wallet.settings.undelegate.dialog.confirmUnsupportNotice', - defaultMessage: - '!!!I understand that I am not supporting the Cardano network when my stake is undelegated.', - description: - 'Notice to confirm if the user understands unsupporting Cardano network after undelegation', - }, - confirmIneligibleNotice: { - id: 'wallet.settings.undelegate.dialog.confirmIneligibleNotice', - defaultMessage: - '!!!I understand that I will not be eligible to earn rewards when my stake is undelegated.', - description: - 'Notice to confirm if the user understands non-earning rewards after undelegation', - }, - feesLabel: { - id: 'wallet.settings.undelegate.dialog.feesLabel', - defaultMessage: '!!!Fees', - description: 'Fees label in the "Undelegate wallet" dialog.', - }, - depositLabel: { - id: 'wallet.settings.undelegate.dialog.depositLabel', - defaultMessage: '!!!Deposits reclaimed', - description: 'Deposits reclaimed label in the "Undelegate wallet" dialog.', - }, - spendingPasswordLabel: { - id: 'wallet.settings.undelegate.dialog.spendingPasswordLabel', - defaultMessage: '!!!Spending password', - description: 'Spending password label in the "Undelegate wallet" dialog.', - }, - spendingPasswordPlaceholder: { - id: 'wallet.settings.undelegate.dialog.spendingPasswordPlaceholder', - defaultMessage: '!!!Type your spending password here', - description: - 'Spending password placeholder in the "Undelegate wallet" dialog.', - }, - passwordErrorMessage: { - id: 'wallet.settings.undelegate.dialog.passwordError', - defaultMessage: '!!!Incorrect spending password.', - description: 'Label for password error in the "Undelegate wallet" dialog.', - }, - calculatingFees: { - id: 'wallet.settings.undelegate.dialog.calculatingFees', - defaultMessage: '!!!Calculating fees', - description: - '"Calculating fees" message in the "Undelegate wallet" dialog.', - }, -}); +const messages = getUndelegateWalletConfirmationDialogMessages(); messages.fieldIsRequired = globalMessages.fieldIsRequired; diff --git a/source/renderer/app/components/wallet/settings/UndelegateWalletConfirmationDialog.messages.js b/source/renderer/app/components/wallet/settings/UndelegateWalletConfirmationDialog.messages.js new file mode 100644 index 0000000000..47e1af51fc --- /dev/null +++ b/source/renderer/app/components/wallet/settings/UndelegateWalletConfirmationDialog.messages.js @@ -0,0 +1,91 @@ +// @flow +import { defineMessages } from 'react-intl'; +import type { ReactIntlMessage } from '../../../types/i18nTypes'; + +const getUndelegateWalletConfirmationDialogMessages = (): { + [string]: ReactIntlMessage, +} => + defineMessages({ + title: { + id: 'wallet.settings.undelegate.dialog.title', + defaultMessage: '!!!Undelegate', + description: 'Title for the "Undelegate wallet" dialog.', + }, + confirmButtonLabel: { + id: 'wallet.settings.undelegate.dialog.confirmButtonLabel', + defaultMessage: '!!!Undelegate', + description: + 'Label for the "Undelegate" button in the undelegate wallet dialog.', + }, + descriptionWithTicker: { + id: 'wallet.settings.undelegate.dialog.descriptionWithTicker', + defaultMessage: + '!!!

The stake from your wallet {walletName} is currently delegated to the [{stakePoolTicker}] {stakePoolName} stake pool.

Do you want to undelegate your stake and stop earning rewards?

', + description: + 'Description of current delegation of wallet in the "Undelegate wallet" dialog.', + }, + descriptionWithUnknownTicker: { + id: 'wallet.settings.undelegate.dialog.descriptionWithUnknownTicker', + defaultMessage: + '!!!

The stake from your wallet {walletName} is currently delegated to the {stakePoolTicker} stake pool.

Do you want to undelegate your stake and stop earning rewards?

', + description: + 'Description of current delegation of wallet in the "Undelegate wallet" dialog.', + }, + unknownStakePoolLabel: { + id: 'wallet.settings.undelegate.dialog.unknownStakePoolLabel', + defaultMessage: '!!!unknown', + description: + 'unknown stake pool label in the "Undelegate wallet" dialog.', + }, + confirmUnsupportNotice: { + id: 'wallet.settings.undelegate.dialog.confirmUnsupportNotice', + defaultMessage: + '!!!I understand that I am not supporting the Cardano network when my stake is undelegated.', + description: + 'Notice to confirm if the user understands unsupporting Cardano network after undelegation', + }, + confirmIneligibleNotice: { + id: 'wallet.settings.undelegate.dialog.confirmIneligibleNotice', + defaultMessage: + '!!!I understand that I will not be eligible to earn rewards when my stake is undelegated.', + description: + 'Notice to confirm if the user understands non-earning rewards after undelegation', + }, + feesLabel: { + id: 'wallet.settings.undelegate.dialog.feesLabel', + defaultMessage: '!!!Fees', + description: 'Fees label in the "Undelegate wallet" dialog.', + }, + depositLabel: { + id: 'wallet.settings.undelegate.dialog.depositLabel', + defaultMessage: '!!!Deposits reclaimed', + description: + 'Deposits reclaimed label in the "Undelegate wallet" dialog.', + }, + spendingPasswordLabel: { + id: 'wallet.settings.undelegate.dialog.spendingPasswordLabel', + defaultMessage: '!!!Spending password', + description: 'Spending password label in the "Undelegate wallet" dialog.', + }, + spendingPasswordPlaceholder: { + id: 'wallet.settings.undelegate.dialog.spendingPasswordPlaceholder', + defaultMessage: '!!!Type your spending password here', + description: + 'Spending password placeholder in the "Undelegate wallet" dialog.', + }, + + passwordErrorMessage: { + id: 'wallet.settings.undelegate.dialog.passwordError', + defaultMessage: '!!!Incorrect spending password.', + description: + 'Label for password error in the "Undelegate wallet" dialog.', + }, + calculatingFees: { + id: 'wallet.settings.undelegate.dialog.calculatingFees', + defaultMessage: '!!!Calculating fees', + description: + '"Calculating fees" message in the "Undelegate wallet" dialog.', + }, + }); + +export default getUndelegateWalletConfirmationDialogMessages; diff --git a/source/renderer/app/components/wallet/settings/WalletSettings.js b/source/renderer/app/components/wallet/settings/WalletSettings.js index 0b0df22619..1ec9ed58b5 100644 --- a/source/renderer/app/components/wallet/settings/WalletSettings.js +++ b/source/renderer/app/components/wallet/settings/WalletSettings.js @@ -2,7 +2,7 @@ import type { Node } from 'react'; import React, { Component } from 'react'; import { observer } from 'mobx-react'; -import { defineMessages, intlShape } from 'react-intl'; +import { intlShape } from 'react-intl'; import moment from 'moment'; import LocalizableError from '../../../i18n/LocalizableError'; import { @@ -30,89 +30,10 @@ import ICOPublicKeyDialog from './ICOPublicKeyDialog'; import ICOPublicKeyQRCodeDialog from './ICOPublicKeyQRCodeDialog'; import WalletPublicKeyDialog from './WalletPublicKeyDialog'; import WalletPublicKeyQRCodeDialog from './WalletPublicKeyQRCodeDialog'; -import type { ReactIntlMessage } from '../../../types/i18nTypes'; +import getWalletSettingsMessages from './WalletSettings.messages'; +import UndelegateWalletBox from './UndelegateWalletBox'; -export const messages: { [string]: ReactIntlMessage } = defineMessages({ - assuranceLevelLabel: { - id: 'wallet.settings.assurance', - defaultMessage: '!!!Transaction assurance security level', - description: - 'Label for the "Transaction assurance security level" dropdown.', - }, - undelegateWalletHeader: { - id: 'wallet.settings.undelegateWallet.header', - defaultMessage: '!!!Undelegating your wallet', - description: 'Undelegate wallet header on the wallet settings page.', - }, - undelegateWalletWarning: { - id: 'wallet.settings.undelegateWallet.warning', - defaultMessage: - '!!!If you are planning to stop using this wallet and remove all funds, you should first undelegate it to recover your 2 ada deposit. You will continue getting delegation rewards during the three Cardano epochs after undelegating your wallet.', - description: 'Undelegate wallet warning explaining the consequences.', - }, - undelegateWalletDisabledWarning: { - id: 'wallet.settings.undelegateWallet.disabledWarning', - defaultMessage: - "!!!This wallet is synchronizing with the blockchain, so this wallet's delegation status is currently unknown, and undelegation is not possible.", - description: - 'Undelegate wallet disabled warning explaining why it is disabled.', - }, - delegateWalletHeader: { - id: 'wallet.settings.delegateWallet.header', - defaultMessage: '!!!Delegate your wallet', - description: 'Delegate wallet header on the wallet settings page.', - }, - delegateWalletWarning: { - id: 'wallet.settings.delegateWallet.warning', - defaultMessage: - "!!!This wallet is not delegated. Please, delegate the stake from this wallet to earn rewards and support the Cardano network's security.", - description: 'Delegate wallet warning.', - }, - delegateWalletDisabledWarning: { - id: 'wallet.settings.delegateWallet.disabledWarning', - defaultMessage: - "!!!This wallet is synchronizing with the blockchain, so this wallet's delegation status is currently unknown, and delegation is not possible.", - description: - 'Delegate wallet disabled warning explaining why it is disabled.', - }, - deleteWalletHeader: { - id: 'wallet.settings.deleteWallet.header', - defaultMessage: '!!!Delete wallet', - description: 'Delete wallet header on the wallet settings page.', - }, - deleteWalletWarning1: { - id: 'wallet.settings.deleteWallet.warning1', - defaultMessage: - '!!!Once you delete this wallet it will be removed from the Daedalus interface and you will lose access to any remaining funds in the wallet. The only way to regain access after deletion is by restoring it using your wallet recovery phrase.', - description: 'Delete wallet warning explaining the consequences.', - }, - deleteWalletWarning2: { - id: 'wallet.settings.deleteWallet.warning2', - defaultMessage: - '!!!You may wish to verify your recovery phrase before deletion to ensure that you can restore this wallet in the future, if desired.', - description: 'Delete wallet warning explaining the consequences.', - }, - name: { - id: 'wallet.settings.name.label', - defaultMessage: '!!!Name', - description: 'Label for the "Name" text input on the wallet settings page.', - }, - passwordLabel: { - id: 'wallet.settings.password', - defaultMessage: '!!!Password', - description: 'Label for the "Password" field.', - }, - passwordLastUpdated: { - id: 'wallet.settings.passwordLastUpdated', - defaultMessage: '!!!Last updated', - description: 'Last updated X time ago message.', - }, - passwordNotSet: { - id: 'wallet.settings.passwordNotSet', - defaultMessage: "!!!You still don't have password", - description: "You still don't have password set message.", - }, -}); +const messages = getWalletSettingsMessages(); type Props = { walletId: string, @@ -309,6 +230,13 @@ export default class WalletSettings extends Component { render() { const { intl } = this.context; const { + isDelegating, + isRestoring, + isSyncing, + undelegateWalletDialogContainer, + walletId, + onDelegateClick, + updateDataForActiveDialogAction, walletName, creationDate, spendingPasswordUpdateDate, @@ -436,7 +364,22 @@ export default class WalletSettings extends Component { )} - {this.renderUndelegateWalletBox()} + {IS_WALLET_UNDELEGATION_ENABLED && !isLegacy && ( + + )} {this.renderDeleteWalletBox()}
); diff --git a/source/renderer/app/components/wallet/settings/WalletSettings.messages.js b/source/renderer/app/components/wallet/settings/WalletSettings.messages.js new file mode 100644 index 0000000000..0e695a4464 --- /dev/null +++ b/source/renderer/app/components/wallet/settings/WalletSettings.messages.js @@ -0,0 +1,89 @@ +// @flow +import { defineMessages } from 'react-intl'; +import type { ReactIntlMessage } from '../../../types/i18nTypes'; + +const getWalletSettingsMessages = (): { [string]: ReactIntlMessage } => + defineMessages({ + assuranceLevelLabel: { + id: 'wallet.settings.assurance', + defaultMessage: '!!!Transaction assurance security level', + description: + 'Label for the "Transaction assurance security level" dropdown.', + }, + undelegateWalletHeader: { + id: 'wallet.settings.undelegateWallet.header', + defaultMessage: '!!!Undelegating your wallet', + description: 'Undelegate wallet header on the wallet settings page.', + }, + undelegateWalletWarning: { + id: 'wallet.settings.undelegateWallet.warning', + defaultMessage: + '!!!If you are planning to stop using this wallet and remove all funds, you should first undelegate it to recover your 2 ada deposit. You will continue getting delegation rewards during the three Cardano epochs after undelegating your wallet.', + description: 'Undelegate wallet warning explaining the consequences.', + }, + undelegateWalletDisabledWarning: { + id: 'wallet.settings.undelegateWallet.disabledWarning', + defaultMessage: + "!!!This wallet is synchronizing with the blockchain, so this wallet's delegation status is currently unknown, and undelegation is not possible.", + description: + 'Undelegate wallet disabled warning explaining why it is disabled.', + }, + delegateWalletHeader: { + id: 'wallet.settings.delegateWallet.header', + defaultMessage: '!!!Delegate your wallet', + description: 'Delegate wallet header on the wallet settings page.', + }, + delegateWalletWarning: { + id: 'wallet.settings.delegateWallet.warning', + defaultMessage: + "!!!This wallet is not delegated. Please, delegate the stake from this wallet to earn rewards and support the Cardano network's security.", + description: 'Delegate wallet warning.', + }, + delegateWalletDisabledWarning: { + id: 'wallet.settings.delegateWallet.disabledWarning', + defaultMessage: + "!!!This wallet is synchronizing with the blockchain, so this wallet's delegation status is currently unknown, and delegation is not possible.", + description: + 'Delegate wallet disabled warning explaining why it is disabled.', + }, + deleteWalletHeader: { + id: 'wallet.settings.deleteWallet.header', + defaultMessage: '!!!Delete wallet', + description: 'Delete wallet header on the wallet settings page.', + }, + deleteWalletWarning1: { + id: 'wallet.settings.deleteWallet.warning1', + defaultMessage: + '!!!Once you delete this wallet it will be removed from the Daedalus interface and you will lose access to any remaining funds in the wallet. The only way to regain access after deletion is by restoring it using your wallet recovery phrase.', + description: 'Delete wallet warning explaining the consequences.', + }, + deleteWalletWarning2: { + id: 'wallet.settings.deleteWallet.warning2', + defaultMessage: + '!!!You may wish to verify your recovery phrase before deletion to ensure that you can restore this wallet in the future, if desired.', + description: 'Delete wallet warning explaining the consequences.', + }, + name: { + id: 'wallet.settings.name.label', + defaultMessage: '!!!Name', + description: + 'Label for the "Name" text input on the wallet settings page.', + }, + passwordLabel: { + id: 'wallet.settings.password', + defaultMessage: '!!!Password', + description: 'Label for the "Password" field.', + }, + passwordLastUpdated: { + id: 'wallet.settings.passwordLastUpdated', + defaultMessage: '!!!Last updated', + description: 'Last updated X time ago message.', + }, + passwordNotSet: { + id: 'wallet.settings.passwordNotSet', + defaultMessage: "!!!You still don't have password", + description: "You still don't have password set message.", + }, + }); + +export default getWalletSettingsMessages; diff --git a/source/renderer/app/config/walletsConfig.js b/source/renderer/app/config/walletsConfig.js index 65fa97d985..6372e2d48b 100644 --- a/source/renderer/app/config/walletsConfig.js +++ b/source/renderer/app/config/walletsConfig.js @@ -47,6 +47,6 @@ export const WALLET_ASSETS_ENABLED = true; // Byron wallet migration has been temporarily disabled due to missing Api support after Mary HF export const IS_BYRON_WALLET_MIGRATION_ENABLED = false; -export const IS_WALLET_UNDELEGATION_ENABLED = false; +export const IS_WALLET_UNDELEGATION_ENABLED = true; export const TRANSACTION_MIN_ADA_VALUE = 1; From 1af4724c5b03d78c32aad27ba69dd9b355b434e3 Mon Sep 17 00:00:00 2001 From: Daniel Main Date: Wed, 6 Oct 2021 17:22:29 +0200 Subject: [PATCH 2/2] [DDW-703] Refactor wallet settings page --- CHANGELOG.md | 4 + .../wallet/settings/WalletSettings.js | 117 ++++++---------- .../settings/WalletSettings.messages.js | 125 +++++++++--------- 3 files changed, 104 insertions(+), 142 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea25b6180a..26a7ebfa9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## vNext +### Features + +- Added functionality to undelegate a wallet ([PR 2636](https://github.com/input-output-hk/daedalus/pull/2636)) + ### Chores - Added the possibility to unpair a hardware wallet from Daedalus ([PR 2676](https://github.com/input-output-hk/daedalus/pull/2676)) diff --git a/source/renderer/app/components/wallet/settings/WalletSettings.js b/source/renderer/app/components/wallet/settings/WalletSettings.js index 88e6878849..35a527d4dd 100644 --- a/source/renderer/app/components/wallet/settings/WalletSettings.js +++ b/source/renderer/app/components/wallet/settings/WalletSettings.js @@ -13,8 +13,6 @@ import { import BorderedBox from '../../widgets/BorderedBox'; import InlineEditingInput from '../../widgets/forms/InlineEditingInput'; import ReadOnlyInput from '../../widgets/forms/ReadOnlyInput'; -import UndelegateWalletButton from './UndelegateWalletButton'; -import DelegateWalletButton from './DelegateWalletButton'; import UndelegateWalletConfirmationDialog from './UndelegateWalletConfirmationDialog'; import WalletSettingsActionConfirmationDialog from './WalletSettingsRemoveConfirmationDialog'; import UnpairWallet from './UnpairWallet'; @@ -133,99 +131,44 @@ export default class WalletSettings extends Component { }); }; - renderUndelegateWalletBox = () => { - const { intl } = this.context; - const { - isDelegating, - isRestoring, - isSyncing, - isLegacy, - isDialogOpen, - onDelegateClick, - undelegateWalletDialogContainer, - } = this.props; - - /// @TODO: Once undelegation for rewarded wallet works fine with api, remove reward checking and config - if (!IS_WALLET_UNDELEGATION_ENABLED || isLegacy) { - return null; - } - - let headerMessage; - let warningMessage; - - if (isDelegating) { - headerMessage = intl.formatMessage(messages.undelegateWalletHeader); - warningMessage = - isRestoring || isSyncing - ? intl.formatMessage(messages.undelegateWalletDisabledWarning) - : intl.formatMessage(messages.undelegateWalletWarning); - } else { - headerMessage = intl.formatMessage(messages.delegateWalletHeader); - warningMessage = - isRestoring || isSyncing - ? intl.formatMessage(messages.delegateWalletDisabledWarning) - : intl.formatMessage(messages.delegateWalletWarning); - } - - return ( - <> - - {headerMessage} -
-
-

{warningMessage}

-
- {isDelegating ? ( - - ) : ( - - )} -
-
- {isDialogOpen(UndelegateWalletConfirmationDialog) - ? undelegateWalletDialogContainer - : false} - - ); - }; - render() { const { intl } = this.context; const { - walletName, + changeSpendingPasswordDialog, creationDate, - spendingPasswordUpdateDate, + deleteWalletDialogContainer, error, + icoPublicKeyDialogContainer, + icoPublicKeyQRCodeDialogContainer, + isDelegating, isDialogOpen, - openDialogAction, + isHardwareWallet, + isLegacy, + isRestoring, + isSpendingPasswordSet, + isSyncing, + locale, + nameValidator, + onCancel, + onDelegateClick, onFieldValueChange, onStartEditing, onStopEditing, - onCancel, onVerifyRecoveryPhrase, - nameValidator, - isLegacy, - changeSpendingPasswordDialog, + openDialogAction, recoveryPhraseVerificationDate, recoveryPhraseVerificationStatus, recoveryPhraseVerificationStatusType, - locale, - isSpendingPasswordSet, - isHardwareWallet, shouldDisplayRecoveryPhrase, - wordCount, + spendingPasswordUpdateDate, + undelegateWalletDialogContainer, + unpairWalletDialogContainer, + updateDataForActiveDialogAction, + walletId, + walletName, walletPublicKeyDialogContainer, walletPublicKeyQRCodeDialogContainer, - icoPublicKeyDialogContainer, - icoPublicKeyQRCodeDialogContainer, - deleteWalletDialogContainer, - unpairWalletDialogContainer, + wordCount, } = this.props; const { isFormBlocked } = this.state; @@ -328,7 +271,21 @@ export default class WalletSettings extends Component { )} - {this.renderUndelegateWalletBox()} + {IS_WALLET_UNDELEGATION_ENABLED && ( + + )} + {isHardwareWallet ? ( defineMessages({ - assuranceLevelLabel: { - id: 'wallet.settings.assurance', - defaultMessage: '!!!Transaction assurance security level', - description: - 'Label for the "Transaction assurance security level" dropdown.', - }, - undelegateWalletHeader: { - id: 'wallet.settings.undelegateWallet.header', - defaultMessage: '!!!Undelegating your wallet', - description: 'Undelegate wallet header on the wallet settings page.', - }, - undelegateWalletWarning: { - id: 'wallet.settings.undelegateWallet.warning', - defaultMessage: - '!!!If you are planning to stop using this wallet and remove all funds, you should first undelegate it to recover your 2 ada deposit. You will continue getting delegation rewards during the three Cardano epochs after undelegating your wallet.', - description: 'Undelegate wallet warning explaining the consequences.', - }, - undelegateWalletDisabledWarning: { - id: 'wallet.settings.undelegateWallet.disabledWarning', - defaultMessage: - "!!!This wallet is synchronizing with the blockchain, so this wallet's delegation status is currently unknown, and undelegation is not possible.", - description: - 'Undelegate wallet disabled warning explaining why it is disabled.', - }, - delegateWalletHeader: { - id: 'wallet.settings.delegateWallet.header', - defaultMessage: '!!!Delegate your wallet', - description: 'Delegate wallet header on the wallet settings page.', - }, - delegateWalletWarning: { - id: 'wallet.settings.delegateWallet.warning', - defaultMessage: - "!!!This wallet is not delegated. Please, delegate the stake from this wallet to earn rewards and support the Cardano network's security.", - description: 'Delegate wallet warning.', - }, - delegateWalletDisabledWarning: { - id: 'wallet.settings.delegateWallet.disabledWarning', - defaultMessage: - "!!!This wallet is synchronizing with the blockchain, so this wallet's delegation status is currently unknown, and delegation is not possible.", - description: - 'Delegate wallet disabled warning explaining why it is disabled.', - }, - name: { - id: 'wallet.settings.name.label', - defaultMessage: '!!!Name', - description: 'Label for the "Name" text input on the wallet settings page.', - }, - passwordLabel: { - id: 'wallet.settings.password', - defaultMessage: '!!!Password', - description: 'Label for the "Password" field.', - }, - passwordLastUpdated: { - id: 'wallet.settings.passwordLastUpdated', - defaultMessage: '!!!Last updated', - description: 'Last updated X time ago message.', - }, - passwordNotSet: { - id: 'wallet.settings.passwordNotSet', - defaultMessage: "!!!You still don't have password", - description: "You still don't have password set message.", - }, + assuranceLevelLabel: { + id: 'wallet.settings.assurance', + defaultMessage: '!!!Transaction assurance security level', + description: + 'Label for the "Transaction assurance security level" dropdown.', + }, + undelegateWalletHeader: { + id: 'wallet.settings.undelegateWallet.header', + defaultMessage: '!!!Undelegating your wallet', + description: 'Undelegate wallet header on the wallet settings page.', + }, + undelegateWalletWarning: { + id: 'wallet.settings.undelegateWallet.warning', + defaultMessage: + '!!!If you are planning to stop using this wallet and remove all funds, you should first undelegate it to recover your 2 ada deposit. You will continue getting delegation rewards during the three Cardano epochs after undelegating your wallet.', + description: 'Undelegate wallet warning explaining the consequences.', + }, + undelegateWalletDisabledWarning: { + id: 'wallet.settings.undelegateWallet.disabledWarning', + defaultMessage: + "!!!This wallet is synchronizing with the blockchain, so this wallet's delegation status is currently unknown, and undelegation is not possible.", + description: + 'Undelegate wallet disabled warning explaining why it is disabled.', + }, + delegateWalletHeader: { + id: 'wallet.settings.delegateWallet.header', + defaultMessage: '!!!Delegate your wallet', + description: 'Delegate wallet header on the wallet settings page.', + }, + delegateWalletWarning: { + id: 'wallet.settings.delegateWallet.warning', + defaultMessage: + "!!!This wallet is not delegated. Please, delegate the stake from this wallet to earn rewards and support the Cardano network's security.", + description: 'Delegate wallet warning.', + }, + delegateWalletDisabledWarning: { + id: 'wallet.settings.delegateWallet.disabledWarning', + defaultMessage: + "!!!This wallet is synchronizing with the blockchain, so this wallet's delegation status is currently unknown, and delegation is not possible.", + description: + 'Delegate wallet disabled warning explaining why it is disabled.', + }, + name: { + id: 'wallet.settings.name.label', + defaultMessage: '!!!Name', + description: + 'Label for the "Name" text input on the wallet settings page.', + }, + passwordLabel: { + id: 'wallet.settings.password', + defaultMessage: '!!!Password', + description: 'Label for the "Password" field.', + }, + passwordLastUpdated: { + id: 'wallet.settings.passwordLastUpdated', + defaultMessage: '!!!Last updated', + description: 'Last updated X time ago message.', + }, + passwordNotSet: { + id: 'wallet.settings.passwordNotSet', + defaultMessage: "!!!You still don't have password", + description: "You still don't have password set message.", + }, }); export default getWalletSettingsMessages;