Created
September 14, 2023 22:06
-
-
Save csuwildcat/9a4f604da0ac034a3180c0a317a5ba25 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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