Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function removeAllChildrenFromGroupWithNameAsync(groupName: string) {
try {
const groupId = await ensureGroupAsync(groupName);
const { data: contacts } = await Contacts.getContactsAsync({ groupId });
await Promise.all(
contacts.map(contact => Contacts.removeContactFromGroupAsync(contact.id, groupId!))
);
} catch ({ message }) {
// tslint:disable-next-line no-console
console.error(message);
}
}
export async function fetchContacts(
kit: ContractKit
): Promise<{ rawContacts: ContactsById; phoneNumbersByAddress: PhoneNumberMappingEntryByAddress }> {
const contacts = await getContactsAsync({
fields: [Fields.PhoneNumbers, Fields.Image],
})
const filteredContacts = contacts.data.filter((contact) => {
return (
contact.phoneNumbers && find(contact.phoneNumbers, (p) => isValidPhoneNumber(p) !== undefined)
)
})
const rawContacts = fromPairs(filteredContacts.map((contact) => [contact.id, contact]))
// @ts-ignore
const phoneNumbersToContacts = createPhoneNumberToContactMapping(filteredContacts)
const phoneNumbersByAddress = await lookupPhoneNumbersOnAttestations(kit, phoneNumbersToContacts)
export async function debugAddFirstContactToGroupAsync() {
const groupId = await ensureGroupAsync('Expo Contacts');
const { data: contacts } = await Contacts.getContactsAsync({ pageSize: 1 });
const contact = contacts[0];
Contacts.addExistingContactToGroupAsync(contact.id, groupId!);
}
export async function getContacts() {
const { status } = await Permissions.askAsync(Permissions.CONTACTS);
if (status !== "granted") {
return [];
}
const { data } = await Contacts.getContactsAsync({
fields: [Contacts.Fields.Name, Contacts.Fields.PhoneNumbers]
});
if (!data.length) {
return [];
}
const contacts = data
.reduce((contacts, item) => {
const hasUSNumber =
item.phoneNumbers &&
item.phoneNumbers.length &&
item.phoneNumbers[0] &&
item.phoneNumbers[0].countryCode === "us";
if (hasUSNumber) {