fix: build

This commit is contained in:
2024-12-29 19:25:14 +00:00
parent f4227fa121
commit e9d88279cf
7 changed files with 41 additions and 71 deletions

View File

@ -1,7 +1,6 @@
import { useEffect, useMemo, useState } from "react";
import { LNVpsApi, UserSshKey } from "../api";
import { useEffect, useState } from "react";
import { UserSshKey } from "../api";
import useLogin from "../hooks/login";
import { ApiUrl } from "../const";
import { AsyncButton } from "./button";
export default function SSHKeySelector({
@ -18,23 +17,17 @@ export default function SSHKeySelector({
const [showAddKey, setShowAddKey] = useState(false);
const [sshKeys, setSshKeys] = useState<Array<UserSshKey>>([]);
const api = useMemo(() => {
if (!login?.builder) return;
const api = new LNVpsApi(ApiUrl, login.builder);
return api;
}, [login]);
async function addNewKey() {
if (!api) return;
if (!login?.api) return;
setNewKeyError("");
try {
const nk = await api.addSshKey(newKeyName, newKey);
const nk = await login?.api.addSshKey(newKeyName, newKey);
setNewKey("");
setNewKeyName("");
setSelectedKey(nk.id);
setShowAddKey(false);
api.listSshKeys().then((a) => setSshKeys(a));
login?.api.listSshKeys().then((a) => setSshKeys(a));
} catch (e) {
if (e instanceof Error) {
setNewKeyError(e.message);
@ -43,8 +36,8 @@ export default function SSHKeySelector({
}
useEffect(() => {
if (!api) return;
api.listSshKeys().then((a) => {
if (!login?.api) return;
login?.api.listSshKeys().then((a) => {
setSshKeys(a);
if (a.length > 0) {
setSelectedKey(a[0].id);

View File

@ -1,6 +1,4 @@
import { EventPublisher } from "@snort/system";
import { LNVpsApi, VmInstance } from "../api";
import { ApiUrl } from "../const";
import { VmInstance } from "../api";
import useLogin from "../hooks/login";
import { Icon } from "./icon";
import { AsyncButton } from "./button";
@ -14,12 +12,8 @@ export default function VmActions({
}) {
const login = useLogin();
const state = vm.status?.state;
if (!state) return;
if (!login?.api) return;
const api = new LNVpsApi(
ApiUrl,
login?.signer ? new EventPublisher(login.signer, login.pubkey) : undefined,
);
return (
<div className="flex flex-col gap-1">
<div className="flex gap-2">
@ -28,9 +22,9 @@ export default function VmActions({
e.stopPropagation();
if (state === "running") {
await api.stopVm(vm.id);
await login?.api.stopVm(vm.id);
} else {
await api.startVm(vm.id);
await login?.api.startVm(vm.id);
}
onReload?.();
}}

View File

@ -2,8 +2,6 @@ import { useEffect } from "react";
import { LNVpsApi, VmPayment } from "../api";
import QrCode from "./qr";
import useLogin from "../hooks/login";
import { ApiUrl } from "../const";
import { EventPublisher } from "@snort/system";
export default function VpsPayment({
payment,
@ -29,13 +27,10 @@ export default function VpsPayment({
}
useEffect(() => {
if (!login?.signer) return;
const api = new LNVpsApi(
ApiUrl,
new EventPublisher(login.signer, login.pubkey),
);
if (!login?.api) return;
const tx = setInterval(async () => {
if (await checkPayment(api)) {
if (await checkPayment(login.api)) {
clearInterval(tx);
}
}, 2_000);