mirror of
https://github.com/aljazceru/mutiny-web.git
synced 2026-01-29 11:04:20 +01:00
add load bar home and emergency kit
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
/* @refresh reload */
|
||||
|
||||
import initMutinyWallet, { MutinyWallet } from "@mutinywallet/mutiny-wasm";
|
||||
import initWaila from "@mutinywallet/waila-wasm";
|
||||
|
||||
export type Network = "bitcoin" | "testnet" | "regtest" | "signet";
|
||||
export type MutinyWalletSettingStrings = {
|
||||
@@ -105,10 +104,8 @@ export async function checkForWasm() {
|
||||
}
|
||||
}
|
||||
|
||||
export async function setupMutinyWallet(
|
||||
settings?: MutinyWalletSettingStrings,
|
||||
password?: string
|
||||
): Promise<MutinyWallet> {
|
||||
export async function doubleInitDefense() {
|
||||
console.log("Starting init...");
|
||||
// Ultimate defense against getting multiple instances of the wallet running.
|
||||
// If we detect that the wallet has already been initialized in this session, we'll reload the page.
|
||||
// A successful stop of the wallet in onCleanup will clear this flag
|
||||
@@ -121,11 +118,17 @@ export async function setupMutinyWallet(
|
||||
sessionStorage.removeItem("MUTINY_WALLET_INITIALIZED");
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
|
||||
export async function initializeWasm() {
|
||||
// Actually intialize the WASM, this should be the first thing that requires the WASM blob to be downloaded
|
||||
await initMutinyWallet();
|
||||
// Might as well init waila while we're at it
|
||||
await initWaila();
|
||||
}
|
||||
|
||||
export async function setupMutinyWallet(
|
||||
settings?: MutinyWalletSettingStrings,
|
||||
password?: string
|
||||
): Promise<MutinyWallet> {
|
||||
console.log("Starting setup...");
|
||||
const { network, proxy, esplora, rgs, lsp, auth, subscriptions } =
|
||||
await setAndGetMutinySettings(settings);
|
||||
|
||||
58
src/logic/waila.ts
Normal file
58
src/logic/waila.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import initWaila, { PaymentParams } from "@mutinywallet/waila-wasm";
|
||||
import { Result } from "~/utils/typescript";
|
||||
|
||||
// Make sure we've initialzied waila before we try to use it
|
||||
await initWaila();
|
||||
|
||||
export type ParsedParams = {
|
||||
address?: string;
|
||||
invoice?: string;
|
||||
amount_sats?: bigint;
|
||||
network?: string;
|
||||
memo?: string;
|
||||
node_pubkey?: string;
|
||||
lnurl?: string;
|
||||
};
|
||||
|
||||
export function toParsedParams(
|
||||
str: string,
|
||||
ourNetwork: string
|
||||
): Result<ParsedParams> {
|
||||
let params;
|
||||
try {
|
||||
params = new PaymentParams(str || "");
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return { ok: false, error: new Error("Invalid payment request") };
|
||||
}
|
||||
|
||||
// If WAILA doesn't return a network we should default to our own
|
||||
// If the networks is testnet and we're on signet we should use signet
|
||||
const network = !params.network
|
||||
? ourNetwork
|
||||
: params.network === "testnet" && ourNetwork === "signet"
|
||||
? "signet"
|
||||
: params.network;
|
||||
|
||||
if (network !== ourNetwork) {
|
||||
return {
|
||||
ok: false,
|
||||
error: new Error(
|
||||
`Destination is for ${params.network} but you're on ${ourNetwork}`
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
ok: true,
|
||||
value: {
|
||||
address: params.address,
|
||||
invoice: params.invoice,
|
||||
amount_sats: params.amount_sats,
|
||||
network,
|
||||
memo: params.memo,
|
||||
node_pubkey: params.node_pubkey,
|
||||
lnurl: params.lnurl
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user