Skip to content
This repository has been archived by the owner on Jul 29, 2020. It is now read-only.

Adds filter options to selectContacts and selectContact in SDK #491

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 10 additions & 1 deletion packages/launcher/src/main/rpc/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@ export const sandboxed = {

contacts_select: withPermission(
'CONTACTS_READ',
async (ctx: AppContext, params: { multi?: boolean }) => {
async (
ctx: AppContext,
params: { multi?: boolean, options?: { withWallet?: boolean } },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than adding options.withWallet, I think withWallet could be set in the params object directly, such as params: { multi?: boolean, withWallet?: boolean }

) => {
const res = await ctx.trustedRPC.request('user_request', {
key: 'CONTACTS_SELECT',
params: { CONTACTS_SELECT: params },
Expand Down Expand Up @@ -242,6 +245,12 @@ export const sandboxed = {
userID,
contactIDs: ids,
})
if (params.options && params.options.withWallet) {
const filteredContacts = contactsRes.contacts.filter(
contact => contact.data.profile.ethAddress,
)
return filteredContacts
}
return contactsRes.contacts
},
),
Expand Down
10 changes: 6 additions & 4 deletions packages/sdk/src/apis/Contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import ClientAPIs from '../ClientAPIs'
import type { ContactID, Contact } from '../types'

export default class ContactsAPIs extends ClientAPIs {
async selectContacts(): Promise<Array<Contact>> {
return this._rpc.request('contacts_select', { multi: true })
async selectContacts(options?: {
withWallet?: boolean,
}): Promise<Array<Contact>> {
return this._rpc.request('contacts_select', { multi: true, options })
}

async selectContact(): Promise<?Contact> {
const contacts = await this._rpc.request('contacts_select', {})
async selectContact(options?: { withWallet?: boolean }): Promise<?Contact> {
const contacts = await this._rpc.request('contacts_select', { options })
if (contacts && contacts.length) {
return contacts[0]
}
Expand Down