diff --git a/source/renderer/app/api/api.ts b/source/renderer/app/api/api.ts index 0f4f697cde..116e92933a 100644 --- a/source/renderer/app/api/api.ts +++ b/source/renderer/app/api/api.ts @@ -1292,7 +1292,6 @@ export default class AdaApi { logger.debug('AdaApi::constructTransaction error', { error, }); - console.log('!DEBUG', error); throw new ApiError(error); } diff --git a/source/renderer/app/components/voting/voting-governance/VotingPowerDelegation.messages.ts b/source/renderer/app/components/voting/voting-governance/VotingPowerDelegation.messages.ts index 5db484a031..98e9ffe430 100644 --- a/source/renderer/app/components/voting/voting-governance/VotingPowerDelegation.messages.ts +++ b/source/renderer/app/components/voting/voting-governance/VotingPowerDelegation.messages.ts @@ -77,4 +77,14 @@ export const messages = defineMessages({ defaultMessage: '!!!Submit', description: 'Label for the submit button on the governance page', }, + initializeTxErrorGeneric: { + id: 'voting.governance.initializeTxError.generic', + defaultMessage: '!!!Could not initialize transaction. Please try again!', + description: 'Generic error for initialize transaction', + }, + initializeTxErrorSameVote: { + id: 'voting.governance.initializeTxError.sameVote', + defaultMessage: '!!!Chosen same value as previously', + description: 'Chosen same value as previously', + }, }); diff --git a/source/renderer/app/components/voting/voting-governance/VotingPowerDelegation.scss b/source/renderer/app/components/voting/voting-governance/VotingPowerDelegation.scss index b98a4862e2..0ca5e2cb17 100644 --- a/source/renderer/app/components/voting/voting-governance/VotingPowerDelegation.scss +++ b/source/renderer/app/components/voting/voting-governance/VotingPowerDelegation.scss @@ -1,11 +1,6 @@ @import '../votingConfig'; @import '../../../themes/mixins/error-message.scss'; -.generalError { - @include error-message; - margin-top: 28px; -} - .component { flex: 1 0 0; padding: 20px; @@ -57,12 +52,21 @@ } } +.generalError { + @include error-message; +} + .voteTypeSelect, .drepInput, -.voteSubmit { +.generalError { margin-top: 40px; } +.generalError, +.voteSubmit { + margin-top: 28px; +} + .voteSubmit { width: 100%; } diff --git a/source/renderer/app/components/voting/voting-governance/VotingPowerDelegation.tsx b/source/renderer/app/components/voting/voting-governance/VotingPowerDelegation.tsx index 1a2ab1398e..dc3a8e1c94 100644 --- a/source/renderer/app/components/voting/voting-governance/VotingPowerDelegation.tsx +++ b/source/renderer/app/components/voting/voting-governance/VotingPowerDelegation.tsx @@ -16,6 +16,7 @@ import StakePool from '../../../domains/StakePool'; import ItemsDropdown from '../../widgets/forms/ItemsDropdown'; import { assertIsBech32WithPrefix } from '../../../../../common/utils/assertIsBech32WithPrefix'; import { Separator } from '../../widgets/separator/Separator'; +import { InitializeVPDelegationTxError } from '../../../stores/VotingStore'; type Props = { getStakePoolById: (...args: Array) => any; @@ -23,7 +24,8 @@ type Props = { chosenOption: string; wallet: Wallet; }) => Promise< - { success: true; fees: BigNumber } | { success: false; error: string } + | { success: true; fees: BigNumber } + | { success: false; errorCode: InitializeVPDelegationTxError } >; intl: Intl; onExternalLinkClick: (...args: Array) => any; @@ -53,7 +55,7 @@ type Form = Omit & { }; type FormWithError = Omit & { - txInitError: string; + txInitError: InitializeVPDelegationTxError; status: 'form-with-error'; }; @@ -81,6 +83,14 @@ const isDrepIdValid = (drepId: string) => { return true; }; +const mapOfTxErrorCodeToIntl: Record< + InitializeVPDelegationTxError, + typeof messages[keyof typeof messages] +> = { + generic: messages.initializeTxErrorGeneric, + same_vote: messages.initializeTxErrorSameVote, +}; + function VotingPowerDelegation({ getStakePoolById, initiateTransaction, @@ -109,6 +119,7 @@ function VotingPowerDelegation({ const submitButtonDisabled = !formIsValid || state.status === 'form-submitted' || + state.status === 'form-with-error' || state.status === 'form-initiating-tx'; const voteTypes: { value: VoteType; label: string }[] = [ @@ -149,12 +160,12 @@ function VotingPowerDelegation({ } else { setState({ ...state, - txInitError: result.error, + txInitError: result.errorCode, status: 'form-with-error', }); } })(); - }, [initiateTransaction, state]); + }, [initiateTransaction, intl, state]); return ( <> @@ -252,6 +263,13 @@ function VotingPowerDelegation({ } /> )} + + {state.status === 'form-with-error' && ( +

+ {intl.formatMessage(mapOfTxErrorCodeToIntl[state.txInitError])} +

+ )} +