status-desktop/ui/app/AppLayouts/Wallet/AddCustomTokenModal.qml

178 lines
4.9 KiB
QML
Raw Normal View History

2020-06-17 19:18:31 +00:00
import QtQuick 2.13
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.13
import utils 1.0
import "../../../shared"
import "../../../shared/status"
ModalPopup {
id: popup
2020-10-30 19:22:54 +00:00
property bool editable: true
property int marginBetweenInputs: 35
property string validationError: ""
2020-10-30 19:22:54 +00:00
title: editable ?
//% "Add custom token"
qsTrId("add-custom-token")
: nameInput.text
height: editable ? 450 : 380
onOpened: {
2020-11-02 18:18:13 +00:00
addressInput.forceActiveFocus(Qt.MouseFocusReason)
}
function openEditable(){
2020-10-30 19:22:54 +00:00
addressInput.text = "";
nameInput.text = "";
symbolInput.text = "";
decimalsInput.text = "";
2020-11-02 18:18:13 +00:00
editable = true;
open();
}
2020-11-02 18:18:13 +00:00
function openWithData(address, name, symbol, decimals){
2020-10-30 19:22:54 +00:00
addressInput.text = address;
nameInput.text = name;
symbolInput.text = symbol;
decimalsInput.text = decimals;
editable = false;
2020-11-02 18:18:13 +00:00
open();
2020-10-30 19:22:54 +00:00
}
function validate() {
if (addressInput.text !== "" && !Utils.isAddress(addressInput.text)) {
2021-02-18 16:36:05 +00:00
//% "This needs to be a valid address"
validationError = qsTrId("this-needs-to-be-a-valid-address");
}
return validationError === ""
}
property var getTokenDetails: Backpressure.debounce(popup, 500, function (tokenAddress){
refactor wallet views add getSettings methods to src/status fix issue with calling getSettings; document issue remove most direct references to libstatus; document some common issues remove most references to libstatus wallet add mailserver layer to status lib; remove references to libstatus mailservers remove libstatus accounts references move types out of libstatus; remove libstatus types references remove libstatus browser references refactor libstatus utils references remove more references to libstatus stickers remove references to libstatus constants from src/app remove more libstatus references from src/app refactor token_list usage of libstatus refactor stickers usage of libstatus refactor chat usage of libstatus remove libstatus references from the wallet view remove logic from ens manager view fix issue with import & namespace conflict remove unnecessary imports refactor provider view to not depend on libstatus refactor provider view refactor: move accounts specific code to its own section fix account selection move collectibles to their own module update references to wallet transactions refactor: move gas methods to their own file refactor: extract tokens into their own file refactor: extract ens to its own file refactor: extract dappbrowser code to its own file refactor: extract history related code to its own file refactor: extract balance to its own file refactor: extract utils to its own file clean up wallet imports fix: identicon for transaction commands Fixes #2533
2021-06-08 12:48:31 +00:00
walletModel.tokensView.customTokenList.getTokenDetails(tokenAddress)
});
function onKeyReleased(){
validationError = "";
if (!validate() || addressInput.text === "") {
return;
}
Qt.callLater(getTokenDetails, addressInput.text)
}
Item {
Connections {
refactor wallet views add getSettings methods to src/status fix issue with calling getSettings; document issue remove most direct references to libstatus; document some common issues remove most references to libstatus wallet add mailserver layer to status lib; remove references to libstatus mailservers remove libstatus accounts references move types out of libstatus; remove libstatus types references remove libstatus browser references refactor libstatus utils references remove more references to libstatus stickers remove references to libstatus constants from src/app remove more libstatus references from src/app refactor token_list usage of libstatus refactor stickers usage of libstatus refactor chat usage of libstatus remove libstatus references from the wallet view remove logic from ens manager view fix issue with import & namespace conflict remove unnecessary imports refactor provider view to not depend on libstatus refactor provider view refactor: move accounts specific code to its own section fix account selection move collectibles to their own module update references to wallet transactions refactor: move gas methods to their own file refactor: extract tokens into their own file refactor: extract ens to its own file refactor: extract dappbrowser code to its own file refactor: extract history related code to its own file refactor: extract balance to its own file refactor: extract utils to its own file clean up wallet imports fix: identicon for transaction commands Fixes #2533
2021-06-08 12:48:31 +00:00
target: walletModel.tokensView.customTokenList
onTokenDetailsWereResolved: {
const jsonObj = JSON.parse(tokenDetails)
if (jsonObj.error) {
validationError = jsonObj.error
return
}
if (jsonObj.name === "" && jsonObj.symbol === "" && jsonObj.decimals === "") {
2021-02-18 16:36:05 +00:00
//% "Invalid ERC20 address"
validationError = qsTrId("invalid-erc20-address")
return;
}
if (addressInput.text.toLowerCase() === jsonObj.address.toLowerCase()) {
symbolInput.text = jsonObj.symbol;
decimalsInput.text = jsonObj.decimals;
nameInput.text = jsonObj.name;
}
}
}
}
Input {
id: addressInput
2020-10-30 19:22:54 +00:00
readOnly: !editable
textField.maximumLength: 42
//% "Enter contract address..."
placeholderText: qsTrId("enter-contract-address...")
//% "Contract address"
label: qsTrId("contract-address")
validationError: popup.validationError
Keys.onReleased: onKeyReleased()
}
Input {
id: nameInput
2020-10-30 19:22:54 +00:00
readOnly: !editable
anchors.top: addressInput.bottom
anchors.topMargin: marginBetweenInputs
//% "The name of your token..."
placeholderText: qsTrId("the-name-of-your-token...")
//% "Name"
label: qsTrId("name")
}
2020-11-02 18:18:13 +00:00
Input {
id: symbolInput
readOnly: !editable
//% "ABC"
placeholderText: qsTrId("abc")
//% "Symbol"
label: qsTrId("symbol")
anchors.top: nameInput.bottom
anchors.topMargin: marginBetweenInputs
2020-10-30 19:22:54 +00:00
anchors.left: parent.left
2020-11-02 18:18:13 +00:00
anchors.right: undefined
width: parent.width / 2 - 20
}
2020-11-02 18:18:13 +00:00
Input {
id: decimalsInput
readOnly: !editable
placeholderText: "18"
//% "Decimals"
label: qsTrId("decimals")
text: "18"
2020-10-30 19:22:54 +00:00
anchors.top: nameInput.bottom
anchors.topMargin: marginBetweenInputs
2020-10-30 19:22:54 +00:00
anchors.right: parent.right
2020-11-02 18:18:13 +00:00
anchors.left: undefined
width: parent.width / 2 - 20
}
2020-11-02 18:18:13 +00:00
footer: Item {
width: parent.width
height: addBtn.height
2020-10-30 19:22:54 +00:00
visible: editable
StatusButton {
id: addBtn
anchors.top: parent.top
anchors.right: parent.right
anchors.rightMargin: Style.current.padding
//% "Add"
text: qsTrId("add")
enabled: validationError === "" && addressInput.text !== "" && nameInput.text !== "" && symbolInput.text !== "" && decimalsInput.text !== ""
onClicked : {
refactor wallet views add getSettings methods to src/status fix issue with calling getSettings; document issue remove most direct references to libstatus; document some common issues remove most references to libstatus wallet add mailserver layer to status lib; remove references to libstatus mailservers remove libstatus accounts references move types out of libstatus; remove libstatus types references remove libstatus browser references refactor libstatus utils references remove more references to libstatus stickers remove references to libstatus constants from src/app remove more libstatus references from src/app refactor token_list usage of libstatus refactor stickers usage of libstatus refactor chat usage of libstatus remove libstatus references from the wallet view remove logic from ens manager view fix issue with import & namespace conflict remove unnecessary imports refactor provider view to not depend on libstatus refactor provider view refactor: move accounts specific code to its own section fix account selection move collectibles to their own module update references to wallet transactions refactor: move gas methods to their own file refactor: extract tokens into their own file refactor: extract ens to its own file refactor: extract dappbrowser code to its own file refactor: extract history related code to its own file refactor: extract balance to its own file refactor: extract utils to its own file clean up wallet imports fix: identicon for transaction commands Fixes #2533
2021-06-08 12:48:31 +00:00
const error = walletModel.tokensView.addCustomToken(addressInput.text, nameInput.text, symbolInput.text, decimalsInput.text);
if (error) {
errorSound.play()
changeError.text = error
changeError.open()
return
}
refactor wallet views add getSettings methods to src/status fix issue with calling getSettings; document issue remove most direct references to libstatus; document some common issues remove most references to libstatus wallet add mailserver layer to status lib; remove references to libstatus mailservers remove libstatus accounts references move types out of libstatus; remove libstatus types references remove libstatus browser references refactor libstatus utils references remove more references to libstatus stickers remove references to libstatus constants from src/app remove more libstatus references from src/app refactor token_list usage of libstatus refactor stickers usage of libstatus refactor chat usage of libstatus remove libstatus references from the wallet view remove logic from ens manager view fix issue with import & namespace conflict remove unnecessary imports refactor provider view to not depend on libstatus refactor provider view refactor: move accounts specific code to its own section fix account selection move collectibles to their own module update references to wallet transactions refactor: move gas methods to their own file refactor: extract tokens into their own file refactor: extract ens to its own file refactor: extract dappbrowser code to its own file refactor: extract history related code to its own file refactor: extract balance to its own file refactor: extract utils to its own file clean up wallet imports fix: identicon for transaction commands Fixes #2533
2021-06-08 12:48:31 +00:00
walletModel.tokensView.loadCustomTokens()
popup.close();
}
}
}
}
/*##^##
Designer {
D{i:0;autoSize:true;height:480;width:640}
}
##^##*/