status-desktop/ui/app/AppLayouts/Profile/views/EnsView.qml

364 lines
10 KiB
QML
Raw Normal View History

import QtQuick 2.14
2020-05-27 21:28:25 +00:00
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.14
import QtQml.StateMachine 1.14 as DSM
import utils 1.0
import shared 1.0
import "../stores"
2020-05-27 21:28:25 +00:00
Item {
id: ensView
2020-05-27 21:28:25 +00:00
property var store
property var contactsStore
property var messageStore
property int profileContentWidth
property bool showSearchScreen: false
property string addedUsername: ""
2020-08-06 19:45:57 +00:00
property string selectedUsername: ""
signal next(output: string)
2020-08-06 19:45:57 +00:00
signal back()
2020-08-27 16:06:53 +00:00
signal done(ensUsername: string)
signal connect(ensUsername: string)
signal changePubKey(ensUsername: string)
signal goToWelcome();
signal goToList();
function goToStart(){
if(ensView.store.ens.rowCount() > 0 && Global.networkGuarded){
goToList();
} else {
goToWelcome();
}
}
Layout.fillHeight: true
Layout.fillWidth: true
clip: true
DSM.StateMachine {
id: stateMachine
initialState: welcomeState
running: true
DSM.State {
id: welcomeState
onEntered: loader.sourceComponent = welcome
DSM.SignalTransition {
targetState: searchState
signal: next
}
DSM.SignalTransition {
targetState: listState
signal: goToList
}
}
DSM.State {
id: searchState
onEntered: loader.sourceComponent = search
DSM.SignalTransition {
targetState: tAndCState
signal: next
guard: output === "available"
}
DSM.SignalTransition {
targetState: addedState
signal: connect
}
DSM.SignalTransition {
targetState: listState
signal: goToList
}
DSM.SignalTransition {
targetState: welcomeState
signal: goToWelcome
}
DSM.SignalTransition {
targetState: ensConnectedState
signal: done
}
}
DSM.State {
id: addedState
onEntered: {
loader.sourceComponent = added;
loader.item.ensUsername = addedUsername;
}
DSM.SignalTransition {
targetState: listState
signal: next
}
DSM.SignalTransition {
targetState: listState
signal: goToList
}
DSM.SignalTransition {
targetState: welcomeState
signal: goToWelcome
}
}
DSM.State {
id: listState
onEntered: {
loader.sourceComponent = list;
}
DSM.SignalTransition {
targetState: searchState
signal: next
2020-08-06 19:45:57 +00:00
guard: output === "search"
}
DSM.SignalTransition {
targetState: detailsState
signal: next
guard: output === "details"
}
DSM.SignalTransition {
targetState: listState
signal: goToList
}
DSM.SignalTransition {
targetState: welcomeState
signal: goToWelcome
}
}
DSM.State {
id: detailsState
onEntered: {
loader.sourceComponent = details;
}
DSM.SignalTransition {
targetState: listState
signal: back
}
DSM.SignalTransition {
targetState: listState
signal: goToList
}
DSM.SignalTransition {
targetState: welcomeState
signal: goToWelcome
}
2021-08-09 22:23:52 +00:00
DSM.SignalTransition {
targetState: ensReleasedState
signal: done
}
}
DSM.State {
id: tAndCState
onEntered:loader.sourceComponent = termsAndConditions
DSM.SignalTransition {
targetState: listState
signal: goToList
}
DSM.SignalTransition {
targetState: welcomeState
signal: goToWelcome
}
DSM.SignalTransition {
targetState: listState
signal: back
}
2020-08-27 16:06:53 +00:00
DSM.SignalTransition {
targetState: listState
signal: back
}
DSM.SignalTransition {
targetState: ensRegisteredState
signal: done
}
}
DSM.State {
id: ensRegisteredState
onEntered:loader.sourceComponent = ensRegistered
DSM.SignalTransition {
targetState: listState
signal: next
}
}
2021-08-09 22:23:52 +00:00
DSM.State {
id: ensReleasedState
onEntered:loader.sourceComponent = ensReleased
DSM.SignalTransition {
targetState: listState
signal: next
}
}
DSM.State {
id: ensConnectedState
onEntered:loader.sourceComponent = ensConnected
DSM.SignalTransition {
targetState: listState
signal: next
}
}
}
Loader {
id: loader
anchors.fill: parent
}
Component {
id: welcome
EnsWelcomeView {
username: ensView.store.username
2020-08-07 16:27:41 +00:00
onStartBtnClicked: next(null)
profileContentWidth: ensView.profileContentWidth
}
}
Component {
id: search
EnsSearchView {
store: ensView.store
contactsStore: ensView.contactsStore
profileContentWidth: ensView.profileContentWidth
2020-08-07 16:27:41 +00:00
onContinueClicked: {
if(output === "connected"){
connect(username)
} else {
selectedUsername = username;
next(output);
}
}
onUsernameUpdated: {
selectedUsername = username;
done(username);
}
}
}
Component {
id: termsAndConditions
EnsTermsAndConditionsView {
store: ensView.store
username: selectedUsername
onBackBtnClicked: back();
2020-08-27 16:06:53 +00:00
onUsernameRegistered: done(userName);
}
}
Component {
id: added
EnsAddedView {
2020-08-07 16:27:41 +00:00
onOkBtnClicked: next(null)
}
}
2020-08-27 16:06:53 +00:00
Component {
id: ensRegistered
EnsRegisteredView {
2020-08-27 16:06:53 +00:00
ensUsername: selectedUsername
onOkBtnClicked: next(null)
}
}
2021-08-09 22:23:52 +00:00
Component {
id: ensReleased
EnsReleasedView {
2021-08-09 22:23:52 +00:00
ensUsername: selectedUsername
onOkBtnClicked: next(null)
}
}
Component {
id: ensConnected
EnsConnectedView {
ensUsername: selectedUsername
onOkBtnClicked: next(null)
}
}
Component {
id: list
EnsListView {
store: ensView.store
messageStore: ensView.messageStore
profileContentWidth: ensView.profileContentWidth
2020-08-07 16:27:41 +00:00
onAddBtnClicked: next("search")
onSelectEns: {
ensView.store.ensDetails(username)
2020-08-06 19:45:57 +00:00
selectedUsername = username;
next("details")
}
}
}
Component {
id: details
EnsDetailsView {
store: ensView.store
contactsStore: ensView.contactsStore
2020-08-06 19:45:57 +00:00
username: selectedUsername
2020-08-07 16:27:41 +00:00
onBackBtnClicked: back();
2021-08-09 22:23:52 +00:00
onUsernameReleased: {
selectedUsername = username;
done(username);
}
}
}
Connections {
target: ensView
onConnect: {
addedUsername = ensUsername;
}
2020-05-27 21:28:25 +00:00
}
Connections {
target: ensView.store.ens
onTransactionWasSent: {
2020-09-18 06:33:20 +00:00
//% "Transaction pending..."
Global.toastMessage.title = qsTrId("ens-transaction-pending")
Global.toastMessage.source = Style.svg("loading")
Global.toastMessage.iconColor = Style.current.primary
Global.toastMessage.iconRotates = true
Global.toastMessage.link = `${root.store.etherscanLink}/${txResult}`
Global.toastMessage.open()
}
onTransactionCompleted: {
switch(trxType){
case "RegisterENS":
Global.toastMessage.title = !success ?
2020-09-18 06:33:20 +00:00
//% "ENS Registration failed"
qsTrId("ens-registration-failed")
2020-09-14 19:41:09 +00:00
:
2020-09-18 06:33:20 +00:00
//% "ENS Registration completed"
qsTrId("ens-registration-completed");
break;
case "SetPubKey":
Global.toastMessage.title = !success ?
2020-09-18 06:33:20 +00:00
//% "Updating ENS pubkey failed"
qsTrId("updating-ens-pubkey-failed")
2020-09-14 19:41:09 +00:00
:
2020-09-18 06:33:20 +00:00
//% "Updating ENS pubkey completed"
qsTrId("updating-ens-pubkey-completed");
break;
}
if (success) {
Global.toastMessage.source = Style.svg("check-circle")
Global.toastMessage.iconColor = Style.current.success
} else {
Global.toastMessage.source = Style.svg("block-icon")
Global.toastMessage.iconColor = Style.current.danger
}
Global.toastMessage.link = `${root.store.etherscanLink}/${txHash}`
Global.toastMessage.open()
}
}
2020-05-27 21:28:25 +00:00
}