Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add limit for get_contacts_sorted #1181

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading