parent
7cbe7332b8
commit
1f3aef3a0b
|
@ -10,6 +10,12 @@ method load*(self: AccessInterface) {.base.} =
|
|||
method isLoaded*(self: AccessInterface): bool {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method onActivated*(self: AccessInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method loadDapps*(self: AccessInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method hasPermission*(self: AccessInterface, hostname: string, address: string, permission: string): bool =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ type
|
|||
view: View
|
||||
viewVariant: QVariant
|
||||
moduleLoaded: bool
|
||||
dappsLoaded: bool
|
||||
controller: Controller
|
||||
|
||||
proc newModule*(
|
||||
|
@ -30,6 +31,7 @@ proc newModule*(
|
|||
result.view = view.newView(result)
|
||||
result.viewVariant = newQVariant(result.view)
|
||||
result.moduleLoaded = false
|
||||
result.dappsLoaded = false
|
||||
result.controller = controller.newController(result, dappPermissionsService, walletAccountServive)
|
||||
|
||||
method delete*(self: Module) =
|
||||
|
@ -74,10 +76,21 @@ method isLoaded*(self: Module): bool =
|
|||
return self.moduleLoaded
|
||||
|
||||
method viewDidLoad*(self: Module) =
|
||||
self.fetchDapps()
|
||||
self.moduleLoaded = true
|
||||
self.delegate.dappsDidLoad()
|
||||
|
||||
|
||||
method loadDapps*(self: Module) =
|
||||
if self.dappsLoaded:
|
||||
return
|
||||
|
||||
self.fetchDapps()
|
||||
|
||||
self.dappsLoaded = true
|
||||
|
||||
method onActivated*(self: Module) =
|
||||
self.loadDapps()
|
||||
|
||||
method hasPermission*(self: Module, hostname: string, address: string, permission: string): bool =
|
||||
self.controller.hasPermission(hostname, address, permission.toPermission())
|
||||
|
||||
|
|
|
@ -40,6 +40,9 @@ QtObject:
|
|||
read = getDappsModel
|
||||
notify = modelChanged
|
||||
|
||||
proc loadDapps(self: View) {.slot.} =
|
||||
self.delegate.loadDapps()
|
||||
|
||||
proc hasPermission(self: View, hostname: string, address: string, permission: string): bool {.slot.} =
|
||||
return self.delegate.hasPermission(hostname, address, permission)
|
||||
|
||||
|
|
|
@ -71,6 +71,7 @@ method load*(self: Module) =
|
|||
|
||||
method onActivated*(self: Module) =
|
||||
self.bookmarkModule.onActivated()
|
||||
self.dappsModule.onActivated()
|
||||
|
||||
method isLoaded*(self: Module): bool =
|
||||
return self.moduleLoaded
|
||||
|
|
|
@ -16,6 +16,7 @@ logScope:
|
|||
type
|
||||
Service* = ref object
|
||||
dapps: Table[string, Dapp]
|
||||
permissionsFetched: bool
|
||||
|
||||
type R = Result[Dapp, string]
|
||||
|
||||
|
@ -25,8 +26,13 @@ proc delete*(self: Service) =
|
|||
proc newService*(): Service =
|
||||
result = Service()
|
||||
result.dapps = initTable[string, Dapp]()
|
||||
result.permissionsFetched = false
|
||||
|
||||
proc init*(self: Service) =
|
||||
discard
|
||||
|
||||
proc fetchDappPermissions*(self: Service) =
|
||||
# TODO later we can make this async, but it's not worth it for now
|
||||
try:
|
||||
let response = backend.getDappPermissions()
|
||||
for dapp in response.result.getElems().mapIt(it.toDapp()):
|
||||
|
@ -34,11 +40,13 @@ proc init*(self: Service) =
|
|||
continue
|
||||
|
||||
self.dapps[dapp.name & dapp.address] = dapp
|
||||
self.permissionsFetched = true
|
||||
except Exception as e:
|
||||
let errDescription = e.msg
|
||||
error "error: ", errDescription
|
||||
error "error fetching permissions: ", msg=e.msg
|
||||
|
||||
proc getDapps*(self: Service): seq[Dapp] =
|
||||
if not self.permissionsFetched:
|
||||
self.fetchDappPermissions()
|
||||
return toSeq(self.dapps.values)
|
||||
|
||||
proc getDapp*(self: Service, name: string, address: string): Option[Dapp] =
|
||||
|
|
|
@ -49,4 +49,8 @@ QtObject {
|
|||
function disconnectAddress(dappName, address) {
|
||||
return dappPermissionsModule.disconnectAddress(dappName, address)
|
||||
}
|
||||
|
||||
function loadDapps() {
|
||||
dappPermissionsModule.loadDapps()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,12 @@ Column {
|
|||
signal goToAccountView(address: string)
|
||||
signal goToDappPermissionsView()
|
||||
|
||||
Component.onCompleted: {
|
||||
// TODO remove this call and handle it from the backend
|
||||
// once the profile is refactored and the navigation is driven from the backend
|
||||
root.walletStore.loadDapps()
|
||||
}
|
||||
|
||||
Separator {
|
||||
height: 17
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue