From 3246cbe28288449aa556e9752a9a453ea38f7de3 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Mon, 13 Jan 2025 15:01:37 +0100 Subject: [PATCH] Display validator consistently in UI component --- components/SelectValidator.tsx | 18 ++++++++++++------ .../MsgForm/MsgBeginRedelegateForm.tsx | 4 ++-- .../MsgForm/MsgDelegateForm.tsx | 2 +- .../MsgForm/MsgUndelegateForm.tsx | 2 +- .../MsgForm/MsgWithdrawDelegatorRewardForm.tsx | 2 +- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/components/SelectValidator.tsx b/components/SelectValidator.tsx index 35e68bd3..acfef138 100644 --- a/components/SelectValidator.tsx +++ b/components/SelectValidator.tsx @@ -12,16 +12,17 @@ import { import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; import { useChains } from "@/context/ChainsContext"; import { cn } from "@/lib/utils"; +import { Validator } from "cosmjs-types/cosmos/staking/v1beta1/staking"; import { Check, ChevronsUpDown } from "lucide-react"; import { useState } from "react"; interface SelectValidatorProps { - readonly validatorAddress: string; + readonly selectedValidatorAddress: string; readonly setValidatorAddress: (validatorAddress: string) => void; } export default function SelectValidator({ - validatorAddress, + selectedValidatorAddress, setValidatorAddress, }: SelectValidatorProps) { const { @@ -38,6 +39,12 @@ export default function SelectValidator({ // reasonable filtering here. const validators = [...bonded, ...unbonding, ...unbonded]; + function displayValidator(val: Validator): string { + return val.description.moniker + (val.jailed ? " (jailed)" : "") + } + + const selectedValidator = validators.find((validatorItem) => selectedValidatorAddress === validatorItem.operatorAddress); + return ( @@ -47,9 +54,8 @@ export default function SelectValidator({ aria-expanded={open} className="mb-4 w-full max-w-[300px] justify-between border-white bg-fuchsia-900 hover:bg-fuchsia-900" > - {validatorAddress - ? validators.find((validatorItem) => validatorAddress === validatorItem.operatorAddress) - ?.description.moniker || "Unknown validator" + {selectedValidatorAddress + ? selectedValidator ? displayValidator(selectedValidator): "Unknown validator" : "Select validator…"} @@ -76,7 +82,7 @@ export default function SelectValidator({ MsgBeginRedelegate
MsgDelegate
MsgUndelegate
MsgWithdrawDelegatorReward