forked from digital-asset/daml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create-daml-app: Use alias templates for display names (digital-asset…
…#12390) * create-daml-app: Use alias templates for display names We introduce Alias contracts to the create-daml-app Daml model and use them to display aliases in the UI instead of party identifier strings. CHANGELOG_BEGIN CHANGELOG_END * fix tests * addressing review * Add comments to Setup.daml * factor out alias to option conversion CHANGELOG_BEGIN CHANGELOG_END * small fix in setup.daml * replace user dropdown with input in login screen * fix compatibility tests * fix alias loading flick in mainscreen * remove canton incompatible sandbox options from daml.yaml * fix gsg-trigger.patc
- Loading branch information
Robin Krom
authored
Jan 27, 2022
1 parent
2e3ae0d
commit 345e267
Showing
13 changed files
with
179 additions
and
85 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,56 @@ | ||
module Setup where | ||
|
||
import DA.Foldable (forA_) | ||
import DA.Optional (fromSomeNote) | ||
import qualified DA.Text as T | ||
import Daml.Script | ||
|
||
import User (Alias(..)) | ||
|
||
-- | A test user for the create-daml-app network. | ||
data TestUser = TestUser with | ||
alias : Text | ||
public : Party | ||
|
||
-- | Create a public party, then create three test users. | ||
setup : Script () | ||
setup = do | ||
public <- createPublic | ||
let aliases = ["Alice", "Bob", "Charlie"] | ||
forA_ aliases $ \alias -> createTestUser $ TestUser alias public | ||
|
||
-- | Create a test user. | ||
createTestUser : TestUser -> Script Party | ||
createTestUser TestUser{alias, public} = do | ||
u <- getOrCreateUser alias (Some public) | ||
let p = getPrimaryParty u | ||
submit public $ createCmd $ Alias p alias public | ||
pure p | ||
|
||
-- | Create the public party. | ||
createPublic : Script Party | ||
createPublic = do | ||
publicUser <- getOrCreateUser "Public" None | ||
pure $ getPrimaryParty publicUser | ||
|
||
|
||
let displayNames = ["Alice", "Bob", "Charlie"] | ||
forA_ displayNames $ \displayName -> do | ||
userId <- validateUserId $ toUserId displayName | ||
userExists userId >>= \case | ||
True -> | ||
-- user already exists do nothing | ||
pure () | ||
False -> do | ||
let partyIdHint = toPartyIdHint displayName | ||
p <- allocatePartyWithHint displayName (PartyIdHint partyIdHint) | ||
createUser (User userId (Some p)) [CanActAs p] | ||
pure () | ||
|
||
userExists : UserId -> Script Bool | ||
userExists u = do | ||
try do _ <- getUser u; pure True | ||
catch UserNotFound _ -> pure False | ||
-- | Get a user by their id. If the user doesn't exist, it is created. | ||
getOrCreateUser : Text -> Optional Party -> Script User | ||
getOrCreateUser alias publicM = do | ||
userId <- validateUserId $ toUserId alias | ||
try | ||
getUser userId | ||
catch | ||
UserNotFound _ -> do | ||
p <- allocateParty alias | ||
let u = User userId (Some p) | ||
createUser u $ [CanActAs p] ++ [CanReadAs public | Some public <- [publicM]] | ||
pure u | ||
|
||
-- | Convert a text to a valid user id. | ||
toUserId : Text -> Text | ||
toUserId = T.asciiToLower | ||
|
||
-- TODO Drop hints once we have aliases. | ||
toPartyIdHint : Text -> Text | ||
toPartyIdHint p = "p" <> toUserId p | ||
-- | Try to get the primary party of a user and fail if the user has no associated primary party. | ||
getPrimaryParty : User -> Party | ||
getPrimaryParty u = fromSomeNote ("User " <> userIdToText u.userId <> " is missing a primary party.") u.primaryParty |
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
File renamed without changes.
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
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
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
Oops, something went wrong.