Skip to content

Commit

Permalink
refactor(web): fix-unique-id-as-key-instead-of-array-index
Browse files Browse the repository at this point in the history
  • Loading branch information
Harman-singh-waraich committed Jan 5, 2024
1 parent e69f849 commit 18c288f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
6 changes: 3 additions & 3 deletions web/src/components/DisputePreview/DisputeContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const DisputeContext: React.FC<IDisputeContext> = ({ disputeTemplate }) =
{isUndefined(disputeTemplate) ? null : <h3>Voting Options</h3>}
<AnswersContainer>
{disputeTemplate?.answers?.map((answer: IAnswer, i: number) => (
<Answer key={`${answer.title}-${i}`}>
<Answer key={answer.title}>
<small>Option {i + 1}:</small>
<label>{answer.title}</label>
</Answer>
Expand All @@ -94,8 +94,8 @@ export const DisputeContext: React.FC<IDisputeContext> = ({ disputeTemplate }) =
<>
<Divider />
<AliasesContainer>
{disputeTemplate.aliases.map((alias, index) => (
<AliasDisplay alias={alias} key={`${alias.address}-${index}`} />
{disputeTemplate.aliases.map((alias) => (
<AliasDisplay alias={alias} key={alias.address} />
))}
</AliasesContainer>
</>
Expand Down
10 changes: 7 additions & 3 deletions web/src/context/NewDisputeContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type Answer = {
};

export type Alias = {
id?: string;
name: string;
address: string | Address;
};
Expand Down Expand Up @@ -55,10 +56,13 @@ const initialDisputeData: IDisputeData = {
title: "",
description: "",
question: "",
answers: [{ title: "" }, { title: "" }],
answers: [
{ title: "", id: "1" },
{ title: "", id: "2" },
],
aliases: [
{ name: "", address: "" },
{ name: "", address: "" },
{ name: "", address: "", id: "1" },
{ name: "", address: "", id: "2" },
],
};
const initialDisputeTemplate = initialDisputeData as IDisputeTemplate;
Expand Down
4 changes: 2 additions & 2 deletions web/src/pages/Resolver/Parameters/CounterParties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const CounterParties: React.FC = () => {

//value here is the total number of fields-
const updateAliases = (value: number) => {
let defaultAlias = { name: "", address: "" };
let defaultAlias = { name: "", address: "", id: value.toString() };
let aliases = disputeData.aliases;

if (isUndefined(aliases)) {
Expand All @@ -68,7 +68,7 @@ const CounterParties: React.FC = () => {
<Header text="Counterparties" />
<MiddleContainer>
{disputeData.aliases?.map((alias, index) => (
<AliasContainer key={index}>
<AliasContainer key={alias?.id}>
<LabeledInput
name="name"
label={`Party ${index + 1}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const OptionsFields: React.FC = () => {
const { disputeData, setDisputeData } = useNewDisputeContext();

const updateOptions = (value: number) => {
let defaultAnswer: Answer = { title: "" };
let defaultAnswer: Answer = { title: "", id: value.toString() };
let answers = disputeData.answers;

if (value < answers?.length) return setDisputeData({ ...disputeData, answers: answers.splice(0, value) });
Expand All @@ -48,7 +48,7 @@ const OptionsFields: React.FC = () => {
name="title"
label={`Voting Option ${index + 1}`}
placeholder="eg. Pay 150 DAI"
key={index}
key={answer?.id}
value={answer.title ?? ""}
onChange={(event) => handleOptionWrite(event, index)}
/>
Expand Down

0 comments on commit 18c288f

Please sign in to comment.