I have found the following way to use display names instead of party identifiers on the React UI:
I copy into every component where I want either to display party display names or submit commands submitting party display names, the following code snippet:
// DISPLAYNAME_DEPENDENCIES_START
import { useEffect } from 'react';
import { useLedger, useParty } from '@daml/react';
import Ledger, { PartyInfo } from '@daml/ledger';
// DISPLAYNAME_DEPENDENCIES_END
// DISPLAYNAME_START
const [knownParties, setKnownParties] = React.useState<PartyInfo[]>([]);
const partyId = useParty();
const ledger: Ledger = useLedger();
useEffect(() => {
const getKnownParties = async () => {
let lst = await ledger.listKnownParties();
setKnownParties(lst);
} ;
getKnownParties()
}, [ledger]);
function displayName (id: string | undefined): (string | undefined) {
if (id === undefined) {
return id;
} else {
return knownParties.filter(x => x.identifier === id)[0]?.displayName
}}
function partyIdentifier (displayName: string | undefined): string {
let filterResult = knownParties.filter(x => x.displayName === displayName)
if (filterResult === []) {
throw new Error("Party display name doesn't exist")
} else {
return filterResult[0].identifier
}
}
// DISPLAYNAME_END
In the Create Daml App this means I have to copy this into four components.
I can imagine that I could do something similar once in the code on the top level. Is there a way to do that?