2022-03-31 11:46:25 +00:00
import QtQuick 2.12
import QtQml . Models 2.14
import StatusQ . Core . Theme 0.1
import StatusQ . Controls 0.1
import StatusQ . Components 0.1
import StatusQ . Core . Utils 0.1
import utils 1.0
import "../stores"
StatusSelect {
id: selectAccountType
property int addAccountType
property string derivedFromAddress: ""
2022-10-27 09:26:34 +00:00
property string selectedKeyUid: userProfile . keyUid
property bool selectedKeyUidMigratedToKeycard: userProfile . isKeycardUser
2022-03-31 11:46:25 +00:00
function resetMe ( ) {
_internal . getGeneratedAccountsModel ( )
2023-01-18 09:25:36 +00:00
selectAccountType . addAccountType = Constants . AddAccountType . GenerateNew
2022-10-27 09:26:34 +00:00
selectAccountType . selectedKeyUid = userProfile . keyUid
selectAccountType . selectedKeyUidMigratedToKeycard = userProfile . isKeycardUser
2022-03-31 11:46:25 +00:00
}
Connections {
target: RootStore . generatedAccountsViewModel
2023-01-18 09:25:36 +00:00
function onModelReset ( ) {
2022-03-31 11:46:25 +00:00
_internal . delegateModel . model = RootStore . generatedAccountsViewModel
_internal . getGeneratedAccountsModel ( )
}
}
QtObject {
id: _internal
2023-02-24 12:59:14 +00:00
property string importSeedPhraseID: "importNewSeedPhrase"
property string importPrivateKeyID: "generateFromPrivateKey"
property string addWatchOnlyAccountID: "watchOnlyAccount"
2022-03-31 11:46:25 +00:00
property var delegateModel: DelegateModel {
model: RootStore . generatedAccountsViewModel
onModelUpdated: {
_internal . getGeneratedAccountsModel ( )
}
}
property ListModel generatedAccountsModel: ListModel { }
function getGeneratedAccountsModel ( ) {
if ( generatedAccountsModel ) {
generatedAccountsModel . clear ( )
for ( var row = 0 ; row < _internal . delegateModel . model . count ; row ++ ) {
2022-05-16 15:02:03 +00:00
if ( _internal . delegateModel . items . count > 0 ) {
var item = _internal . delegateModel . items . get ( row ) . model ;
2022-10-27 09:26:34 +00:00
generatedAccountsModel . append ( { "name" : item . name , "iconName" : item . iconName , "generatedModel" : item . generatedModel , "derivedfrom" : item . derivedfrom , "isHeader" : false ,
"keyUid" : item . keyUid , "migratedToKeycard" : item . migratedToKeycard } )
2022-05-16 15:02:03 +00:00
if ( row === 0 && _internal . delegateModel . model . count > 1 ) {
2022-10-27 09:26:34 +00:00
generatedAccountsModel . append ( { "name" : qsTr ( "Imported" ) , "iconName" : "" , "derivedfrom" : "" , "isHeader" : true , "keyUid" : "" , "migratedToKeycard" : false } )
2022-05-16 15:02:03 +00:00
}
2022-03-31 11:46:25 +00:00
}
}
2022-10-27 09:26:34 +00:00
generatedAccountsModel . append ( { "name" : qsTr ( "Add new" ) , "iconName" : "" , "derivedfrom" : "" , "isHeader" : true , "keyUid" : "" , "migratedToKeycard" : false } )
2023-02-24 12:59:14 +00:00
generatedAccountsModel . append ( { "name" : qsTr ( "Import new Seed Phrase" ) , "iconName" : "seed-phrase" , "derivedfrom" : "" , "isHeader" : false , "keyUid" : "" , "migratedToKeycard" : false , "objectName" : _internal . importSeedPhraseID } )
generatedAccountsModel . append ( { "name" : qsTr ( "Generate from Private key" ) , "iconName" : "password" , "derivedfrom" : "" , "isHeader" : false , "keyUid" : "" , "migratedToKeycard" : false , "objectName" : _internal . importPrivateKeyID } )
generatedAccountsModel . append ( { "name" : qsTr ( "Add a watch-only address" ) , "iconName" : "show" , "derivedfrom" : "" , "isHeader" : false , "keyUid" : "" , "migratedToKeycard" : false , "objectName" : _internal . addWatchOnlyAccountID } )
2022-03-31 11:46:25 +00:00
}
}
}
label: qsTr ( "Origin" )
model: _internal . generatedAccountsModel
selectedItemComponent: StatusListItem {
id: selectedItem
2022-08-11 11:55:08 +00:00
asset.bgColor: "transparent"
2022-03-31 11:46:25 +00:00
border.width: 1
border.color: Theme . palette . baseColor2
tagsDelegate: StatusListItemTag {
2022-12-21 13:57:41 +00:00
bgColor: model . color
bgRadius: 6
2022-03-31 11:46:25 +00:00
height: Style . current . bigPadding
closeButtonVisible: false
2022-08-11 11:55:08 +00:00
asset.emoji: model . emoji
asset.emojiSize: Emoji . size . verySmall
asset.isLetterIdenticon: true
2022-03-31 11:46:25 +00:00
title: model . name
titleText.font.pixelSize: 12
titleText.color: Theme . palette . indirectColor1
}
}
2022-12-01 16:58:37 +00:00
menuDelegate: StatusListItem {
2022-03-31 11:46:25 +00:00
id: defaultListItem
2023-02-24 12:59:14 +00:00
objectName: ! ! model . objectName ? model.objectName : ""
2022-03-31 11:46:25 +00:00
title: model . name
2022-08-11 11:55:08 +00:00
asset.name: model . iconName
2022-03-31 11:46:25 +00:00
tagsModel : model . generatedModel
enabled: ! model . isHeader
2022-08-11 11:55:08 +00:00
asset.bgColor: "transparent"
asset.color: model . generatedModel ? Theme.palette.primaryColor1 : Theme . palette . directColor5
2022-03-31 11:46:25 +00:00
tagsDelegate: StatusListItemTag {
2022-12-21 13:57:41 +00:00
bgColor: model . color
bgRadius: 6
2022-03-31 11:46:25 +00:00
height: 24
closeButtonVisible: false
2022-08-11 11:55:08 +00:00
asset.emoji: model . emoji
asset.emojiSize: Emoji . size . verySmall
asset.isLetterIdenticon: true
2022-03-31 11:46:25 +00:00
title: model . name
titleText.font.pixelSize: 12
titleText.color: Theme . palette . indirectColor1
}
onClicked: {
2023-02-24 12:59:14 +00:00
selectAccountType . addAccountType = ( model . objectName === _internal . importSeedPhraseID ) ? Constants.AddAccountType.ImportSeedPhrase :
( model . objectName === _internal . importPrivateKeyID ) ? Constants.AddAccountType.ImportPrivateKey :
( model . objectName === _internal . addWatchOnlyAccountID ) ? Constants.AddAccountType.WatchOnly :
2023-01-18 09:25:36 +00:00
Constants . AddAccountType . GenerateNew
2022-03-31 11:46:25 +00:00
selectedItem . title = model . name
2022-08-11 11:55:08 +00:00
selectedItem . asset . name = model . iconName
2022-03-31 11:46:25 +00:00
selectedItem . tagsModel = model . generatedModel
selectedItem . enabled = ! model . isHeader
selectAccountType . derivedFromAddress = model . derivedfrom
2022-10-27 09:26:34 +00:00
selectAccountType . selectedKeyUid = model . keyUid
selectAccountType . selectedKeyUidMigratedToKeycard = model . migratedToKeycard
2022-03-31 11:46:25 +00:00
selectMenu . close ( )
}
Component.onCompleted: {
if ( index === 0 ) {
selectedItem . title = model . name
2022-08-11 11:55:08 +00:00
selectedItem . asset . name = model . iconName
2022-03-31 11:46:25 +00:00
selectedItem . tagsModel = model . generatedModel
selectedItem . enabled = ! model . isHeader
selectAccountType . derivedFromAddress = model . derivedfrom
}
}
}
}