diff --git a/src/app/wallet/views/token_list.nim b/src/app/wallet/views/token_list.nim index 603066a8c8..e35dd894ab 100644 --- a/src/app/wallet/views/token_list.nim +++ b/src/app/wallet/views/token_list.nim @@ -10,10 +10,12 @@ type HasIcon = UserRole + 3, Address = UserRole + 4, Decimals = UserRole + 5 + IsCustom = UserRole + 6 QtObject: type TokenList* = ref object of QAbstractListModel tokens*: seq[Erc20Contract] + isCustom*: bool proc setup(self: TokenList) = self.QAbstractListModel.setup @@ -27,12 +29,14 @@ QtObject: proc loadDefaultTokens*(self:TokenList) = if self.tokens.len == 0: self.tokens = getErc20Contracts() + self.isCustom = false self.tokensLoaded(self.tokens.len) proc loadCustomTokens*(self: TokenList) = self.beginResetModel() self.tokens = getCustomTokens() self.tokensLoaded(self.tokens.len) + self.isCustom = true self.endResetModel() proc newTokenList*(): TokenList = @@ -67,11 +71,13 @@ QtObject: of TokenRoles.HasIcon: result = newQVariant(token.hasIcon) of TokenRoles.Address: result = newQVariant($token.address) of TokenRoles.Decimals: result = newQVariant(token.decimals) + of TokenRoles.IsCustom: result = newQVariant(self.isCustom) method roleNames(self: TokenList): Table[int, string] = {TokenRoles.Name.int:"name", TokenRoles.Symbol.int:"symbol", TokenRoles.HasIcon.int:"hasIcon", TokenRoles.Address.int:"address", - TokenRoles.Decimals.int:"decimals"}.toTable + TokenRoles.Decimals.int:"decimals", + TokenRoles.IsCustom.int:"isCustom"}.toTable diff --git a/ui/app/AppLayouts/Wallet/AddCustomTokenModal.qml b/ui/app/AppLayouts/Wallet/AddCustomTokenModal.qml index 0f28d836a0..1a636a119e 100644 --- a/ui/app/AppLayouts/Wallet/AddCustomTokenModal.qml +++ b/ui/app/AppLayouts/Wallet/AddCustomTokenModal.qml @@ -6,18 +6,36 @@ import "../../../shared" ModalPopup { id: popup - //% "Add custom token" - title: qsTrId("add-custom-token") - height: 630 + property bool editable: true property int marginBetweenInputs: 35 + title: editable ? + //% "Add custom token" + qsTrId("add-custom-token") + : nameInput.text + + height: editable ? 450 : 380 + onOpened: { + addressInput.text = ""; + nameInput.text = ""; + symbolInput.text = ""; + decimalsInput.text = ""; addressInput.forceActiveFocus(Qt.MouseFocusReason) } + function setData(address, name, symbol, decimals){ + addressInput.text = address; + nameInput.text = name; + symbolInput.text = symbol; + decimalsInput.text = decimals; + editable = false; + } + Input { id: addressInput + readOnly: !editable //% "Enter contract address..." placeholderText: qsTrId("enter-contract-address...") //% "Contract address" @@ -26,6 +44,7 @@ ModalPopup { Input { id: nameInput + readOnly: !editable anchors.top: addressInput.bottom anchors.topMargin: marginBetweenInputs //% "The name of your token..." @@ -34,31 +53,43 @@ ModalPopup { label: qsTrId("name") } - Input { - id: symbolInput + + Item { + width: 200 anchors.top: nameInput.bottom anchors.topMargin: marginBetweenInputs - //% "ABC" - placeholderText: qsTrId("abc") - //% "Symbol" - label: qsTrId("symbol") + anchors.left: parent.left + Input { + id: symbolInput + readOnly: !editable + //% "ABC" + placeholderText: qsTrId("abc") + //% "Symbol" + label: qsTrId("symbol") + + } } - Input { - id: decimalsInput - anchors.top: symbolInput.bottom + Item { + width: 200 + anchors.top: nameInput.bottom anchors.topMargin: marginBetweenInputs - //% "Decimals" - label: qsTrId("decimals") - text: "18" + anchors.right: parent.right + Input { + id: decimalsInput + readOnly: !editable + //% "Decimals" + label: qsTrId("decimals") + text: "18" + } } footer: Item { + visible: editable anchors.fill: parent StyledButton { id: addBtn anchors.top: parent.top - anchors.topMargin: Style.current.padding anchors.right: parent.right anchors.rightMargin: Style.current.padding //% "Add" diff --git a/ui/app/AppLayouts/Wallet/TokenSettingsModal.qml b/ui/app/AppLayouts/Wallet/TokenSettingsModal.qml index 0a6b51c361..ae5ab17fab 100644 --- a/ui/app/AppLayouts/Wallet/TokenSettingsModal.qml +++ b/ui/app/AppLayouts/Wallet/TokenSettingsModal.qml @@ -20,7 +20,10 @@ ModalPopup { //% "Add custom token" label: qsTrId("add-custom-token") anchors.top: parent.top - onClicked: addCustomTokenModal.open() + onClicked: { + addCustomTokenModal.editable = true; + addCustomTokenModal.open() + } } } diff --git a/ui/app/AppLayouts/Wallet/components/TokenSettingsModalContent.qml b/ui/app/AppLayouts/Wallet/components/TokenSettingsModalContent.qml index 16d8f374e8..70a6ce080b 100644 --- a/ui/app/AppLayouts/Wallet/components/TokenSettingsModalContent.qml +++ b/ui/app/AppLayouts/Wallet/components/TokenSettingsModalContent.qml @@ -79,12 +79,14 @@ Item { //% "Token details" text: qsTrId("token-details") onTriggered: { - console.log("TODO") + addCustomTokenModal.open() + addCustomTokenModal.setData(address, name, symbol, decimals) } } Action { icon.source: "../../../img/remove-from-group.svg" icon.color: Style.current.red + enabled: isCustom //% "Remove token" text: qsTrId("remove-token") onTriggered: walletModel.removeCustomToken(address) diff --git a/ui/shared/PopupMenu.qml b/ui/shared/PopupMenu.qml index 7aea8620c5..7993beae81 100644 --- a/ui/shared/PopupMenu.qml +++ b/ui/shared/PopupMenu.qml @@ -115,7 +115,6 @@ Menu { Rectangle { id: bgPopupMenuContent - y: 7 implicitWidth: bgPopupMenu.width implicitHeight: bgPopupMenu.height color: Style.current.modalBackground