From 9ce830eb6d5ab1004a22b6bc36dbd6eed2de0a89 Mon Sep 17 00:00:00 2001 From: Davide Grilli Date: Mon, 9 Mar 2026 14:24:04 +0100 Subject: [PATCH] refactor: replace fetch() calls with window.electronAPI in React components - HDWallet, SingleAddress, DecryptWallet now call window.electronAPI.* - Remove Vite proxy (no more HTTP backend) --- frontend/src/components/DecryptWallet.jsx | 10 +----- frontend/src/components/HDWallet.jsx | 39 ++++++----------------- frontend/src/components/SingleAddress.jsx | 17 +++------- frontend/vite.config.js | 6 ---- 4 files changed, 15 insertions(+), 57 deletions(-) diff --git a/frontend/src/components/DecryptWallet.jsx b/frontend/src/components/DecryptWallet.jsx index a53eec1..a96d9db 100644 --- a/frontend/src/components/DecryptWallet.jsx +++ b/frontend/src/components/DecryptWallet.jsx @@ -1,8 +1,6 @@ import { useState, useRef } from 'react' import CopyButton from './CopyButton' -const API = '' - export default function DecryptWallet() { const [password, setPassword] = useState('') const [wallet, setWallet] = useState(null) @@ -37,13 +35,7 @@ export default function DecryptWallet() { setError(null) setResult(null) try { - const res = await fetch(`${API}/api/hd/decrypt`, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ wallet, password }), - }) - if (!res.ok) throw new Error((await res.json()).detail) - setResult(await res.json()) + setResult(await window.electronAPI.hdDecrypt({ wallet, password })) setSeedVisible(false) } catch (e) { setError(e.message) diff --git a/frontend/src/components/HDWallet.jsx b/frontend/src/components/HDWallet.jsx index 1e04a5a..1865959 100644 --- a/frontend/src/components/HDWallet.jsx +++ b/frontend/src/components/HDWallet.jsx @@ -1,8 +1,6 @@ import { useState } from 'react' import CopyButton from './CopyButton' -const API = '' - export default function HDWallet() { const [form, setForm] = useState({ network: 'mainnet', @@ -28,23 +26,15 @@ export default function HDWallet() { setWallet(null) setSeedVisible(false) try { - const res = await fetch(`${API}/api/hd/generate`, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ - network: form.network, - bip_type: form.bip_type, - mnemonic: form.mnemonic.trim() || null, - passphrase: form.passphrase, - account: parseInt(form.account) || 0, - num_addresses: parseInt(form.num_addresses) || 5, - }), + const data = await window.electronAPI.hdGenerate({ + network: form.network, + bip_type: form.bip_type, + mnemonic: form.mnemonic.trim() || null, + passphrase: form.passphrase, + account: parseInt(form.account) || 0, + num_addresses: parseInt(form.num_addresses) || 5, }) - if (!res.ok) { - const e = await res.json() - throw new Error(e.detail || 'API error') - } - setWallet(await res.json()) + setWallet(data) } catch (e) { setError(e.message) } finally { @@ -59,13 +49,7 @@ export default function HDWallet() { try { let data = wallet if (savePassword.trim()) { - const res = await fetch(`${API}/api/hd/encrypt`, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ wallet, password: savePassword }), - }) - if (!res.ok) throw new Error((await res.json()).detail) - data = await res.json() + data = await window.electronAPI.hdEncrypt({ wallet, password: savePassword }) } const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' }) const url = URL.createObjectURL(blob) @@ -89,7 +73,6 @@ export default function HDWallet() {
HD Wallet
BIP-32/39 · Hierarchical deterministic wallet
- {/* ── Configuration ── */}
Configuration
@@ -141,7 +124,6 @@ export default function HDWallet() { {wallet && ( <> - {/* ── Seed phrase ── */}
Seed Phrase @@ -161,7 +143,6 @@ export default function HDWallet() {
- {/* ── Keystore ── */}
Keystore
{[ @@ -178,7 +159,6 @@ export default function HDWallet() { ))}
- {/* ── Addresses ── */}
Receiving Addresses
@@ -212,7 +192,6 @@ export default function HDWallet() {
- {/* ── Save ── */}
Save Wallet
diff --git a/frontend/src/components/SingleAddress.jsx b/frontend/src/components/SingleAddress.jsx index 9d393f6..8e61618 100644 --- a/frontend/src/components/SingleAddress.jsx +++ b/frontend/src/components/SingleAddress.jsx @@ -1,8 +1,6 @@ import { useState } from 'react' import CopyButton from './CopyButton' -const API = '' - const TABS = [ { id: 'p2pkh', label: 'P2PKH', desc: 'Legacy · starts with 1 / m' }, { id: 'p2wpkh', label: 'P2WPKH', desc: 'Native SegWit · bc1q / tb1q' }, @@ -26,17 +24,12 @@ export default function SingleAddress({ initialTab = 'p2pkh' }) { setError(null) setResult(null) try { - let body = { network } - if (tab === 'p2sh') body = { ...body, m, n, compressed } - else if (tab !== 'p2tr') body = { ...body, compressed } + let args = { network } + if (tab === 'p2sh') args = { ...args, m, n, compressed } + else if (tab !== 'p2tr') args = { ...args, compressed } - const res = await fetch(`${API}/api/${tab}`, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(body), - }) - if (!res.ok) throw new Error((await res.json()).detail) - setResult(await res.json()) + const fn = window.electronAPI[tab === 'p2pkh' ? 'p2pkh' : tab === 'p2wpkh' ? 'p2wpkh' : tab === 'p2tr' ? 'p2tr' : tab === 'p2pk' ? 'p2pk' : 'p2sh'] + setResult(await fn(args)) } catch (e) { setError(e.message) } finally { diff --git a/frontend/vite.config.js b/frontend/vite.config.js index 1406734..abccf69 100644 --- a/frontend/vite.config.js +++ b/frontend/vite.config.js @@ -5,11 +5,5 @@ export default defineConfig({ plugins: [react()], server: { port: 5173, - proxy: { - '/api': { - target: 'http://localhost:8000', - changeOrigin: true, - }, - }, }, })