2024-02-08 16:59:53 +00:00
import QtQuick 2.15
import QtQuick . Controls 2.15
import QtQuick . Layouts 1.15
2023-03-22 15:48:44 +00:00
import StatusQ . Core 0.1
2024-10-15 19:26:12 +00:00
import StatusQ . Core . Theme 0.1
2023-03-22 15:48:44 +00:00
import StatusQ . Popups 0.1
import StatusQ . Controls 0.1
2024-08-05 08:18:17 +00:00
import StatusQ . Popups . Dialog 0.1
2023-03-22 15:48:44 +00:00
import utils 1.0
2024-01-23 08:15:07 +00:00
import shared . popups 1.0
2023-03-22 15:48:44 +00:00
import "./stores"
import "./states"
2023-08-04 12:41:57 +00:00
import "../common"
2023-03-22 15:48:44 +00:00
StatusModal {
id: root
2023-03-28 13:47:54 +00:00
property AddAccountStore store: AddAccountStore { }
2023-03-22 15:48:44 +00:00
2024-08-05 08:18:17 +00:00
enum LimitWarning {
Accounts ,
Keypairs ,
WatchOnlyAccounts
}
2023-03-22 15:48:44 +00:00
width: Constants . addAccountPopup . popupWidth
closePolicy: root . store . disablePopup ? Popup.NoAutoClose : Popup . CloseOnEscape | Popup . CloseOnPressOutside
hasCloseButton: ! root . store . disablePopup
2023-05-23 12:46:16 +00:00
headerSettings.title: root . store . editMode ? qsTr ( "Edit account" ) : qsTr ( "Add a new account" )
2023-03-22 15:48:44 +00:00
onOpened: {
root . store . resetStoreValues ( )
2024-08-05 08:18:17 +00:00
root . store . showLimitPopup . connect ( limitPopup . showPopup )
2023-03-22 15:48:44 +00:00
}
onClosed: {
root . store . currentState . doCancelAction ( )
}
2024-01-23 08:15:07 +00:00
Connections {
target: root . store . addAccountModule
function onConfirmSavedAddressRemoval ( name , address ) {
Global . openPopup ( confirmSavedAddressRemoval , { address: address , name: name } )
}
}
2023-05-31 20:58:23 +00:00
StatusScrollView {
2023-03-22 15:48:44 +00:00
id: scrollView
2023-05-31 20:58:23 +00:00
anchors.fill: parent
2023-03-22 15:48:44 +00:00
padding: 0
2023-05-31 20:58:23 +00:00
contentWidth: availableWidth
2023-03-22 15:48:44 +00:00
Item {
id: content
objectName: "AddAccountPopup-Content"
2023-05-31 20:58:23 +00:00
implicitWidth: loader . implicitWidth
implicitHeight: loader . implicitHeight
2023-03-22 15:48:44 +00:00
width: scrollView . availableWidth
2024-08-05 08:18:17 +00:00
Loader {
id: limitPopup
active: false
asynchronous: true
property string title
property string content
function showPopup ( warningType ) {
if ( warningType === AddAccountPopup . LimitWarning . Accounts ) {
limitPopup . title = Constants . walletConstants . maxNumberOfAccountsTitle
limitPopup . content = Constants . walletConstants . maxNumberOfAccountsContent
} else if ( warningType === AddAccountPopup . LimitWarning . Keypairs ) {
limitPopup . title = Constants . walletConstants . maxNumberOfKeypairsTitle
limitPopup . content = Constants . walletConstants . maxNumberOfKeypairsContent
} else if ( warningType === AddAccountPopup . LimitWarning . WatchOnlyAccounts ) {
limitPopup . title = Constants . walletConstants . maxNumberOfWatchOnlyAccountsTitle
limitPopup . content = Constants . walletConstants . maxNumberOfSavedAddressesContent
} else {
console . error ( "unsupported warning type" )
return
}
limitPopup . active = true
}
sourceComponent: StatusDialog {
2024-10-15 19:26:12 +00:00
width: root . width - 2 * Theme . padding
2024-08-05 08:18:17 +00:00
property string contentText
title: Constants . walletConstants . maxNumberOfAccountsTitle
StatusBaseText {
anchors.fill: parent
text: contentText
wrapMode: Text . WordWrap
}
standardButtons: Dialog . Ok
onClosed: {
limitPopup . active = false
}
}
onLoaded: {
limitPopup . item . title = limitPopup . title
limitPopup . item . contentText = limitPopup . content
limitPopup . item . open ( )
}
}
2023-03-22 15:48:44 +00:00
Loader {
id: loader
width: parent . width
sourceComponent: {
switch ( root . store . currentState . stateType ) {
case Constants.addAccountPopup.state.main:
return mainComponent
case Constants.addAccountPopup.state.confirmAddingNewMasterKey:
return confirmAddingNewMasterKeyComponent
case Constants.addAccountPopup.state.confirmSeedPhraseBackup:
return confirmSeedPhraseBackupComponent
case Constants.addAccountPopup.state.displaySeedPhrase:
return displaySeedPhraseComponent
case Constants.addAccountPopup.state.enterKeypairName:
return enterKeypairNameComponent
case Constants.addAccountPopup.state.enterPrivateKey:
return enterPrivateKeyComponent
case Constants.addAccountPopup.state.enterSeedPhraseWord1:
case Constants.addAccountPopup.state.enterSeedPhraseWord2:
return enterSeedPhraseWordComponent
case Constants.addAccountPopup.state.enterSeedPhrase:
return enterSeedPhraseComponent
case Constants.addAccountPopup.state.selectMasterKey:
return selectMasterKeyComponent
}
return undefined
}
onLoaded: {
content . height = Qt . binding ( function ( ) { return item . height } )
}
}
Component {
id: mainComponent
Main {
store: root . store
2024-08-05 08:18:17 +00:00
onWatchOnlyAccountsLimitReached: {
limitPopup . showPopup ( AddAccountPopup . LimitWarning . WatchOnlyAccounts )
}
onKeypairLimitReached: {
limitPopup . showPopup ( AddAccountPopup . LimitWarning . Keypairs )
}
2023-03-22 15:48:44 +00:00
}
}
Component {
id: confirmAddingNewMasterKeyComponent
ConfirmAddingNewMasterKey {
height: Constants . addAccountPopup . contentHeight1
store: root . store
}
}
Component {
id: confirmSeedPhraseBackupComponent
ConfirmSeedPhraseBackup {
height: Constants . addAccountPopup . contentHeight1
store: root . store
}
}
Component {
id: displaySeedPhraseComponent
DisplaySeedPhrase {
height: Constants . addAccountPopup . contentHeight1
store: root . store
}
}
Component {
id: enterKeypairNameComponent
EnterKeypairName {
height: Constants . addAccountPopup . contentHeight1
store: root . store
}
}
Component {
id: enterPrivateKeyComponent
EnterPrivateKey {
height: Constants . addAccountPopup . contentHeight1
store: root . store
}
}
Component {
id: enterSeedPhraseComponent
EnterSeedPhrase {
height: Constants . addAccountPopup . contentHeight2
store: root . store
}
}
Component {
id: enterSeedPhraseWordComponent
EnterSeedPhraseWord {
height: Constants . addAccountPopup . contentHeight1
store: root . store
}
}
Component {
id: selectMasterKeyComponent
SelectMasterKey {
height: Constants . addAccountPopup . contentHeight1
store: root . store
2023-07-24 10:04:54 +00:00
onContinueOnKeycard: {
root . close ( )
}
2023-03-22 15:48:44 +00:00
}
}
}
2024-01-23 08:15:07 +00:00
Component {
id: confirmSavedAddressRemoval
ConfirmationDialog {
property string name
property string address
closePolicy: Popup . NoAutoClose
hasCloseButton: false
headerSettings.title: qsTr ( "Removing saved address" )
confirmationText: qsTr ( "The account you're trying to add <b>%1</b> is already saved under the name <b>%2</b>.<br/><br/>Do you want to remove it from saved addresses in favour of adding it to the Wallet?" )
. arg ( address )
. arg ( name )
showCancelButton: true
cancelBtnType: ""
confirmButtonLabel: qsTr ( "Yes" )
cancelButtonLabel: qsTr ( "No" )
onConfirmButtonClicked: {
root . store . addAccountModule . removingSavedAddressConfirmed ( address )
close ( )
}
onCancelButtonClicked: {
root . store . addAccountModule . removingSavedAddressRejected ( )
close ( )
}
}
}
2023-03-22 15:48:44 +00:00
}
leftButtons: [
StatusBackButton {
id: backButton
objectName: "AddAccountPopup-BackButton"
visible: root . store . currentState . displayBackButton
enabled: ! root . store . disablePopup
2024-02-08 16:59:53 +00:00
Layout.minimumWidth: implicitWidth
2023-03-22 15:48:44 +00:00
onClicked: {
if ( root . store . currentState . stateType === Constants . addAccountPopup . state . confirmAddingNewMasterKey ) {
root . store . addingNewMasterKeyConfirmed = false
}
else if ( root . store . currentState . stateType === Constants . addAccountPopup . state . displaySeedPhrase ) {
root . store . seedPhraseRevealed = false
}
else if ( root . store . currentState . stateType === Constants . addAccountPopup . state . enterSeedPhraseWord1 ) {
root . store . seedPhraseWord1Valid = false
root . store . seedPhraseWord1WordNumber = - 1
root . store . seedPhraseWord2Valid = false
root . store . seedPhraseWord2WordNumber = - 1
}
else if ( root . store . currentState . stateType === Constants . addAccountPopup . state . confirmSeedPhraseBackup ) {
root . store . seedPhraseBackupConfirmed = false
}
else if ( root . store . currentState . stateType === Constants . addAccountPopup . state . enterKeypairName ) {
root . store . addAccountModule . newKeyPairName = ""
}
root . store . currentState . doBackAction ( )
}
}
]
rightButtons: [
StatusButton {
id: primaryButton
objectName: "AddAccountPopup-PrimaryButton"
type: root . store . currentState . stateType === Constants . addAccountPopup . state . main ?
StatusBaseButton.Type.Primary :
StatusBaseButton . Type . Normal
height: Constants . addAccountPopup . footerButtonsHeight
text: {
2023-03-30 13:00:55 +00:00
if ( root . store . editMode ) {
return qsTr ( "Save changes" )
}
2023-03-22 15:48:44 +00:00
switch ( root . store . currentState . stateType ) {
case Constants.addAccountPopup.state.main:
return qsTr ( "Add account" )
case Constants.addAccountPopup.state.enterPrivateKey:
case Constants.addAccountPopup.state.enterSeedPhrase:
case Constants.addAccountPopup.state.enterSeedPhraseWord1:
case Constants.addAccountPopup.state.enterSeedPhraseWord2:
case Constants.addAccountPopup.state.confirmSeedPhraseBackup:
case Constants.addAccountPopup.state.enterKeypairName:
return qsTr ( "Continue" )
case Constants.addAccountPopup.state.confirmAddingNewMasterKey:
return qsTr ( "Reveal seed phrase" )
case Constants.addAccountPopup.state.displaySeedPhrase:
return qsTr ( "Confirm seed phrase" )
}
return ""
}
visible: text !== ""
enabled: root . store . primaryPopupButtonEnabled
icon.name: {
2023-03-30 13:00:55 +00:00
if ( root . store . editMode ) {
return ""
}
2023-03-22 15:48:44 +00:00
if ( root . store . currentState . stateType === Constants . addAccountPopup . state . enterPrivateKey ||
root . store . currentState . stateType === Constants . addAccountPopup . state . enterSeedPhrase ||
root . store . currentState . stateType === Constants . addAccountPopup . state . confirmAddingNewMasterKey ||
root . store . currentState . stateType === Constants . addAccountPopup . state . displaySeedPhrase ||
root . store . currentState . stateType === Constants . addAccountPopup . state . enterSeedPhraseWord1 ||
root . store . currentState . stateType === Constants . addAccountPopup . state . enterSeedPhraseWord2 ||
root . store . currentState . stateType === Constants . addAccountPopup . state . confirmSeedPhraseBackup ||
root . store . currentState . stateType === Constants . addAccountPopup . state . enterKeypairName ||
root . store . addAccountModule . actionAuthenticated ||
root . store . selectedOrigin . pairType === Constants . addAccountPopup . keyPairType . unknown &&
root . store . selectedOrigin . keyUid === Constants . appTranslatableConstants . addAccountLabelOptionAddWatchOnlyAcc ) {
return ""
}
if ( root . store . selectedOrigin . keyUid === root . store . userProfileKeyUid &&
root . store . userProfileUsingBiometricLogin ) {
return "touch-id"
}
if ( root . store . selectedOrigin . migratedToKeycard || root . store . userProfileIsKeycardUser ) {
return "keycard"
}
return "password"
}
onClicked: {
2023-08-04 12:41:57 +00:00
root . store . submitPopup ( null )
2023-03-22 15:48:44 +00:00
}
}
]
}