mirror of
https://github.com/aljazceru/mutiny-web.git
synced 2025-12-29 03:44:20 +01:00
don't allow network switching in settings
This commit is contained in:
@@ -2,6 +2,8 @@ import { createSignal } from "solid-js";
|
||||
import { ConfirmDialog } from "~/components/Dialog";
|
||||
import { Button } from "~/components/layout";
|
||||
import { showToast } from "~/components/Toaster";
|
||||
import { useMegaStore } from "~/state/megaStore";
|
||||
import eify from "~/utils/eify";
|
||||
|
||||
export function deleteDb(name: string) {
|
||||
const req = indexedDB.deleteDatabase(name);
|
||||
@@ -20,17 +22,28 @@ export function deleteDb(name: string) {
|
||||
}
|
||||
|
||||
export function DeleteEverything() {
|
||||
const [_store, actions] = useMegaStore();
|
||||
|
||||
async function resetNode() {
|
||||
setConfirmLoading(true);
|
||||
deleteDb("gossip")
|
||||
deleteDb("wallet")
|
||||
localStorage.clear();
|
||||
showToast({ title: "Deleted", description: `Deleted all data` })
|
||||
setConfirmOpen(false);
|
||||
setConfirmLoading(false);
|
||||
setTimeout(() => {
|
||||
window.location.href = "/";
|
||||
}, 3000);
|
||||
try {
|
||||
setConfirmLoading(true);
|
||||
deleteDb("gossip")
|
||||
deleteDb("wallet")
|
||||
localStorage.clear();
|
||||
|
||||
showToast({ title: "Deleted", description: `Deleted all data` })
|
||||
|
||||
setTimeout(() => {
|
||||
window.location.href = "/";
|
||||
}, 3000);
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
showToast(eify(e))
|
||||
} finally {
|
||||
setConfirmOpen(false);
|
||||
setConfirmLoading(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async function confirmReset() {
|
||||
|
||||
@@ -1,36 +1,22 @@
|
||||
import { createForm, url } from '@modular-forms/solid';
|
||||
import { TextField } from '~/components/layout/TextField';
|
||||
import { MutinyWalletSettingStrings, getExistingSettings } from '~/logic/mutinyWalletSetup';
|
||||
import { Button } from '~/components/layout';
|
||||
import { createSignal } from 'solid-js';
|
||||
import { deleteDb } from '~/components/DeleteEverything';
|
||||
import { Button, SmallHeader } from '~/components/layout';
|
||||
import { showToast } from './Toaster';
|
||||
import eify from '~/utils/eify';
|
||||
import { ConfirmDialog } from "~/components/Dialog";
|
||||
import { useMegaStore } from '~/state/megaStore';
|
||||
|
||||
export function SettingsStringsEditor() {
|
||||
const existingSettings = getExistingSettings();
|
||||
const [_settingsForm, { Form, Field }] = createForm<MutinyWalletSettingStrings>({ initialValues: existingSettings });
|
||||
const [confirmOpen, setConfirmOpen] = createSignal(false);
|
||||
|
||||
const [settingsTemp, setSettingsTemp] = createSignal<MutinyWalletSettingStrings>();
|
||||
|
||||
const [_store, actions] = useMegaStore();
|
||||
|
||||
async function handleSubmit(values: MutinyWalletSettingStrings) {
|
||||
try {
|
||||
const existing = getExistingSettings();
|
||||
const newSettings = { ...existing, ...values }
|
||||
if (existing.network !== values.network) {
|
||||
// If the network changes we need to confirm the wipe
|
||||
// Save the settings so we can get them later
|
||||
setSettingsTemp(newSettings);
|
||||
setConfirmOpen(true);
|
||||
} else {
|
||||
await actions.setupMutinyWallet(newSettings);
|
||||
window.location.reload();
|
||||
}
|
||||
await actions.setupMutinyWallet(newSettings);
|
||||
window.location.reload();
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
showToast(eify(e))
|
||||
@@ -38,42 +24,15 @@ export function SettingsStringsEditor() {
|
||||
console.log(values)
|
||||
}
|
||||
|
||||
async function confirmStateReset() {
|
||||
try {
|
||||
deleteDb("gossip")
|
||||
localStorage.clear();
|
||||
showToast({ title: "Deleted", description: `Deleted all data` })
|
||||
const loadedValues = settingsTemp();
|
||||
|
||||
await actions.setupMutinyWallet(loadedValues);
|
||||
window.location.reload();
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
showToast(eify(e))
|
||||
}
|
||||
|
||||
setConfirmOpen(false);
|
||||
}
|
||||
|
||||
return <Form onSubmit={handleSubmit} class="flex flex-col gap-4">
|
||||
<ConfirmDialog loading={false} isOpen={confirmOpen()} onConfirm={confirmStateReset} onCancel={() => setConfirmOpen(false)}>
|
||||
Are you sure? Changing networks will delete your node's state. This can't be undone!
|
||||
</ConfirmDialog>
|
||||
<h2 class="text-2xl font-light">Don't trust us! Use your own servers to back Mutiny.</h2>
|
||||
<Field name="network">
|
||||
{(field, props) => (
|
||||
// TODO: make a cool select component
|
||||
<div class="flex flex-col gap-2">
|
||||
<label class="text-sm font-semibold uppercase">Network</label>
|
||||
<select {...field} {...props} class="bg-black rounded-xl border border-white px-4 py-2">
|
||||
<option value="bitcoin">Mainnet</option>
|
||||
<option value="testnet">Testnet</option>
|
||||
<option value="regtest">Regtest</option>
|
||||
<option value="signet">Signet</option>
|
||||
</select>
|
||||
</div>
|
||||
)}
|
||||
</Field>
|
||||
<div class="flex flex-col gap-2">
|
||||
<SmallHeader>Network</SmallHeader>
|
||||
<pre>
|
||||
{existingSettings.network}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<Field name="proxy" validate={[url("Should be a url starting with wss://")]}>
|
||||
{(field, props) => (
|
||||
<TextField {...props} value={field.value} error={field.error} label="Websockets Proxy" />
|
||||
|
||||
Reference in New Issue
Block a user