mirror of
https://github.com/aljazceru/mutiny-web.git
synced 2026-01-28 10:34:26 +01:00
better types thx wasm-bindgen
This commit is contained in:
@@ -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