Skip to content

Commit

Permalink
LW-11518 Catch send error for staking conway wallets which have not r…
Browse files Browse the repository at this point in the history
…egistered voting rights yet
  • Loading branch information
DominikGuzei committed Nov 12, 2024
1 parent e2ffb9a commit 9c9f1ad
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 21 deletions.
3 changes: 3 additions & 0 deletions source/renderer/app/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,9 @@ export default class AdaApi {
.set('wrongEncryptionPassphrase')
.where('code', 'bad_request')
.inc('message', 'passphrase is too short')
.set('conwayWalletNotDelegatedToDRep')
.where('code', 'created_invalid_transaction')
.inc('message', 'ConwayWdrlNotDelegatedToDRep')
.set('transactionIsTooBig', true, {
linkLabel: 'tooBigTransactionErrorLinkLabel',
linkURL: 'tooBigTransactionErrorLinkURL',
Expand Down
6 changes: 6 additions & 0 deletions source/renderer/app/api/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ export const messages = defineMessages({
description:
'"Balance after transaction would not leave enough ada in the wallet to support tokens remaining in wallet',
},
conwayWalletNotDelegatedToDRep: {
id: 'api.errors.conwayWalletNotDelegatedToDRep',
defaultMessage: '!!!conwayWalletNotDelegatedToDRep',
description:
'Error message shown when conway era wallet has staking rewards but has not participated in governance yet.',
},
});

type Balances = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ function View({
!isPasswordValid({
isHardwareWallet,
isValid: passphraseField.isValid,
}),
}) ||
!!error,
},
];

Expand Down
5 changes: 5 additions & 0 deletions source/renderer/app/i18n/locales/defaultMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@
"defaultMessage": "!!!Insufficient funds to support tokens. You need at least an additional {adaAmount} ADA in your wallet to process this transaction.",
"description": "\"Balance after transaction would not leave enough ada in the wallet to support tokens remaining in wallet",
"id": "api.errors.NotEnoughFundsForTransactionFeesErrorWithTokens"
},
{
"defaultMessage": "!!!conwayWalletNotDelegatedToDRep",
"description": "Error message shown when conway era wallet has staking rewards but has not participated in governance yet.",
"id": "api.errors.conwayWalletNotDelegatedToDRep"
}
],
"path": "source/renderer/app/api/errors.ts"
Expand Down
1 change: 1 addition & 0 deletions source/renderer/app/i18n/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"api.errors.WalletAlreadyImportedError": "Wallet you are trying to import already exists.",
"api.errors.WalletAlreadyRestoredError": "Wallet you are trying to restore already exists.",
"api.errors.WalletFileImportError": "Wallet could not be imported, please make sure you are providing a correct file.",
"api.errors.conwayWalletNotDelegatedToDRep": "Daedalus cannot process this transaction because of blocked staking rewards. To unblock your rewards go to the <a href=\"#\">Cardano voting power delegation tab</a> and delegate your voting power",
"api.errors.inputsDepleted": "Your wallet contains only reward funds.<br />Please send at least 1 ADA to your wallet so that you can spend the funds.",
"api.errors.invalidAddress": "Please enter a valid address.",
"api.errors.invalidSmashServer": "This URL is not a valid SMASH server",
Expand Down
1 change: 1 addition & 0 deletions source/renderer/app/i18n/locales/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"api.errors.WalletAlreadyImportedError": "インポートしようとしているウォレットは既に存在します。",
"api.errors.WalletAlreadyRestoredError": "復元しようとしているウォレットは既に存在します。",
"api.errors.WalletFileImportError": "ウォレットをインポートできませんでした。有効なファイルを指定していることを確認してください。",
"api.errors.conwayWalletNotDelegatedToDRep": "!!!conwayWalletNotDelegatedToDRep",
"api.errors.inputsDepleted": "このウォレットには報酬として得られた資金しか入っていません。<br />資金を使用するには1ADA以上をウォレットに入金してください。",
"api.errors.invalidAddress": "有効なアドレスを入力してください。",
"api.errors.invalidSmashServer": "このURLは有効なSMASHサーバーではありません",
Expand Down
42 changes: 23 additions & 19 deletions source/renderer/app/stores/WalletsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -837,25 +837,29 @@ export default class WalletsStore extends Store {
: null;
const wallet = this.active;
if (!wallet) throw new Error('Active wallet required before sending.');
// @ts-ignore ts-migrate(1320) FIXME: Type of 'await' operand must either be a valid pro... Remove this comment to see the full error message
await this.sendMoneyRequest.execute({
address: receiver,
amount: parseInt(amount, 10),
passphrase,
walletId: wallet.id,
isLegacy: wallet.isLegacy,
assets: formattedAssets,
hasAssetsRemainingAfterTransaction,
});
this.analytics.sendEvent(
EventCategories.WALLETS,
'Transaction made',
'Software wallet'
);
this.refreshWalletsData();
this.actions.dialogs.closeActiveDialog.trigger();
this.sendMoneyRequest.reset();
this.goToWalletRoute(wallet.id);
try {
await this.sendMoneyRequest.execute({
address: receiver,
amount: parseInt(amount, 10),
passphrase,
walletId: wallet.id,
isLegacy: wallet.isLegacy,
assets: formattedAssets,
hasAssetsRemainingAfterTransaction,
}).promise;

this.analytics.sendEvent(
EventCategories.WALLETS,
'Transaction made',
'Software wallet'
);
this.refreshWalletsData();
this.actions.dialogs.closeActiveDialog.trigger();
this.sendMoneyRequest.reset();
this.goToWalletRoute(wallet.id);
} catch (error) {
console.log(error);
}
};
@action
_transferFundsNextStep = async () => {
Expand Down
8 changes: 7 additions & 1 deletion storybook/stories/wallets/send/WalletSend.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ import { NUMBER_OPTIONS } from '../../../../source/renderer/app/config/profileCo
import Wallet, {
HwDeviceStatuses,
} from '../../../../source/renderer/app/domains/Wallet';
import { messages } from '../../../../source/renderer/app/api/errors';
// Screens
import WalletSendForm from '../../../../source/renderer/app/components/wallet/WalletSendForm';
import type { WalletTokens } from '../../../../source/renderer/app/api/assets/types';
import { WalletSendConfirmationDialogView } from '../../../../source/renderer/app/containers/wallet/dialogs/send-confirmation/SendConfirmation.view';
import { noopAnalyticsTracker as analyticsTracker } from '../../../../source/renderer/app/analytics';
import LocalizableError from '../../../../source/renderer/app/i18n/LocalizableError';

const allAssets = [
generateAssetToken(
Expand Down Expand Up @@ -470,7 +472,11 @@ storiesOf('Wallets / Send', module)
isSubmitting={boolean('isSubmitting', false)}
isHardwareWallet={boolean('isHardwareWallet', false)}
formattedTotalAmount="21.000000"
error={null}
error={
new LocalizableError({
...messages.conwayWalletNotDelegatedToDRep,
})
}
onCancel={action('onCancel')}
onSubmitCb={action('onSubmitCb')}
onTermsCheckboxClick={action('onTermsCheckboxClick')}
Expand Down
5 changes: 5 additions & 0 deletions translations/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@
"defaultMessage": "!!!Insufficient funds to support tokens. You need at least an additional {adaAmount} ADA in your wallet to process this transaction.",
"description": "\"Balance after transaction would not leave enough ada in the wallet to support tokens remaining in wallet",
"id": "api.errors.NotEnoughFundsForTransactionFeesErrorWithTokens"
},
{
"defaultMessage": "!!!conwayWalletNotDelegatedToDRep",
"description": "Error message shown when conway era wallet has staking rewards but has not participated in governance yet.",
"id": "api.errors.conwayWalletNotDelegatedToDRep"
}
],
"path": "source/renderer/app/api/errors.ts"
Expand Down

0 comments on commit 9c9f1ad

Please sign in to comment.