parent
53b0c74fd2
commit
9d771b53dc
|
@ -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
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -115,7 +115,6 @@ Menu {
|
|||
|
||||
Rectangle {
|
||||
id: bgPopupMenuContent
|
||||
y: 7
|
||||
implicitWidth: bgPopupMenu.width
|
||||
implicitHeight: bgPopupMenu.height
|
||||
color: Style.current.modalBackground
|
||||
|
|
Loading…
Reference in New Issue