openwallet-foundation / credo-ts-ext

Extension libraries for Credo
https://credo.js.org
Apache License 2.0
29 stars 38 forks source link

[react-hooks] agent returned from useAgent should not be optional #72

Open TimoGlastra opened 3 years ago

TimoGlastra commented 3 years ago

It makes for a (IMO) very cluncky API. E.g the following code

const retrievedCreds = await agent?.proofs?.getRequestedCredentialsForProofRequest(
   proof?.requestMessage?.indyProofRequest,
   undefined
)

if (!retrievedCreds) {
   throw new Error('Retrieved creds not found')
}

could be reduced to the following

const retrievedCreds = await agent.proofs.getRequestedCredentialsForProofRequest(
  proof?.requestMessage?.indyProofRequest,
  undefined
)

if agent was always of type Agent.

I think we could throw an error in useAgent if it is not available yet? Or we make sure you can pass a uninitalized agent to the agent provider so the value is at least defined

TimoGlastra commented 3 years ago

cc @JamesKEbert @NeilSMyers