2022-12-16 09:37:08 +00:00
|
|
|
import QtQuick 2.14
|
|
|
|
import QtQuick.Layouts 1.14
|
|
|
|
import QtQuick.Controls 2.14
|
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Core.Utils 0.1 as StatusQUtils
|
|
|
|
import StatusQ.Controls 0.1
|
2022-12-27 13:20:58 +00:00
|
|
|
import StatusQ.Components 0.1
|
2022-12-16 09:37:08 +00:00
|
|
|
|
2024-01-16 12:42:22 +00:00
|
|
|
import AppLayouts.Wallet.stores 1.0 as WalletStore
|
|
|
|
|
2022-12-16 09:37:08 +00:00
|
|
|
import utils 1.0
|
|
|
|
import shared.popups 1.0
|
|
|
|
|
|
|
|
import "../helpers"
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: root
|
|
|
|
|
|
|
|
property var sharedKeycardModule
|
|
|
|
property var emojiPopup
|
|
|
|
|
|
|
|
signal validation(bool result)
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
property var observedAccount: root.sharedKeycardModule.keyPairForProcessing.observedAccount
|
|
|
|
property bool entryValid: false
|
|
|
|
property string emptyName: " "
|
|
|
|
property string accountNameToBeRemoved: ""
|
|
|
|
property int accountIndexToBeRemoved: -1
|
2022-12-27 13:20:58 +00:00
|
|
|
property string observedImportingAccountShortAddress: root.sharedKeycardModule.currentState.flowType === Constants.keycardSharedFlow.importFromKeycard?
|
|
|
|
StatusQUtils.Utils.elideText(root.sharedKeycardModule.keyPairHelper.observedAccount.address, 6, 4)
|
|
|
|
: ""
|
2022-12-16 09:37:08 +00:00
|
|
|
|
|
|
|
onObservedAccountChanged: {
|
|
|
|
if (d.observedAccount.name.trim().length > 0) {
|
|
|
|
accountName.text = d.observedAccount.name
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
accountName.text = ""
|
|
|
|
d.observedAccount.name = d.emptyName
|
|
|
|
}
|
|
|
|
|
2023-05-22 15:55:47 +00:00
|
|
|
if (d.observedAccount.colorId.length === 0) {
|
|
|
|
let color = Theme.palette.customisationColorsArray[Math.floor(Math.random() * Theme.palette.customisationColorsArray.length)]
|
2022-12-16 09:37:08 +00:00
|
|
|
let emoji = StatusQUtils.Emoji.getRandomEmoji(StatusQUtils.Emoji.size.verySmall)
|
2023-05-22 15:55:47 +00:00
|
|
|
d.observedAccount.colorId = Utils.getIdForColor(color)
|
2022-12-16 09:37:08 +00:00
|
|
|
d.observedAccount.emoji = emoji
|
|
|
|
}
|
|
|
|
|
2023-05-22 15:55:47 +00:00
|
|
|
let ind = d.evaluateColorIndex(d.observedAccount.colorId)
|
2022-12-16 09:37:08 +00:00
|
|
|
colorSelection.selectedColorIndex = ind
|
|
|
|
d.updateValidity()
|
2022-12-27 13:20:58 +00:00
|
|
|
accountName.input.edit.forceActiveFocus()
|
2022-12-16 09:37:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateValidity() {
|
|
|
|
d.entryValid = d.observedAccount.name.trim().length > 0
|
|
|
|
root.validation(d.entryValid)
|
|
|
|
}
|
|
|
|
|
|
|
|
function evaluateColorIndex(color) {
|
2023-05-22 15:55:47 +00:00
|
|
|
for (let i = 0; i < Theme.palette.customisationColorsArray.length; i++) {
|
|
|
|
if(Theme.palette.customisationColorsArray[i] === color) {
|
2022-12-16 09:37:08 +00:00
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
d.updateValidity()
|
|
|
|
accountName.input.edit.forceActiveFocus()
|
|
|
|
}
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: root.emojiPopup
|
2022-12-26 12:52:21 +00:00
|
|
|
enabled: root.sharedKeycardModule.currentState.flowType === Constants.keycardSharedFlow.setupNewKeycardNewSeedPhrase ||
|
2022-12-27 13:20:58 +00:00
|
|
|
root.sharedKeycardModule.currentState.flowType === Constants.keycardSharedFlow.setupNewKeycardOldSeedPhrase ||
|
|
|
|
root.sharedKeycardModule.currentState.flowType === Constants.keycardSharedFlow.importFromKeycard
|
2022-12-16 09:37:08 +00:00
|
|
|
|
|
|
|
function onEmojiSelected (emojiText, atCursor) {
|
2023-10-12 16:20:55 +00:00
|
|
|
let emoji = StatusQUtils.Emoji.deparse(emojiText)
|
|
|
|
d.observedAccount.emoji = emoji
|
2022-12-16 09:37:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfirmationDialog {
|
|
|
|
id: confirmationPopup
|
2023-05-23 12:46:16 +00:00
|
|
|
headerSettings.title: qsTr("Remove account")
|
2022-12-16 09:37:08 +00:00
|
|
|
confirmationText: d.accountNameToBeRemoved.length > 0?
|
|
|
|
qsTr("Do you want to delete the %1 account?").arg(d.accountNameToBeRemoved)
|
|
|
|
: qsTr("Do you want to delete the last account?")
|
|
|
|
confirmButtonLabel: qsTr("Yes, delete this account")
|
|
|
|
onConfirmButtonClicked: {
|
|
|
|
confirmationPopup.close();
|
|
|
|
root.sharedKeycardModule.keyPairForProcessing.removeAccountAtIndex(d.accountIndexToBeRemoved)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
anchors.fill: parent
|
|
|
|
anchors.topMargin: Style.current.xlPadding
|
|
|
|
anchors.bottomMargin: Style.current.halfPadding
|
|
|
|
anchors.leftMargin: Style.current.xlPadding
|
|
|
|
anchors.rightMargin: Style.current.xlPadding
|
|
|
|
spacing: Style.current.padding
|
|
|
|
|
2022-12-27 13:20:58 +00:00
|
|
|
StatusStepper {
|
|
|
|
id: stepper
|
|
|
|
Layout.preferredWidth: Constants.keycard.general.keycardNameInputWidth
|
|
|
|
Layout.alignment: Qt.AlignCenter
|
|
|
|
titleFontSize: Constants.keycard.general.fontSize2
|
|
|
|
}
|
|
|
|
|
2022-12-16 09:37:08 +00:00
|
|
|
StatusBaseText {
|
|
|
|
id: title
|
|
|
|
Layout.alignment: Qt.AlignCenter
|
|
|
|
font.weight: Font.Bold
|
|
|
|
}
|
|
|
|
|
2022-12-27 13:20:58 +00:00
|
|
|
Rectangle {
|
|
|
|
id: accountDetails
|
|
|
|
Layout.preferredWidth: Constants.keycard.general.keycardNameInputWidth
|
|
|
|
Layout.alignment: Qt.AlignCenter
|
2023-06-30 07:03:09 +00:00
|
|
|
visible: root.sharedKeycardModule.currentState.flowType === Constants.keycardSharedFlow.importFromKeycard
|
2022-12-27 13:20:58 +00:00
|
|
|
height: Style.current.xlPadding * 2
|
|
|
|
color: "transparent"
|
|
|
|
border.color: Theme.palette.baseColor2
|
|
|
|
border.width: 1
|
|
|
|
radius: Style.current.halfPadding
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.leftMargin: Style.current.padding
|
|
|
|
anchors.rightMargin: Style.current.padding
|
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
StatusBaseText {
|
|
|
|
text: d.observedImportingAccountShortAddress
|
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
font.pixelSize: Constants.keycard.general.fontSize2
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusBaseText {
|
2023-06-30 07:03:09 +00:00
|
|
|
text: root.sharedKeycardModule.currentState.flowType === Constants.keycardSharedFlow.importFromKeycard?
|
|
|
|
root.sharedKeycardModule.keyPairHelper.observedAccount.path : ""
|
2022-12-27 13:20:58 +00:00
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
font.pixelSize: Constants.keycard.general.fontSize2
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.preferredHeight: parent.height
|
|
|
|
}
|
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
StatusBaseText {
|
2024-01-16 12:42:22 +00:00
|
|
|
text: qsTr("Balance: %1").arg(LocaleUtils.currencyAmountToLocaleString(root.sharedKeycardModule.keyPairHelper.observedAccount.balance))
|
2022-12-27 13:20:58 +00:00
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
font.pixelSize: Constants.keycard.general.fontSize2
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
}
|
|
|
|
|
|
|
|
Row {
|
|
|
|
padding: 0
|
|
|
|
|
|
|
|
StatusBaseText {
|
|
|
|
text: qsTr("View on Etherscan")
|
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
font.pixelSize: Constants.keycard.general.fontSize2
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusFlatRoundButton {
|
|
|
|
height: 20
|
|
|
|
width: 20
|
|
|
|
icon.name: "external"
|
|
|
|
icon.width: 16
|
|
|
|
icon.height: 16
|
|
|
|
onClicked: {
|
2024-01-16 12:42:22 +00:00
|
|
|
let link = Utils.getUrlForAddressOnNetwork(Constants.networkShortChainNames.mainnet,
|
|
|
|
WalletStore.RootStore.areTestNetworksEnabled,
|
2024-02-20 09:31:04 +00:00
|
|
|
WalletStore.RootStore.isGoerliEnabled,
|
2024-01-16 12:42:22 +00:00
|
|
|
root.sharedKeycardModule.keyPairHelper.observedAccount.address)
|
|
|
|
Global.openLink(link)
|
2022-12-27 13:20:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-16 09:37:08 +00:00
|
|
|
StatusInput {
|
|
|
|
id: accountName
|
|
|
|
Layout.preferredWidth: Constants.keycard.general.keycardNameInputWidth
|
|
|
|
Layout.alignment: Qt.AlignCenter
|
|
|
|
charLimit: Constants.keycard.general.keycardNameLength
|
2022-12-27 13:20:58 +00:00
|
|
|
placeholderText: {
|
|
|
|
if (root.sharedKeycardModule.currentState.flowType === Constants.keycardSharedFlow.importFromKeycard) {
|
|
|
|
return qsTr("What name should account %1 have?").arg(d.observedImportingAccountShortAddress)
|
|
|
|
}
|
|
|
|
|
|
|
|
return qsTr("What would you like this account to be called?")
|
|
|
|
}
|
2022-12-16 09:37:08 +00:00
|
|
|
input.acceptReturn: true
|
|
|
|
input.isIconSelectable: true
|
|
|
|
input.leftPadding: Style.current.padding
|
2023-05-22 15:55:47 +00:00
|
|
|
input.asset.color: Utils.getColorForId(d.observedAccount.colorId)
|
2022-12-16 09:37:08 +00:00
|
|
|
input.asset.emoji: d.observedAccount.emoji
|
|
|
|
|
|
|
|
onTextChanged: {
|
|
|
|
d.observedAccount.name = text.trim().length > 0? text : d.emptyName
|
|
|
|
d.updateValidity()
|
|
|
|
}
|
|
|
|
|
|
|
|
onKeyPressed: {
|
|
|
|
if (d.entryValid &&
|
|
|
|
(input.edit.keyEvent === Qt.Key_Return ||
|
|
|
|
input.edit.keyEvent === Qt.Key_Enter)) {
|
|
|
|
event.accepted = true
|
|
|
|
root.sharedKeycardModule.currentState.doPrimaryAction()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onIconClicked: {
|
|
|
|
let inputCoords = accountName.mapToItem(appMain, 0, 0)
|
|
|
|
root.emojiPopup.open()
|
|
|
|
root.emojiPopup.emojiSize = StatusQUtils.Emoji.size.verySmall
|
|
|
|
root.emojiPopup.x = inputCoords.x
|
|
|
|
root.emojiPopup.y = inputCoords.y + accountName.height + Style.current.halfPadding
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusColorSelectorGrid {
|
|
|
|
id: colorSelection
|
|
|
|
Layout.alignment: Qt.AlignCenter
|
|
|
|
title.text: qsTr("Colour")
|
|
|
|
title.font.pixelSize: Constants.keycard.general.fontSize2
|
2023-05-22 15:55:47 +00:00
|
|
|
model: Theme.palette.customisationColorsArray
|
2022-12-16 09:37:08 +00:00
|
|
|
|
|
|
|
onSelectedColorChanged: {
|
2023-05-22 15:55:47 +00:00
|
|
|
d.observedAccount.colorId = Utils.getIdForColor(selectedColor)
|
2022-12-16 09:37:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusBaseText {
|
|
|
|
Layout.alignment: Qt.AlignLeft
|
|
|
|
text: qsTr("Preview")
|
|
|
|
font.pixelSize: Constants.keycard.general.fontSize2
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyPairItem {
|
|
|
|
Layout.preferredWidth: parent.width
|
|
|
|
tagClickable: true
|
2022-12-27 13:20:58 +00:00
|
|
|
tagDisplayRemoveAccountButton: root.sharedKeycardModule.currentState.flowType !== Constants.keycardSharedFlow.importFromKeycard
|
2022-12-16 09:37:08 +00:00
|
|
|
keyPairType: root.sharedKeycardModule.keyPairForProcessing.pairType
|
2023-05-18 18:28:46 +00:00
|
|
|
keyPairKeyUid: root.sharedKeycardModule.keyPairForProcessing.keyUid
|
2022-12-27 13:20:58 +00:00
|
|
|
keyPairName: root.sharedKeycardModule.currentState.flowType === Constants.keycardSharedFlow.importFromKeycard?
|
|
|
|
root.sharedKeycardModule.keyPairHelper.name
|
|
|
|
: root.sharedKeycardModule.keyPairForProcessing.name
|
2022-12-16 09:37:08 +00:00
|
|
|
keyPairIcon: root.sharedKeycardModule.keyPairForProcessing.icon
|
|
|
|
keyPairImage: root.sharedKeycardModule.keyPairForProcessing.image
|
|
|
|
keyPairDerivedFrom: root.sharedKeycardModule.keyPairForProcessing.derivedFrom
|
|
|
|
keyPairAccounts: root.sharedKeycardModule.keyPairForProcessing.accounts
|
|
|
|
keyPairCardLocked: root.sharedKeycardModule.keyPairForProcessing.locked
|
|
|
|
|
|
|
|
onRemoveAccount: {
|
2022-12-27 13:20:58 +00:00
|
|
|
if (root.sharedKeycardModule.currentState.flowType === Constants.keycardSharedFlow.importFromKeycard)
|
|
|
|
return
|
2023-06-30 07:03:09 +00:00
|
|
|
if (name.trim().length == 0) {
|
|
|
|
root.sharedKeycardModule.keyPairForProcessing.removeAccountAtIndex(index)
|
|
|
|
return
|
|
|
|
}
|
2022-12-16 09:37:08 +00:00
|
|
|
d.accountIndexToBeRemoved = index
|
|
|
|
d.accountNameToBeRemoved = name
|
|
|
|
confirmationPopup.open()
|
|
|
|
}
|
|
|
|
|
|
|
|
onAccountClicked: {
|
2022-12-27 13:20:58 +00:00
|
|
|
if (root.sharedKeycardModule.currentState.flowType === Constants.keycardSharedFlow.importFromKeycard) {
|
|
|
|
root.sharedKeycardModule.keyPairHelper.setAccountAtIndexAsObservedAccount(index)
|
|
|
|
}
|
2022-12-16 09:37:08 +00:00
|
|
|
root.sharedKeycardModule.keyPairForProcessing.setAccountAtIndexAsObservedAccount(index)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
states: [
|
|
|
|
State {
|
|
|
|
name: Constants.keycardSharedState.manageKeycardAccounts
|
|
|
|
when: root.sharedKeycardModule.currentState.stateType === Constants.keycardSharedState.manageKeycardAccounts
|
2022-12-27 13:20:58 +00:00
|
|
|
PropertyChanges {
|
|
|
|
target: stepper
|
|
|
|
visible: root.sharedKeycardModule.currentState.flowType === Constants.keycardSharedFlow.importFromKeycard &&
|
|
|
|
root.sharedKeycardModule.keyPairHelper.accounts.count > 1
|
2023-06-30 07:03:09 +00:00
|
|
|
totalSteps: root.sharedKeycardModule.currentState.flowType === Constants.keycardSharedFlow.importFromKeycard?
|
|
|
|
root.sharedKeycardModule.keyPairHelper.accounts.count : 0
|
2022-12-27 13:20:58 +00:00
|
|
|
completedSteps: root.sharedKeycardModule.keyPairForProcessing.accounts.count
|
|
|
|
title: qsTr("Account %1 of %2").arg(completedSteps).arg(totalSteps)
|
|
|
|
}
|
2022-12-16 09:37:08 +00:00
|
|
|
PropertyChanges {
|
|
|
|
target: title
|
2022-12-27 13:20:58 +00:00
|
|
|
text: {
|
|
|
|
if (root.sharedKeycardModule.currentState.flowType === Constants.keycardSharedFlow.importFromKeycard) {
|
|
|
|
return qsTr("Name account %1").arg(d.observedImportingAccountShortAddress)
|
|
|
|
}
|
|
|
|
|
|
|
|
return qsTr("Name accounts")
|
|
|
|
}
|
2022-12-16 09:37:08 +00:00
|
|
|
font.pixelSize: Constants.keycard.general.fontSize1
|
|
|
|
color: Theme.palette.directColor1
|
|
|
|
}
|
2022-12-27 13:20:58 +00:00
|
|
|
PropertyChanges {
|
|
|
|
target: accountDetails
|
|
|
|
visible: root.sharedKeycardModule.currentState.flowType === Constants.keycardSharedFlow.importFromKeycard &&
|
|
|
|
root.sharedKeycardModule.keyPairHelper.accounts.count > 1
|
|
|
|
}
|
2022-12-16 09:37:08 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|