mirror of
https://github.com/aljazceru/mutiny-web.git
synced 2025-12-19 15:24:25 +01:00
Fix for mutiny_wallet, handle new storage
This commit is contained in:
@@ -141,19 +141,19 @@ export function Activity() {
|
|||||||
|
|
||||||
const getTransactions = async () => {
|
const getTransactions = async () => {
|
||||||
console.log("Getting onchain txs");
|
console.log("Getting onchain txs");
|
||||||
const txs = await state.mutiny_manager?.list_onchain() as OnChainTx[];
|
const txs = await state.mutiny_wallet?.list_onchain() as OnChainTx[];
|
||||||
return txs.reverse();
|
return txs.reverse();
|
||||||
}
|
}
|
||||||
|
|
||||||
const getInvoices = async () => {
|
const getInvoices = async () => {
|
||||||
console.log("Getting invoices");
|
console.log("Getting invoices");
|
||||||
const invoices = await state.mutiny_manager?.list_invoices() as MutinyInvoice[];
|
const invoices = await state.mutiny_wallet?.list_invoices() as MutinyInvoice[];
|
||||||
return invoices.filter((inv) => inv.paid).reverse();
|
return invoices.filter((inv) => inv.paid).reverse();
|
||||||
}
|
}
|
||||||
|
|
||||||
const getUtXos = async () => {
|
const getUtXos = async () => {
|
||||||
console.log("Getting utxos");
|
console.log("Getting utxos");
|
||||||
const utxos = await state.mutiny_manager?.list_utxos() as UtxoItem[];
|
const utxos = await state.mutiny_wallet?.list_utxos() as UtxoItem[];
|
||||||
return utxos;
|
return utxos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import logo from '~/assets/icons/mutiny-logo.svg';
|
import logo from '~/assets/icons/mutiny-logo.svg';
|
||||||
import { DefaultMain, MutinyManagerGuard, SafeArea } from "~/components/layout";
|
import { DefaultMain, MutinyWalletGuard, SafeArea } from "~/components/layout";
|
||||||
import BalanceBox from "~/components/BalanceBox";
|
import BalanceBox from "~/components/BalanceBox";
|
||||||
import NavBar from "~/components/NavBar";
|
import NavBar from "~/components/NavBar";
|
||||||
import ReloadPrompt from "~/components/Reload";
|
import ReloadPrompt from "~/components/Reload";
|
||||||
@@ -9,7 +9,7 @@ import settings from '~/assets/icons/settings.svg';
|
|||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
return (
|
return (
|
||||||
<MutinyManagerGuard>
|
<MutinyWalletGuard>
|
||||||
<SafeArea>
|
<SafeArea>
|
||||||
<DefaultMain>
|
<DefaultMain>
|
||||||
<header class="w-full flex justify-between items-center mt-4 mb-2">
|
<header class="w-full flex justify-between items-center mt-4 mb-2">
|
||||||
@@ -22,6 +22,6 @@ export default function App() {
|
|||||||
</DefaultMain>
|
</DefaultMain>
|
||||||
<NavBar activeTab="home" />
|
<NavBar activeTab="home" />
|
||||||
</SafeArea>
|
</SafeArea>
|
||||||
</MutinyManagerGuard>
|
</MutinyWalletGuard>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,15 +21,15 @@ export default function BalanceBox() {
|
|||||||
|
|
||||||
const fetchOnchainBalance = async () => {
|
const fetchOnchainBalance = async () => {
|
||||||
console.log("Refetching onchain balance");
|
console.log("Refetching onchain balance");
|
||||||
await state.mutiny_manager?.sync();
|
await state.mutiny_wallet?.sync();
|
||||||
const balance = await state.mutiny_manager?.get_balance();
|
const balance = await state.mutiny_wallet?.get_balance();
|
||||||
return balance
|
return balance
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: it's hacky to do these separately, but ln doesn't need the sync so I don't want to wait
|
// TODO: it's hacky to do these separately, but ln doesn't need the sync so I don't want to wait
|
||||||
const fetchLnBalance = async () => {
|
const fetchLnBalance = async () => {
|
||||||
console.log("Refetching ln balance");
|
console.log("Refetching ln balance");
|
||||||
const balance = await state.mutiny_manager?.get_balance();
|
const balance = await state.mutiny_wallet?.get_balance();
|
||||||
return balance
|
return balance
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -16,13 +16,13 @@ function PeerItem(props: { peer: MutinyPeer }) {
|
|||||||
const [state, _] = useMegaStore()
|
const [state, _] = useMegaStore()
|
||||||
|
|
||||||
const handleDisconnectPeer = async () => {
|
const handleDisconnectPeer = async () => {
|
||||||
const nodes = await state.mutiny_manager?.list_nodes();
|
const nodes = await state.mutiny_wallet?.list_nodes();
|
||||||
const firstNode = nodes[0] as string || ""
|
const firstNode = nodes[0] as string || ""
|
||||||
|
|
||||||
if (props.peer.is_connected) {
|
if (props.peer.is_connected) {
|
||||||
await state.mutiny_manager?.disconnect_peer(firstNode, props.peer.pubkey);
|
await state.mutiny_wallet?.disconnect_peer(firstNode, props.peer.pubkey);
|
||||||
} else {
|
} else {
|
||||||
await state.mutiny_manager?.delete_peer(firstNode, props.peer.pubkey);
|
await state.mutiny_wallet?.delete_peer(firstNode, props.peer.pubkey);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ function PeersList() {
|
|||||||
const [state, _] = useMegaStore()
|
const [state, _] = useMegaStore()
|
||||||
|
|
||||||
const getPeers = async () => {
|
const getPeers = async () => {
|
||||||
return await state.mutiny_manager?.list_peers() as Promise<MutinyPeer[]>
|
return await state.mutiny_wallet?.list_peers() as Promise<MutinyPeer[]>
|
||||||
};
|
};
|
||||||
|
|
||||||
const [peers, { refetch }] = createResource(getPeers);
|
const [peers, { refetch }] = createResource(getPeers);
|
||||||
@@ -94,10 +94,10 @@ function ConnectPeer(props: { refetchPeers: RefetchPeersType }) {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const peerConnectString = value().trim();
|
const peerConnectString = value().trim();
|
||||||
const nodes = await state.mutiny_manager?.list_nodes();
|
const nodes = await state.mutiny_wallet?.list_nodes();
|
||||||
const firstNode = nodes[0] as string || ""
|
const firstNode = nodes[0] as string || ""
|
||||||
|
|
||||||
await state.mutiny_manager?.connect_to_peer(firstNode, peerConnectString)
|
await state.mutiny_wallet?.connect_to_peer(firstNode, peerConnectString)
|
||||||
|
|
||||||
await props.refetchPeers()
|
await props.refetchPeers()
|
||||||
|
|
||||||
@@ -139,7 +139,7 @@ function ChannelItem(props: { channel: MutinyChannel, network?: string }) {
|
|||||||
async function confirmCloseChannel() {
|
async function confirmCloseChannel() {
|
||||||
setConfirmLoading(true);
|
setConfirmLoading(true);
|
||||||
try {
|
try {
|
||||||
await state.mutiny_manager?.close_channel(props.channel.outpoint as string)
|
await state.mutiny_wallet?.close_channel(props.channel.outpoint as string)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
showToast(eify(e));
|
showToast(eify(e));
|
||||||
@@ -178,7 +178,7 @@ function ChannelsList() {
|
|||||||
const [state, _] = useMegaStore()
|
const [state, _] = useMegaStore()
|
||||||
|
|
||||||
const getChannels = async () => {
|
const getChannels = async () => {
|
||||||
return await state.mutiny_manager?.list_channels() as Promise<MutinyChannel[]>
|
return await state.mutiny_wallet?.list_channels() as Promise<MutinyChannel[]>
|
||||||
};
|
};
|
||||||
|
|
||||||
const [channels, { refetch }] = createResource(getChannels);
|
const [channels, { refetch }] = createResource(getChannels);
|
||||||
@@ -193,7 +193,7 @@ function ChannelsList() {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
const network = state.mutiny_manager?.get_network();
|
const network = state.mutiny_wallet?.get_network();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -235,10 +235,10 @@ function OpenChannel(props: { refetchChannels: RefetchChannelsListType }) {
|
|||||||
const pubkey = peerPubkey().trim();
|
const pubkey = peerPubkey().trim();
|
||||||
const bigAmount = BigInt(amount());
|
const bigAmount = BigInt(amount());
|
||||||
|
|
||||||
const nodes = await state.mutiny_manager?.list_nodes();
|
const nodes = await state.mutiny_wallet?.list_nodes();
|
||||||
const firstNode = nodes[0] as string || ""
|
const firstNode = nodes[0] as string || ""
|
||||||
|
|
||||||
const new_channel = await state.mutiny_manager?.open_channel(firstNode, pubkey, bigAmount)
|
const new_channel = await state.mutiny_wallet?.open_channel(firstNode, pubkey, bigAmount)
|
||||||
|
|
||||||
setNewChannel(new_channel)
|
setNewChannel(new_channel)
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { As, Dialog } from "@kobalte/core";
|
|||||||
import { Button, Card } from "~/components/layout";
|
import { Button, Card } from "~/components/layout";
|
||||||
import { useMegaStore } from "~/state/megaStore";
|
import { useMegaStore } from "~/state/megaStore";
|
||||||
import { Show, createResource } from "solid-js";
|
import { Show, createResource } from "solid-js";
|
||||||
import { getExistingSettings } from "~/logic/mutinyManagerSetup";
|
import { getExistingSettings } from "~/logic/mutinyWalletSetup";
|
||||||
import getHostname from "~/utils/getHostname";
|
import getHostname from "~/utils/getHostname";
|
||||||
|
|
||||||
const OVERLAY = "fixed inset-0 z-50 bg-black/50 backdrop-blur-sm"
|
const OVERLAY = "fixed inset-0 z-50 bg-black/50 backdrop-blur-sm"
|
||||||
@@ -15,9 +15,9 @@ export default function PeerConnectModal() {
|
|||||||
const [state, _] = useMegaStore()
|
const [state, _] = useMegaStore()
|
||||||
|
|
||||||
const getPeerConnectString = async () => {
|
const getPeerConnectString = async () => {
|
||||||
if (state.mutiny_manager) {
|
if (state.mutiny_wallet) {
|
||||||
const { proxy } = getExistingSettings();
|
const { proxy } = getExistingSettings();
|
||||||
const nodes = await state.mutiny_manager.list_nodes();
|
const nodes = await state.mutiny_wallet.list_nodes();
|
||||||
const firstNode = nodes[0] as string || ""
|
const firstNode = nodes[0] as string || ""
|
||||||
const hostName = getHostname(proxy || "")
|
const hostName = getHostname(proxy || "")
|
||||||
const connectString = `mutiny:${firstNode}@${hostName}`
|
const connectString = `mutiny:${firstNode}@${hostName}`
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { createForm, url } from '@modular-forms/solid';
|
import { createForm, url } from '@modular-forms/solid';
|
||||||
import { TextField } from '~/components/layout/TextField';
|
import { TextField } from '~/components/layout/TextField';
|
||||||
import { MutinyManagerSettingStrings, getExistingSettings } from '~/logic/mutinyManagerSetup';
|
import { MutinyWalletSettingStrings, getExistingSettings } from '~/logic/mutinyWalletSetup';
|
||||||
import { Button } from '~/components/layout';
|
import { Button } from '~/components/layout';
|
||||||
import { createSignal } from 'solid-js';
|
import { createSignal } from 'solid-js';
|
||||||
import { deleteDb } from '~/components/DeleteEverything';
|
import { deleteDb } from '~/components/DeleteEverything';
|
||||||
@@ -11,14 +11,14 @@ import { useMegaStore } from '~/state/megaStore';
|
|||||||
|
|
||||||
export function SettingsStringsEditor() {
|
export function SettingsStringsEditor() {
|
||||||
const existingSettings = getExistingSettings();
|
const existingSettings = getExistingSettings();
|
||||||
const [_settingsForm, { Form, Field }] = createForm<MutinyManagerSettingStrings>({ initialValues: existingSettings });
|
const [_settingsForm, { Form, Field }] = createForm<MutinyWalletSettingStrings>({ initialValues: existingSettings });
|
||||||
const [confirmOpen, setConfirmOpen] = createSignal(false);
|
const [confirmOpen, setConfirmOpen] = createSignal(false);
|
||||||
|
|
||||||
const [settingsTemp, setSettingsTemp] = createSignal<MutinyManagerSettingStrings>();
|
const [settingsTemp, setSettingsTemp] = createSignal<MutinyWalletSettingStrings>();
|
||||||
|
|
||||||
const [_store, actions] = useMegaStore();
|
const [_store, actions] = useMegaStore();
|
||||||
|
|
||||||
async function handleSubmit(values: MutinyManagerSettingStrings) {
|
async function handleSubmit(values: MutinyWalletSettingStrings) {
|
||||||
try {
|
try {
|
||||||
const existing = getExistingSettings();
|
const existing = getExistingSettings();
|
||||||
const newSettings = { ...existing, ...values }
|
const newSettings = { ...existing, ...values }
|
||||||
@@ -28,7 +28,7 @@ export function SettingsStringsEditor() {
|
|||||||
setSettingsTemp(newSettings);
|
setSettingsTemp(newSettings);
|
||||||
setConfirmOpen(true);
|
setConfirmOpen(true);
|
||||||
} else {
|
} else {
|
||||||
await actions.setupMutinyManager(newSettings);
|
await actions.setupMutinyWallet(newSettings);
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -45,7 +45,7 @@ export function SettingsStringsEditor() {
|
|||||||
showToast({ title: "Deleted", description: `Deleted all data` })
|
showToast({ title: "Deleted", description: `Deleted all data` })
|
||||||
const loadedValues = settingsTemp();
|
const loadedValues = settingsTemp();
|
||||||
|
|
||||||
await actions.setupMutinyManager(loadedValues);
|
await actions.setupMutinyWallet(loadedValues);
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
|
|||||||
@@ -71,11 +71,11 @@ export const FullscreenLoader = () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MutinyManagerGuard: ParentComponent = (props) => {
|
export const MutinyWalletGuard: ParentComponent = (props) => {
|
||||||
const [state, _] = useMegaStore();
|
const [state, _] = useMegaStore();
|
||||||
return (
|
return (
|
||||||
<Suspense fallback={<FullscreenLoader />}>
|
<Suspense fallback={<FullscreenLoader />}>
|
||||||
<Show when={state.mutiny_manager}>
|
<Show when={state.mutiny_wallet}>
|
||||||
{props.children}
|
{props.children}
|
||||||
</Show>
|
</Show>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
|
|
||||||
import initMutinyManager, { MutinyManager } from '@mutinywallet/mutiny-wasm';
|
import initMutinyWallet, { MutinyWallet } from '@mutinywallet/mutiny-wasm';
|
||||||
import initWaila from '@mutinywallet/waila-wasm'
|
import initWaila from '@mutinywallet/waila-wasm'
|
||||||
|
|
||||||
// export type MutinyManagerSettingStrings = {
|
// export type MutinyWalletSettingStrings = {
|
||||||
// network?: string, proxy?: string, esplora?: string, rgs?: string, lsp?: string,
|
// network?: string, proxy?: string, esplora?: string, rgs?: string, lsp?: string,
|
||||||
// }
|
// }
|
||||||
|
|
||||||
type Network = "bitcoin" | "testnet" | "regtest" | "signet";
|
type Network = "bitcoin" | "testnet" | "regtest" | "signet";
|
||||||
export type MutinyManagerSettingStrings = {
|
export type MutinyWalletSettingStrings = {
|
||||||
network?: Network, proxy?: string, esplora?: string, rgs?: string, lsp?: string,
|
network?: Network, proxy?: string, esplora?: string, rgs?: string, lsp?: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getExistingSettings(): MutinyManagerSettingStrings {
|
export function getExistingSettings(): MutinyWalletSettingStrings {
|
||||||
const network = localStorage.getItem('MUTINY_SETTINGS_network') || import.meta.env.VITE_NETWORK;
|
const network = localStorage.getItem('MUTINY_SETTINGS_network') || import.meta.env.VITE_NETWORK;
|
||||||
const proxy = localStorage.getItem('MUTINY_SETTINGS_proxy') || import.meta.env.VITE_PROXY;
|
const proxy = localStorage.getItem('MUTINY_SETTINGS_proxy') || import.meta.env.VITE_PROXY;
|
||||||
const esplora = localStorage.getItem('MUTINY_SETTINGS_esplora') || import.meta.env.VITE_ESPLORA;
|
const esplora = localStorage.getItem('MUTINY_SETTINGS_esplora') || import.meta.env.VITE_ESPLORA;
|
||||||
@@ -21,7 +21,7 @@ export function getExistingSettings(): MutinyManagerSettingStrings {
|
|||||||
return { network, proxy, esplora, rgs, lsp }
|
return { network, proxy, esplora, rgs, lsp }
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function setAndGetMutinySettings(settings?: MutinyManagerSettingStrings): Promise<MutinyManagerSettingStrings> {
|
export async function setAndGetMutinySettings(settings?: MutinyWalletSettingStrings): Promise<MutinyWalletSettingStrings> {
|
||||||
let { network, proxy, esplora, rgs, lsp } = settings || {};
|
let { network, proxy, esplora, rgs, lsp } = settings || {};
|
||||||
|
|
||||||
const existingSettings = getExistingSettings();
|
const existingSettings = getExistingSettings();
|
||||||
@@ -70,8 +70,8 @@ export async function checkForWasm() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function setupMutinyManager(settings?: MutinyManagerSettingStrings): Promise<MutinyManager> {
|
export async function setupMutinyWallet(settings?: MutinyWalletSettingStrings): Promise<MutinyWallet> {
|
||||||
await initMutinyManager();
|
await initMutinyWallet();
|
||||||
// Might as well init waila while we're at it
|
// Might as well init waila while we're at it
|
||||||
await initWaila();
|
await initWaila();
|
||||||
|
|
||||||
@@ -85,14 +85,14 @@ export async function setupMutinyManager(settings?: MutinyManagerSettingStrings)
|
|||||||
console.log("Using rgs address", rgs);
|
console.log("Using rgs address", rgs);
|
||||||
console.log("Using lsp address", lsp);
|
console.log("Using lsp address", lsp);
|
||||||
|
|
||||||
const mutinyManager = await new MutinyManager("", undefined, proxy, network, esplora, rgs, lsp)
|
const mutinyWallet = await new MutinyWallet("", undefined, proxy, network, esplora, rgs, lsp)
|
||||||
|
|
||||||
const nodes = await mutinyManager.list_nodes();
|
const nodes = await mutinyWallet.list_nodes();
|
||||||
|
|
||||||
// If we don't have any nodes yet, create one
|
// If we don't have any nodes yet, create one
|
||||||
if (!nodes.length) {
|
if (!nodes.length) {
|
||||||
await mutinyManager?.new_node()
|
await mutinyWallet?.new_node()
|
||||||
}
|
}
|
||||||
|
|
||||||
return mutinyManager
|
return mutinyWallet
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
import { DeleteEverything } from "~/components/DeleteEverything";
|
import { DeleteEverything } from "~/components/DeleteEverything";
|
||||||
import KitchenSink from "~/components/KitchenSink";
|
import KitchenSink from "~/components/KitchenSink";
|
||||||
import NavBar from "~/components/NavBar";
|
import NavBar from "~/components/NavBar";
|
||||||
import { Card, DefaultMain, LargeHeader, MutinyManagerGuard, SafeArea, SmallHeader, VStack } from "~/components/layout";
|
import { Card, DefaultMain, LargeHeader, MutinyWalletGuard, SafeArea, SmallHeader, VStack } from "~/components/layout";
|
||||||
import { BackLink } from "~/components/layout/BackLink";
|
import { BackLink } from "~/components/layout/BackLink";
|
||||||
|
|
||||||
export default function Admin() {
|
export default function Admin() {
|
||||||
return (
|
return (
|
||||||
<MutinyManagerGuard>
|
<MutinyWalletGuard>
|
||||||
<SafeArea>
|
<SafeArea>
|
||||||
<DefaultMain>
|
<DefaultMain>
|
||||||
<BackLink href="/settings" title="Settings" />
|
<BackLink href="/settings" title="Settings" />
|
||||||
@@ -22,6 +22,6 @@ export default function Admin() {
|
|||||||
</DefaultMain>
|
</DefaultMain>
|
||||||
<NavBar activeTab="none" />
|
<NavBar activeTab="none" />
|
||||||
</SafeArea>
|
</SafeArea>
|
||||||
</MutinyManagerGuard>
|
</MutinyWalletGuard>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@ import { MutinyBip21RawMaterials, MutinyInvoice } from "@mutinywallet/mutiny-was
|
|||||||
import { createEffect, createResource, createSignal, For, Match, onCleanup, Switch } from "solid-js";
|
import { createEffect, createResource, createSignal, For, Match, onCleanup, Switch } from "solid-js";
|
||||||
import { QRCodeSVG } from "solid-qr-code";
|
import { QRCodeSVG } from "solid-qr-code";
|
||||||
import { AmountEditable } from "~/components/AmountEditable";
|
import { AmountEditable } from "~/components/AmountEditable";
|
||||||
import { Button, Card, LargeHeader, MutinyManagerGuard, SafeArea, SmallHeader } from "~/components/layout";
|
import { Button, Card, LargeHeader, MutinyWalletGuard, SafeArea, SmallHeader } from "~/components/layout";
|
||||||
import NavBar from "~/components/NavBar";
|
import NavBar from "~/components/NavBar";
|
||||||
import { useMegaStore } from "~/state/megaStore";
|
import { useMegaStore } from "~/state/megaStore";
|
||||||
import { objectToSearchParams } from "~/utils/objectToSearchParams";
|
import { objectToSearchParams } from "~/utils/objectToSearchParams";
|
||||||
@@ -138,7 +138,7 @@ export default function Receive() {
|
|||||||
async function getUnifiedQr(amount: string) {
|
async function getUnifiedQr(amount: string) {
|
||||||
const bigAmount = BigInt(amount);
|
const bigAmount = BigInt(amount);
|
||||||
try {
|
try {
|
||||||
const raw = await state.mutiny_manager?.create_bip21(bigAmount);
|
const raw = await state.mutiny_wallet?.create_bip21(bigAmount);
|
||||||
// Save the raw info so we can watch the address and invoice
|
// Save the raw info so we can watch the address and invoice
|
||||||
setBip21Raw(raw);
|
setBip21Raw(raw);
|
||||||
|
|
||||||
@@ -171,7 +171,7 @@ export default function Receive() {
|
|||||||
const lightning = bip21.invoice
|
const lightning = bip21.invoice
|
||||||
const address = bip21.address
|
const address = bip21.address
|
||||||
|
|
||||||
const invoice = await state.mutiny_manager?.get_invoice(lightning)
|
const invoice = await state.mutiny_wallet?.get_invoice(lightning)
|
||||||
|
|
||||||
if (invoice && invoice.paid) {
|
if (invoice && invoice.paid) {
|
||||||
setReceiveState("paid")
|
setReceiveState("paid")
|
||||||
@@ -179,7 +179,7 @@ export default function Receive() {
|
|||||||
return "lightning_paid"
|
return "lightning_paid"
|
||||||
}
|
}
|
||||||
|
|
||||||
const tx = await state.mutiny_manager?.check_address(address) as OnChainTx | undefined;
|
const tx = await state.mutiny_wallet?.check_address(address) as OnChainTx | undefined;
|
||||||
|
|
||||||
if (tx) {
|
if (tx) {
|
||||||
setReceiveState("paid")
|
setReceiveState("paid")
|
||||||
@@ -201,7 +201,7 @@ export default function Receive() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MutinyManagerGuard>
|
<MutinyWalletGuard>
|
||||||
<SafeArea>
|
<SafeArea>
|
||||||
<main class="max-w-[600px] flex flex-col gap-4 mx-auto p-4">
|
<main class="max-w-[600px] flex flex-col gap-4 mx-auto p-4">
|
||||||
<BackLink />
|
<BackLink />
|
||||||
@@ -285,6 +285,6 @@ export default function Receive() {
|
|||||||
</main>
|
</main>
|
||||||
<NavBar activeTab="receive" />
|
<NavBar activeTab="receive" />
|
||||||
</SafeArea >
|
</SafeArea >
|
||||||
</MutinyManagerGuard>
|
</MutinyWalletGuard>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Component, createEffect, createMemo, createResource, createSignal, For, Match, onCleanup, onMount, ParentComponent, Show, Suspense, Switch } from "solid-js";
|
import { Component, createEffect, createMemo, createResource, createSignal, For, Match, onCleanup, onMount, ParentComponent, Show, Suspense, Switch } from "solid-js";
|
||||||
import { CENTER_COLUMN, MISSING_LABEL, REDSHIFT_LABEL, RIGHT_COLUMN, THREE_COLUMNS, UtxoItem } from "~/components/Activity";
|
import { CENTER_COLUMN, MISSING_LABEL, REDSHIFT_LABEL, RIGHT_COLUMN, THREE_COLUMNS, UtxoItem } from "~/components/Activity";
|
||||||
import { Card, DefaultMain, LargeHeader, LoadingSpinner, NiceP, MutinyManagerGuard, SafeArea, SmallAmount, SmallHeader, VStack } from "~/components/layout";
|
import { Card, DefaultMain, LargeHeader, LoadingSpinner, NiceP, MutinyWalletGuard, SafeArea, SmallAmount, SmallHeader, VStack } from "~/components/layout";
|
||||||
import { BackLink } from "~/components/layout/BackLink";
|
import { BackLink } from "~/components/layout/BackLink";
|
||||||
import { StyledRadioGroup } from "~/components/layout/Radio";
|
import { StyledRadioGroup } from "~/components/layout/Radio";
|
||||||
import NavBar from "~/components/NavBar";
|
import NavBar from "~/components/NavBar";
|
||||||
@@ -19,12 +19,12 @@ type ShiftOption = "utxo" | "lightning"
|
|||||||
type ShiftStage = "choose" | "observe" | "success" | "failure"
|
type ShiftStage = "choose" | "observe" | "success" | "failure"
|
||||||
|
|
||||||
type OutPoint = string; // Replace with the actual TypeScript type for OutPoint
|
type OutPoint = string; // Replace with the actual TypeScript type for OutPoint
|
||||||
type RedshiftStatus = any; // Replace with the actual TypeScript type for RedshiftStatus
|
type RedshiftStatus = string; // Replace with the actual TypeScript type for RedshiftStatus
|
||||||
type RedshiftRecipient = any; // Replace with the actual TypeScript type for RedshiftRecipient
|
type RedshiftRecipient = any; // Replace with the actual TypeScript type for RedshiftRecipient
|
||||||
type PublicKey = any; // Replace with the actual TypeScript type for PublicKey
|
type PublicKey = any; // Replace with the actual TypeScript type for PublicKey
|
||||||
|
|
||||||
interface RedshiftResult {
|
interface RedshiftResult {
|
||||||
id: bigint;
|
id: string;
|
||||||
input_utxo: OutPoint;
|
input_utxo: OutPoint;
|
||||||
status: RedshiftStatus;
|
status: RedshiftStatus;
|
||||||
recipient: RedshiftRecipient;
|
recipient: RedshiftRecipient;
|
||||||
@@ -38,9 +38,9 @@ interface RedshiftResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const dummyRedshift: RedshiftResult = {
|
const dummyRedshift: RedshiftResult = {
|
||||||
id: BigInt(1),
|
id: "44036599c37d590899e8d5d920860286",
|
||||||
input_utxo: "44036599c37d590899e8d5d92086028695d2c2966fdc354ce1da9a9eac610a53:1",
|
input_utxo: "44036599c37d590899e8d5d92086028695d2c2966fdc354ce1da9a9eac610a53:1",
|
||||||
status: {}, // Replace with a dummy value for RedshiftStatus
|
status: "Completed", // Replace with a dummy value for RedshiftStatus
|
||||||
recipient: {}, // Replace with a dummy value for RedshiftRecipient
|
recipient: {}, // Replace with a dummy value for RedshiftRecipient
|
||||||
output_utxo: "44036599c37d590899e8d5d92086028695d2c2966fdc354ce1da9a9eac610a53:1",
|
output_utxo: "44036599c37d590899e8d5d92086028695d2c2966fdc354ce1da9a9eac610a53:1",
|
||||||
introduction_channel: "a7773e57f8595848a635e9af105927cac9ecaf292d71a76456ae0455bd3c9c64:0",
|
introduction_channel: "a7773e57f8595848a635e9af105927cac9ecaf292d71a76456ae0455bd3c9c64:0",
|
||||||
@@ -56,7 +56,7 @@ function RedshiftReport(props: { redshift: RedshiftResult, utxo: UtxoItem }) {
|
|||||||
|
|
||||||
const getUtXos = async () => {
|
const getUtXos = async () => {
|
||||||
console.log("Getting utxos");
|
console.log("Getting utxos");
|
||||||
return await state.mutiny_manager?.list_utxos() as UtxoItem[];
|
return await state.mutiny_wallet?.list_utxos() as UtxoItem[];
|
||||||
}
|
}
|
||||||
|
|
||||||
function findUtxoByOutpoint(outpoint?: string, utxos: UtxoItem[] = []): UtxoItem | undefined {
|
function findUtxoByOutpoint(outpoint?: string, utxos: UtxoItem[] = []): UtxoItem | undefined {
|
||||||
@@ -75,15 +75,15 @@ function RedshiftReport(props: { redshift: RedshiftResult, utxo: UtxoItem }) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
async function checkRedshift(outpoint: string) {
|
async function checkRedshift(id: string) {
|
||||||
// const rs = redshiftItems[0] as RedshiftResult;
|
// const rs = redshiftItems[0] as RedshiftResult;
|
||||||
console.log("Checking redshift", outpoint)
|
console.log("Checking redshift", id)
|
||||||
const redshift = await state.mutiny_manager?.get_redshift(outpoint);
|
const redshift = await state.mutiny_wallet?.get_redshift(id);
|
||||||
console.log(redshift)
|
console.log(redshift)
|
||||||
return redshift[0]
|
return redshift;
|
||||||
}
|
}
|
||||||
|
|
||||||
const [redshiftResource, { refetch }] = createResource(props.utxo.outpoint, checkRedshift);
|
const [redshiftResource, { refetch }] = createResource(props.redshift.id, checkRedshift);
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
const interval = setInterval(() => {
|
const interval = setInterval(() => {
|
||||||
if (redshiftResource()) refetch();
|
if (redshiftResource()) refetch();
|
||||||
@@ -196,7 +196,7 @@ export function Utxo(props: { item: UtxoItem, onClick?: () => void }) {
|
|||||||
|
|
||||||
const FAKE_STATES = ["Creating a new node", "Opening a channel", "Sending funds through", "Closing the channel", "Redshift complete"]
|
const FAKE_STATES = ["Creating a new node", "Opening a channel", "Sending funds through", "Closing the channel", "Redshift complete"]
|
||||||
|
|
||||||
function ShiftObserver(props: { setShiftStage: (stage: ShiftStage) => void, utxo: UtxoItem }) {
|
function ShiftObserver(props: { setShiftStage: (stage: ShiftStage) => void, redshiftId: String }) {
|
||||||
const [state, _actions] = useMegaStore();
|
const [state, _actions] = useMegaStore();
|
||||||
|
|
||||||
const [fakeStage, setFakeStage] = createSignal(2);
|
const [fakeStage, setFakeStage] = createSignal(2);
|
||||||
@@ -216,15 +216,14 @@ function ShiftObserver(props: { setShiftStage: (stage: ShiftStage) => void, utxo
|
|||||||
}, 1000)
|
}, 1000)
|
||||||
})
|
})
|
||||||
|
|
||||||
async function checkRedshift(outpoint: string) {
|
async function checkRedshift(id: string) {
|
||||||
// const rs = redshiftItems[0] as RedshiftResult;
|
console.log("Checking redshift", id)
|
||||||
console.log("Checking redshift", outpoint)
|
const redshift = await state.mutiny_wallet?.get_redshift(id);
|
||||||
const redshift = await state.mutiny_manager?.get_redshift(outpoint);
|
|
||||||
console.log(redshift)
|
console.log(redshift)
|
||||||
return redshift
|
return redshift
|
||||||
}
|
}
|
||||||
|
|
||||||
const [redshiftResource, { refetch }] = createResource(props.utxo.outpoint, checkRedshift);
|
const [redshiftResource, { refetch }] = createResource(props.redshiftId, checkRedshift);
|
||||||
|
|
||||||
// onMount(() => {
|
// onMount(() => {
|
||||||
// const interval = setInterval(() => {
|
// const interval = setInterval(() => {
|
||||||
@@ -282,13 +281,13 @@ export default function Redshift() {
|
|||||||
|
|
||||||
const getUtXos = async () => {
|
const getUtXos = async () => {
|
||||||
console.log("Getting utxos");
|
console.log("Getting utxos");
|
||||||
return await state.mutiny_manager?.list_utxos() as UtxoItem[];
|
return await state.mutiny_wallet?.list_utxos() as UtxoItem[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const getChannels = async () => {
|
const getChannels = async () => {
|
||||||
console.log("Getting channels");
|
console.log("Getting channels");
|
||||||
await state.mutiny_manager?.sync()
|
await state.mutiny_wallet?.sync()
|
||||||
const channels = await state.mutiny_manager?.list_channels() as Promise<MutinyChannel[]>;
|
const channels = await state.mutiny_wallet?.list_channels() as Promise<MutinyChannel[]>;
|
||||||
console.log(channels)
|
console.log(channels)
|
||||||
return channels
|
return channels
|
||||||
|
|
||||||
@@ -315,7 +314,7 @@ export default function Redshift() {
|
|||||||
|
|
||||||
async function redshiftUtxo(utxo: UtxoItem) {
|
async function redshiftUtxo(utxo: UtxoItem) {
|
||||||
console.log("Redshifting utxo", utxo.outpoint)
|
console.log("Redshifting utxo", utxo.outpoint)
|
||||||
const redshift = await state.mutiny_manager?.init_redshift(utxo.outpoint);
|
const redshift = await state.mutiny_wallet?.init_redshift(utxo.outpoint);
|
||||||
console.log("Redshift initialized:")
|
console.log("Redshift initialized:")
|
||||||
console.log(redshift)
|
console.log(redshift)
|
||||||
return redshift
|
return redshift
|
||||||
@@ -331,7 +330,7 @@ export default function Redshift() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MutinyManagerGuard>
|
<MutinyWalletGuard>
|
||||||
<SafeArea>
|
<SafeArea>
|
||||||
<DefaultMain>
|
<DefaultMain>
|
||||||
<BackLink />
|
<BackLink />
|
||||||
@@ -405,6 +404,6 @@ export default function Redshift() {
|
|||||||
</DefaultMain>
|
</DefaultMain>
|
||||||
<NavBar activeTab="redshift" />
|
<NavBar activeTab="redshift" />
|
||||||
</SafeArea>
|
</SafeArea>
|
||||||
</MutinyManagerGuard>
|
</MutinyWalletGuard>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -87,7 +87,7 @@ export default function Scanner() {
|
|||||||
// When we have a nice result we can head over to the send screen
|
// When we have a nice result we can head over to the send screen
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
if (scanResult()) {
|
if (scanResult()) {
|
||||||
const network = state.mutiny_manager?.get_network() || "signet";
|
const network = state.mutiny_wallet?.get_network() || "signet";
|
||||||
const result = toParsedParams(scanResult() || "", network);
|
const result = toParsedParams(scanResult() || "", network);
|
||||||
if (!result.ok) {
|
if (!result.ok) {
|
||||||
showToast(result.error);
|
showToast(result.error);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Match, Show, Switch, createEffect, createMemo, createResource, createSignal, onCleanup, onMount } from "solid-js";
|
import { Match, Show, Switch, createEffect, createMemo, createResource, createSignal, onCleanup, onMount } from "solid-js";
|
||||||
import { Amount } from "~/components/Amount";
|
import { Amount } from "~/components/Amount";
|
||||||
import NavBar from "~/components/NavBar";
|
import NavBar from "~/components/NavBar";
|
||||||
import { Button, ButtonLink, DefaultMain, HStack, LargeHeader, MutinyManagerGuard, SafeArea, SmallHeader, VStack } from "~/components/layout";
|
import { Button, ButtonLink, DefaultMain, HStack, LargeHeader, MutinyWalletGuard, SafeArea, SmallHeader, VStack } from "~/components/layout";
|
||||||
import { Paste } from "~/assets/svg/Paste";
|
import { Paste } from "~/assets/svg/Paste";
|
||||||
import { Scan } from "~/assets/svg/Scan";
|
import { Scan } from "~/assets/svg/Scan";
|
||||||
import { useMegaStore } from "~/state/megaStore";
|
import { useMegaStore } from "~/state/megaStore";
|
||||||
@@ -84,7 +84,7 @@ export default function Send() {
|
|||||||
if (source.memo) setDescription(source.memo);
|
if (source.memo) setDescription(source.memo);
|
||||||
|
|
||||||
if (source.invoice) {
|
if (source.invoice) {
|
||||||
state.mutiny_manager?.decode_invoice(source.invoice).then(invoice => {
|
state.mutiny_wallet?.decode_invoice(source.invoice).then(invoice => {
|
||||||
if (invoice?.amount_sats) setAmountSats(invoice.amount_sats);
|
if (invoice?.amount_sats) setAmountSats(invoice.amount_sats);
|
||||||
setInvoice(invoice)
|
setInvoice(invoice)
|
||||||
setSource("lightning")
|
setSource("lightning")
|
||||||
@@ -107,7 +107,7 @@ export default function Send() {
|
|||||||
|
|
||||||
function parsePaste(text: string) {
|
function parsePaste(text: string) {
|
||||||
if (text) {
|
if (text) {
|
||||||
const network = state.mutiny_manager?.get_network() || "signet";
|
const network = state.mutiny_wallet?.get_network() || "signet";
|
||||||
const result = toParsedParams(text || "", network);
|
const result = toParsedParams(text || "", network);
|
||||||
if (!result.ok) {
|
if (!result.ok) {
|
||||||
showToast(result.error);
|
showToast(result.error);
|
||||||
@@ -144,21 +144,21 @@ export default function Send() {
|
|||||||
const bolt11 = invoice()?.bolt11;
|
const bolt11 = invoice()?.bolt11;
|
||||||
let sentDetails: Partial<SentDetails> = {};
|
let sentDetails: Partial<SentDetails> = {};
|
||||||
if (source() === "lightning" && invoice() && bolt11) {
|
if (source() === "lightning" && invoice() && bolt11) {
|
||||||
const nodes = await state.mutiny_manager?.list_nodes();
|
const nodes = await state.mutiny_wallet?.list_nodes();
|
||||||
const firstNode = nodes[0] as string || ""
|
const firstNode = nodes[0] as string || ""
|
||||||
sentDetails.destination = bolt11;
|
sentDetails.destination = bolt11;
|
||||||
// If the invoice has sats use that, otherwise we pass the user-defined amount
|
// If the invoice has sats use that, otherwise we pass the user-defined amount
|
||||||
if (invoice()?.amount_sats) {
|
if (invoice()?.amount_sats) {
|
||||||
await state.mutiny_manager?.pay_invoice(firstNode, bolt11);
|
await state.mutiny_wallet?.pay_invoice(firstNode, bolt11);
|
||||||
sentDetails.amount = invoice()?.amount_sats;
|
sentDetails.amount = invoice()?.amount_sats;
|
||||||
} else {
|
} else {
|
||||||
await state.mutiny_manager?.pay_invoice(firstNode, bolt11, amountSats());
|
await state.mutiny_wallet?.pay_invoice(firstNode, bolt11, amountSats());
|
||||||
sentDetails.amount = amountSats();
|
sentDetails.amount = amountSats();
|
||||||
}
|
}
|
||||||
} else if (source() === "lightning" && nodePubkey()) {
|
} else if (source() === "lightning" && nodePubkey()) {
|
||||||
const nodes = await state.mutiny_manager?.list_nodes();
|
const nodes = await state.mutiny_wallet?.list_nodes();
|
||||||
const firstNode = nodes[0] as string || ""
|
const firstNode = nodes[0] as string || ""
|
||||||
const payment = await state.mutiny_manager?.keysend(firstNode, nodePubkey()!, amountSats());
|
const payment = await state.mutiny_wallet?.keysend(firstNode, nodePubkey()!, amountSats());
|
||||||
console.log(payment?.value)
|
console.log(payment?.value)
|
||||||
|
|
||||||
// TODO: handle timeouts
|
// TODO: handle timeouts
|
||||||
@@ -169,7 +169,7 @@ export default function Send() {
|
|||||||
}
|
}
|
||||||
} else if (source() === "onchain" && address()) {
|
} else if (source() === "onchain" && address()) {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
const txid = await state.mutiny_manager?.send_to_address(address()!, amountSats());
|
const txid = await state.mutiny_wallet?.send_to_address(address()!, amountSats());
|
||||||
sentDetails.amount = amountSats();
|
sentDetails.amount = amountSats();
|
||||||
sentDetails.destination = address();
|
sentDetails.destination = address();
|
||||||
// TODO: figure out if this is necessary, it takes forever
|
// TODO: figure out if this is necessary, it takes forever
|
||||||
@@ -194,7 +194,7 @@ export default function Send() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MutinyManagerGuard>
|
<MutinyWalletGuard>
|
||||||
<SafeArea>
|
<SafeArea>
|
||||||
<DefaultMain>
|
<DefaultMain>
|
||||||
<BackLink />
|
<BackLink />
|
||||||
@@ -216,7 +216,7 @@ export default function Send() {
|
|||||||
<img src={handshake} alt="handshake" class="w-1/2 mx-auto max-w-[50vh]" />
|
<img src={handshake} alt="handshake" class="w-1/2 mx-auto max-w-[50vh]" />
|
||||||
<Amount amountSats={sentDetails()?.amount} showFiat />
|
<Amount amountSats={sentDetails()?.amount} showFiat />
|
||||||
<Show when={sentDetails()?.txid}>
|
<Show when={sentDetails()?.txid}>
|
||||||
<a href={mempoolTxUrl(sentDetails()?.txid, state.mutiny_manager?.get_network())} target="_blank" rel="noreferrer">
|
<a href={mempoolTxUrl(sentDetails()?.txid, state.mutiny_wallet?.get_network())} target="_blank" rel="noreferrer">
|
||||||
Mempool Link
|
Mempool Link
|
||||||
</a>
|
</a>
|
||||||
</Show>
|
</Show>
|
||||||
@@ -315,6 +315,6 @@ export default function Send() {
|
|||||||
</DefaultMain>
|
</DefaultMain>
|
||||||
<NavBar activeTab="send" />
|
<NavBar activeTab="send" />
|
||||||
</SafeArea >
|
</SafeArea >
|
||||||
</MutinyManagerGuard >
|
</MutinyWalletGuard >
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ButtonLink, DefaultMain, LargeHeader, MutinyManagerGuard, SafeArea, VStack } from "~/components/layout";
|
import { ButtonLink, DefaultMain, LargeHeader, MutinyWalletGuard, SafeArea, VStack } from "~/components/layout";
|
||||||
import { BackLink } from "~/components/layout/BackLink";
|
import { BackLink } from "~/components/layout/BackLink";
|
||||||
import NavBar from "~/components/NavBar";
|
import NavBar from "~/components/NavBar";
|
||||||
import { SeedWords } from "~/components/SeedWords";
|
import { SeedWords } from "~/components/SeedWords";
|
||||||
@@ -9,7 +9,7 @@ export default function Settings() {
|
|||||||
const [store, _actions] = useMegaStore();
|
const [store, _actions] = useMegaStore();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MutinyManagerGuard>
|
<MutinyWalletGuard>
|
||||||
<SafeArea>
|
<SafeArea>
|
||||||
<DefaultMain>
|
<DefaultMain>
|
||||||
<BackLink />
|
<BackLink />
|
||||||
@@ -17,7 +17,7 @@ export default function Settings() {
|
|||||||
<VStack biggap>
|
<VStack biggap>
|
||||||
<VStack>
|
<VStack>
|
||||||
<p class="text-2xl font-light">Write down these words or you'll die!</p>
|
<p class="text-2xl font-light">Write down these words or you'll die!</p>
|
||||||
<SeedWords words={store.mutiny_manager?.show_seed() || ""} />
|
<SeedWords words={store.mutiny_wallet?.show_seed() || ""} />
|
||||||
</VStack>
|
</VStack>
|
||||||
<SettingsStringsEditor />
|
<SettingsStringsEditor />
|
||||||
<ButtonLink href="/admin">"I know what I'm doing"</ButtonLink>
|
<ButtonLink href="/admin">"I know what I'm doing"</ButtonLink>
|
||||||
@@ -25,6 +25,6 @@ export default function Settings() {
|
|||||||
</DefaultMain>
|
</DefaultMain>
|
||||||
<NavBar activeTab="settings" />
|
<NavBar activeTab="settings" />
|
||||||
</SafeArea>
|
</SafeArea>
|
||||||
</MutinyManagerGuard>
|
</MutinyWalletGuard>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
import { ParentComponent, createContext, createEffect, onCleanup, onMount, useContext } from "solid-js";
|
import { ParentComponent, createContext, createEffect, onCleanup, onMount, useContext } from "solid-js";
|
||||||
import { createStore } from "solid-js/store";
|
import { createStore } from "solid-js/store";
|
||||||
import { MutinyManagerSettingStrings, setupMutinyManager } from "~/logic/mutinyManagerSetup";
|
import { MutinyWalletSettingStrings, setupMutinyWallet } from "~/logic/mutinyWalletSetup";
|
||||||
import { MutinyBalance, MutinyManager } from "@mutinywallet/mutiny-wasm";
|
import { MutinyBalance, MutinyWallet } from "@mutinywallet/mutiny-wasm";
|
||||||
import { ParsedParams } from "~/routes/Scanner";
|
import { ParsedParams } from "~/routes/Scanner";
|
||||||
|
|
||||||
const MegaStoreContext = createContext<MegaStore>();
|
const MegaStoreContext = createContext<MegaStore>();
|
||||||
@@ -12,7 +12,7 @@ type UserStatus = undefined | "new_here" | "waitlisted" | "approved" | "paid"
|
|||||||
|
|
||||||
export type MegaStore = [{
|
export type MegaStore = [{
|
||||||
waitlist_id?: string;
|
waitlist_id?: string;
|
||||||
mutiny_manager?: MutinyManager;
|
mutiny_wallet?: MutinyWallet;
|
||||||
user_status: UserStatus;
|
user_status: UserStatus;
|
||||||
scan_result?: ParsedParams;
|
scan_result?: ParsedParams;
|
||||||
balance?: MutinyBalance;
|
balance?: MutinyBalance;
|
||||||
@@ -20,7 +20,7 @@ export type MegaStore = [{
|
|||||||
price: number
|
price: number
|
||||||
}, {
|
}, {
|
||||||
fetchUserStatus(): Promise<UserStatus>;
|
fetchUserStatus(): Promise<UserStatus>;
|
||||||
setupMutinyManager(settings?: MutinyManagerSettingStrings): Promise<void>;
|
setupMutinyWallet(settings?: MutinyWalletSettingStrings): Promise<void>;
|
||||||
setWaitlistId(waitlist_id: string): void;
|
setWaitlistId(waitlist_id: string): void;
|
||||||
setScanResult(scan_result: ParsedParams | undefined): void;
|
setScanResult(scan_result: ParsedParams | undefined): void;
|
||||||
sync(): Promise<void>;
|
sync(): Promise<void>;
|
||||||
@@ -29,7 +29,7 @@ export type MegaStore = [{
|
|||||||
export const Provider: ParentComponent = (props) => {
|
export const Provider: ParentComponent = (props) => {
|
||||||
const [state, setState] = createStore({
|
const [state, setState] = createStore({
|
||||||
waitlist_id: localStorage.getItem("waitlist_id"),
|
waitlist_id: localStorage.getItem("waitlist_id"),
|
||||||
mutiny_manager: undefined as MutinyManager | undefined,
|
mutiny_wallet: undefined as MutinyWallet | undefined,
|
||||||
user_status: undefined as UserStatus,
|
user_status: undefined as UserStatus,
|
||||||
scan_result: undefined as ParsedParams | undefined,
|
scan_result: undefined as ParsedParams | undefined,
|
||||||
// TODO: wire this up to real price once we have caching
|
// TODO: wire this up to real price once we have caching
|
||||||
@@ -55,10 +55,10 @@ export const Provider: ParentComponent = (props) => {
|
|||||||
return "new_here"
|
return "new_here"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async setupMutinyManager(settings?: MutinyManagerSettingStrings): Promise<void> {
|
async setupMutinyWallet(settings?: MutinyWalletSettingStrings): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const mutinyManager = await setupMutinyManager(settings)
|
const mutinyWallet = await setupMutinyWallet(settings)
|
||||||
setState({ mutiny_manager: mutinyManager })
|
setState({ mutiny_wallet: mutinyWallet })
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
}
|
}
|
||||||
@@ -69,7 +69,7 @@ export const Provider: ParentComponent = (props) => {
|
|||||||
async sync(): Promise<void> {
|
async sync(): Promise<void> {
|
||||||
console.time("BDK Sync Time")
|
console.time("BDK Sync Time")
|
||||||
try {
|
try {
|
||||||
await state.mutiny_manager?.sync()
|
await state.mutiny_wallet?.sync()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
@@ -89,9 +89,9 @@ export const Provider: ParentComponent = (props) => {
|
|||||||
|
|
||||||
// Only load node manager when status is approved
|
// Only load node manager when status is approved
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
if (state.user_status === "approved" && !state.mutiny_manager) {
|
if (state.user_status === "approved" && !state.mutiny_wallet) {
|
||||||
console.log("running setup node manager...")
|
console.log("running setup node manager...")
|
||||||
actions.setupMutinyManager().then(() => console.log("node manager setup done"))
|
actions.setupMutinyWallet().then(() => console.log("node manager setup done"))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -102,7 +102,7 @@ export const Provider: ParentComponent = (props) => {
|
|||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
const interval = setInterval(() => {
|
const interval = setInterval(() => {
|
||||||
if (state.mutiny_manager) actions.sync();
|
if (state.mutiny_wallet) actions.sync();
|
||||||
}, 60 * 1000); // Poll every minute
|
}, 60 * 1000); // Poll every minute
|
||||||
|
|
||||||
onCleanup(() => {
|
onCleanup(() => {
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { MutinyManager } from "@mutinywallet/mutiny-wasm";
|
import { MutinyWallet } from "@mutinywallet/mutiny-wasm";
|
||||||
|
|
||||||
export function satsToUsd(amount: number | undefined, price: number, formatted: boolean): string {
|
export function satsToUsd(amount: number | undefined, price: number, formatted: boolean): string {
|
||||||
if (typeof amount !== "number" || isNaN(amount)) {
|
if (typeof amount !== "number" || isNaN(amount)) {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const btc = MutinyManager.convert_sats_to_btc(BigInt(Math.floor(amount)));
|
const btc = MutinyWallet.convert_sats_to_btc(BigInt(Math.floor(amount)));
|
||||||
const usd = btc * price;
|
const usd = btc * price;
|
||||||
|
|
||||||
if (formatted) {
|
if (formatted) {
|
||||||
@@ -26,7 +26,7 @@ export function usdToSats(amount: number | undefined, price: number, formatted:
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const btc = price / amount;
|
const btc = price / amount;
|
||||||
const sats = MutinyManager.convert_btc_to_sats(btc);
|
const sats = MutinyWallet.convert_btc_to_sats(btc);
|
||||||
if (formatted) {
|
if (formatted) {
|
||||||
return parseInt(sats.toString()).toLocaleString();
|
return parseInt(sats.toString()).toLocaleString();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user