Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't require profile to be loaded if necessary permissions are empty #694

Merged
merged 1 commit into from
Feb 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 57 additions & 41 deletions src/elm/Session/LoggedIn.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2513,29 +2513,37 @@ withPrivateKey :
-> UR.UpdateResult subModel subMsg (External subMsg)
-> UR.UpdateResult subModel subMsg (External subMsg)
withPrivateKey loggedIn necessaryPermissions subModel subMsg successfulUR =
case profile loggedIn of
Just validProfile ->
if hasPermissions validProfile necessaryPermissions then
if hasPrivateKey loggedIn then
successfulUR
let
actWithPrivateKey =
if hasPrivateKey loggedIn then
successfulUR

else
UR.init subModel
|> UR.addExt (RequiredPrivateKey subMsg)
in
if List.isEmpty necessaryPermissions then
actWithPrivateKey

else
case profile loggedIn of
Just validProfile ->
if hasPermissions validProfile necessaryPermissions then
actWithPrivateKey

else
UR.init subModel
|> UR.addExt (RequiredPrivateKey subMsg)
|> UR.addExt ShowInsufficientPermissionsModal

else
Nothing ->
UR.init subModel
|> UR.addExt ShowInsufficientPermissionsModal

Nothing ->
UR.init subModel
|> UR.logImpossible subMsg.successMsg
"Tried signing eos transaction, but profile wasn't loaded"
(Just loggedIn.accountName)
{ moduleName = "Session.LoggedIn"
, function = "withPrivateKey"
}
[]
|> UR.logImpossible subMsg.successMsg
"Tried signing eos transaction, but profile wasn't loaded"
(Just loggedIn.accountName)
{ moduleName = "Session.LoggedIn"
, function = "withPrivateKey"
}
[]


{-| Determines if a profile has a set of permissions
Expand All @@ -2552,32 +2560,40 @@ hasPermissions profile_ permissions =

withPrivateKeyInternal : Msg msg -> Model -> List Permission -> (Eos.PrivateKey -> UpdateResult msg) -> UpdateResult msg
withPrivateKeyInternal msg loggedIn necessaryPermissions successfulUR =
case profile loggedIn of
Just validProfile ->
if hasPermissions validProfile necessaryPermissions then
case maybePrivateKey loggedIn of
Just privateKey ->
successfulUR privateKey
let
actWithPrivateKey =
case maybePrivateKey loggedIn of
Just privateKey ->
successfulUR privateKey

Nothing ->
askedAuthentication loggedIn
|> UR.init
|> UR.addExt (AddAfterPrivateKeyCallback msg)
Nothing ->
askedAuthentication loggedIn
|> UR.init
|> UR.addExt (AddAfterPrivateKeyCallback msg)
in
if List.isEmpty necessaryPermissions then
actWithPrivateKey

else
{ loggedIn | showInsufficientPermissionsModal = True }
|> UR.init
else
case profile loggedIn of
Just validProfile ->
if hasPermissions validProfile necessaryPermissions then
actWithPrivateKey

_ ->
loggedIn
|> UR.init
|> UR.logImpossible msg
"Tried signing eos transaction internally, but profile wasn't loaded"
(Just loggedIn.accountName)
{ moduleName = "Session.LoggedIn"
, function = "withPrivateKeyInternal"
}
[]
else
{ loggedIn | showInsufficientPermissionsModal = True }
|> UR.init

_ ->
loggedIn
|> UR.init
|> UR.logImpossible msg
"Tried signing eos transaction internally, but profile wasn't loaded"
(Just loggedIn.accountName)
{ moduleName = "Session.LoggedIn"
, function = "withPrivateKeyInternal"
}
[]


isCommunityMember : Model -> Bool
Expand Down