Skip to content

Commit

Permalink
Merge pull request #1379 from DA0-DA0/development
Browse files Browse the repository at this point in the history
Deploy various polytone fixes
  • Loading branch information
NoahSaso authored Sep 13, 2023
2 parents 5dfdcb0 + 3bc1062 commit 8dfcf03
Show file tree
Hide file tree
Showing 25 changed files with 294 additions and 180 deletions.
2 changes: 2 additions & 0 deletions packages/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
"rateContributions": "Rate contributions",
"readLess": "Read less",
"readMore": "Read more",
"refundAndCancel": "Refund and cancel",
"registerSlashes": "Register slashes",
"reject": "Reject",
"relay": "Relay",
Expand Down Expand Up @@ -1120,6 +1121,7 @@
"bulkImportActions": "Bulk Import Actions",
"burnNft": "Burn NFT",
"cancelVesting": "Cancel vesting",
"canceled": "Canceled",
"casting": "Casting",
"chain": "Chain",
"chainModule": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,21 @@ import {
MsgCreateValidator,
MsgEditValidator,
} from '@dao-dao/protobuf/codegen/cosmos/staking/v1beta1/tx'
import { CodeMirrorInput, InputLabel, SelectInput } from '@dao-dao/stateless'
import { ActionComponent } from '@dao-dao/types/actions'
import { validateJSON } from '@dao-dao/utils'
import {
ChainPickerInput,
CodeMirrorInput,
InputLabel,
SelectInput,
} from '@dao-dao/stateless'
import { ActionComponent, ActionContextType } from '@dao-dao/types/actions'
import {
getChainForChainId,
getNativeTokenForChainId,
toValidatorAddress,
validateJSON,
} from '@dao-dao/utils'

import { useActionOptions } from '../../../react'

export const VALIDATOR_ACTION_TYPES = [
{
Expand All @@ -32,6 +44,7 @@ export const VALIDATOR_ACTION_TYPES = [
]

export type ValidatorActionsData = {
chainId: string
validatorActionTypeUrl: string
createMsg: string
editMsg: string
Expand All @@ -43,21 +56,70 @@ export const ValidatorActionsComponent: ActionComponent = ({
isCreating,
}) => {
const { t } = useTranslation()
const { control, register, watch } = useFormContext<ValidatorActionsData>()
const {
chain: { chain_id: currentChainId },
address: _address,
context,
} = useActionOptions()
const { control, register, watch, getValues, setValue } =
useFormContext<ValidatorActionsData>()

const chainId = watch((fieldNamePrefix + 'chainId') as 'chainId')
const validatorActionTypeUrl = watch(
(fieldNamePrefix + 'validatorActionTypeUrl') as 'validatorActionTypeUrl'
)

const updateChainValues = (chainId: string, typeUrl: string) => {
const address =
context.type === ActionContextType.Dao && currentChainId !== chainId
? context.info.polytoneProxies[chainId] || ''
: _address
const validatorAddress =
address &&
toValidatorAddress(address, getChainForChainId(chainId).bech32_prefix)

if (typeUrl === MsgCreateValidator.typeUrl) {
const createMsg = JSON.parse(
getValues((fieldNamePrefix + 'createMsg') as 'createMsg')
)
createMsg.delegatorAddress = address
createMsg.validatorAddress = validatorAddress
createMsg.value.denom = getNativeTokenForChainId(chainId).denomOrAddress
setValue(
(fieldNamePrefix + 'createMsg') as 'createMsg',
JSON.stringify(createMsg, null, 2)
)
} else if (typeUrl === MsgEditValidator.typeUrl) {
const editMsg = JSON.parse(
getValues((fieldNamePrefix + 'editMsg') as 'editMsg')
)
editMsg.validatorAddress = validatorAddress
setValue(
(fieldNamePrefix + 'editMsg') as 'editMsg',
JSON.stringify(editMsg, null, 2)
)
}
}

return (
<>
<ChainPickerInput
className="mb-4"
disabled={!isCreating}
fieldName={fieldNamePrefix + 'chainId'}
onChange={(chainId) =>
updateChainValues(chainId, validatorActionTypeUrl)
}
/>

<SelectInput
disabled={!isCreating}
error={errors?.validatorActionTypeUrl}
fieldName={
(fieldNamePrefix +
'validatorActionTypeUrl') as 'validatorActionTypeUrl'
}
onChange={(value) => updateChainValues(chainId, value)}
register={register}
>
{VALIDATOR_ACTION_TYPES.map(({ typeUrl, i18nKey }) => (
Expand Down
Loading

2 comments on commit 8dfcf03

@vercel
Copy link

@vercel vercel bot commented on 8dfcf03 Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 8dfcf03 Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.