Files
paperclip-wallet/renderer/wallets.js
Taegus 62f8be866e + tooltips
+ sort transactions by date correctly
+ confirmed transactions indicator
2018-12-20 18:29:23 +01:00

189 lines
5.2 KiB
JavaScript

const {ipcRenderer} = require('electron');
class Wallets {
constructor() {
this.addressList = [];
}
getAddressList() {
return this.addressList;
}
clearAddressList() {
this.addressList = [];
}
getAddressExists(address) {
return this.addressList.indexOf(address.toLowerCase()) > -1;
}
addAddressToList(address) {
this.addressList.push(address.toLowerCase());
}
enableButtonTooltips() {
EthoUtils.createToolTip("#btnNewAddress", "Create New Address");
EthoUtils.createToolTip("#btnExportAccounts", "Export Accounts");
EthoUtils.createToolTip("#btnImportAccounts", "Import Accounts");
}
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 {
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);
});
// render the wallets current state
EthoMainGUI.renderTemplate("wallets.html", data);
$(document).trigger("render_wallets");
EthoWallets.enableButtonTooltips();
}
);
}
}
// the event to tell us that the wallets are rendered
$(document).on("render_wallets", function() {
$('#addressTable').floatThead();
$("#btnNewAddress").off('click').on('click', function() {
$("#dlgCreateWalletPassword").iziModal();
$("#walletPasswordFirst").val("");
$("#walletPasswordSecond").val("");
$('#dlgCreateWalletPassword').iziModal('open');
function doCreateNewWallet() {
$('#dlgCreateWalletPassword').iziModal('close');
if (EthoWallets.validateNewAccountForm()) {
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
});
}
);
}
}
$("#btnCreateWalletConfirm").off('click').on('click', function() {
doCreateNewWallet();
});
$("#dlgCreateWalletPassword").off('keypress').on('keypress', function(e) {
if(e.which == 13) {
doCreateNewWallet();
}
});
});
$(".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');
function doChangeWalletName() {
var wallets = ipcRenderer.sendSync('getJSONFile', 'wallets.json');
if (!wallets) {
wallets = { names: {} };
}
// set the wallet name from the dialog box
wallets.names[walletAddress] = $("#inputWalletName").val();
ipcRenderer.sendSync('setJSONFile',
{
file: 'wallets.json',
data: wallets
});
$('#dlgChangeWalletName').iziModal('close');
EthoWallets.renderWalletsState();
}
$("#btnChangeWalletNameConfirm").off('click').on('click', function() {
doChangeWalletName();
});
$("#dlgChangeWalletName").off('keypress').on('keypress', function(e) {
if(e.which == 13) {
doChangeWalletName();
}
});
});
$("#btnExportAccounts").off('click').on('click', function() {
ipcRenderer.send('exportAccounts', {});
});
$("#btnImportAccounts").off('click').on('click', function() {
ipcRenderer.sendSync('importAccounts', {});
});
$(".textAddress").off('click').on('click', function() {
EthoMainGUI.copyToClipboard($(this).html());
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() {
EthoMainGUI.changeAppState("account");
EthoWallets.renderWalletsState();
});
$(document).on("onNewAccountTransaction", function() {
if (EthoMainGUI.getAppState() == "account") {
EthoWallets.renderWalletsState();
}
});
EthoWallets = new Wallets();