Hey DAML’ers.
I have a question on useStreamQueries
, particularly when using multiple queries in the query factory.
The docs for the @daml/react
bindings here say that
The factory function is expected to return a list of queries, and the resulting set of contracts is the union of all the contracts that match at least one query.
My current dilemma looks something like this:
const dvpPending = useStreamQueries(DvpNotification, () => [{c:{dvpId:dvpId}}, {status:"pending"}], []);
const dvpFinalized = useStreamQueries(DvpNotification, () => [{c:{dvpId:dvpId}}, {status:"Finalized"}], []);
I then have a conditional switch statement to return different views based on whether the dvp
by the unique dvpId
is pending or has been finalized.
Since only 1 query has to return true for the contract to be retrieved, I can’t distinguish between the two as is currently written (dvpPending
and dvpFinalized
).
Is it possible to return nothing if both conditions in the query factory are not met?
Looking at your code, I would expect that dvpPending
will return the contract with dvpId
, regardless of its status, and all pending
contracts, while dvpFinalized
returns the contract with dvpId
, regardless of its status, and all finalized
contracts. Can you confirm that is what is happening here?
Based on you explanation, it looks like what you want is to retrieve one specific contract, and then switch based on its status. I’m not sure I understand why you’re not just getting the contract (() => [{c:{dvpId:dvpId}}]
) and then looking at its status
field. What am I missing?
If you really want two separate queries, one returning the contract if it is pending and the other returning the contract if it is finalized, you could write your queries like this:
const dvpPending = useStreamQueries(DvpNotification, () => [{c:{dvpId:dvpId}, status:"pending"}], []);
const dvpFinalized = useStreamQueries(DvpNotification, () => [{c:{dvpId:dvpId}, status:"Finalized"}], []);
were we now have a single query in each stream, and that query matches a contract that has both the expected id and the expected status (rather than the expected id or the expected status).
2 Likes
Hey @Gary_Verhaegen . You interpreted my dilemma correctly.
I misinterpreted the docs and didn’t fully understand how to query for dvpId
and status
at the same time.
Thanks for the help!
1 Like