Skip to content

Commit fcb78af

Browse files
committed
Merge branch 'develop' into chore/ddw-1034-refactor-error-handling-in-rewards-only-wallets
2 parents c98e1be + d4c5122 commit fcb78af

File tree

4 files changed

+48
-27
lines changed

4 files changed

+48
-27
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Fixes
66

77
- Ensured non-recommended decimal place setting alert is correctly shown ([PR 3007](https://github.com/input-output-hk/daedalus/pull/3007))
8+
- Disabled the possibility to choose a syncing wallet for ITN rewards and delegation ([PR 3015](https://github.com/input-output-hk/daedalus/pull/3015))
89

910
### Chores
1011

source/main/trezor/connection.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export const initTrezorConnect = async () => {
1414
logger.info('[TREZOR-CONNECT] Called TrezorConnect.init()');
1515
} catch (error) {
1616
logger.info('[TREZOR-CONNECT] Failed to call TrezorConnect.init()');
17-
throw error;
1817
}
1918
};
2019

source/renderer/app/components/staking/delegation-setup-wizard/DelegationStepsChooseWalletDialog.tsx

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import DialogBackButton from '../../widgets/DialogBackButton';
1616
import Dialog from '../../widgets/Dialog';
1717
import WalletsDropdown from '../../widgets/forms/WalletsDropdown';
1818
import Wallet from '../../../domains/Wallet';
19+
import LocalizableError from '../../../i18n/LocalizableError';
1920

2021
const messages = defineMessages({
2122
title: {
@@ -116,6 +117,30 @@ export default class DelegationStepsChooseWalletDialog extends Component<
116117
this.props.onSelectWallet(selectedWalletId);
117118
};
118119

120+
getErrorMessage = (wallet?: Wallet): LocalizableError | null => {
121+
if (!wallet) {
122+
return null;
123+
}
124+
125+
const { amount, reward, isRestoring } = wallet;
126+
127+
if (isRestoring) {
128+
return messages.errorRestoringWallet;
129+
}
130+
131+
if (!this.props.isWalletAcceptable(amount, reward)) {
132+
// Wallet only has Reward balance
133+
if (!amount.isZero() && amount.isEqualTo(reward)) {
134+
return messages.errorMinDelegationFundsRewardsOnly;
135+
}
136+
137+
// Wallet balance < min delegation funds
138+
return messages.errorMinDelegationFunds;
139+
}
140+
141+
return null;
142+
};
143+
119144
render() {
120145
const { intl } = this.context;
121146
const { selectedWalletId } = this.state;
@@ -125,25 +150,13 @@ export default class DelegationStepsChooseWalletDialog extends Component<
125150
minDelegationFunds,
126151
onClose,
127152
onBack,
128-
isWalletAcceptable,
129153
numberOfStakePools,
130154
getStakePoolById,
131155
} = this.props;
132156
const selectedWallet: Wallet | null | undefined = wallets.find(
133157
(wallet: Wallet) => wallet && wallet.id === selectedWalletId
134158
);
135-
const { amount, reward, isRestoring } = selectedWallet || {};
136-
let errorMessage;
137-
138-
if (selectedWallet && !isWalletAcceptable(amount, reward)) {
139-
// Wallet is restoring
140-
if (isRestoring) errorMessage = messages.errorRestoringWallet;
141-
// Wallet only has Reward balance
142-
else if (!amount.isZero() && amount.isEqualTo(reward))
143-
errorMessage = messages.errorMinDelegationFundsRewardsOnly;
144-
// Wallet balance < min delegation funds
145-
else errorMessage = messages.errorMinDelegationFunds;
146-
}
159+
const errorMessage = this.getErrorMessage(selectedWallet);
147160

148161
const error = errorMessage && (
149162
<p className={styles.errorMessage}>

source/renderer/app/containers/staking/dialogs/redeem-itn-rewards/Step1ConfigurationContainer.tsx

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import validWords from '../../../../../../common/config/crypto/valid-words.en';
1010
import { isValidMnemonic } from '../../../../../../common/config/crypto/decrypt';
1111
import { MIN_REWARDS_REDEMPTION_RECEIVER_BALANCE } from '../../../../config/stakingConfig';
1212
import Wallet from '../../../../domains/Wallet';
13+
import LocalizableError from '../../../../i18n/LocalizableError';
1314

1415
type Props = InjectedDialogContainerStepProps;
1516
const DefaultProps = InjectedDialogContainerStepDefaultProps;
@@ -34,15 +35,32 @@ const messages = defineMessages({
3435
@observer
3536
class Step1ConfigurationContainer extends Component<Props> {
3637
static defaultProps = DefaultProps;
37-
onWalletAcceptable = (walletAmount?: BigNumber) => {
38+
hasEnoughAdaToCoverFees = (walletAmount?: BigNumber) => {
3839
const minRewardsFunds = new BigNumber(
3940
MIN_REWARDS_REDEMPTION_RECEIVER_BALANCE
4041
);
4142
return walletAmount && walletAmount.gte(minRewardsFunds);
4243
};
4344

45+
getErrorMessage = (wallet?: Wallet): LocalizableError | null => {
46+
if (!wallet) {
47+
return null;
48+
}
49+
50+
const { amount, isRestoring } = wallet;
51+
52+
if (isRestoring) {
53+
return messages.errorRestoringWallet;
54+
}
55+
if (!this.hasEnoughAdaToCoverFees(amount)) {
56+
return messages.errorMinRewardFunds;
57+
}
58+
59+
return null;
60+
};
61+
4462
render() {
45-
const { actions, stores, onBack, onClose } = this.props;
63+
const { actions, stores, onClose } = this.props;
4664
const { app, staking, wallets } = stores;
4765
const { allWallets } = wallets;
4866
const {
@@ -59,23 +77,13 @@ class Step1ConfigurationContainer extends Component<Props> {
5977
const selectedWallet: Wallet | null | undefined = allWallets.find(
6078
(current: Wallet) => current && current.id === selectedWalletId
6179
);
62-
const { amount, isRestoring } = selectedWallet || {};
63-
let errorMessage = null;
64-
65-
if (selectedWallet && !this.onWalletAcceptable(amount)) {
66-
// Wallet is restoring
67-
if (isRestoring) errorMessage = messages.errorRestoringWallet;
68-
// Wallet balance < min rewards redemption funds
69-
else errorMessage = messages.errorMinRewardFunds;
70-
}
80+
const errorMessage = this.getErrorMessage(selectedWallet);
7181

7282
return (
7383
<Step1ConfigurationDialog
7484
error={errorMessage}
7585
isCalculatingReedemFees={isCalculatingReedemFees}
7686
mnemonicValidator={isValidMnemonic}
77-
// @ts-ignore ts-migrate(2769) FIXME: No overload matches this call.
78-
onBack={onBack}
7987
onClose={onClose}
8088
onContinue={onConfigurationContinue.trigger}
8189
onSelectWallet={(walletId, recoveryPhrase) =>

0 commit comments

Comments
 (0)