Skip to content

Commit

Permalink
fix: cairo version mechanics
Browse files Browse the repository at this point in the history
  • Loading branch information
varex83 committed Dec 16, 2024
1 parent 431907d commit 6c34f76
Show file tree
Hide file tree
Showing 12 changed files with 759 additions and 232 deletions.
604 changes: 601 additions & 3 deletions api/Cargo.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ crossbeam-skiplist = "0.1.1"
fmt = "0.1.0"
thiserror = "1.0.50"
chrono = "0.4.31"
prometheus = "0.13.4"
prometheus = "0.13.4"
reqwest = { version = "0.11", features = ["json"] }
lazy_static = "1.4.0"
tokio = { version = "1.0", features = ["full"] }
1 change: 1 addition & 0 deletions api/src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod scarb_test;
pub mod scarb_version;
pub mod types;
pub mod utils;
pub mod allowed_versions;

use tracing::info;
use tracing::instrument;
Expand Down
4 changes: 3 additions & 1 deletion api/src/handlers/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ pub struct CompilationRequest {

impl CompilationRequest {
pub fn has_scarb_toml(&self) -> bool {
self.files.iter().any(|f| &f.file_name == "Scarb.toml")
self.files
.iter()
.any(|f| f.file_name.ends_with("Scarb.toml"))
}

pub fn file_names(&self) -> Vec<String> {
Expand Down
5 changes: 5 additions & 0 deletions api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use handlers::process::get_process_status;
use handlers::scarb_test::{get_scarb_test_result, scarb_test_async};
use handlers::scarb_version::{get_scarb_version_result, scarb_version_async};
use handlers::utils::on_plugin_launched;
use handlers::allowed_versions::{get_allowed_versions, start_version_updater};
use handlers::{health, who_is_this};
use prometheus::Registry;
use rocket::{Build, Config, Rocket};
Expand Down Expand Up @@ -86,6 +87,7 @@ fn create_app(metrics: Metrics) -> Rocket<Build> {
get_scarb_test_result,
scarb_test_async,
on_plugin_launched,
get_allowed_versions,
],
)
}
Expand All @@ -94,6 +96,9 @@ fn create_app(metrics: Metrics) -> Rocket<Build> {
async fn main() -> anyhow::Result<()> {
init_logger().context("Failed to initialize logger")?;

// Start the version updater
start_version_updater().await;

let registry = Registry::new();
let metrics = initialize_metrics(registry.clone()).context("Failed to initialize metrics")?;

Expand Down
2 changes: 1 addition & 1 deletion plugin/src/atoms/cairoVersion.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { atom } from "jotai";

const cairoVersionAtom = atom<string>("v2.8.4");
const cairoVersionAtom = atom<string | null>(null);

const versionsAtom = atom<string[]>([]);

Expand Down
5 changes: 3 additions & 2 deletions plugin/src/atoms/compilation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import { atom } from "jotai";
enum CompilationStatus {
Compiling = "Compiling...",
Success = "Success",
Error = "Error"
Error = "Error",
Idle = "Idle"
}

const statusAtom = atom<string>(CompilationStatus.Compiling);
const statusAtom = atom<string>(CompilationStatus.Idle);

const currentFilenameAtom = atom<string>("");

Expand Down
25 changes: 25 additions & 0 deletions plugin/src/components/LoadingDots/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React, { useEffect, useState } from "react";

const LoadingDots: React.FC<{ message: string }> = ({ message }) => {
const [dots, setDots] = useState("");

useEffect(() => {
const interval = setInterval(() => {
setDots((prev) => {
return prev.length >= 3 ? "" : prev + ".";
});
}, 500);

return () => {
clearInterval(interval);
};
}, []);

return (
<span className="loading-text">
{message}{dots}
</span>
);
};

export default LoadingDots;
55 changes: 32 additions & 23 deletions plugin/src/components/Settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useAtom, useAtomValue } from "jotai";
import { cairoVersionAtom, versionsAtom } from "../../atoms/cairoVersion";
import ExplorerSelector, { useCurrentExplorer } from "../ExplorerSelector";
import * as Select from "../ui_components/Select";
import LoadingDots from "../LoadingDots";

export const Settings: React.FC = () => {
const [cairoVersion, setCairoVersion] = useAtom(cairoVersionAtom);
Expand All @@ -18,29 +19,37 @@ export const Settings: React.FC = () => {
<div className={"settings-box-header"}>Cairo Version</div>
<div className={"blank"}></div>
<div className={"settings-box-content"}>
<Select.Root value={cairoVersion} onValueChange={setCairoVersion}>
<Select.Trigger className="flex flex-row justify-between align-items-center devnet-trigger-wrapper w-100">
<Select.Value>
<div className="flex flex-column align-items-center m-0">
<p>{cairoVersion}</p>
</div>
</Select.Value>
<Select.Icon>
<BsChevronDown />
</Select.Icon>
</Select.Trigger>
<Select.Portal>
<Select.Content>
<Select.Viewport>
{getVersions.map((v, i) => (
<Select.Item value={v} key={v}>
<Select.ItemText>{v}</Select.ItemText>
</Select.Item>
))}
</Select.Viewport>
</Select.Content>
</Select.Portal>
</Select.Root>
{cairoVersion !== null
? (
<Select.Root value={cairoVersion} onValueChange={setCairoVersion}>
<Select.Trigger className="flex flex-row justify-between align-items-center devnet-trigger-wrapper w-100">
<Select.Value>
<div className="flex flex-column align-items-center m-0">
<p>{cairoVersion}</p>
</div>
</Select.Value>
<Select.Icon>
<BsChevronDown />
</Select.Icon>
</Select.Trigger>
<Select.Portal>
<Select.Content>
<Select.Viewport>
{getVersions.map((v, i) => (
<Select.Item value={v} key={v}>
<Select.ItemText>{v}</Select.ItemText>
</Select.Item>
))}
</Select.Viewport>
</Select.Content>
</Select.Portal>
</Select.Root>
)
: (
<div>
<LoadingDots message="Loading" />
</div>
)}
</div>
</div>

Expand Down
Loading

0 comments on commit 6c34f76

Please sign in to comment.