From d5836bf106a98bd07f19afbcefd8ab8924d6c91a Mon Sep 17 00:00:00 2001 From: stefanpetkov90 Date: Wed, 28 Sep 2022 17:53:07 +0300 Subject: [PATCH 1/2] CUDOS-1484-Param-change-error --- .../Faucet/components/Activity/index.tsx | 2 +- .../ProposalTypes/ParameterChange.tsx | 1 - .../components/ProposalModal/Proposals.tsx | 19 +++++++++-- .../RedelegationModal/Redelegation.tsx | 19 ++++++++--- src/store/modal.ts | 33 +++++++++++-------- 5 files changed, 52 insertions(+), 22 deletions(-) diff --git a/src/containers/Faucet/components/Activity/index.tsx b/src/containers/Faucet/components/Activity/index.tsx index 8160072..00da00d 100644 --- a/src/containers/Faucet/components/Activity/index.tsx +++ b/src/containers/Faucet/components/Activity/index.tsx @@ -31,7 +31,7 @@ const Activity = () => { ), timestamp: ( - {moment(item.timestamp).parseZone().fromNow(true)} + {moment(new Date(item.timestamp.parseZone().fromNow(true)))} ) })) diff --git a/src/containers/Proposals/components/ProposalModal/ProposalTypes/ParameterChange.tsx b/src/containers/Proposals/components/ProposalModal/ProposalTypes/ParameterChange.tsx index f2d3663..6f8c2b1 100644 --- a/src/containers/Proposals/components/ProposalModal/ProposalTypes/ParameterChange.tsx +++ b/src/containers/Proposals/components/ProposalModal/ProposalTypes/ParameterChange.tsx @@ -98,7 +98,6 @@ const ParameterChange = () => { setEvent(e)} disableUnderline diff --git a/src/containers/Proposals/components/ProposalModal/Proposals.tsx b/src/containers/Proposals/components/ProposalModal/Proposals.tsx index 6454b42..f80b35f 100644 --- a/src/containers/Proposals/components/ProposalModal/Proposals.tsx +++ b/src/containers/Proposals/components/ProposalModal/Proposals.tsx @@ -9,6 +9,7 @@ import _ from 'lodash' import BigNumber from 'bignumber.js' import { useNotifications } from 'components/NotificationPopup/hooks' import { + FailureMessage, initialProposalModalState, ModalStatus, ProposalModalProps, @@ -65,6 +66,17 @@ const Proposals: React.FC = ({ handleModal, modalProps }) => { }) } + const handleError = (error: string) => { + if ( + error.includes( + FailureMessage.CREATING_PROPOSAL_FAILED_TO_UNMARSHAL_NUMBER + ) + ) { + return FailureMessage.CREATING_PROPOSAL_FAILED_TO_UNMARSHAL_END_USER + } + return FailureMessage.DEFAULT_PROPOSAL_FAILED + } + const handleProposalSubmit = async (proposerAddress: string) => { try { handleModal({ @@ -87,10 +99,13 @@ const Proposals: React.FC = ({ handleModal, modalProps }) => { hash: result.transactionHash }) } catch (error) { - setError(error.message) handleModal({ open: true, - status: ModalStatus.FAILURE + status: ModalStatus.FAILURE, + failureMessage: { + title: 'Creating Proposal Failed.', + subtitle: handleError(error.message) + } }) } } diff --git a/src/containers/ValidatorDetails/components/Details/components/ValidatorInfo/components/RedelegationModal/Redelegation.tsx b/src/containers/ValidatorDetails/components/Details/components/ValidatorInfo/components/RedelegationModal/Redelegation.tsx index 58e8227..218416d 100644 --- a/src/containers/ValidatorDetails/components/Details/components/ValidatorInfo/components/RedelegationModal/Redelegation.tsx +++ b/src/containers/ValidatorDetails/components/Details/components/ValidatorInfo/components/RedelegationModal/Redelegation.tsx @@ -9,7 +9,8 @@ import { coin, GasPrice } from 'cudosjs' import { ModalStatus, RedelegationModalProps, - initialRedelegationModalState + initialRedelegationModalState, + FailureMessage } from 'store/modal' import { calculateFee, redelegate } from 'ledgers/transactions' import getMiddleEllipsis from 'utils/get_middle_ellipsis' @@ -191,6 +192,17 @@ const Redelegation: React.FC = ({ setRedelegationAmount(delegated) } + const handleError = (error: string) => { + switch (error) { + case FailureMessage.REJECTED_BY_USER: + return FailureMessage.REJECTED_BY_USER_END_USER + case FailureMessage.REDELEGATION_IN_PROGRESS: + return FailureMessage.REDELEGATION_IN_PROGRESS_END_USER + default: + return FailureMessage.DEFAULT_TRANSACTION_FAILED + } + } + const handleSubmit = async (): Promise => { handleModal({ status: ModalStatus.LOADING }) @@ -221,10 +233,7 @@ const Redelegation: React.FC = ({ status: ModalStatus.FAILURE, failureMessage: { title: 'Redelegation Failed!', - subtitle: - e.message === 'Request rejected' - ? 'Request rejected by the user' - : 'Seems like something went wrong with executing the transaction. Try again or check your wallet balance.' + subtitle: handleError(e.message) } }) } diff --git a/src/store/modal.ts b/src/store/modal.ts index e4cb51e..487a772 100644 --- a/src/store/modal.ts +++ b/src/store/modal.ts @@ -17,6 +17,19 @@ export type Modal = { } } +export enum FailureMessage { + REJECTED_BY_USER = 'Request rejected', + REJECTED_BY_USER_END_USER = 'Request rejected by the user', + REDELEGATION_IN_PROGRESS = 'Query failed with (18): failed to execute message; message index: 0: redelegation to this validator already in progress; first redelegation to this validator must complete before next redelegation: invalid request', + REDELEGATION_IN_PROGRESS_END_USER = 'Redelegation to this validator already in progress. First redelegation to this validator must complete before next redelegation.', + CREATING_PROPOSAL_FAILED_TO_UNMARSHAL_NUMBER = 'err: json: cannot unmarshal number into Go value of type string: failed to set parameter: invalid proposal content: invalid request', + CREATING_PROPOSAL_FAILED_TO_UNMARSHAL_END_USER = 'Failed to parse field "Change Value", please wrap the input in " " and try again.', + DEFAULT_PROPOSAL_FAILED = 'Seems like something went wrong with creating the proposal. Try again or check your wallet balance.', + DEFAULT_TRANSACTION_FAILED = 'Seems like something went wrong with executing the transaction. Try again or check your wallet balance.', + DEFAULT_VOTING_PROPOSAL_FAILED = 'Seems like something went wrong with voting for the proposal. Try again or check your wallet balance.', + DEFAULT_DEPOSITING_PROPOSAL_FAILED = 'Seems like something went wrong with depositing for the proposal. Try again or check your wallet balance.' +} + // ======================== // REWARDS MODAL // ======================== @@ -45,8 +58,7 @@ export const initialRewardsModalProps: RewardsModalProps = { txRestakeHash: '', failureMessage: { title: 'Claiming Rewards Failed', - subtitle: - 'Seems like something went wrong with executing the transaction. Try again or check your wallet balance.' + subtitle: FailureMessage.DEFAULT_TRANSACTION_FAILED } } @@ -76,8 +88,7 @@ export const initialDelegationModalState: DelegationModalProps = { txHash: '', failureMessage: { title: 'Delegation Failed', - subtitle: - 'Seems like something went wrong with executing the transaction. Try again or check your wallet balance.' + subtitle: FailureMessage.DEFAULT_TRANSACTION_FAILED } } @@ -123,8 +134,7 @@ export const initialVotingModalState: VotingModalProps = { hash: '', failureMessage: { title: 'Voting for Proposal Failed!', - subtitle: `Seems like something went wrong with voting for the proposal. Try - again or check your wallet balance.` + subtitle: FailureMessage.DEFAULT_VOTING_PROPOSAL_FAILED } } @@ -192,8 +202,7 @@ export const initialProposalModalState: ProposalModalProps = { }, failureMessage: { title: 'Creating Proposal Failed!', - subtitle: `Seems like something went wrong with creating the proposal. Try again - or check your wallet balance.` + subtitle: FailureMessage.DEFAULT_PROPOSAL_FAILED } } @@ -230,9 +239,8 @@ export const initialDepositModalState: DepositModalProps = { fee: new BigNumber(0), hash: '', failureMessage: { - title: 'Voting for Proposal Failed!', - subtitle: `Seems like something went wrong with depositing for the proposal. Try again - or check your wallet balance.` + title: 'Depositing for Proposal Failed!', + subtitle: FailureMessage.DEFAULT_DEPOSITING_PROPOSAL_FAILED } } @@ -249,8 +257,7 @@ export const initialFaucetModalProps: FaucetModalProps = { status: null, failureMessage: { title: 'Transaction failed!', - subtitle: - 'Seems like something went wrong with executing the transaction. Please try again.' + subtitle: FailureMessage.DEFAULT_TRANSACTION_FAILED } } From 57d32d2b3db0aabf3c36ec0ea7408134418f77b0 Mon Sep 17 00:00:00 2001 From: stefanpetkov90 Date: Wed, 28 Sep 2022 18:09:44 +0300 Subject: [PATCH 2/2] CUDOS-1529 Out of range Select component --- .../RedelegationModal/Redelegation.tsx | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/containers/ValidatorDetails/components/Details/components/ValidatorInfo/components/RedelegationModal/Redelegation.tsx b/src/containers/ValidatorDetails/components/Details/components/ValidatorInfo/components/RedelegationModal/Redelegation.tsx index 218416d..7f9ce14 100644 --- a/src/containers/ValidatorDetails/components/Details/components/ValidatorInfo/components/RedelegationModal/Redelegation.tsx +++ b/src/containers/ValidatorDetails/components/Details/components/ValidatorInfo/components/RedelegationModal/Redelegation.tsx @@ -48,7 +48,6 @@ const Redelegation: React.FC = ({ handleModal }) => { const [delegated, setDelegated] = useState('') - const [redelegationAddress, setRedelegationAddress] = useState('') const [redelegationAmount, setRedelegationAmount] = useState('') const { validator, amount, fee } = modalProps const dispatch = useDispatch() @@ -57,8 +56,14 @@ const Redelegation: React.FC = ({ ({ profile }: RootState) => profile ) const validators = useSelector(({ validator }: RootState) => validator.items) - const data = validators.map((item) => ({ - value: item.validator, + + const filteredValidators = validators.filter( + (item) => item.validator !== validator?.address + ) + + const data = filteredValidators.map((item, idx) => ({ + value: (idx + 1).toString(), + address: item.validator, label: ( = ({ ) })) - const handleDropdown = (validatorAddress: string) => { - setRedelegationAddress(validatorAddress) + const [redelegationAddress, setRedelegationAddress] = useState( + data[0].address + ) + + const handleDropdown = (validatorIndex: string) => { + const validatorAddress = data.filter( + (item, idx) => idx + 1 === Number(validatorIndex) + ) + + setRedelegationAddress(validatorAddress[0].address) } useEffect(() => {