+ delete and re-sync transactions

+ add to address book from send screen
This commit is contained in:
Taegus
2018-12-28 10:26:32 +01:00
parent d33f90b738
commit 1c629801c4
7 changed files with 94 additions and 40 deletions

View File

@@ -110,11 +110,11 @@ body.pg-loaded > .inner {
} }
#dlgGeneralError .modalBody { #dlgGeneralError .modalBody {
height: 100px; height: 100px;
} }
#dlgGeneralConfirm .modalBody { #dlgGeneralConfirm .modalBody {
height: 100px; height: 100px;
} }
#dlgDeleteAddressConfirm .modalBody { #dlgDeleteAddressConfirm .modalBody {
height: 100px; height: 100px;
@@ -129,6 +129,7 @@ body.pg-loaded > .inner {
height: 300px; height: 300px;
} }
#dlgAddAddressToBook .modalBody,
#dlgChangeWalletName .modalBody, #dlgChangeWalletName .modalBody,
#dlgChangeAddressName .modalBody { #dlgChangeAddressName .modalBody {
height: 150px; height: 150px;
@@ -364,4 +365,13 @@ div.noAddressWrapper {
#addressListFilter { #addressListFilter {
color: #aaa; color: #aaa;
}
.btnSendToolButton {
width: 40px;
padding: 0px;
}
#btnAddToAddressBook {
margin-right: 3px;
} }

View File

@@ -14,7 +14,8 @@
<div class="input-field col s6 addressInputWrapper"> <div class="input-field col s6 addressInputWrapper">
<input id="sendToAddress" placeholder="recipient address" type="text"> <input id="sendToAddress" placeholder="recipient address" type="text">
<label for="sendToAddress" class="active">To address:</label> <label for="sendToAddress" class="active">To address:</label>
<button type="button" class="btn btn-etho addressLookup" id="btnLookForToAddress"><i class="fas fa-search"></i></button> <button type="button" class="btn btn-etho btnSendToolButton" id="btnAddToAddressBook"><i class="fas fa-plus"></i></button>
<button type="button" class="btn btn-etho btnSendToolButton" id="btnLookForToAddress"><i class="fas fa-search"></i></button>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
@@ -91,4 +92,15 @@
<div class="modalBody" id="dlgAddressListBody"> <div class="modalBody" id="dlgAddressListBody">
</div> </div>
</div> </div>
<!-- The modal to add address to address book -->
<div id="dlgAddAddressToBook" class="modalDialog" data-iziModal-title="Address Name" data-iziModal-subtitle="Enter the name for this address" data-iziModal-icon="icon-home">
<div class="modalBody">
<div class="form-group">
<label for="usr">Address Name:</label>
<input type="text" class="form-control" id="inputAddressName">
</div>
<button type="button" class="btn btn-etho btn-dialog-confirm" id="btnAddAddressToBookConfirm">Confirm</button>
</div>
</div>

View File

@@ -1,8 +1,9 @@
const {app, ipcMain} = require('electron'); const {app, dialog, ipcMain} = require('electron');
const storage = require('electron-storage'); const storage = require('electron-storage');
const datastore = require('nedb'); const datastore = require('nedb');
const moment = require('moment'); const moment = require('moment');
const path = require('path'); const path = require('path');
const fs = require('fs');
const dbPath = path.join(app.getPath('userData'), 'storage.db'); const dbPath = path.join(app.getPath('userData'), 'storage.db');
const db = new datastore({ filename: dbPath }); const db = new datastore({ filename: dbPath });
@@ -76,4 +77,15 @@ ipcMain.on('setJSONFile', (event, arg) => {
event.returnValue = { success: true, error: null }; event.returnValue = { success: true, error: null };
} }
}); });
});
ipcMain.on('deleteTransactions', (event, arg) => {
fs.unlink(dbPath, (err) => {
if (err) {
event.returnValue = { success: false, error: err };
dialog.showErrorBox("Error deleting the file", err.message);
} else {
event.returnValue = { success: true, error: null };
}
});
}); });

View File

@@ -55,6 +55,7 @@ class MainGUI {
$("#btnGeneralConfirmYes").click(function() { $("#btnGeneralConfirmYes").click(function() {
$('#dlgGeneralConfirm').iziModal('close'); $('#dlgGeneralConfirm').iziModal('close');
console.log(true);
callback(true); callback(true);
}); });

View File

@@ -109,6 +109,39 @@ $(document).on("render_send", function() {
} }
); );
}); });
$("#btnAddToAddressBook").off('click').on('click', function() {
if (EthoBlockchain.isAddress($("#sendToAddress").val())) {
$("#dlgAddAddressToBook").iziModal();
$("#inputAddressName").val("");
$('#dlgAddAddressToBook').iziModal('open');
function doAddAddressToAddressBook() {
EthoAddressBook.setAddressName($("#sendToAddress").val(), $("#inputAddressName").val());
$('#dlgAddAddressToBook').iziModal('close');
iziToast.success({
title: 'Success',
message: 'Address was added to address book',
position: 'topRight',
timeout: 2000
});
}
} else {
EthoMainGUI.showGeneralError("Recipient address is not valid!");
}
$("#btnAddAddressToBookConfirm").off('click').on('click', function() {
doAddAddressToAddressBook();
});
$("#dlgAddAddressToBook").off('keypress').on('keypress', function(e) {
if(e.which == 13) {
doAddAddressToAddressBook();
}
});
});
$("#btnSendTransaction").off('click').on('click', function() { $("#btnSendTransaction").off('click').on('click', function() {
if (EthoSend.validateSendForm()) { if (EthoSend.validateSendForm()) {

View File

@@ -17,7 +17,29 @@ $(document).on("render_settings", function() {
if (EthoTransactions.getIsSyncing()) { if (EthoTransactions.getIsSyncing()) {
EthoMainGUI.showGeneralError("Transactions sync is currently in progress"); EthoMainGUI.showGeneralError("Transactions sync is currently in progress");
} else { } else {
// first disable keepInSync
EthoTransactions.disableKeepInSync(); EthoTransactions.disableKeepInSync();
// then delete the transactions data
var counters = EthoDatatabse.getCounters();
counters.transactions = 0;
EthoDatatabse.setCounters(counters);
ipcRenderer.sendSync('deleteTransactions', null);
// sync all the transactions to the current block
web3Local.eth.getBlock("latest", function(error, localBlock) {
if (error) {
EthoMainGUI.showGeneralError(error);
} else {
EthoTransactions.enableKeepInSync();
EthoTransactions.syncTransactionsForAllAddresses(localBlock.number);
iziToast.success({
title: 'Success',
message: 'Transactions are being resynced',
position: 'topRight',
timeout: 5000
});
}
});
} }
} }
}); });

View File

@@ -102,42 +102,6 @@ class Transactions {
} }
enableKeepInSync() { enableKeepInSync() {
function processTransaction(data) {
if ((EthoWallets.getAddressExists(data.from)) || (EthoWallets.getAddressExists(data.to))) {
if (data.blockNumber) {
console.log(data.blockNumber);
}
var Transaction = {
block: null,
txhash: data.hash.toLowerCase(),
fromaddr: data.from.toLowerCase(),
timestamp: moment.unix(data.timestamp).format('YYYY-MM-DD HH:mm:ss'),
toaddr: data.to.toLowerCase(),
value: Number(data.value).toExponential(5).toString().replace('+','')
}
// store transaction and notify about new transactions
ipcRenderer.send('storeTransaction', Transaction);
$(document).trigger("onNewAccountTransaction");
iziToast.info({
title: 'New Transaction',
message: vsprintf('Transaction from address %s to address %s was just processed', [Transaction.fromaddr, Transaction.toaddr]),
position: 'topRight',
timeout: 10000
});
// render transactions again to show latest
if (EthoMainGUI.getAppState() == "transactions") {
setTimeout(function() {
EthoTransactions.renderTransactions();
}, 500);
}
}
}
EthoBlockchain.subsribeNewBlockHeaders( EthoBlockchain.subsribeNewBlockHeaders(
function(error) { function(error) {
EthoMainGUI.showGeneralError(error); EthoMainGUI.showGeneralError(error);