Skip to content

Commit 607a244

Browse files
authored
Merge pull request #10 from openSVM/copilot/fix-9
Resolve technical debt: Dark mode, transaction logic, CI robustness, and component architecture
2 parents 3d83f49 + 91ed7d3 commit 607a244

File tree

21 files changed

+14323
-105
lines changed

21 files changed

+14323
-105
lines changed

.github/workflows/ci.yml

Lines changed: 119 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,35 @@ jobs:
5959
sudo apt-get update
6060
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libayatana-appindicator3-dev librsvg2-dev patchelf pkg-config libssl-dev libsoup-3.0-dev
6161
62-
- name: Install wasm-bindgen-cli
62+
- name: Install wasm-bindgen-cli and wasm-opt
6363
if: ${{ matrix.platform == 'web' }}
64-
run: cargo install wasm-bindgen-cli
64+
run: |
65+
cargo install wasm-bindgen-cli
66+
# Install wasm-opt via binaryen
67+
curl -L https://github.com/WebAssembly/binaryen/releases/download/version_117/binaryen-version_117-x86_64-linux.tar.gz | tar xz
68+
sudo cp binaryen-version_117/bin/wasm-opt /usr/local/bin/
69+
wasm-opt --version
6570
6671
- name: Build for Web
6772
if: ${{ matrix.platform == 'web' }}
6873
run: |
6974
cd opensvm-dioxus
7075
cargo build --target wasm32-unknown-unknown --features web --release --no-default-features
76+
77+
# Optimize WASM binary with wasm-opt
78+
echo "Original WASM size:"
79+
ls -lh target/wasm32-unknown-unknown/release/opensvm_dioxus.wasm
80+
81+
wasm-opt -Oz --enable-mutable-globals \
82+
target/wasm32-unknown-unknown/release/opensvm_dioxus.wasm \
83+
-o target/wasm32-unknown-unknown/release/opensvm_dioxus_opt.wasm
84+
85+
# Replace original with optimized version
86+
mv target/wasm32-unknown-unknown/release/opensvm_dioxus_opt.wasm \
87+
target/wasm32-unknown-unknown/release/opensvm_dioxus.wasm
88+
89+
echo "Optimized WASM size:"
90+
ls -lh target/wasm32-unknown-unknown/release/opensvm_dioxus.wasm
7191
7292
- name: Build for Desktop (macOS)
7393
if: ${{ matrix.platform == 'desktop' && matrix.os == 'macos-latest' }}
@@ -187,12 +207,84 @@ jobs:
187207
VERSION=${GITHUB_REF#refs/tags/v}
188208
DOWNLOAD_URL="https://github.com/${{ github.repository }}/releases/download/v${VERSION}/opensvm-dioxus-macos.zip"
189209
190-
# Wait for release to be available
191-
sleep 30
210+
# Function to retry downloading with exponential backoff
211+
download_with_retry() {
212+
local url="$1"
213+
local output="$2"
214+
local max_attempts=5
215+
local attempt=1
216+
local delay=10
217+
218+
while [ $attempt -le $max_attempts ]; do
219+
echo "Attempt $attempt/$max_attempts: Downloading $url"
220+
221+
if curl -L --fail --retry 3 --retry-delay 5 -o "$output" "$url"; then
222+
echo "Download successful on attempt $attempt"
223+
return 0
224+
fi
225+
226+
echo "Download failed on attempt $attempt"
227+
228+
if [ $attempt -eq $max_attempts ]; then
229+
echo "All download attempts failed"
230+
return 1
231+
fi
232+
233+
echo "Waiting ${delay} seconds before next attempt..."
234+
sleep $delay
235+
delay=$((delay * 2)) # Exponential backoff
236+
attempt=$((attempt + 1))
237+
done
238+
}
239+
240+
# Wait for release to be available with health check
241+
echo "Checking if release is available..."
242+
HEALTH_CHECK_URL="https://api.github.com/repos/${{ github.repository }}/releases/tags/v${VERSION}"
243+
max_wait_attempts=12 # 12 * 10 seconds = 2 minutes max wait
244+
wait_attempt=1
245+
246+
while [ $wait_attempt -le $max_wait_attempts ]; do
247+
echo "Health check attempt $wait_attempt/$max_wait_attempts"
248+
249+
if curl -s --fail "$HEALTH_CHECK_URL" > /dev/null; then
250+
echo "Release found in GitHub API"
251+
break
252+
fi
253+
254+
if [ $wait_attempt -eq $max_wait_attempts ]; then
255+
echo "Release not found after waiting, proceeding anyway..."
256+
break
257+
fi
258+
259+
echo "Release not yet available, waiting 10 seconds..."
260+
sleep 10
261+
wait_attempt=$((wait_attempt + 1))
262+
done
263+
264+
# Download the release asset with retry logic
265+
if ! download_with_retry "$DOWNLOAD_URL" "opensvm-dioxus-macos.zip"; then
266+
echo "Failed to download release asset after all retries"
267+
echo "URL: $DOWNLOAD_URL"
268+
echo "Checking available assets..."
269+
curl -s "https://api.github.com/repos/${{ github.repository }}/releases/tags/v${VERSION}" | jq '.assets[].name' || true
270+
exit 1
271+
fi
272+
273+
# Verify the downloaded file
274+
if [ ! -f "opensvm-dioxus-macos.zip" ] || [ ! -s "opensvm-dioxus-macos.zip" ]; then
275+
echo "Downloaded file is missing or empty"
276+
exit 1
277+
fi
192278
193-
# Calculate SHA256 of the released asset
194-
curl -L -o opensvm-dioxus-macos.zip "$DOWNLOAD_URL" || exit 1
279+
# Calculate SHA256 of the downloaded asset
195280
SHA256=$(shasum -a 256 opensvm-dioxus-macos.zip | awk '{print $1}')
281+
echo "Calculated SHA256: $SHA256"
282+
283+
# Validate SHA256 format
284+
if ! echo "$SHA256" | grep -q '^[a-f0-9]\{64\}$'; then
285+
echo "Invalid SHA256 format: $SHA256"
286+
exit 1
287+
fi
196288
197289
# Create formula directory if it doesn't exist
198290
mkdir -p Formula
@@ -213,16 +305,33 @@ jobs:
213305
end
214306
EOF
215307
308+
# Validate the generated formula syntax
309+
if ! ruby -c Formula/opensvm-dioxus.rb; then
310+
echo "Generated formula has syntax errors"
311+
exit 1
312+
fi
313+
314+
echo "Generated formula:"
315+
cat Formula/opensvm-dioxus.rb
316+
216317
# Create a new branch for the formula update
217318
git checkout -b update-homebrew-formula-v$VERSION
218319
219-
# Commit and push changes
320+
# Commit and push changes with error handling
220321
git add Formula/opensvm-dioxus.rb
221322
git commit -m "Update Homebrew formula to v$VERSION"
222-
git push origin update-homebrew-formula-v$VERSION
323+
324+
if ! git push origin update-homebrew-formula-v$VERSION; then
325+
echo "Failed to push branch, may already exist"
326+
git push --force origin update-homebrew-formula-v$VERSION
327+
fi
223328
224-
# Create pull request using GitHub CLI
225-
gh pr create --title "Update Homebrew formula to v$VERSION" --body "Updates the Homebrew formula for opensvm-dioxus to version $VERSION" --base main --head update-homebrew-formula-v$VERSION
329+
# Create pull request using GitHub CLI with error handling
330+
if ! gh pr create --title "Update Homebrew formula to v$VERSION" --body "Updates the Homebrew formula for opensvm-dioxus to version $VERSION" --base main --head update-homebrew-formula-v$VERSION; then
331+
echo "Failed to create PR, it may already exist"
332+
echo "Checking existing PRs..."
333+
gh pr list --head update-homebrew-formula-v$VERSION || true
334+
fi
226335
env:
227336
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
228337

opensvm-dioxus/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ web-sys = { version = "0.3.64", features = [
3333
"Clipboard",
3434
"ClipboardEvent",
3535
"Location",
36+
"MediaQueryList",
37+
"Request",
38+
"RequestInit",
39+
"RequestMode",
40+
"Response",
41+
"Headers",
3642
], optional = true }
3743
gloo = { version = "0.10.0", optional = true, features = ["futures"] }
3844
console_log = { version = "1.0.0", optional = true }

opensvm-dioxus/desktop_config.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"window": {
3+
"title": "OpenSVM Explorer",
4+
"width": 1200.0,
5+
"height": 800.0,
6+
"resizable": true,
7+
"maximized": false,
8+
"min_width": 800.0,
9+
"min_height": 600.0
10+
},
11+
"menu": {
12+
"enabled": true,
13+
"show_file_menu": true,
14+
"show_edit_menu": false,
15+
"show_view_menu": true,
16+
"show_help_menu": true,
17+
"custom_items": [
18+
{
19+
"label": "Explorer",
20+
"action": "navigate_explorer",
21+
"shortcut": "Ctrl+E",
22+
"enabled": true
23+
},
24+
{
25+
"label": "Transactions",
26+
"action": "navigate_transactions",
27+
"shortcut": "Ctrl+T",
28+
"enabled": true
29+
},
30+
{
31+
"label": "Validators",
32+
"action": "navigate_validators",
33+
"shortcut": "Ctrl+V",
34+
"enabled": true
35+
}
36+
]
37+
},
38+
"features": {
39+
"auto_updater": false,
40+
"system_tray": false,
41+
"notifications": true,
42+
"file_associations": false
43+
}
44+
}

opensvm-dioxus/src/app.rs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ use crate::routes::{
66
solanow::SolanowPage, transaction::TransactionPage, validators::ValidatorsPage,
77
wallet::WalletPage,
88
};
9+
use crate::stores::theme_store::{use_theme_store, get_current_theme, Theme};
10+
11+
#[cfg(feature = "web")]
12+
use web_sys::{window, MediaQueryList};
913

1014
// Define the routes for our app
1115
#[derive(Routable, Clone)]
@@ -63,8 +67,12 @@ fn AI(cx: Scope) -> Element {
6367
}
6468

6569
#[component]
66-
fn Transaction(cx: Scope, #[allow(unused_variables)] id: String) -> Element {
67-
cx.render(rsx! { TransactionPage {} })
70+
fn Transaction(cx: Scope, id: String) -> Element {
71+
cx.render(rsx! {
72+
TransactionPage {
73+
transaction_id: id.clone()
74+
}
75+
})
6876
}
6977

7078
#[component]
@@ -83,6 +91,37 @@ fn NotFound(cx: Scope, #[allow(unused_variables)] route: Vec<String>) -> Element
8391

8492
// Main App component
8593
pub fn App(cx: Scope) -> Element {
94+
let theme_store = use_theme_store(cx);
95+
let current_theme = get_current_theme(theme_store);
96+
97+
// Apply theme to document body
98+
use_effect(cx, (&current_theme,), |(theme,)| {
99+
async move {
100+
#[cfg(feature = "web")]
101+
{
102+
if let Some(window) = web_sys::window() {
103+
if let Some(document) = window.document() {
104+
if let Some(body) = document.body() {
105+
let theme_str = match theme {
106+
Theme::Light => "light",
107+
Theme::Dark => "dark",
108+
Theme::System => {
109+
// Use media query to determine system theme
110+
if let Ok(Some(media_query)) = window.match_media("(prefers-color-scheme: dark)") {
111+
if media_query.matches() { "dark" } else { "light" }
112+
} else {
113+
"light"
114+
}
115+
}
116+
};
117+
let _ = body.set_attribute("data-theme", theme_str);
118+
}
119+
}
120+
}
121+
}
122+
}
123+
});
124+
86125
cx.render(rsx! {
87126
style { include_str!("./assets/styles.css") }
88127
Router::<Route> {}

0 commit comments

Comments
 (0)