Skip to content

Commit

Permalink
Merge pull request #56 from Ilya-dobri/main
Browse files Browse the repository at this point in the history
Update API route to serve settings from JSON file and fixed bug in SequenceNumberInput
  • Loading branch information
grandmotivator authored Nov 11, 2024
2 parents 780d3cc + be6f3b9 commit e663bc0
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion src/views/Layout/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import Modals from "@/widgets/Layout/Modals";
type Props = {
children: React.ReactNode;
};
const allowedDomains = [{ domain: "stellar-multisig.montelibero.org" }];

const isDomainAllowed = () => {
const currentDomain = window.location.hostname;
return allowedDomains.some((entry) => entry.domain === currentDomain);
};

const PageLayout: FC<Props> = ({ children }) => {
const [isWindowDefined, setIsWindowDefined] = useState<boolean>(false);
Expand Down Expand Up @@ -88,6 +94,11 @@ const PageLayout: FC<Props> = ({ children }) => {
let timeoutId: ReturnType<typeof setTimeout> | null = null;

const fetchLatestCommitHash = async () => {
if (!isDomainAllowed()) {
console.error("Unauthorized domain. Skipping commit hash fetch.");
return;
}

try {
const response = await axios.get(
"https://api.github.com/repos/montelibero-org/stellar-multisig/commits",
Expand All @@ -111,7 +122,6 @@ const PageLayout: FC<Props> = ({ children }) => {
}, 60000);
}
setLastFetchedHash(latestHash);

} catch (error) {
console.warn("Error fetching commit hash:", error);
}
Expand Down
56 changes: 42 additions & 14 deletions src/widgets/BuildTransaction/SequenceNumberInput/ui/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ const SequenceNumberInput: FC<Props> = ({ firebaseID }) => {
const { tx, setSeqNum, server } = useStore(useShallow((state) => state));
const [error, setError] = useState<string>("");
const [isShowUpdateSeqNum, setIsShowUpdateSeqNum] = useState<boolean>(false);
const [initialSeqNum, setInitialSeqNum] = useState<bigint | null>(null);
const searchParams = useSearchParams();

const fetchSequenceNumber = async () => {
try {
const { data } = await axios.get<Information>(
`${server}/accounts/${tx.tx.source_account}`
);
if (data.sequence !== undefined) {

if (data.sequence !== undefined && /^[0-9]+$/.test(data.sequence)) {
const sequence = BigInt(data.sequence) + BigInt(1);
setSeqNum(sequence);
setIsShowUpdateSeqNum(false);
} else {
setError("Sequence number is undefined.");
setError("Sequence number is undefined or invalid.");
}
} catch (error) {
console.error(error);
Expand All @@ -41,32 +45,38 @@ const SequenceNumberInput: FC<Props> = ({ firebaseID }) => {
const { data } = await axios.get<Information>(
`https://horizon.stellar.org/accounts/${tx.tx.source_account}`
);
if (data.sequence !== undefined) {

if (data.sequence !== undefined && /^[0-9]+$/.test(data.sequence)) {
const sequence = BigInt(tx.tx.seq_num) + BigInt(1);
const result = isSequenceNumberOutdated(sequence, tx.tx.seq_num);
setIsShowUpdateSeqNum(result);
} else {
setError("Sequence number is undefined.");
setError("Sequence number is undefined or invalid.");
}
};

if (firebaseID !== "" && tx.tx.source_account) {
comparisonSeqs();
}
}, [firebaseID, tx.tx.source_account, tx.tx.seq_num]);

useEffect(() => {
const storedSeqNum = localStorage.getItem("initialSeqNum");
if (storedSeqNum) {
setInitialSeqNum(BigInt(storedSeqNum));
} else {
setInitialSeqNum(BigInt(tx.tx.seq_num));
localStorage.setItem("initialSeqNum", tx.tx.seq_num.toString());
}
setSeqNum(tx.tx.seq_num);
}, [setSeqNum]);
useEffect(() => {


}, [setSeqNum, tx.tx.seq_num]);

useEffect(() => {
const params = new URLSearchParams(searchParams.toString());
params.set("TransactionSequenceNumber", tx.tx.seq_num.toString());



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

return (
<div>
<h4>Transaction Sequence Number</h4>
Expand All @@ -86,8 +96,21 @@ const SequenceNumberInput: FC<Props> = ({ firebaseID }) => {
placeholder="Ex: 559234806710273"
value={tx.tx.seq_num?.toString() || ""}
onChange={(e) => {
const value = e.target.value;
setSeqNum(value ? BigInt(value) : BigInt(0));
const value = e.target.value.trim();
if (/^[0-9]*$/.test(value)) {
const newSeqNum = value ? BigInt(value) : BigInt(0);
setSeqNum(newSeqNum);

if (
initialSeqNum !== null &&
newSeqNum !== initialSeqNum &&
isSequenceNumberOutdated(newSeqNum, tx.tx.seq_num)
) {
setIsShowUpdateSeqNum(true);
} else {
setIsShowUpdateSeqNum(false);
}
}
}}
/>
{tx.tx.source_account && (
Expand All @@ -103,6 +126,11 @@ const SequenceNumberInput: FC<Props> = ({ firebaseID }) => {
The transaction sequence number is usually one higher than current
account sequence number.
</p>
{isShowUpdateSeqNum && (
<p className="warning">
The sequence number is outdated. Please update it.
</p>
)}
{error && <p className="error">{error}</p>}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const SourceAccountInput: FC = () => {
<div>
<div className="flex items-center ">
<h4>Source Account</h4>
<h5 className="ml-4">(optional)</h5>

</div>
<input
placeholder="Example: GCEXAMPLE..."
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/OperationTypes/ManageData/ui/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const ManageData: FC<Props> = ({ id }) => {
StellarSdk.StrKey.isValidEd25519PublicKey(value) || value === ""
}
errorMessage="Public key is invalid."
isOptional={false}
isOptional={true}
/>
</div>
</>
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/OperationTypes/SetOptions/ui/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ const SetOptions: FC<Props> = ({ id }) => {
StellarSdk.StrKey.isValidEd25519PublicKey(value) || value === ""
}
errorMessage="Public key is invalid."
isOptional={false}
isOptional={true}
/>
</div>
</>
Expand Down

0 comments on commit e663bc0

Please sign in to comment.