feat: saved address view

Connect list and change
Provide view API
Create events
This commit is contained in:
Anthony Laibe 2021-12-15 11:08:47 +01:00 committed by Sale Djenic
parent 129266497d
commit fdca0da77d
9 changed files with 74 additions and 19 deletions

View File

@ -171,7 +171,7 @@ proc newAppController*(statusFoundation: StatusFoundation): AppController =
result.privacyService = privacy_service.newService() result.privacyService = privacy_service.newService()
result.ensService = ens_service.newService() result.ensService = ens_service.newService()
result.providerService = provider_service.newService(result.dappPermissionsService, result.settingsService, result.ensService) result.providerService = provider_service.newService(result.dappPermissionsService, result.settingsService, result.ensService)
result.savedAddressService = saved_address_service.newService() result.savedAddressService = saved_address_service.newService(statusFoundation.status.events)
# Modules # Modules
result.startupModule = startup_module.newModule[AppController]( result.startupModule = startup_module.newModule[AppController](

View File

@ -1,3 +1,4 @@
import eventemitter
import ./controller_interface import ./controller_interface
import io_interface import io_interface
import ../../../../../app_service/service/saved_address/service as saved_address_service import ../../../../../app_service/service/saved_address/service as saved_address_service
@ -7,27 +8,31 @@ export controller_interface
type type
Controller* = ref object of controller_interface.AccessInterface Controller* = ref object of controller_interface.AccessInterface
delegate: io_interface.AccessInterface delegate: io_interface.AccessInterface
events: EventEmitter
savedAddressService: saved_address_service.ServiceInterface savedAddressService: saved_address_service.ServiceInterface
proc newController*( proc newController*(
delegate: io_interface.AccessInterface, delegate: io_interface.AccessInterface,
events: EventEmitter,
savedAddressService: saved_address_service.ServiceInterface savedAddressService: saved_address_service.ServiceInterface
): Controller = ): Controller =
result = Controller() result = Controller()
result.delegate = delegate result.delegate = delegate
result.events = events
result.savedAddressService = savedAddressService result.savedAddressService = savedAddressService
method delete*(self: Controller) = method delete*(self: Controller) =
discard discard
method init*(self: Controller) = method init*(self: Controller) =
discard self.events.on(SIGNAL_SAVED_ADDRESS_CHANGED) do(e:Args):
self.delegate.loadSavedAddresses()
method getSavedAddresses*(self: Controller): seq[saved_address_service.SavedAddressDto] = method getSavedAddresses*(self: Controller): seq[saved_address_service.SavedAddressDto] =
return self.savedAddressService.getSavedAddresses() return self.savedAddressService.getSavedAddresses()
method addSavedAddress*(self: Controller, name, address: string) = method createOrUpdateSavedAddress*(self: Controller, name, address: string) =
self.savedAddressService.addSavedAddress(name, address) self.savedAddressService.createOrUpdateSavedAddress(name, address)
method deleteSavedAddress*(self: Controller, address: string) = method deleteSavedAddress*(self: Controller, address: string) =
self.savedAddressService.deleteSavedAddress(address) self.savedAddressService.deleteSavedAddress(address)

View File

@ -13,10 +13,10 @@ method init*(self: AccessInterface) {.base.} =
method getSavedAddresses*(self: AccessInterface): seq[saved_address_service.SavedAddressDto] {.base.} = method getSavedAddresses*(self: AccessInterface): seq[saved_address_service.SavedAddressDto] {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method addSavedAddresses*(self: AccessInterface, name, address: string) {.base.} = method createOrUpdateSavedAddress*(self: AccessInterface, name, address: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method deleteSavedAddresses*(self: AccessInterface, address: string) {.base.} = method deleteSavedAddress*(self: AccessInterface, address: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
type type

View File

@ -14,6 +14,15 @@ method isLoaded*(self: AccessInterface): bool {.base.} =
method viewDidLoad*(self: AccessInterface) {.base.} = method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method loadSavedAddresses*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method createOrUpdateSavedAddress*(self: AccessInterface, name, address: string) {.base.} =
raise newException(ValueError, "No implementation available")
method deleteSavedAddress*(self: AccessInterface, address: string) {.base.} =
raise newException(ValueError, "No implementation available")
type type
## Abstract class (concept) which must be implemented by object/s used in this ## Abstract class (concept) which must be implemented by object/s used in this
## module. ## module.

View File

@ -11,7 +11,6 @@ export io_interface
type type
Module* = ref object of io_interface.AccessInterface Module* = ref object of io_interface.AccessInterface
delegate: delegate_interface.AccessInterface delegate: delegate_interface.AccessInterface
events: EventEmitter
view: View view: View
moduleLoaded: bool moduleLoaded: bool
controller: controller.AccessInterface controller: controller.AccessInterface
@ -23,17 +22,14 @@ proc newModule*(
): Module = ): Module =
result = Module() result = Module()
result.delegate = delegate result.delegate = delegate
result.events = events
result.view = newView(result) result.view = newView(result)
result.controller = newController(result, savedAddressService) result.controller = newController(result, events, savedAddressService)
result.moduleLoaded = false result.moduleLoaded = false
method delete*(self: Module) = method delete*(self: Module) =
self.view.delete self.view.delete
method load*(self: Module) = method loadSavedAddresses*(self: Module) =
singletonInstance.engine.setRootContextProperty("walletSectionSavedAddresses", newQVariant(self.view))
let savedAddresses = self.controller.getSavedAddresses() let savedAddresses = self.controller.getSavedAddresses()
self.view.setItems( self.view.setItems(
savedAddresses.map(s => initItem( savedAddresses.map(s => initItem(
@ -42,6 +38,10 @@ method load*(self: Module) =
)) ))
) )
method load*(self: Module) =
singletonInstance.engine.setRootContextProperty("walletSectionSavedAddresses", newQVariant(self.view))
self.loadSavedAddresses()
self.controller.init() self.controller.init()
self.view.load() self.view.load()
@ -51,3 +51,9 @@ method isLoaded*(self: Module): bool =
method viewDidLoad*(self: Module) = method viewDidLoad*(self: Module) =
self.moduleLoaded = true self.moduleLoaded = true
self.delegate.savedAddressesModuleDidLoad() self.delegate.savedAddressesModuleDidLoad()
method createOrUpdateSavedAddress*(self: Module, name: string, address: string) =
self.controller.createOrUpdateSavedAddress(name, address)
method deleteSavedAddress*(self: Module, address: string) =
self.controller.deleteSavedAddress(address)

View File

@ -36,3 +36,9 @@ QtObject:
proc setItems*(self: View, items: seq[Item]) = proc setItems*(self: View, items: seq[Item]) =
self.model.setItems(items) self.model.setItems(items)
proc createOrUpdateSavedAddress*(self: View, name: string, address: string) {.slot.} =
self.delegate.createOrUpdateSavedAddress(name, address)
proc deleteSavedAddress*(self: View, address: string) {.slot.} =
self.delegate.deleteSavedAddress(address)

View File

@ -1,7 +1,6 @@
import chronicles, sequtils, json import chronicles, sequtils, json
import eventemitter
import ./service_interface, ./dto import ./service_interface, ./dto
import status/statusgo_backend_new/saved_addresses as backend import status/statusgo_backend_new/saved_addresses as backend
export service_interface export service_interface
@ -9,15 +8,19 @@ export service_interface
logScope: logScope:
topics = "saved-address-service" topics = "saved-address-service"
const SIGNAL_SAVED_ADDRESS_CHANGED* = "savedAddress/changed"
type type
Service* = ref object of service_interface.ServiceInterface Service* = ref object of service_interface.ServiceInterface
events: EventEmitter
savedAddresses: seq[SavedAddressDto] savedAddresses: seq[SavedAddressDto]
method delete*(self: Service) = method delete*(self: Service) =
discard discard
proc newService*(): Service = proc newService*(events: EventEmitter): Service =
result = Service() result = Service()
result.events = events
method init*(self: Service) = method init*(self: Service) =
try: try:
@ -34,9 +37,20 @@ method init*(self: Service) =
method getSavedAddresses(self: Service): seq[SavedAddressDto] = method getSavedAddresses(self: Service): seq[SavedAddressDto] =
return self.savedAddresses return self.savedAddresses
method addSavedAddress(self: Service, name, address: string) = method createOrUpdateSavedAddress(self: Service, name, address: string) =
try: try:
discard backend.addSavedAddress(name, address) discard backend.addSavedAddress(name, address)
var found = false
for savedAddress in self.savedAddresses:
if savedAddress.address == address:
savedAddress.name = name
found = true
break
if not found:
self.savedAddresses.add(newSavedAddressDto(name, address))
self.events.emit(SIGNAL_SAVED_ADDRESS_CHANGED, Args())
except Exception as e: except Exception as e:
let errDesription = e.msg let errDesription = e.msg
error "error: ", errDesription error "error: ", errDesription
@ -45,5 +59,12 @@ method addSavedAddress(self: Service, name, address: string) =
method deleteSavedAddress(self: Service, address: string) = method deleteSavedAddress(self: Service, address: string) =
try: try:
discard backend.deleteSavedAddress(address) discard backend.deleteSavedAddress(address)
for i in 0..<self.savedAddresses.len:
if self.savedAddresses[i].address == address:
self.savedAddresses.delete(i)
break
self.events.emit(SIGNAL_SAVED_ADDRESS_CHANGED, Args())
except Exception as e: except Exception as e:
let errDesription = e.msg let errDesription = e.msg

View File

@ -15,7 +15,7 @@ method init*(self: ServiceInterface) {.base.} =
method getSavedAddresses*(self: ServiceInterface): seq[SavedAddressDto] {.base.} = method getSavedAddresses*(self: ServiceInterface): seq[SavedAddressDto] {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method addSavedAddress*(self: ServiceInterface, name: string, address: string) {.base.} = method createOrUpdateSavedAddress*(self: ServiceInterface, name: string, address: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method deleteSavedAddress*(self: ServiceInterface, address: string) {.base.} = method deleteSavedAddress*(self: ServiceInterface, address: string) {.base.} =

View File

@ -28,8 +28,8 @@ QtObject {
property var history: walletSectionTransactions property var history: walletSectionTransactions
property var historyTransactions: walletSectionTransactions.model property var historyTransactions: walletSectionTransactions.model
// property var transactions: walletModel.transactionsView.transactions
// property var historyView: walletModel.historyView property var savedAddresses: walletSectionSavedAddresses.model
// This should be exposed to the UI via "walletModule", WalletModule should use // This should be exposed to the UI via "walletModule", WalletModule should use
// Accounts Service which keeps the info about that (isFirstTimeAccountLogin). // Accounts Service which keeps the info about that (isFirstTimeAccountLogin).
@ -187,4 +187,12 @@ QtObject {
// return parseInt(value) + qsTr(" of ") + // return parseInt(value) + qsTr(" of ") +
// walletModelV2Inst.collectiblesView.collections.getCollectionTraitMaxValue(collectionIndex, traitType).toString(); // walletModelV2Inst.collectiblesView.collections.getCollectionTraitMaxValue(collectionIndex, traitType).toString();
} }
function createOrUpdateSavedAddress(name, address) {
walletSectionSavedAddresses.createOrUpdateSavedAddress(name, address)
}
function deleteSavedAddress(address) {
walletSectionSavedAddresses.deleteSavedAddress(address)
}
} }