+ beautifier

* version info
This commit is contained in:
Taegus
2019-03-03 10:37:19 +01:00
parent de73afd5cd
commit b0cd7d517a
19 changed files with 1648 additions and 1697 deletions

View File

@@ -1,13 +1,12 @@
const {ipcRenderer} = require('electron');
const {ipcRenderer} = require("electron");
class Wallets {
constructor() {
this.addressList = [];
this.addressList = [];
$.getJSON("https://min-api.cryptocompare.com/data/price?fsym=ETHO&tsyms=USD", function( price )
{
$.getJSON("https://min-api.cryptocompare.com/data/price?fsym=ETHO&tsyms=USD", function (price) {
EthoWallets._setPrice(price.USD);
});
});
}
_getPrice() {
@@ -23,7 +22,7 @@ class Wallets {
}
clearAddressList() {
this.addressList = [];
this.addressList = [];
}
getAddressExists(address) {
@@ -47,111 +46,103 @@ class Wallets {
EthoUtils.createToolTip("#btnImportAccounts", "Import Accounts");
EthoUtils.createToolTip("#btnImportFromPrivateKey", "Import From Private Key");
}
validateNewAccountForm() {
if (EthoMainGUI.getAppState() == "account") {
if (!$("#walletPasswordFirst").val()) {
EthoMainGUI.showGeneralError("Password cannot be empty!");
return false;
}
if (!$("#walletPasswordSecond").val()) {
EthoMainGUI.showGeneralError("Password cannot be empty!");
return false;
}
if ($("#walletPasswordFirst").val() !== $("#walletPasswordSecond").val()) {
EthoMainGUI.showGeneralError("Passwords do not match!");
return false;
}
return true;
} else {
if (!$("#walletPasswordFirst").val()) {
EthoMainGUI.showGeneralError("Password cannot be empty!");
return false;
}
}
}
renderWalletsState() {
if (!$("#walletPasswordSecond").val()) {
EthoMainGUI.showGeneralError("Password cannot be empty!");
return false;
}
if ($("#walletPasswordFirst").val() !== $("#walletPasswordSecond").val()) {
EthoMainGUI.showGeneralError("Passwords do not match!");
return false;
}
return true;
} else {
return false;
}
}
renderWalletsState() {
// clear the list of addresses
EthoWallets.clearAddressList();
EthoBlockchain.getAccountsData(
function(error) {
EthoMainGUI.showGeneralError(error);
},
function(data) {
data.addressData.forEach(element => {
EthoWallets.addAddressToList(element.address);
});
EthoBlockchain.getAccountsData(function (error) {
EthoMainGUI.showGeneralError(error);
}, function (data) {
data.addressData.forEach(element => {
EthoWallets.addAddressToList(element.address);
});
// render the wallets current state
EthoMainGUI.renderTemplate("wallets.html", data);
$(document).trigger("render_wallets");
EthoWallets.enableButtonTooltips();
// render the wallets current state
EthoMainGUI.renderTemplate("wallets.html", data);
$(document).trigger("render_wallets");
EthoWallets.enableButtonTooltips();
$("#labelSumDollars").html(vsprintf("/ %.2f $ / %.4f $ per ETHO", [data.sumBalance * EthoWallets._getPrice(), EthoWallets._getPrice()]));
}
);
$("#labelSumDollars").html(vsprintf("/ %.2f $ / %.4f $ per ETHO", [
data.sumBalance * EthoWallets._getPrice(),
EthoWallets._getPrice()
]));
});
}
}
// the event to tell us that the wallets are rendered
$(document).on("render_wallets", function() {
$('#addressTable').floatThead();
$(document).on("render_wallets", function () {
$("#addressTable").floatThead();
$("#btnNewAddress").off('click').on('click', function() {
$("#btnNewAddress").off("click").on("click", function () {
$("#dlgCreateWalletPassword").iziModal();
$("#walletPasswordFirst").val("");
$("#walletPasswordSecond").val("");
$('#dlgCreateWalletPassword').iziModal('open');
$("#dlgCreateWalletPassword").iziModal("open");
function doCreateNewWallet() {
$('#dlgCreateWalletPassword').iziModal('close');
$("#dlgCreateWalletPassword").iziModal("close");
if (EthoWallets.validateNewAccountForm()) {
EthoBlockchain.createNewAccount($("#walletPasswordFirst").val(),
function(error) {
EthoMainGUI.showGeneralError(error);
},
function(account) {
EthoWallets.addAddressToList(account);
EthoWallets.renderWalletsState();
EthoBlockchain.createNewAccount($("#walletPasswordFirst").val(), function (error) {
EthoMainGUI.showGeneralError(error);
}, function (account) {
EthoWallets.addAddressToList(account);
EthoWallets.renderWalletsState();
iziToast.success({
title: 'Created',
message: 'New wallet was successfully created',
position: 'topRight',
timeout: 5000
});
}
);
}
iziToast.success({title: "Created", message: "New wallet was successfully created", position: "topRight", timeout: 5000});
});
}
}
$("#btnCreateWalletConfirm").off('click').on('click', function() {
$("#btnCreateWalletConfirm").off("click").on("click", function () {
doCreateNewWallet();
});
$("#dlgCreateWalletPassword").off('keypress').on('keypress', function(e) {
if(e.which == 13) {
$("#dlgCreateWalletPassword").off("keypress").on("keypress", function (e) {
if (e.which == 13) {
doCreateNewWallet();
}
});
});
});
});
$(".btnShowAddressTransactions").off('click').on('click', function() {
EthoTransactions.setFilter($(this).attr('data-wallet'));
$(".btnShowAddressTransactions").off("click").on("click", function () {
EthoTransactions.setFilter($(this).attr("data-wallet"));
EthoMainGUI.changeAppState("transactions");
EthoTransactions.renderTransactions();
});
$(".btnChangWalletName").off('click').on('click', function() {
var walletAddress = $(this).attr('data-wallet');
var walletName = $(this).attr('data-name');
$(".btnChangWalletName").off("click").on("click", function () {
var walletAddress = $(this).attr("data-wallet");
var walletName = $(this).attr("data-name");
$("#dlgChangeWalletName").iziModal();
$("#inputWalletName").val(walletName);
$('#dlgChangeWalletName').iziModal('open');
$("#dlgChangeWalletName").iziModal("open");
function doChangeWalletName() {
var wallets = EthoDatatabse.getWallets();
@@ -160,103 +151,86 @@ $(document).on("render_wallets", function() {
wallets.names[walletAddress] = $("#inputWalletName").val();
EthoDatatabse.setWallets(wallets);
$('#dlgChangeWalletName').iziModal('close');
$("#dlgChangeWalletName").iziModal("close");
EthoWallets.renderWalletsState();
}
$("#btnChangeWalletNameConfirm").off('click').on('click', function() {
$("#btnChangeWalletNameConfirm").off("click").on("click", function () {
doChangeWalletName();
});
$("#dlgChangeWalletName").off('keypress').on('keypress', function(e) {
if(e.which == 13) {
$("#dlgChangeWalletName").off("keypress").on("keypress", function (e) {
if (e.which == 13) {
doChangeWalletName();
}
});
});
$("#btnRefreshAddress").off('click').on('click', function() {
});
});
$("#btnRefreshAddress").off("click").on("click", function () {
EthoWallets.renderWalletsState();
});
$("#btnExportAccounts").off('click').on('click', function() {
ipcRenderer.send('exportAccounts', {});
$("#btnExportAccounts").off("click").on("click", function () {
ipcRenderer.send("exportAccounts", {});
});
$("#btnImportAccounts").off('click').on('click', function() {
var ImportResult = ipcRenderer.sendSync('importAccounts', {});
$("#btnImportAccounts").off("click").on("click", function () {
var ImportResult = ipcRenderer.sendSync("importAccounts", {});
if (ImportResult.success) {
iziToast.success({
title: 'Imported',
message: ImportResult.text,
position: 'topRight',
timeout: 2000
});
iziToast.success({title: "Imported", message: ImportResult.text, position: "topRight", timeout: 2000});
} else if (ImportResult.success == false) {
EthoMainGUI.showGeneralError(ImportResult.text);
}
});
$("#btnImportFromPrivateKey").off('click').on('click', function() {
$("#btnImportFromPrivateKey").off("click").on("click", function () {
$("#dlgImportFromPrivateKey").iziModal();
$("#inputPrivateKey").val("");
$('#dlgImportFromPrivateKey').iziModal('open');
$("#dlgImportFromPrivateKey").iziModal("open");
function doImportFromPrivateKeys() {
var account = EthoBlockchain.importFromPrivateKey($("#inputPrivateKey").val());
$('#dlgImportFromPrivateKey').iziModal('close');
$("#dlgImportFromPrivateKey").iziModal("close");
if (account) {
ipcRenderer.sendSync('saveAccount', account[0]);
ipcRenderer.sendSync("saveAccount", account[0]);
EthoWallets.renderWalletsState();
iziToast.success({
title: 'Imported',
message: "Account was succesfully imported",
position: 'topRight',
timeout: 2000
});
iziToast.success({title: "Imported", message: "Account was succesfully imported", position: "topRight", timeout: 2000});
} else {
EthoMainGUI.showGeneralError("Error importing account from private key!");
}
}
$("#btnImportFromPrivateKeyConfirm").off('click').on('click', function() {
$("#btnImportFromPrivateKeyConfirm").off("click").on("click", function () {
doImportFromPrivateKeys();
});
$("#dlgImportFromPrivateKey").off('keypress').on('keypress', function(e) {
if(e.which == 13) {
$("#dlgImportFromPrivateKey").off("keypress").on("keypress", function (e) {
if (e.which == 13) {
doImportFromPrivateKeys();
}
});
});
});
$(".textAddress").off('click').on('click', function() {
$(".textAddress").off("click").on("click", function () {
EthoMainGUI.copyToClipboard($(this).html());
iziToast.success({
title: 'Copied',
message: 'Address was copied to clipboard',
position: 'topRight',
timeout: 2000
});
iziToast.success({title: "Copied", message: "Address was copied to clipboard", position: "topRight", timeout: 2000});
});
});
// event that tells us that geth is ready and up
$(document).on("onGethReady", function() {
$(document).on("onGethReady", function () {
EthoMainGUI.changeAppState("account");
EthoWallets.renderWalletsState();
});
$(document).on("onNewAccountTransaction", function() {
$(document).on("onNewAccountTransaction", function () {
if (EthoMainGUI.getAppState() == "account") {
EthoWallets.renderWalletsState();
EthoWallets.renderWalletsState();
}
});
EthoWallets = new Wallets();