2022-03-01 10:14:13 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
2023-04-26 17:31:34 +00:00
|
|
|
import QtQuick.Layouts 1.13
|
2022-03-01 10:14:13 +00:00
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Components 0.1
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Popups 0.1
|
2022-07-19 15:09:20 +00:00
|
|
|
import shared.controls 1.0
|
2023-03-08 13:44:22 +00:00
|
|
|
import SortFilterProxyModel 0.2
|
2022-03-01 10:14:13 +00:00
|
|
|
|
2022-07-19 15:09:20 +00:00
|
|
|
import "../stores"
|
2022-03-01 10:14:13 +00:00
|
|
|
import "../popups"
|
|
|
|
import "../controls"
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: root
|
2022-07-19 13:16:14 +00:00
|
|
|
anchors.leftMargin: Style.current.padding
|
|
|
|
anchors.rightMargin: Style.current.padding
|
2022-03-01 10:14:13 +00:00
|
|
|
|
2022-07-19 15:09:20 +00:00
|
|
|
property var sendModal
|
2022-03-01 10:14:13 +00:00
|
|
|
property var contactsStore
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: _internal
|
|
|
|
property bool loading: false
|
|
|
|
property string error: ""
|
2023-02-20 10:57:45 +00:00
|
|
|
property var lastCreatedAddress // used to display animation for the newly saved address
|
|
|
|
function saveAddress(name, address, favourite, chainShortNames, ens) {
|
2022-09-05 09:15:47 +00:00
|
|
|
loading = true
|
2023-02-20 10:57:45 +00:00
|
|
|
error = RootStore.createOrUpdateSavedAddress(name, address, favourite, chainShortNames, ens)
|
2022-09-05 09:15:47 +00:00
|
|
|
loading = false
|
|
|
|
}
|
2023-02-20 10:57:45 +00:00
|
|
|
function deleteSavedAddress(address, ens) {
|
2022-09-05 09:15:47 +00:00
|
|
|
loading = true
|
2023-02-20 10:57:45 +00:00
|
|
|
error = RootStore.deleteSavedAddress(address, ens)
|
2022-09-05 09:15:47 +00:00
|
|
|
loading = false
|
|
|
|
}
|
2023-02-20 10:57:45 +00:00
|
|
|
|
|
|
|
function resetLastCreatedAddress() {
|
|
|
|
lastCreatedAddress = undefined
|
|
|
|
}
|
2022-03-01 10:14:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: header
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.top: parent.top
|
|
|
|
height: btnAdd.height
|
|
|
|
|
2022-07-19 13:16:14 +00:00
|
|
|
StatusBaseText {
|
2022-03-01 10:14:13 +00:00
|
|
|
anchors.left: parent.left
|
2022-07-19 13:16:14 +00:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
id: title
|
|
|
|
text: qsTr("Saved addresses")
|
|
|
|
font.weight: Font.Bold
|
|
|
|
font.pixelSize: 28
|
|
|
|
color: Theme.palette.directColor1
|
2022-03-01 10:14:13 +00:00
|
|
|
}
|
|
|
|
StatusButton {
|
2022-08-03 10:08:46 +00:00
|
|
|
objectName: "addNewAddressBtn"
|
2022-03-01 10:14:13 +00:00
|
|
|
id: btnAdd
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.top: parent.top
|
2022-07-19 13:16:14 +00:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
size: StatusBaseButton.Size.Small
|
|
|
|
font.weight: Font.Medium
|
|
|
|
text: qsTr("Add new address")
|
2022-03-01 10:14:13 +00:00
|
|
|
visible: !_internal.loading
|
|
|
|
onClicked: {
|
|
|
|
Global.openPopup(addEditSavedAddress)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
StatusLoadingIndicator {
|
|
|
|
anchors.centerIn: parent
|
|
|
|
visible: _internal.loading
|
|
|
|
color: Theme.palette.directColor4
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SavedAddressesError {
|
|
|
|
id: errorMessage
|
|
|
|
anchors.top: header.bottom
|
|
|
|
anchors.topMargin: Style.current.padding
|
|
|
|
visible: _internal.error !== ""
|
|
|
|
text: _internal.error
|
|
|
|
height: visible ? 36 : 0
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusBaseText {
|
|
|
|
anchors.centerIn: parent
|
|
|
|
visible: listView.count === 0
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
text: qsTr("No saved addresses")
|
|
|
|
}
|
|
|
|
|
2022-07-14 11:03:36 +00:00
|
|
|
StatusListView {
|
|
|
|
id: listView
|
2022-08-24 08:23:43 +00:00
|
|
|
objectName: "SavedAddressesView_savedAddresses"
|
2023-04-26 17:31:34 +00:00
|
|
|
anchors.top: header.bottom
|
2022-03-01 10:14:13 +00:00
|
|
|
anchors.topMargin: Style.current.padding
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.left: parent.left
|
2022-07-14 11:03:36 +00:00
|
|
|
spacing: 5
|
2023-04-26 17:31:34 +00:00
|
|
|
visible: count > 0
|
2023-03-08 13:44:22 +00:00
|
|
|
model: SortFilterProxyModel {
|
|
|
|
sourceModel: RootStore.savedAddresses
|
|
|
|
sorters: RoleSorter { roleName: "createdAt"; sortOrder: Qt.DescendingOrder }
|
|
|
|
}
|
2022-09-05 09:15:47 +00:00
|
|
|
delegate: SavedAddressesDelegate {
|
2023-02-20 10:57:45 +00:00
|
|
|
id: savedAddressDelegate
|
2022-08-24 08:23:43 +00:00
|
|
|
objectName: "savedAddressView_Delegate_" + name
|
2022-09-05 09:15:47 +00:00
|
|
|
name: model.name
|
|
|
|
address: model.address
|
2023-02-20 10:57:45 +00:00
|
|
|
chainShortNames: model.chainShortNames
|
2022-10-20 13:33:23 +00:00
|
|
|
ens: model.ens
|
2022-08-18 14:44:48 +00:00
|
|
|
favourite: model.favourite
|
2022-09-05 09:15:47 +00:00
|
|
|
store: RootStore
|
|
|
|
contactsStore: root.contactsStore
|
2023-07-03 09:23:26 +00:00
|
|
|
areTestNetworksEnabled: RootStore.areTestNetworksEnabled
|
2023-02-20 10:57:45 +00:00
|
|
|
onOpenSendModal: root.sendModal.open(recipient);
|
|
|
|
saveAddress: function(name, address, favourite, chainShortNames, ens) {
|
|
|
|
_internal.saveAddress(name, address, favourite, chainShortNames, ens)
|
2022-09-05 09:15:47 +00:00
|
|
|
}
|
2023-02-20 10:57:45 +00:00
|
|
|
deleteSavedAddress: function(address, ens) {
|
|
|
|
_internal.deleteSavedAddress(address, ens)
|
2022-09-05 09:15:47 +00:00
|
|
|
}
|
2023-02-20 10:57:45 +00:00
|
|
|
|
|
|
|
states: [
|
|
|
|
State {
|
|
|
|
name: "highlighted"
|
|
|
|
when: _internal.lastCreatedAddress ? (_internal.lastCreatedAddress.address.toLowerCase() === address.toLowerCase() &&
|
|
|
|
_internal.lastCreatedAddress.ens === ens) : false
|
|
|
|
PropertyChanges { target: savedAddressDelegate; color: Theme.palette.baseColor2 }
|
|
|
|
StateChangeScript {
|
|
|
|
script: Qt.callLater(_internal.resetLastCreatedAddress)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
transitions: [
|
|
|
|
Transition {
|
|
|
|
from: "highlighted"
|
|
|
|
ColorAnimation {
|
|
|
|
target: savedAddressDelegate
|
|
|
|
duration: 3000
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2022-09-05 09:15:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: addEditSavedAddress
|
|
|
|
AddEditSavedAddressPopup {
|
|
|
|
id: addEditModal
|
|
|
|
anchors.centerIn: parent
|
|
|
|
onClosed: destroy()
|
|
|
|
contactsStore: root.contactsStore
|
2023-02-20 10:57:45 +00:00
|
|
|
store: RootStore
|
2022-09-05 09:15:47 +00:00
|
|
|
onSave: {
|
2023-02-20 10:57:45 +00:00
|
|
|
_internal.lastCreatedAddress = { address: address, ens: ens }
|
|
|
|
_internal.saveAddress(name, address, favourite, chainShortNames, ens)
|
2022-09-05 09:15:47 +00:00
|
|
|
close()
|
|
|
|
}
|
|
|
|
}
|
2022-03-01 10:14:13 +00:00
|
|
|
}
|
|
|
|
}
|