2022-03-01 10:14:13 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
|
|
|
|
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
|
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"
|
2022-03-01 10:14:13 +00:00
|
|
|
anchors.top: errorMessage.bottom
|
|
|
|
anchors.topMargin: Style.current.padding
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.bottomMargin: Style.current.halfPadding
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.left: parent.left
|
|
|
|
visible: listView.count > 0
|
2022-07-14 11:03:36 +00:00
|
|
|
spacing: 5
|
|
|
|
model: RootStore.savedAddresses
|
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-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
|
|
|
}
|
|
|
|
}
|