mirror of
https://github.com/aljazceru/mutiny-web.git
synced 2026-02-08 15:54:29 +01:00
better types thx wasm-bindgen
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import { NwcProfile } from "@mutinywallet/mutiny-wasm";
|
||||
import {
|
||||
createEffect,
|
||||
createResource,
|
||||
@@ -42,10 +41,11 @@ export function PendingNwc() {
|
||||
const [error, setError] = createSignal<Error>();
|
||||
|
||||
async function fetchPendingRequests() {
|
||||
const profiles: NwcProfile[] =
|
||||
await state.mutiny_wallet?.get_nwc_profiles();
|
||||
const profiles = await state.mutiny_wallet?.get_nwc_profiles();
|
||||
if (!profiles) return [];
|
||||
|
||||
const pending = await state.mutiny_wallet?.get_pending_nwc_invoices();
|
||||
if (!pending) return [];
|
||||
|
||||
const pendingItems: PendingItem[] = [];
|
||||
|
||||
|
||||
@@ -2,30 +2,31 @@ import { createOptions, Select } from "@thisbeyond/solid-select";
|
||||
|
||||
import "~/styles/solid-select.css";
|
||||
|
||||
import { TagItem, TagKind } from "@mutinywallet/mutiny-wasm";
|
||||
import { createMemo, createSignal, onMount } from "solid-js";
|
||||
|
||||
import { useMegaStore } from "~/state/megaStore";
|
||||
import { MutinyTagItem, sortByLastUsed } from "~/utils";
|
||||
import { sortByLastUsed } from "~/utils";
|
||||
|
||||
const createLabelValue = (label: string): Partial<MutinyTagItem> => {
|
||||
return { name: label, kind: "Contact" };
|
||||
const createLabelValue = (label: string): Partial<TagItem> => {
|
||||
return { name: label, kind: TagKind.Contact };
|
||||
};
|
||||
|
||||
export function TagEditor(props: {
|
||||
selectedValues: Partial<MutinyTagItem>[];
|
||||
setSelectedValues: (value: Partial<MutinyTagItem>[]) => void;
|
||||
selectedValues: Partial<TagItem>[];
|
||||
setSelectedValues: (value: Partial<TagItem>[]) => void;
|
||||
placeholder: string;
|
||||
autoFillTag?: string | undefined;
|
||||
}) {
|
||||
const [_state, actions] = useMegaStore();
|
||||
const [availableTags, setAvailableTags] = createSignal<MutinyTagItem[]>([]);
|
||||
const [availableTags, setAvailableTags] = createSignal<TagItem[]>([]);
|
||||
|
||||
onMount(async () => {
|
||||
const tags = await actions.listTags();
|
||||
if (tags) {
|
||||
setAvailableTags(
|
||||
tags
|
||||
.filter((tag) => tag.kind === "Contact")
|
||||
.filter((tag) => tag.kind === TagKind.Contact)
|
||||
.sort(sortByLastUsed)
|
||||
);
|
||||
if (props.autoFillTag && availableTags()) {
|
||||
@@ -51,7 +52,7 @@ export function TagEditor(props: {
|
||||
});
|
||||
});
|
||||
|
||||
const onChange = (selected: MutinyTagItem[]) => {
|
||||
const onChange = (selected: TagItem[]) => {
|
||||
props.setSelectedValues(selected);
|
||||
|
||||
const lastValue = selected[selected.length - 1];
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
Checkbox as KCheckbox,
|
||||
Separator
|
||||
} from "@kobalte/core";
|
||||
import { TagItem, TagKind } from "@mutinywallet/mutiny-wasm";
|
||||
import {
|
||||
createResource,
|
||||
createSignal,
|
||||
@@ -27,7 +28,7 @@ import {
|
||||
} from "~/components";
|
||||
import { useI18n } from "~/i18n/context";
|
||||
import { useMegaStore } from "~/state/megaStore";
|
||||
import { generateGradient, MutinyTagItem } from "~/utils";
|
||||
import { generateGradient } from "~/utils";
|
||||
|
||||
export const SmallHeader: ParentComponent<{ class?: string }> = (props) => {
|
||||
return (
|
||||
@@ -268,7 +269,7 @@ export const TinyText: ParentComponent = (props) => {
|
||||
|
||||
export const TinyButton: ParentComponent<{
|
||||
onClick: () => void;
|
||||
tag?: MutinyTagItem;
|
||||
tag?: TagItem;
|
||||
}> = (props) => {
|
||||
// TODO: don't need to run this if it's not a contact
|
||||
const [gradient] = createResource(async () => {
|
||||
@@ -276,7 +277,7 @@ export const TinyButton: ParentComponent<{
|
||||
});
|
||||
|
||||
const bg = () =>
|
||||
props.tag?.name && props.tag?.kind === "Contact"
|
||||
props.tag?.name && props.tag?.kind === TagKind.Contact
|
||||
? gradient()
|
||||
: "rgb(255 255 255 / 0.1)";
|
||||
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
import {
|
||||
Contact,
|
||||
MutinyBip21RawMaterials,
|
||||
MutinyInvoice
|
||||
MutinyInvoice,
|
||||
TagItem
|
||||
} from "@mutinywallet/mutiny-wasm";
|
||||
import {
|
||||
createEffect,
|
||||
@@ -49,12 +50,7 @@ import {
|
||||
} from "~/components";
|
||||
import { useI18n } from "~/i18n/context";
|
||||
import { useMegaStore } from "~/state/megaStore";
|
||||
import {
|
||||
eify,
|
||||
MutinyTagItem,
|
||||
objectToSearchParams,
|
||||
vibrateSuccess
|
||||
} from "~/utils";
|
||||
import { eify, objectToSearchParams, vibrateSuccess } from "~/utils";
|
||||
|
||||
type OnChainTx = {
|
||||
transaction: {
|
||||
@@ -126,9 +122,7 @@ export default function Receive() {
|
||||
const [lspFee, setLspFee] = createSignal(0n);
|
||||
|
||||
// Tagging stuff
|
||||
const [selectedValues, setSelectedValues] = createSignal<MutinyTagItem[]>(
|
||||
[]
|
||||
);
|
||||
const [selectedValues, setSelectedValues] = createSignal<TagItem[]>([]);
|
||||
|
||||
// The data we get after a payment
|
||||
const [paymentTx, setPaymentTx] = createSignal<OnChainTx>();
|
||||
@@ -215,7 +209,7 @@ export default function Receive() {
|
||||
}
|
||||
|
||||
async function processContacts(
|
||||
contacts: Partial<MutinyTagItem>[]
|
||||
contacts: Partial<TagItem>[]
|
||||
): Promise<string[]> {
|
||||
if (contacts.length) {
|
||||
const first = contacts![0];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Clipboard } from "@capacitor/clipboard";
|
||||
import { Capacitor } from "@capacitor/core";
|
||||
import { Contact, MutinyInvoice } from "@mutinywallet/mutiny-wasm";
|
||||
import { Contact, MutinyInvoice, TagItem } from "@mutinywallet/mutiny-wasm";
|
||||
import {
|
||||
createEffect,
|
||||
createMemo,
|
||||
@@ -48,7 +48,7 @@ import {
|
||||
import { useI18n } from "~/i18n/context";
|
||||
import { ParsedParams } from "~/logic/waila";
|
||||
import { useMegaStore } from "~/state/megaStore";
|
||||
import { eify, MutinyTagItem, vibrateSuccess } from "~/utils";
|
||||
import { eify, vibrateSuccess } from "~/utils";
|
||||
|
||||
export type SendSource = "lightning" | "onchain";
|
||||
|
||||
@@ -250,7 +250,7 @@ export default function Send() {
|
||||
|
||||
// Tagging stuff
|
||||
const [selectedContacts, setSelectedContacts] = createSignal<
|
||||
Partial<MutinyTagItem>[]
|
||||
Partial<TagItem>[]
|
||||
>([]);
|
||||
|
||||
// Details Modal
|
||||
@@ -476,7 +476,7 @@ export default function Send() {
|
||||
}
|
||||
|
||||
async function processContacts(
|
||||
contacts: Partial<MutinyTagItem>[]
|
||||
contacts: Partial<TagItem>[]
|
||||
): Promise<string[]> {
|
||||
if (contacts.length) {
|
||||
const first = contacts![0];
|
||||
|
||||
@@ -219,8 +219,8 @@ function Nwc() {
|
||||
|
||||
async function fetchNwcProfiles() {
|
||||
try {
|
||||
const profiles: NwcProfile[] =
|
||||
await state.mutiny_wallet?.get_nwc_profiles();
|
||||
const profiles = await state.mutiny_wallet?.get_nwc_profiles();
|
||||
if (!profiles) return [];
|
||||
|
||||
return profiles;
|
||||
} catch (e) {
|
||||
|
||||
@@ -104,8 +104,8 @@ function ExistingGifts() {
|
||||
|
||||
const [giftNWCProfiles, { refetch }] = createResource(async () => {
|
||||
try {
|
||||
const profiles: NwcProfile[] =
|
||||
await state.mutiny_wallet?.get_nwc_profiles();
|
||||
const profiles = await state.mutiny_wallet?.get_nwc_profiles();
|
||||
if (!profiles) return [];
|
||||
|
||||
const filteredForGifts = profiles.filter((p) => p.tag === "Gift");
|
||||
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
/* @refresh reload */
|
||||
|
||||
// Inspired by https://github.com/solidjs/solid-realworld/blob/main/src/store/index.js
|
||||
import { MutinyBalance, MutinyWallet } from "@mutinywallet/mutiny-wasm";
|
||||
import {
|
||||
MutinyBalance,
|
||||
MutinyWallet,
|
||||
TagItem
|
||||
} from "@mutinywallet/mutiny-wasm";
|
||||
import {
|
||||
createContext,
|
||||
onCleanup,
|
||||
@@ -25,7 +29,6 @@ import {
|
||||
BTC_OPTION,
|
||||
Currency,
|
||||
eify,
|
||||
MutinyTagItem,
|
||||
subscriptionValid,
|
||||
USD_OPTION
|
||||
} from "~/utils";
|
||||
@@ -70,7 +73,7 @@ export type MegaStore = [
|
||||
setScanResult(scan_result: ParsedParams | undefined): void;
|
||||
sync(): Promise<void>;
|
||||
setHasBackedUp(): void;
|
||||
listTags(): Promise<MutinyTagItem[]>;
|
||||
listTags(): Promise<TagItem[]>;
|
||||
checkForSubscription(justPaid?: boolean): Promise<void>;
|
||||
fetchPrice(fiat: Currency): Promise<number>;
|
||||
saveFiat(fiat: Currency): void;
|
||||
@@ -317,9 +320,9 @@ export const Provider: ParentComponent = (props) => {
|
||||
localStorage.setItem("has_backed_up", "true");
|
||||
setState({ has_backed_up: true });
|
||||
},
|
||||
async listTags(): Promise<MutinyTagItem[]> {
|
||||
async listTags(): Promise<TagItem[] | undefined> {
|
||||
try {
|
||||
return state.mutiny_wallet?.get_tag_items() as MutinyTagItem[];
|
||||
return state.mutiny_wallet?.get_tag_items();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return [];
|
||||
|
||||
@@ -1,47 +1,12 @@
|
||||
import { TagItem } from "@mutinywallet/mutiny-wasm";
|
||||
|
||||
export type MutinyTagItem = {
|
||||
id: string;
|
||||
kind: "Label" | "Contact";
|
||||
name: string;
|
||||
last_used_time: bigint;
|
||||
npub?: string;
|
||||
ln_address?: string;
|
||||
lnurl?: string;
|
||||
};
|
||||
|
||||
export const UNKNOWN_TAG: MutinyTagItem = {
|
||||
id: "Unknown",
|
||||
kind: "Label",
|
||||
name: "Unknown",
|
||||
last_used_time: 0n
|
||||
};
|
||||
|
||||
export function tagsToIds(tags?: MutinyTagItem[]): string[] {
|
||||
export function tagsToIds(tags?: TagItem[]): string[] {
|
||||
if (!tags) {
|
||||
return [];
|
||||
}
|
||||
return tags.filter((tag) => tag.id !== "Unknown").map((tag) => tag.id);
|
||||
}
|
||||
|
||||
export function tagToMutinyTag(tag: TagItem): MutinyTagItem {
|
||||
let kind: MutinyTagItem["kind"];
|
||||
|
||||
switch (tag.kind) {
|
||||
case 0: {
|
||||
kind = "Label";
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
default: {
|
||||
kind = "Contact";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return { ...tag, kind };
|
||||
}
|
||||
|
||||
export function sortByLastUsed(a: MutinyTagItem, b: MutinyTagItem) {
|
||||
export function sortByLastUsed(a: TagItem, b: TagItem) {
|
||||
return Number(b.last_used_time - a.last_used_time);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user