Skip to content

Instantly share code, notes, and snippets.

@csuwildcat
Created September 14, 2023 22:06
Show Gist options
  • Save csuwildcat/9a4f604da0ac034a3180c0a317a5ba25 to your computer and use it in GitHub Desktop.
Save csuwildcat/9a4f604da0ac034a3180c0a317a5ba25 to your computer and use it in GitHub Desktop.
const fetchProfiles = async () => {
const managedIdentities = await IdentityAgentManager.listIdentities();
const promises = await Promise.all(managedIdentities.map(async identity => {
const agent = IdentityAgentManager.getAgent();
const web5 = new Web5({ agent, connectedDid: identity.did });
const queryResult = await web5.dwn.records.query({
message: {
filter: {
schema: profileProtocol.types.displayName.schema,
}
}
})
const recordId = queryResult.records?.at(0)?.id;
if (!recordId) {
return undefined;
}
const readResult = await web5.dwn.records.read({
message: {
recordId: recordId,
}
});
if (readResult) {
return {
identity,
displayName: await readResult?.record.data.text(),
};
}
else {
return undefined;
}
}));
promises.filter(profile => profile !== undefined) as WipProfile[];
setProfiles(profiles);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment