Observers encoding in Daml-Finance

I’m building the UI for an app that utilizes the Finance library. In order to create a role contract for a new user, it’s required to send a payload containing a Provider and list of Observers.
In another app, I saw that the Observers are sent using the following format:

observers: emptyMap<string, any>().set('Public', singleton(publicPartyID))

Does this look like a correct format?
Is there no option to simplify the required datatype? It seems like a somewhat convoluted way to provide what is essentialy a list of ids.

import { Factory as AccountFactory } from '@daml.js/daml-finance-account/lib/Daml/Finance/Account/Account';
const accountFactoryPL = {
  provider: newPartyID,
  observers: emptyMap<string, any>().set('Public', singleton(publicPartyID))
const createAccountFactory = await ledger.create(AccountFactory, accountFactoryPL);

Hey @galiliyo

The type for observers in this case is Map Text (Set Party) for a particular reason: if we just had a list of observers, and some contract gets disclosed as part of two different workflows, if those workflows “undisclose” the contract when finished, one will interfere with the other (ie. undisclose the contract prematurely).

That’s why we use a “context” to differentiate between different workflows, so when one workflow removes an observer from its context it doesn’t affect the others. This is particularly important during settlement, where accounts get disclosed/undisclosed on-the-fly.

I agree this is somewhat awkward to construct using Typescript / Javascript, and a helper function probably makes sense here.

As a general comment, I would suggest to set up factories (like the account factory) as part of a Daml init script. Those are usually one-time actions, that aren’t required during normal operation of an app (and therefore, shouldn’t need to be exposed through the UI).

Of course your use case might vary, and I’d be interested to understand why you’d want such a factory to be created through the UI.