mirror of
https://github.com/aljazceru/mutiny-web.git
synced 2026-02-12 01:34:42 +01:00
add nwc toggle
This commit is contained in:
@@ -6,11 +6,11 @@ import {createResource, Show} from "solid-js";
|
||||
|
||||
const OVERLAY = "fixed inset-0 z-50 bg-black/50 backdrop-blur-sm"
|
||||
const DIALOG_POSITIONER = "fixed inset-0 z-50 flex items-center justify-center"
|
||||
const DIALOG_CONTENT = "w-[80vw] max-w-[400px] p-4 bg-gray/50 backdrop-blur-md shadow-xl rounded-xl border border-white/10"
|
||||
const DIALOG_CONTENT = "w-[80vw] max-w-[400px] max-h-[100dvh] overflow-y-auto disable-scrollbars p-4 bg-gray/50 backdrop-blur-md shadow-xl rounded-xl border border-white/10"
|
||||
const SMALL_HEADER = "text-sm font-semibold uppercase"
|
||||
|
||||
export default function NostrWalletConnectModal() {
|
||||
const [state, _] = useMegaStore()
|
||||
const [state, actions] = useMegaStore()
|
||||
|
||||
const getConnectionURI = () => {
|
||||
if (state.mutiny_wallet) {
|
||||
@@ -22,6 +22,17 @@ export default function NostrWalletConnectModal() {
|
||||
|
||||
const [connectionURI] = createResource(getConnectionURI);
|
||||
|
||||
const toggleNwc = async () => {
|
||||
if (state.nwc_enabled) {
|
||||
actions.setNwc(false)
|
||||
window.location.reload()
|
||||
} else {
|
||||
actions.setNwc(true)
|
||||
const nodes = await state.mutiny_wallet?.list_nodes();
|
||||
const firstNode = nodes[0] as string || "";
|
||||
await state.mutiny_wallet?.start_nostr_wallet_connect(firstNode);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: a lot of this markup is probably reusable as a "Modal" component
|
||||
return (
|
||||
@@ -48,6 +59,7 @@ export default function NostrWalletConnectModal() {
|
||||
<code class="break-all">{connectionURI() || ""}</code>
|
||||
</Card>
|
||||
</Show>
|
||||
<Button onClick={toggleNwc}>{state.nwc_enabled ? "Disable" : "Enable"}</Button>
|
||||
</Dialog.Description>
|
||||
</Dialog.Content>
|
||||
</div>
|
||||
|
||||
@@ -26,6 +26,7 @@ export type MegaStore = [{
|
||||
has_backed_up: boolean,
|
||||
dismissed_restore_prompt: boolean,
|
||||
wallet_loading: boolean
|
||||
nwc_enabled: boolean
|
||||
}, {
|
||||
fetchUserStatus(): Promise<UserStatus>;
|
||||
setupMutinyWallet(settings?: MutinyWalletSettingStrings): Promise<void>;
|
||||
@@ -36,6 +37,7 @@ export type MegaStore = [{
|
||||
dismissRestorePrompt(): void;
|
||||
setHasBackedUp(): void;
|
||||
listTags(): Promise<MutinyTagItem[]>;
|
||||
setNwc(enabled: boolean): void;
|
||||
}];
|
||||
|
||||
export const Provider: ParentComponent = (props) => {
|
||||
@@ -52,7 +54,8 @@ export const Provider: ParentComponent = (props) => {
|
||||
last_sync: undefined as number | undefined,
|
||||
is_syncing: false,
|
||||
dismissed_restore_prompt: localStorage.getItem("dismissed_restore_prompt") === "true",
|
||||
wallet_loading: true
|
||||
wallet_loading: true,
|
||||
nwc_enabled: localStorage.getItem("nwc_enabled") === "true",
|
||||
});
|
||||
|
||||
const actions = {
|
||||
@@ -88,6 +91,12 @@ export const Provider: ParentComponent = (props) => {
|
||||
const mutinyWallet = await setupMutinyWallet(settings)
|
||||
// Get balance optimistically
|
||||
const balance = await mutinyWallet.get_balance();
|
||||
// start nwc if enabled
|
||||
if (state.nwc_enabled) {
|
||||
const nodes = await mutinyWallet.list_nodes();
|
||||
const firstNode = nodes[0] as string || "";
|
||||
await mutinyWallet.start_nostr_wallet_connect(firstNode);
|
||||
}
|
||||
setState({ mutiny_wallet: mutinyWallet, wallet_loading: false, balance })
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
@@ -136,6 +145,10 @@ export const Provider: ParentComponent = (props) => {
|
||||
},
|
||||
async listTags(): Promise<MutinyTagItem[]> {
|
||||
return state.mutiny_wallet?.get_tag_items() as MutinyTagItem[]
|
||||
},
|
||||
setNwc(enabled: boolean) {
|
||||
localStorage.setItem("nwc_enabled", enabled.toString())
|
||||
setState({ nwc_enabled: enabled })
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user