feat: saved address view
Connect list and change Provide view API Create events
This commit is contained in:
parent
129266497d
commit
fdca0da77d
|
@ -171,7 +171,7 @@ proc newAppController*(statusFoundation: StatusFoundation): AppController =
|
|||
result.privacyService = privacy_service.newService()
|
||||
result.ensService = ens_service.newService()
|
||||
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
|
||||
result.startupModule = startup_module.newModule[AppController](
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import eventemitter
|
||||
import ./controller_interface
|
||||
import io_interface
|
||||
import ../../../../../app_service/service/saved_address/service as saved_address_service
|
||||
|
@ -7,27 +8,31 @@ export controller_interface
|
|||
type
|
||||
Controller* = ref object of controller_interface.AccessInterface
|
||||
delegate: io_interface.AccessInterface
|
||||
events: EventEmitter
|
||||
savedAddressService: saved_address_service.ServiceInterface
|
||||
|
||||
proc newController*(
|
||||
delegate: io_interface.AccessInterface,
|
||||
events: EventEmitter,
|
||||
savedAddressService: saved_address_service.ServiceInterface
|
||||
): Controller =
|
||||
result = Controller()
|
||||
result.delegate = delegate
|
||||
result.events = events
|
||||
result.savedAddressService = savedAddressService
|
||||
|
||||
method delete*(self: Controller) =
|
||||
discard
|
||||
|
||||
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] =
|
||||
return self.savedAddressService.getSavedAddresses()
|
||||
|
||||
method addSavedAddress*(self: Controller, name, address: string) =
|
||||
self.savedAddressService.addSavedAddress(name, address)
|
||||
method createOrUpdateSavedAddress*(self: Controller, name, address: string) =
|
||||
self.savedAddressService.createOrUpdateSavedAddress(name, address)
|
||||
|
||||
method deleteSavedAddress*(self: Controller, address: string) =
|
||||
self.savedAddressService.deleteSavedAddress(address)
|
||||
|
|
|
@ -13,10 +13,10 @@ method init*(self: AccessInterface) {.base.} =
|
|||
method getSavedAddresses*(self: AccessInterface): seq[saved_address_service.SavedAddressDto] {.base.} =
|
||||
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")
|
||||
|
||||
method deleteSavedAddresses*(self: AccessInterface, address: string) {.base.} =
|
||||
method deleteSavedAddress*(self: AccessInterface, address: string) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
type
|
||||
|
|
|
@ -14,6 +14,15 @@ method isLoaded*(self: AccessInterface): bool {.base.} =
|
|||
method viewDidLoad*(self: AccessInterface) {.base.} =
|
||||
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
|
||||
## Abstract class (concept) which must be implemented by object/s used in this
|
||||
## module.
|
||||
|
|
|
@ -11,7 +11,6 @@ export io_interface
|
|||
type
|
||||
Module* = ref object of io_interface.AccessInterface
|
||||
delegate: delegate_interface.AccessInterface
|
||||
events: EventEmitter
|
||||
view: View
|
||||
moduleLoaded: bool
|
||||
controller: controller.AccessInterface
|
||||
|
@ -23,17 +22,14 @@ proc newModule*(
|
|||
): Module =
|
||||
result = Module()
|
||||
result.delegate = delegate
|
||||
result.events = events
|
||||
result.view = newView(result)
|
||||
result.controller = newController(result, savedAddressService)
|
||||
result.controller = newController(result, events, savedAddressService)
|
||||
result.moduleLoaded = false
|
||||
|
||||
method delete*(self: Module) =
|
||||
self.view.delete
|
||||
|
||||
method load*(self: Module) =
|
||||
singletonInstance.engine.setRootContextProperty("walletSectionSavedAddresses", newQVariant(self.view))
|
||||
|
||||
method loadSavedAddresses*(self: Module) =
|
||||
let savedAddresses = self.controller.getSavedAddresses()
|
||||
self.view.setItems(
|
||||
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.view.load()
|
||||
|
||||
|
@ -51,3 +51,9 @@ method isLoaded*(self: Module): bool =
|
|||
method viewDidLoad*(self: Module) =
|
||||
self.moduleLoaded = true
|
||||
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)
|
||||
|
|
|
@ -36,3 +36,9 @@ QtObject:
|
|||
|
||||
proc setItems*(self: View, items: seq[Item]) =
|
||||
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)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import chronicles, sequtils, json
|
||||
|
||||
import eventemitter
|
||||
import ./service_interface, ./dto
|
||||
|
||||
import status/statusgo_backend_new/saved_addresses as backend
|
||||
|
||||
export service_interface
|
||||
|
@ -9,15 +8,19 @@ export service_interface
|
|||
logScope:
|
||||
topics = "saved-address-service"
|
||||
|
||||
const SIGNAL_SAVED_ADDRESS_CHANGED* = "savedAddress/changed"
|
||||
|
||||
type
|
||||
Service* = ref object of service_interface.ServiceInterface
|
||||
events: EventEmitter
|
||||
savedAddresses: seq[SavedAddressDto]
|
||||
|
||||
method delete*(self: Service) =
|
||||
discard
|
||||
|
||||
proc newService*(): Service =
|
||||
proc newService*(events: EventEmitter): Service =
|
||||
result = Service()
|
||||
result.events = events
|
||||
|
||||
method init*(self: Service) =
|
||||
try:
|
||||
|
@ -34,9 +37,20 @@ method init*(self: Service) =
|
|||
method getSavedAddresses(self: Service): seq[SavedAddressDto] =
|
||||
return self.savedAddresses
|
||||
|
||||
method addSavedAddress(self: Service, name, address: string) =
|
||||
method createOrUpdateSavedAddress(self: Service, name, address: string) =
|
||||
try:
|
||||
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:
|
||||
let errDesription = e.msg
|
||||
error "error: ", errDesription
|
||||
|
@ -45,5 +59,12 @@ method addSavedAddress(self: Service, name, address: string) =
|
|||
method deleteSavedAddress(self: Service, address: string) =
|
||||
try:
|
||||
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:
|
||||
let errDesription = e.msg
|
||||
|
|
|
@ -15,7 +15,7 @@ method init*(self: ServiceInterface) {.base.} =
|
|||
method getSavedAddresses*(self: ServiceInterface): seq[SavedAddressDto] {.base.} =
|
||||
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")
|
||||
|
||||
method deleteSavedAddress*(self: ServiceInterface, address: string) {.base.} =
|
||||
|
|
|
@ -28,8 +28,8 @@ QtObject {
|
|||
|
||||
property var history: walletSectionTransactions
|
||||
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
|
||||
// Accounts Service which keeps the info about that (isFirstTimeAccountLogin).
|
||||
|
@ -187,4 +187,12 @@ QtObject {
|
|||
// return parseInt(value) + qsTr(" of ") +
|
||||
// walletModelV2Inst.collectiblesView.collections.getCollectionTraitMaxValue(collectionIndex, traitType).toString();
|
||||
}
|
||||
|
||||
function createOrUpdateSavedAddress(name, address) {
|
||||
walletSectionSavedAddresses.createOrUpdateSavedAddress(name, address)
|
||||
}
|
||||
|
||||
function deleteSavedAddress(address) {
|
||||
walletSectionSavedAddresses.deleteSavedAddress(address)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue