From d4be7634cbc80cd40c2ff8456bcd962b21b2dcb6 Mon Sep 17 00:00:00 2001 From: dsc Date: Wed, 1 May 2019 04:05:16 +0200 Subject: Fiat API Co-Authored-By: selsta Co-Authored-By: Gene Peters --- pages/settings/SettingsLayout.qml | 136 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) (limited to 'pages') diff --git a/pages/settings/SettingsLayout.qml b/pages/settings/SettingsLayout.qml index d1945281..f4b3d0b6 100644 --- a/pages/settings/SettingsLayout.qml +++ b/pages/settings/SettingsLayout.qml @@ -157,6 +157,106 @@ Rectangle { } } + //! Manage pricing + RowLayout { + MoneroComponents.CheckBox { + id: enableConvertCurrency + text: qsTr("Enable displaying balance in other currencies") + translationManager.emptyString + checked: persistentSettings.fiatPriceEnabled + onCheckedChanged: { + if (!checked) { + console.log("Disabled price conversion"); + persistentSettings.fiatPriceEnabled = false; + appWindow.fiatTimerStop(); + } + } + } + } + + GridLayout { + visible: enableConvertCurrency.checked + columns: 2 + Layout.fillWidth: true + Layout.leftMargin: 36 + columnSpacing: 32 + + ColumnLayout { + spacing: 10 + Layout.fillWidth: true + + MoneroComponents.Label { + Layout.fillWidth: true + fontSize: 14 + text: qsTr("Price source") + translationManager.emptyString + } + + MoneroComponents.StandardDropdown { + id: fiatPriceProviderDropDown + Layout.fillWidth: true + dataModel: fiatPriceProvidersModel + onChanged: { + var obj = dataModel.get(currentIndex); + persistentSettings.fiatPriceProvider = obj.data; + + if(persistentSettings.fiatPriceEnabled) + appWindow.fiatApiRefresh(); + } + } + } + + ColumnLayout { + spacing: 10 + Layout.fillWidth: true + + MoneroComponents.Label { + Layout.fillWidth: true + fontSize: 14 + text: qsTr("Currency") + translationManager.emptyString + } + + MoneroComponents.StandardDropdown { + id: fiatPriceCurrencyDropdown + Layout.fillWidth: true + dataModel: fiatPriceCurrencyModel + onChanged: { + var obj = dataModel.get(currentIndex); + persistentSettings.fiatPriceCurrency = obj.data; + + if(persistentSettings.fiatPriceEnabled) + appWindow.fiatApiRefresh(); + } + } + } + + z: parent.z + 1 + } + + ColumnLayout { + // Feature needs to be double enabled for security purposes (miss-clicks) + visible: enableConvertCurrency.checked && !persistentSettings.fiatPriceEnabled + spacing: 0 + Layout.topMargin: 5 + Layout.leftMargin: 36 + + MoneroComponents.WarningBox { + text: qsTr("Enabling price conversion exposes your IP address to the selected price source.") + translationManager.emptyString; + } + + MoneroComponents.StandardButton { + Layout.topMargin: 10 + Layout.bottomMargin: 10 + small: true + text: qsTr("Confirm and enable") + translationManager.emptyString + + onClicked: { + console.log("Enabled price conversion"); + persistentSettings.fiatPriceEnabled = true; + appWindow.fiatApiRefresh(); + appWindow.fiatTimerStart(); + } + } + } + MoneroComponents.StandardButton { visible: !persistentSettings.customDecorations Layout.topMargin: 10 @@ -177,7 +277,43 @@ Rectangle { } } + ListModel { + id: fiatPriceProvidersModel + } + + ListModel { + id: fiatPriceCurrencyModel + ListElement { + data: "xmrusd" + column1: "USD" + } + ListElement { + data: "xmreur" + column1: "EUR" + } + } + Component.onCompleted: { + // Dynamically fill fiatPrice dropdown based on `appWindow.fiatPriceAPIs` + var apis = appWindow.fiatPriceAPIs; + fiatPriceProvidersModel.clear(); + + var i = 0; + for (var api in apis){ + if (!apis.hasOwnProperty(api)) + continue; + + fiatPriceProvidersModel.append({"column1": Utils.capitalize(api), "data": api}); + + if(api === persistentSettings.fiatPriceProvider) + fiatPriceProviderDropDown.currentIndex = i; + i += 1; + } + + fiatPriceProviderDropDown.update(); + fiatPriceCurrencyDropdown.currentIndex = persistentSettings.fiatPriceCurrency === "xmrusd" ? 0 : 1; + fiatPriceCurrencyDropdown.update(); + console.log('SettingsLayout loaded'); } } -- cgit v1.2.3