refactor: replace fetch() calls with window.electronAPI in React components

- HDWallet, SingleAddress, DecryptWallet now call window.electronAPI.*
- Remove Vite proxy (no more HTTP backend)
This commit is contained in:
2026-03-09 14:24:04 +01:00
parent 944b30126d
commit 9ce830eb6d
4 changed files with 15 additions and 57 deletions

View File

@@ -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)

View File

@@ -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({
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() {
<div className="page-title">HD Wallet</div>
<div className="page-subtitle">BIP-32/39 · Hierarchical deterministic wallet</div>
{/* ── Configuration ── */}
<div className="card">
<div className="card-title">Configuration</div>
<div className="form-grid">
@@ -141,7 +124,6 @@ export default function HDWallet() {
{wallet && (
<>
{/* ── Seed phrase ── */}
<div className="card">
<div className="card-title" style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<span>Seed Phrase</span>
@@ -161,7 +143,6 @@ export default function HDWallet() {
</div>
</div>
{/* ── Keystore ── */}
<div className="card">
<div className="card-title">Keystore</div>
{[
@@ -178,7 +159,6 @@ export default function HDWallet() {
))}
</div>
{/* ── Addresses ── */}
<div className="card">
<div className="card-title">Receiving Addresses</div>
<table className="addr-table">
@@ -212,7 +192,6 @@ export default function HDWallet() {
</table>
</div>
{/* ── Save ── */}
<div className="card">
<div className="card-title">Save Wallet</div>
<div className="form-grid" style={{ marginBottom: 12 }}>

View File

@@ -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 {

View File

@@ -5,11 +5,5 @@ export default defineConfig({
plugins: [react()],
server: {
port: 5173,
proxy: {
'/api': {
target: 'http://localhost:8000',
changeOrigin: true,
},
},
},
})