Skip to content

Commit

Permalink
fix bugs in SetOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya-dobri committed Dec 25, 2024
1 parent 3d8d5b4 commit f19dd84
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 104 deletions.
2 changes: 1 addition & 1 deletion src/widgets/BuildTransaction/BaseFeeInput/ui/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const BaseFeeInput: FC = () => {
})();

const [sourceError, setSourceError] = useState<string>("");
const [feeState, setfeeState] = useState<number>(initialBaseFee);

const validateFee = (value: number) => {
if (value <= 0) {
setSourceError("Base Fee is required");
Expand Down
168 changes: 65 additions & 103 deletions src/widgets/OperationTypes/SetOptions/ui/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@ import StellarSdk from "stellar-sdk";
import InputField from "../../shared/InputField";
import { useStore } from "@/shared/store";
import { useShallow } from "zustand/react/shallow";


import { useHandleSourceAccountChange } from "@/features/hooks";

import { IFlag } from "../../shared/FlagSelector";
import { useFixUnknownError, useHandleSourceAccountChange } from "@/features/hooks";

import { IOperation } from "@/shared/types";

type Field =
Expand Down Expand Up @@ -78,10 +73,10 @@ const SetOptions: FC<Props> = ({ id }) => {

const sourceAccount = operation.source_account;

const [masterWeightValue, setMasterWeightValue] = useState(
masterWeight?.toString() || ""
const [masterWeightValue, setMasterWeightValue] = useState<number | string>(
masterWeight ?? ""
);
const [selectedSetFlagsBitmask, setSelectedSetFlagsBitmask] = useState(0);

const [selectedClearFlagsBitmask, setSelectedClearFlagsBitmask] = useState(0);
const [selectedClearFlags] = useState<number[][]>([]);
// const [selectedSetFlagsLocal, setSelectedSetFlagsLocal] = useState<number[]>(
Expand All @@ -96,7 +91,7 @@ const SetOptions: FC<Props> = ({ id }) => {
const [lowThresholdValue, setLowThresholdValue] = useState(
lowThreshold != null ? lowThreshold.toString() : ""
);

const [selectedSetFlagsBitmask, setSelectedSetFlagsBitmask] = useState(0);
const [mediumThresholdValue, setMediumThresholdValue] = useState(
mediumThreshold != null ? mediumThreshold.toString() : ""
);
Expand Down Expand Up @@ -359,66 +354,42 @@ useEffect(() => {
}
};

useEffect(() => {
const params = new URLSearchParams(window.location.search);

if (masterWeight !== null && masterWeight !== undefined) {
params.set("masterWeight" + id.toString(), masterWeight?.toString() || "");
}else{
params.delete("masterWeight" + id.toString());
}

if (lowThreshold !== null && lowThreshold !== undefined) {
params.set(
"lowThreshold" + id.toString(),
lowThresholdValue?.toString() || ""
);
}else{
params.delete("lowThreshold" + id.toString());
}

if (mediumThreshold !== null && mediumThreshold !== undefined) {
params.set(
"mediumThreshold" + id.toString(),
mediumThresholdValue?.toString() || ""
);
}else{
params.delete("mediumThreshold" + id.toString());
}

if (highThreshold !== null && highThreshold !== undefined) {
params.set(
"highThreshold" + id.toString(),
highThresholdValue?.toString() || ""
);
}else{
params.delete("highThreshold" + id.toString());
}

if (homeDomain !== null && homeDomain !== undefined) {
params.set("homeDomain" + id.toString(), homeDomain?.toString() || "");
}else{
params.delete("homeDomain" + id.toString());
}

useEffect(() => {
const params = new URLSearchParams(window.location.search);

if (masterWeight !== null && masterWeight !== undefined) {
params.set("masterWeight" + id.toString(), masterWeight?.toString() || "");
} else {
params.delete("masterWeight" + id.toString());
}

if (lowThreshold !== null && lowThreshold !== undefined) {
params.set("lowThreshold" + id.toString(), lowThresholdValue?.toString() || "");
} else {
params.delete("lowThreshold" + id.toString());
}

if (mediumThreshold !== null && mediumThreshold !== undefined) {
params.set("mediumThreshold" + id.toString(), mediumThresholdValue?.toString() || "");
} else {
params.delete("mediumThreshold" + id.toString());
}

if (highThreshold !== null && highThreshold !== undefined) {
params.set("highThreshold" + id.toString(), highThresholdValue?.toString() || "");
} else {
params.delete("highThreshold" + id.toString());
}

if (homeDomain) {
params.set("homeDomain" + id.toString(), homeDomain || "");
} else {
params.delete("homeDomain" + id.toString());
}

window.history.replaceState({}, "", `?${params.toString()}`);
}, [masterWeightValue, lowThresholdValue, mediumThresholdValue, highThresholdValue, id]);

if (sourceAccount !== null && sourceAccount !== undefined && sourceAccount !== "") {
params.set("sourceAccount" + id.toString(), sourceAccount?.toString() || "");
} else {
params.delete("sourceAccount" + id.toString());
}

window.history.replaceState({}, "", `?${params.toString()}`);
}, [
masterWeight,
lowThresholdValue,
mediumThresholdValue,
highThresholdValue,
homeDomain,
sourceAccount,
id,

]);

const handleSignerTypeChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
const selectedType = e.target.value;
Expand Down Expand Up @@ -471,18 +442,18 @@ useEffect(() => {



useEffect(() => {
const params = new URLSearchParams(window.location.search);

const params = new URLSearchParams(window.location.search);

// Проверяем, что значение является числом, прежде чем добавлять его в параметры
if (typeof masterWeight === 'number' && !isNaN(masterWeight)) {
params.set("masterWeight", masterWeight?.toString() ?? "");
} else {
params.delete("masterWeight"); // Удаляем параметр, если он невалиден
}
// Check that the value is a number before adding it to the parameters
if (typeof masterWeight === 'number') {
params.set("masterWeight", masterWeight.toString());
} else {
params.delete("masterWeight"); // Remove the parameter if it is invalid
}

window.history.replaceState({}, "", `?${params.toString()}`);
}, [masterWeight]);
window.history.replaceState({}, "", `?${params.toString()}`);
}, [masterWeight]);


return (
Expand All @@ -497,19 +468,19 @@ useEffect(() => {
selectedFlagsBitmask={selectedSetFlagsBitmask}
onToggle={(flagId) => handleToggleFlag(flagId, "set")}
/>

<FlagSelector
operationIndex={id}
title="Clear Flags"
flags={clearFlagsData}
selectedFlagsBitmask={selectedClearFlagsBitmask}
onToggle={(flagId) => handleToggleFlag(flagId, "clear")}
/>

<InputField
title="Master Weight"
placeholder="0-255"
value={masterWeightValue}
value={String(masterWeightValue)}
onChange={handleInputChange("master_weight")}
validate={validateRange}
errorMessage="Expected an integer between 0 and 255 (inclusive)."
Expand All @@ -518,9 +489,8 @@ useEffect(() => {
? "This can result in a permanently locked account. Are you sure you know what you're doing?"
: ""
}

/>

<InputField
title="Low Threshold"
placeholder="0-255"
Expand All @@ -529,7 +499,7 @@ useEffect(() => {
validate={validateRange}
errorMessage="Expected an integer between 0 and 255 (inclusive)."
/>

<InputField
title="Medium Threshold"
placeholder="0-255"
Expand All @@ -543,31 +513,24 @@ useEffect(() => {
: ""
}
/>

<InputField
title="High Threshold"
placeholder="0-255"
value={highThresholdValue}
onChange={handleInputChange("high_threshold")}
validate={validateRange}
errorMessage="Expected an integer between 0 and 255 (inclusive)."

warningMessage={
highThresholdValue !== "" && +highThresholdValue >= 0
? "This can result in a permanently locked account. Are you sure you know what you're doing?"
: ""
}

/>

<div className={s.section}>


/>




<div className={s.section}>


<h4 className={s.sectionTitle}>
Signer Type <span className={s.optional}>(optional)</span>
</h4>
Expand Down Expand Up @@ -615,28 +578,28 @@ useEffect(() => {
<>
Signer will be removed from account if this weight is 0.
<br />
Used to add/remove or adjust weight of an additional
signer on the account.
Used to add/remove or adjust weight of an additional signer
on the account.
</>
}
/>
</>
)}
</div>
</div>

<InputField
title="Home Domain"
placeholder="Ex: example.com"
value={homeDomain || ""}
onChange={handleHomeDomainChange}
/>

<InputField
title="Source Account"
placeholder="Ex: GCEXAMPLE5HWNK4AYSTEQ4UWDKHTCKADVS2AHF3UI2ZMO3DPUSM6Q4UG"
value={sourceAccount || ""}
onChange={(e) => handleSourceAccountChange(e, id)}
onChange={useHandleSourceAccountChange}
validate={(value) =>
StellarSdk.StrKey.isValidEd25519PublicKey(value) || value === ""
}
Expand All @@ -646,6 +609,5 @@ useEffect(() => {
</div>
</>
);
};

export default SetOptions;
}
export default SetOptions

0 comments on commit f19dd84

Please sign in to comment.