Skip to content

Commit

Permalink
Merge pull request #97 from CudoVentures/cudos-dev
Browse files Browse the repository at this point in the history
Cudos dev
  • Loading branch information
maptuhec authored Sep 29, 2022
2 parents 605b870 + a27cb55 commit 8806726
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/containers/Faucet/components/Activity/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const Activity = () => {
),
timestamp: (
<Typography variant="body2" color="text.secondary">
{moment(item.timestamp).parseZone().fromNow(true)}
{moment(new Date(item.timestamp.parseZone().fromNow(true)))}
</Typography>
)
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ const ParameterChange = () => {
<Box gap={1} display="flex">
<InputContainer
placeholder="Change Value"
type="number"
name="changeValue"
onChange={(e) => setEvent(e)}
disableUnderline
Expand Down
19 changes: 17 additions & 2 deletions src/containers/Proposals/components/ProposalModal/Proposals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import _ from 'lodash'
import BigNumber from 'bignumber.js'
import { useNotifications } from 'components/NotificationPopup/hooks'
import {
FailureMessage,
initialProposalModalState,
ModalStatus,
ProposalModalProps,
Expand Down Expand Up @@ -65,6 +66,17 @@ const Proposals: React.FC<ProposalProps> = ({ 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({
Expand All @@ -87,10 +99,13 @@ const Proposals: React.FC<ProposalProps> = ({ 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)
}
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -47,7 +48,6 @@ const Redelegation: React.FC<RedelegationProps> = ({
handleModal
}) => {
const [delegated, setDelegated] = useState<string>('')
const [redelegationAddress, setRedelegationAddress] = useState<string>('')
const [redelegationAmount, setRedelegationAmount] = useState<string>('')
const { validator, amount, fee } = modalProps
const dispatch = useDispatch()
Expand All @@ -56,8 +56,14 @@ const Redelegation: React.FC<RedelegationProps> = ({
({ 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: (
<AvatarName
name={item.moniker}
Expand All @@ -67,8 +73,16 @@ const Redelegation: React.FC<RedelegationProps> = ({
)
}))

const handleDropdown = (validatorAddress: string) => {
setRedelegationAddress(validatorAddress)
const [redelegationAddress, setRedelegationAddress] = useState<string>(
data[0].address
)

const handleDropdown = (validatorIndex: string) => {
const validatorAddress = data.filter(
(item, idx) => idx + 1 === Number(validatorIndex)
)

setRedelegationAddress(validatorAddress[0].address)
}

useEffect(() => {
Expand Down Expand Up @@ -191,6 +205,17 @@ const Redelegation: React.FC<RedelegationProps> = ({
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<void> => {
handleModal({ status: ModalStatus.LOADING })

Expand Down Expand Up @@ -221,10 +246,7 @@ const Redelegation: React.FC<RedelegationProps> = ({
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)
}
})
}
Expand Down
33 changes: 20 additions & 13 deletions src/store/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
// ========================
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
}
}

Expand All @@ -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
}
}

Expand Down

0 comments on commit 8806726

Please sign in to comment.