Skip to content

Commit

Permalink
add limit for get_contacts_sorted
Browse files Browse the repository at this point in the history
  • Loading branch information
futurepaul authored and TonyGiorgio committed Jun 3, 2024
1 parent 60f1ab8 commit 57af14f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/components/PendingNwc.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { TagItem } from "@mutinywallet/mutiny-wasm";
import { useNavigate } from "@solidjs/router";
import { Check, PlugZap, X } from "lucide-solid";
import {
Expand Down Expand Up @@ -42,7 +41,7 @@ export function PendingNwc() {
setHasPreConfiguredNWC(!!profiles && profiles.length > 0);
if (!profiles) return [];

const contacts: TagItem[] | undefined = await sw.get_contacts_sorted();
const contacts = await sw.get_contacts_sorted();
if (!contacts) return [];

const pending = await sw.get_pending_nwc_invoices();
Expand Down
2 changes: 1 addition & 1 deletion src/components/SocialActionRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function SocialActionRow(props: {

const getContacts = cache(async () => {
try {
const contacts: TagItem[] = (await sw.get_contacts_sorted()) || [];
const contacts = await sw.get_contacts_sorted(40);
const myNpub = (await sw.get_npub()) || "";

// contact must have a npub, ln_address, or lnurl
Expand Down
3 changes: 1 addition & 2 deletions src/routes/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ function ActualSearch(props: { initialValue?: string }) {

const getContacts = cache(async () => {
try {
const contacts = await sw.get_contacts_sorted();
return contacts || ([] as TagItem[]);
return await sw.get_contacts_sorted(40);
} catch (e) {
console.error(e);
return [] as TagItem[];
Expand Down
10 changes: 7 additions & 3 deletions src/workers/walletWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,14 @@ export async function get_invoice(
* Gets all contacts sorted by last used
* @returns {Promise<any>}
*/
export async function get_contacts_sorted(): Promise<TagItem[] | undefined> {
export async function get_contacts_sorted(limit?: number): Promise<TagItem[]> {
const contacts = await wallet!.get_contacts_sorted();
return contacts;
if (!contacts) return [];
if (contacts.length && limit) {
return contacts.slice(0, limit);
} else {
return contacts;
}
}

export async function edit_contact(
Expand Down Expand Up @@ -966,7 +971,6 @@ export async function approve_nostr_wallet_auth(
*/
export async function get_nwc_profile(index: number): Promise<NwcProfile> {
const profile = await wallet!.get_nwc_profile(index);
console.log("get_nwc_profile", profile);
return {
...profile.value
} as NwcProfile;
Expand Down

0 comments on commit 57af14f

Please sign in to comment.