From 1f9675088d20211dc8f3716a3ff82d61d30b6a32 Mon Sep 17 00:00:00 2001
From: Malcolm MacLeod
Date: Sun, 16 Apr 2023 08:56:42 +0200
Subject: [PATCH] UI: Port across currency improvements from Florin
---
src/frontend/electron_vue/src/background.js | 9 ++--
.../src/components/AccountHeader.vue | 4 +-
.../electron_vue/src/layouts/WalletLayout.vue | 4 +-
src/frontend/electron_vue/src/locales/en.json | 9 ++--
src/frontend/electron_vue/src/store/index.js | 4 +-
.../electron_vue/src/store/modules/app.js | 15 +++++-
.../src/views/Account/MiningAccount/index.vue | 4 +-
.../Account/SavingAccount/OptimiseAccount.vue | 16 +++++-
.../src/views/Account/SavingAccount/index.vue | 48 ++++++++++++-----
.../views/Account/SpendingAccount/Send.vue | 53 +++++++++++++++++--
.../views/Account/SpendingAccount/index.vue | 2 +-
.../src/views/DebugDialog/PeersPage.vue | 20 +++++--
.../src/views/Settings/SettingsList.vue | 50 ++++++++++++++++-
13 files changed, 198 insertions(+), 40 deletions(-)
diff --git a/src/frontend/electron_vue/src/background.js b/src/frontend/electron_vue/src/background.js
index 1c9e472fb1..8e2d7d129a 100644
--- a/src/frontend/electron_vue/src/background.js
+++ b/src/frontend/electron_vue/src/background.js
@@ -157,7 +157,7 @@ function createMainWindow() {
});
// Force external hrefs to open in external browser
- winMain.webContents.on("new-window", function(e, url) {
+ winMain.webContents.on("new-window", function (e, url) {
e.preventDefault();
shell.openExternal(url);
});
@@ -276,9 +276,12 @@ app.on("ready", async () => {
async function updateRate(seconds) {
try {
// use blockhut api instead of https://api.munt.org/api/v1/ticker
- const response = await axios.get("https://blockhut.com/munt/munteuro.json");
+ //const response = await axios.get("https://blockhut.com/munt/munteuro.json");
+ const response = await axios.get("https://munt.chainviewer.org/api/v1/ticker");
+ const currentRate = response.data.data.find(item => item.code.toLowerCase() === store.state.app.currency.value.toLowerCase());
- store.dispatch("app/SET_RATE", response.data.eurmunt);
+ store.dispatch("app/SET_RATE", currentRate.rate);
+ store.dispatch("app/SET_CURRENCIES", response.data.data);
} catch (error) {
console.error(error);
} finally {
diff --git a/src/frontend/electron_vue/src/components/AccountHeader.vue b/src/frontend/electron_vue/src/components/AccountHeader.vue
index 9cd4190ce2..8661111b8b 100644
--- a/src/frontend/electron_vue/src/components/AccountHeader.vue
+++ b/src/frontend/electron_vue/src/components/AccountHeader.vue
@@ -94,14 +94,14 @@ export default {
}
},
computed: {
- ...mapState("app", ["rate"]),
+ ...mapState("app", ["rate", "currency"]),
...mapState("wallet", ["walletPassword", "unlocked"]),
name() {
return this.account ? this.account.label : null;
},
totalBalanceFiat() {
if (!this.rate) return "";
- return `€ ${formatMoneyForDisplay(this.account.balance * this.rate, true)}`;
+ return `${this.currency.symbol || ""} ${formatMoneyForDisplay(this.account.balance * this.rate, true)}`;
},
balanceForDisplay() {
if (!this.account || this.account.balance === undefined) return "";
diff --git a/src/frontend/electron_vue/src/layouts/WalletLayout.vue b/src/frontend/electron_vue/src/layouts/WalletLayout.vue
index bd8f1b7039..e1a6314187 100644
--- a/src/frontend/electron_vue/src/layouts/WalletLayout.vue
+++ b/src/frontend/electron_vue/src/layouts/WalletLayout.vue
@@ -74,7 +74,7 @@ export default {
AccountTooltip
},
computed: {
- ...mapState("app", ["progress", "rate"]),
+ ...mapState("app", ["progress", "rate", "currency"]),
...mapState("wallet", ["activeAccount", "unlocked"]),
...mapGetters("wallet", ["totalBalance", "miningAccount", "account"]),
walletLayoutClasses() {
@@ -92,7 +92,7 @@ export default {
},
totalBalanceFiat() {
if (!this.rate) return "";
- return `€ ${formatMoneyForDisplay(this.totalBalance * this.rate, true)}`;
+ return `${this.currency.symbol || ""} ${formatMoneyForDisplay(this.totalBalance * this.rate, true)}`;
},
balanceForDisplay() {
if (this.totalBalance == null) return "";
diff --git a/src/frontend/electron_vue/src/locales/en.json b/src/frontend/electron_vue/src/locales/en.json
index 2488cd20e1..d72a64c42e 100644
--- a/src/frontend/electron_vue/src/locales/en.json
+++ b/src/frontend/electron_vue/src/locales/en.json
@@ -89,7 +89,8 @@
"percent": "%",
"add_to_holdin": "Add to holdin.com",
"remove_from_holdin": "Remove from holdin.com",
- "optimise_holding_account": "Select Funding Account"
+ "optimise_holding_account": "Select Funding Account",
+ "optimise_info": "Your account currently has {parts} parts. After optimisation, your account will have {futureOptimalAmount} parts."
},
"loader": {
"shutdown": "Shutting down...",
@@ -121,7 +122,8 @@
"choose_language": "Language",
"choose_decimal_places": "Decimal places",
"english": "EN",
- "dutch": "NL"
+ "dutch": "NL",
+ "select_display_currency": "Select Display Currency"
},
"setup": {
"choose_password": "Choose a password of at least 6 characters",
@@ -164,7 +166,8 @@
"confirm_transaction": "Confirm transaction",
"target_account": "Send to account",
"fee_will_be_subtracted": "Fee will be subtracted from the amount",
- "unlock_your_wallet_to_complete_the_transaction": "Unlock your wallet to complete the transaction"
+ "unlock_your_wallet_to_complete_the_transaction": "Unlock your wallet to complete the transaction",
+ "select_account": "Select Account"
},
"renew_saving_account": {
"funding_account": "Pay renewal fee from account"
diff --git a/src/frontend/electron_vue/src/store/index.js b/src/frontend/electron_vue/src/store/index.js
index bff38b9298..e80a4305bc 100644
--- a/src/frontend/electron_vue/src/store/index.js
+++ b/src/frontend/electron_vue/src/store/index.js
@@ -22,7 +22,8 @@ if (process.type !== "renderer") {
// only store the paths listed below
"mining.settings",
"app.language",
- "app.decimals"
+ "app.decimals",
+ "app.currency"
],
ignoredCommits: [
// only update persisted state on commits listed below
@@ -30,6 +31,7 @@ if (process.type !== "renderer") {
"mining/SET_THREAD_COUNT",
"mining/SET_ARENA_THREAD_COUNT",
"app/SET_LANGUAGE",
+ "app/SET_CURRENCY",
"app/SET_DECIMALS"
]
});
diff --git a/src/frontend/electron_vue/src/store/modules/app.js b/src/frontend/electron_vue/src/store/modules/app.js
index 058e030367..d3b34ca720 100644
--- a/src/frontend/electron_vue/src/store/modules/app.js
+++ b/src/frontend/electron_vue/src/store/modules/app.js
@@ -25,7 +25,8 @@ const app = {
walletVersion: null,
rate: null,
language: "en",
- decimals: 2
+ decimals: 2,
+ currency: { value: "Eur", label: "Euro", symbol: "€" }
},
mutations: {
SET_CORE_READY(state) {
@@ -50,6 +51,9 @@ const app = {
SET_RATE(state, rate) {
state.rate = rate;
},
+ SET_CURRENCIES(state, currencies) {
+ state.currencies = currencies;
+ },
SET_WALLET_EXISTS(state, walletExists) {
state.walletExists = walletExists;
},
@@ -62,6 +66,9 @@ const app = {
SET_LANGUAGE(state, language) {
state.language = language;
},
+ SET_CURRENCY(state, currency) {
+ state.currency = currency;
+ },
SET_DECIMALS(state, decimal) {
state.decimals = decimal;
}
@@ -90,12 +97,18 @@ const app = {
SET_RATE({ commit }, rate) {
commit("SET_RATE", rate);
},
+ SET_CURRENCIES({ commit }, currencies) {
+ commit("SET_CURRENCIES", currencies);
+ },
SET_ACTIVITY_INDICATOR({ commit }, activityIndicator) {
commit("SET_ACTIVITY_INDICATOR", activityIndicator);
},
SET_LANGUAGE({ commit }, language) {
commit("SET_LANGUAGE", language);
},
+ SET_CURRENCY({ commit }, currency) {
+ commit("SET_CURRENCY", currency);
+ },
SET_DECIMALS({ commit }, decimal) {
commit("SET_DECIMALS", decimal);
},
diff --git a/src/frontend/electron_vue/src/views/Account/MiningAccount/index.vue b/src/frontend/electron_vue/src/views/Account/MiningAccount/index.vue
index a21842a30e..0c6ca7dd73 100644
--- a/src/frontend/electron_vue/src/views/Account/MiningAccount/index.vue
+++ b/src/frontend/electron_vue/src/views/Account/MiningAccount/index.vue
@@ -192,14 +192,14 @@ export default {
settings: "settings",
totalBalanceFiat() {
if (!this.rate) return "";
- return `€ ${formatMoneyForDisplay(this.account.balance * this.rate, true)}`;
+ return `${this.currency.symbol || ""} ${formatMoneyForDisplay(this.account.balance * this.rate, true)}`;
},
balanceForDisplay() {
if (this.account.balance == null) return "";
return formatMoneyForDisplay(this.account.balance);
}
}),
- ...mapState("app", ["rate"]),
+ ...mapState("app", ["rate", "currency"]),
isMiningView() {
return this.$route.name === "account";
},
diff --git a/src/frontend/electron_vue/src/views/Account/SavingAccount/OptimiseAccount.vue b/src/frontend/electron_vue/src/views/Account/SavingAccount/OptimiseAccount.vue
index 2f465f09e9..bcc98b45de 100644
--- a/src/frontend/electron_vue/src/views/Account/SavingAccount/OptimiseAccount.vue
+++ b/src/frontend/electron_vue/src/views/Account/SavingAccount/OptimiseAccount.vue
@@ -5,6 +5,9 @@
+
+ {{ $t("saving_account.optimise_info", { parts: parts, futureOptimalAmount: futureOptimalAmount }) }}
+
@@ -36,7 +39,9 @@ export default {
password: null,
fundingAccount: null,
isAmountInvalid: false,
- isPasswordInvalid: false
+ isPasswordInvalid: false,
+ parts: null,
+ futureOptimalAmount: null
};
},
computed: {
@@ -57,9 +62,18 @@ export default {
disableSendButton() {
if (this.computedPassword.trim().length === 0) return true;
return false;
+ },
+ accountParts() {
+ return this.getStatistics("account_parts");
}
},
mounted() {
+ const stats = WitnessController.GetAccountWitnessStatistics(this.account.UUID);
+ this.parts = stats["account_parts"];
+
+ let optimalAmounts = WitnessController.GetOptimalWitnessDistributionForAccount(this.account.UUID);
+ this.futureOptimalAmount = optimalAmounts.length;
+
if (this.fundingAccounts.length) {
this.fundingAccount = this.fundingAccounts[0];
}
diff --git a/src/frontend/electron_vue/src/views/Account/SavingAccount/index.vue b/src/frontend/electron_vue/src/views/Account/SavingAccount/index.vue
index cfeccbda12..642a9ebdc3 100644
--- a/src/frontend/electron_vue/src/views/Account/SavingAccount/index.vue
+++ b/src/frontend/electron_vue/src/views/Account/SavingAccount/index.vue
@@ -95,7 +95,7 @@
-
+
@@ -132,7 +132,7 @@ export default {
this.isOverflown();
},
computed: {
- ...mapState("app", ["rate", "activityIndicator"]),
+ ...mapState("app", ["rate", "activityIndicator", "currency"]),
isAccountView() {
return this.$route.name === "account";
},
@@ -185,9 +185,17 @@ export default {
optimiseButtonVisible() {
return this.getStatistics("is_optimal") === false;
},
+ optimiseButtonClass() {
+ if (this.getStatistics("is_optimal") === true && this.getStatistics("blocks_since_last_activity") < 100) {
+ return "optimise-button-inactive";
+ } else if (this.getStatistics("is_optimal") === false) {
+ return "optimise-button-hidden";
+ }
+ return "";
+ },
totalBalanceFiat() {
if (!this.rate) return "";
- return `€ ${formatMoneyForDisplay(this.account.balance * this.rate, true)}`;
+ return `${this.currency.symbol || ""} ${formatMoneyForDisplay(this.account.balance * this.rate, true)}`;
},
balanceForDisplay() {
if (this.account.balance == null) return "";
@@ -207,17 +215,23 @@ export default {
account() {
this.initialize();
},
- compoundingPercent() {
+ compoundingPercent(newVal) {
// Prevent calling this on initialization.
if (this.compoundingPercent === 0) {
return;
} else {
- if (this.keyHash) {
- BackendUtilities.holdinAPIActions(this.keyHash, "distribution", this.compoundingPercent);
- WitnessController.SetAccountCompounding(this.account.UUID, this.compoundingPercent);
- } else {
- WitnessController.SetAccountCompounding(this.account.UUID, this.compoundingPercent);
- }
+ const timeoutHandler = setTimeout(() => {
+ if (newVal == this.compoundingPercent) {
+ if (this.keyHash) {
+ BackendUtilities.holdinAPIActions(this.keyHash, "distribution", this.compoundingPercent);
+ WitnessController.SetAccountCompounding(this.account.UUID, this.compoundingPercent);
+ } else {
+ WitnessController.SetAccountCompounding(this.account.UUID, this.compoundingPercent);
+ }
+ }
+ }, 1000);
+
+ return timeoutHandler;
}
}
},
@@ -269,8 +283,12 @@ export default {
return classNames;
},
routeTo(route) {
- if (this.$route.name === route) return;
- this.$router.push({ name: route, params: { id: this.account.UUID } });
+ if (route === "optimise-account" && this.optimiseButtonClass === "optimise-button-inactive") {
+ alert("Cannot perform this operation while account is in cooldown, please wait and try again later.");
+ } else {
+ if (this.$route.name === route) return;
+ this.$router.push({ name: route, params: { id: this.account.UUID } });
+ }
},
isOverflown(e) {
// Determine whether to show the overflow arrow
@@ -374,4 +392,10 @@ export default {
align-items: center;
bottom: 0;
}
+.optimise-button-inactive {
+ color: #a8a8a8;
+}
+.optimise-button-hidden {
+ display: none !important;
+}
diff --git a/src/frontend/electron_vue/src/views/Account/SpendingAccount/Send.vue b/src/frontend/electron_vue/src/views/Account/SpendingAccount/Send.vue
index 74ad70e29b..9466472a06 100644
--- a/src/frontend/electron_vue/src/views/Account/SpendingAccount/Send.vue
+++ b/src/frontend/electron_vue/src/views/Account/SpendingAccount/Send.vue
@@ -19,8 +19,23 @@
{{ this.useMax ? $t("send_coins.fee_will_be_subtracted") : " " }}
-
-
+
+
+
Receiving Address
+
+
+
My Accounts
+
+
+
+
+
+
+