clean code, and use newly created PortalBtcWallet library
This commit is contained in:
parent
9825c53c1c
commit
45dfe1a1c7
22 changed files with 503 additions and 1087 deletions
|
@ -1,11 +1,11 @@
|
|||
<script lang="ts">
|
||||
import "$lib/style.css";
|
||||
import "iconify-icon";
|
||||
import { hasSeed, passwordRequest } from "$lib/wallet.svelte";
|
||||
import { hasMnemonic, walletState } from "$lib/wallet.svelte";
|
||||
import { onMount } from "svelte";
|
||||
import { goto } from "$app/navigation";
|
||||
import PasswordDialog from "$lib/components/PasswordDialog.svelte";
|
||||
import { page } from "$app/stores";
|
||||
import { page } from "$app/state";
|
||||
import { start as startNwc } from "$lib/nwc.svelte";
|
||||
import SplashScreen from "$lib/components/SplashScreen.svelte";
|
||||
import ErrorDialog from "$lib/components/ErrorDialog.svelte";
|
||||
|
@ -16,7 +16,7 @@
|
|||
stack?: string;
|
||||
};
|
||||
|
||||
let passwordDialogOpen = $state(false);
|
||||
let { children } = $props();
|
||||
let showSplash = $state(true);
|
||||
let currentError = $state<AppError | null>(null);
|
||||
let showInstallPrompt = $state(false);
|
||||
|
@ -33,32 +33,15 @@
|
|||
}
|
||||
}
|
||||
|
||||
function handleUnlockAttempt(pw: string) {
|
||||
if (passwordRequest.resolve) {
|
||||
passwordRequest.resolve(pw);
|
||||
passwordRequest.resolve = undefined;
|
||||
passwordRequest.reject = undefined;
|
||||
passwordRequest.pending = false;
|
||||
startNwc();
|
||||
}
|
||||
passwordDialogOpen = false;
|
||||
}
|
||||
|
||||
function goToSettings() {
|
||||
goto("/settings");
|
||||
}
|
||||
|
||||
const { children } = $props();
|
||||
|
||||
$effect(() => {
|
||||
if (passwordRequest.pending && !passwordDialogOpen) {
|
||||
passwordDialogOpen = true;
|
||||
}
|
||||
});
|
||||
|
||||
const isOnSetup = $derived($page.route.id?.startsWith("/setup"));
|
||||
const isOnSettings = $derived($page.route.id?.startsWith("/settings"));
|
||||
const showSettingsButton = $derived(!isOnSetup && !isOnSettings && hasSeed());
|
||||
const isOnSetup = $derived(page.route.id?.startsWith("/setup"));
|
||||
const isOnSettings = $derived(page.route.id?.startsWith("/settings"));
|
||||
const showSettingsButton = $derived(
|
||||
!isOnSetup && !isOnSettings && hasMnemonic()
|
||||
);
|
||||
|
||||
onMount(() => {
|
||||
setTimeout(() => {
|
||||
|
@ -96,7 +79,7 @@
|
|||
}
|
||||
});
|
||||
|
||||
if (!hasSeed() && !isOnSetup) {
|
||||
if (!hasMnemonic() && !isOnSetup) {
|
||||
goto("/setup");
|
||||
}
|
||||
});
|
||||
|
@ -121,12 +104,14 @@
|
|||
</div>
|
||||
{/if}
|
||||
|
||||
{#if !isOnSetup || !passwordRequest.pending}
|
||||
{#if isOnSetup || $walletState.open}
|
||||
{@render children()}
|
||||
{/if}
|
||||
</main>
|
||||
|
||||
<PasswordDialog bind:open={passwordDialogOpen} unlock={handleUnlockAttempt} />
|
||||
{#if !$walletState.open && !isOnSetup}
|
||||
<PasswordDialog onunlock={() => startNwc()} />
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
<ErrorDialog error={currentError} onclose={() => (currentError = null)} />
|
||||
|
|
|
@ -1,24 +1,13 @@
|
|||
<script lang="ts">
|
||||
import type { BindingLiquidSdk } from "@breeztech/breez-sdk-liquid/web";
|
||||
import { balances, getBreezSDK, initBalances } from "$lib/breez.svelte";
|
||||
import BalanceDisplay from "$lib/components/BalanceDisplay.svelte";
|
||||
import PaymentHistory from "$lib/components/PaymentHistory.svelte";
|
||||
import ReceiveDialog from "$lib/components/ReceiveDialog.svelte";
|
||||
import SendDialog from "$lib/components/SendDialog.svelte";
|
||||
import Button from "$lib/components/Button.svelte";
|
||||
import { refreshBalances } from "$lib/breez.svelte";
|
||||
import { onMount } from "svelte";
|
||||
|
||||
let breezSDK = $state<BindingLiquidSdk | undefined>(undefined);
|
||||
|
||||
let receiveDialogOpen = $state(false);
|
||||
let sendDialogOpen = $state(false);
|
||||
|
||||
onMount(async () => {
|
||||
initBalances();
|
||||
breezSDK = await getBreezSDK();
|
||||
});
|
||||
|
||||
function openReceiveDialog() {
|
||||
receiveDialogOpen = true;
|
||||
}
|
||||
|
@ -26,20 +15,13 @@
|
|||
function openSendDialog() {
|
||||
sendDialogOpen = true;
|
||||
}
|
||||
|
||||
function onPaymentSent() {
|
||||
refreshBalances();
|
||||
}
|
||||
</script>
|
||||
|
||||
<ReceiveDialog bind:open={receiveDialogOpen} />
|
||||
<SendDialog bind:open={sendDialogOpen} onsent={onPaymentSent} />
|
||||
<SendDialog bind:open={sendDialogOpen} />
|
||||
|
||||
<div class="container">
|
||||
<BalanceDisplay
|
||||
balance={balances.balance}
|
||||
pending={balances.pendingReceive - balances.pendingSend}
|
||||
/>
|
||||
<BalanceDisplay />
|
||||
<div class="retro-card send-receive-buttons">
|
||||
<Button variant="primary" onclick={openReceiveDialog}>Receive</Button>
|
||||
<Button variant="danger" onclick={openSendDialog}>Send</Button>
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
import {
|
||||
createMnemonic,
|
||||
encryptMnemonic,
|
||||
storeEncryptedSeed,
|
||||
cacheMnemonic,
|
||||
storeEncryptedMnemonic,
|
||||
isValidMnemonic,
|
||||
openWallet,
|
||||
} from "$lib/wallet.svelte";
|
||||
import { start as startNwc } from "$lib/nwc.svelte";
|
||||
|
||||
|
@ -77,8 +77,8 @@
|
|||
return;
|
||||
}
|
||||
const encrypted = await encryptMnemonic(userMnemonic, password);
|
||||
storeEncryptedSeed(encrypted);
|
||||
cacheMnemonic(userMnemonic);
|
||||
storeEncryptedMnemonic(encrypted);
|
||||
await openWallet(userMnemonic);
|
||||
|
||||
startNwc();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue