Skip to content
Permalink
Browse files

Adding pricing functionality to the Monero GUI

  • Loading branch information...
gene-telligent committed Oct 30, 2018
1 parent 02e1663 commit 5a557dffbad44a7e3ee3de9b0100da8d4f7b04ac
@@ -42,6 +42,8 @@ Rectangle {
property alias unlockedBalanceLabelVisible: unlockedBalanceLabel.visible
property alias balanceLabelText: balanceLabel.text
property alias balanceText: balanceText.text
property alias balanceTextFiat: balanceTextFiat.text
property alias unlockedBalanceTextFiat: unlockedBalanceTextFiat.text
property alias networkStatus : networkStatus
property alias progressBar : progressBar
property alias daemonProgressBar : daemonProgressBar
@@ -106,6 +108,12 @@ Rectangle {
anchors.top: parent.top
anchors.topMargin: (persistentSettings.customDecorations)? 50 : 0

MouseArea {
id: balanceArea
anchors.fill: parent
hoverEnabled: true
}

RowLayout {
visible: true
Item {
@@ -191,7 +199,10 @@ Rectangle {
width: 50 * scaleRatio

Text {
visible: !isMobile
visible: !isMobile && !(balanceArea.containsMouse
&& builtWithPrices
&& persistentSettings.enableCurrencyConversion
&& priceManager.priceReady)
id: balanceText
anchors.left: parent.left
anchors.leftMargin: 20
@@ -228,9 +239,25 @@ Rectangle {
}
}

Text {
visible: !isMobile && !balanceText.visible
id: balanceTextFiat
anchors.left: parent.left
anchors.leftMargin: 20
anchors.top: parent.top
anchors.topMargin: 76
font.family: "Arial"
color: "#FFFFFF"
text: "N/A"
font.pixelSize: balanceText.font.pixelSize
}

Text {
id: unlockedBalanceText
visible: true
visible: !(balanceArea.containsMouse
&& builtWithPrices
&& persistentSettings.enableCurrencyConversion
&& priceManager.priceReady)
anchors.left: parent.left
anchors.leftMargin: 20
anchors.top: parent.top
@@ -266,6 +293,21 @@ Rectangle {
}
}


Text {
id: unlockedBalanceTextFiat
visible: !unlockedBalanceText.visible
anchors.left: parent.left
anchors.leftMargin: 20
anchors.top: parent.top
anchors.topMargin: 126
font.family: "Arial"
color: "#FFFFFF"
text: "N/A"
// dynamically adjust text size
font.pixelSize: unlockedBalanceText.font.pixelSize
}

MoneroComponents.Label {
id: unlockedBalanceLabel
visible: true
@@ -27,7 +27,7 @@ find_command() {

if [ "$BUILD_TYPE" == "release" ]; then
echo "Building release"
CONFIG="CONFIG+=release";
CONFIG="CONFIG+=release WITH_PRICES";
BIN_PATH=release/bin
elif [ "$BUILD_TYPE" == "release-static" ]; then
echo "Building release-static"
@@ -53,7 +53,7 @@ elif [ "$BUILD_TYPE" == "debug-android" ]; then
DISABLE_PASS_STRENGTH_METER=true
elif [ "$BUILD_TYPE" == "debug" ]; then
echo "Building debug"
CONFIG="CONFIG+=debug"
CONFIG="CONFIG+=debug WITH_PRICES"
BIN_PATH=debug/bin
else
echo "Valid build types are release, release-static, release-android, debug-android and debug"
@@ -34,6 +34,7 @@ Item {
id: dropdown
property int itemTopMargin: 0
property alias dataModel: repeater.model
property alias colText: firstColText.text
property string shadowPressedColor
property string shadowReleasedColor
property string pressedColor
@@ -70,6 +70,14 @@
#include "QrCodeScanner.h"
#endif

#ifdef WITH_PRICES
#include "prices/Currency.h"
#include "prices/PriceManager.h"
#include "prices/PriceSource.h"
#include "prices/PriceSourceSelectorModel.h"
#include "prices/CurrencySelectorModel.h"
#endif

bool isIOS = false;
bool isAndroid = false;
bool isWindows = false;
@@ -209,6 +217,22 @@ int main(int argc, char *argv[])

qmlRegisterUncreatableType<Subaddress>("moneroComponents.Subaddress", 1, 0, "Subaddress",
"Subaddress can't be instantiated directly");
#ifdef WITH_PRICES
qmlRegisterUncreatableType<PriceManager>("moneroComponents.PriceManager", 1, 0, "PriceManager",
"PriceManager can't be instantiated directly");

qmlRegisterUncreatableType<PriceSource>("moneroComponents.PriceSource", 1, 0, "PriceSource",
"PriceSource can't be instantiated directly");

qmlRegisterUncreatableType<PriceSourceSelectorModel>("moneroComponents.PriceSourceSelectorModel", 1, 0, "PriceSourceSelectorModel",
"PriceSourceSelectorModel can't be instantiated directly");

qmlRegisterUncreatableType<Currency>("moneroComponents.Currency", 1, 0, "Currency",
"Currency can't be instantiated directly");

qmlRegisterUncreatableType<CurrencySelectorModel>("moneroComponents.CurrencySelectorModel", 1, 0, "CurrencySelectorModel",
"CurrencySelectorModel can't be instantiated directly");
#endif

qmlRegisterUncreatableType<SubaddressAccountModel>("moneroComponents.SubaddressAccountModel", 1, 0, "SubaddressAccountModel",
"SubaddressAccountModel can't be instantiated directly");
@@ -248,6 +272,9 @@ int main(int argc, char *argv[])

engine.rootContext()->setContextProperty("walletLogPath", logPath);

#ifdef WITH_PRICES
engine.rootContext()->setContextProperty("priceManager", PriceManager::instance(engine.networkAccessManager()));
#endif
// Exclude daemon manager from IOS
#ifndef Q_OS_IOS
const QStringList arguments = (QStringList) QCoreApplication::arguments().at(0);
@@ -308,6 +335,12 @@ int main(int argc, char *argv[])
#endif
engine.rootContext()->setContextProperty("builtWithScanner", builtWithScanner);

bool builtWithPrices = false;
#ifdef WITH_PRICES
builtWithPrices = true;
#endif
engine.rootContext()->setContextProperty("builtWithPrices", builtWithPrices);

// Load main window (context properties needs to be defined obove this line)
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
if (engine.rootObjects().isEmpty())
@@ -245,6 +245,10 @@ ApplicationWindow {
// enable timers
userInActivityTimer.running = true;
simpleModeConnectionTimer.running = true;
// Start the price manager if applicable
if (builtWithPrices && persistentSettings.enableCurrencyConversion) {
startPriceManager();
}

// wallet already opened with wizard, we just need to initialize it
if (typeof wizard.m_wallet !== 'undefined') {
@@ -387,6 +391,17 @@ ApplicationWindow {
balance = walletManager.displayAmount(currentWallet.balance(currentWallet.currentSubaddressAccount));
}

if (builtWithPrices && persistentSettings.enableCurrencyConversion) {
var balance_unlocked_fiat = qsTr("HIDDEN");
var balance_fiat = qsTr("HIDDEN");
if(!hideBalanceForced && !persistentSettings.hideBalance){
balance_unlocked_fiat = priceManager.convert(currentWallet.unlockedBalance(currentWallet.currentSubaddressAccount));
balance_fiat = priceManager.convert(currentWallet.balance(currentWallet.currentSubaddressAccount));
}
leftPanel.unlockedBalanceTextFiat = balance_unlocked_fiat;
leftPanel.balanceTextFiat = balance_fiat;
}

middlePanel.unlockedBalanceText = balance_unlocked;
leftPanel.unlockedBalanceText = balance_unlocked;
middlePanel.balanceText = balance;
@@ -985,6 +1000,29 @@ ApplicationWindow {
console.log(appWindow.width)
}

function startPriceManager() {
console.log("Starting PriceManager");
var sourceIdx = priceManager.priceSourcesAvailableModel.index(persistentSettings.currencyConversionSourceIndex, 0);
priceManager.setPriceSource(sourceIdx);
var currencyIdx = priceManager.currenciesAvailableModel.index(persistentSettings.currencyConversionCurrencyIndex, 0);
priceManager.setCurrency(currencyIdx);
priceManager.priceRefreshed.connect(updateBalance);
priceManager.start();
}

function stopPriceManager() {
console.log("Stopping PriceManager");
priceManager.priceRefreshed.disconnect(updateBalance);
priceManager.stop();
}

function setPriceManager(bool) {
if (bool && !priceManager.running)
startPriceManager();
if (!bool && priceManager.running)
stopPriceManager();
}


objectName: "appWindow"
visible: true
@@ -1090,6 +1128,9 @@ ApplicationWindow {
property string remoteNodeService: ""
property int lockOnUserInActivityInterval: 10 // minutes
property bool showPid: false
property bool enableCurrencyConversion: false
property int currencyConversionSourceIndex: 0
property int currencyConversionCurrencyIndex: 0
}

// Information dialog
@@ -198,6 +198,26 @@ CONFIG(WITH_SCANNER) {
}
}

CONFIG(WITH_PRICES) {
message("building with prices")
DEFINES += "WITH_PRICES"
HEADERS += \
src/prices/Currency.h \
src/prices/Price.h \
src/prices/PriceSource.h \
src/prices/CurrencySelectorModel.h \
src/prices/PriceSourceSelectorModel.h \
src/prices/PriceManager.h \
src/prices/qtjsonpath.h
SOURCES += \
src/prices/Currency.cpp \
src/prices/Price.cpp \
src/prices/PriceSource.cpp \
src/prices/CurrencySelectorModel.cpp \
src/prices/PriceSourceSelectorModel.cpp \
src/prices/PriceManager.cpp
}


# currently we only support x86 build as qt.io only provides prebuilt qt for x86 mingw

@@ -182,6 +182,85 @@ Rectangle {
Layout.fillWidth: true
text: qsTr("No Layout options exist yet in mobile mode.") + translationManager.emptyString;
}
//! Manage pricing

RowLayout {
MoneroComponents.CheckBox {
visible: builtWithPrices
id: enableConvertCurrency
text: qsTr("Enable displaying balance in other currencies") + translationManager.emptyString
checked: persistentSettings.enableCurrencyConversion
onCheckedChanged: {
persistentSettings.enableCurrencyConversion = checked;
appWindow.setPriceManager(checked);
}
}
}

GridLayout {
visible: builtWithPrices && enableConvertCurrency.checked
columns: (isMobile)? 1 : 2
Layout.fillWidth: true
columnSpacing: 32

ColumnLayout {
spacing: 0
Layout.fillWidth: true

MoneroComponents.StandardDropdown {
id: priceSourceDropDown
dataModel: priceManager.priceSourcesAvailableModel
currentIndex: appWindow.persistentSettings.currencyConversionSourceIndex
onChanged: {
var idx = dataModel.index(currentIndex, 0);
priceManager.setPriceSource(idx);
appWindow.persistentSettings.currencyConversionSourceIndex = currentIndex;
}
Layout.fillWidth: true
shadowReleasedColor: "#FF4304"
shadowPressedColor: "#B32D00"
releasedColor: "#363636"
pressedColor: "#202020"

function update() {
colText = dataModel.getLabelAt(currentIndex);
}
}
}

ColumnLayout {
spacing: 0
Layout.fillWidth: true

MoneroComponents.StandardDropdown {
id: currencyDropDown
dataModel: priceManager.currenciesAvailableModel
currentIndex: appWindow.persistentSettings.currencyConversionCurrencyIndex
onChanged: {
var idx = dataModel.index(currentIndex, 0);
priceManager.setCurrency(idx);
appWindow.persistentSettings.currencyConversionCurrencyIndex = currentIndex;
}
Layout.fillWidth: true
shadowReleasedColor: "#FF4304"
shadowPressedColor: "#B32D00"
releasedColor: "#363636"
pressedColor: "#202020"

function update() {
colText = dataModel.getLabelAt(currentIndex);
}
}

// Make sure dropdown is on top
}

ColumnLayout {
Layout.fillWidth: true
}

z: parent.z + 1
}
}

Component.onCompleted: {
Oops, something went wrong.

0 comments on commit 5a557df

Please sign in to comment.
You can’t perform that action at this time.