Skip to content

Commit

Permalink
GetBalance, shortcuts, small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Spl3en committed Mar 5, 2019
1 parent 79678b0 commit 90a2548
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 102 deletions.
8 changes: 6 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const DEFAULT_SETTINGS = {
pubnodes_exclude_offline: false,
tray_minimize: false,
tray_close: false,
darkmode: true,
darkmode: false,
service_config_format: config.walletServiceConfigFormat
};
const DEFAULT_SIZE = { width: 840, height: 700 };
Expand Down Expand Up @@ -232,6 +232,7 @@ function createWindow() {
}

function serviceBinCheck() {
/*
if (DEFAULT_SERVICE_BIN.startsWith('/tmp')) {
log.warn(`AppImage env, copying service bin file`);
let targetPath = path.join(app.getPath('userData'), SERVICE_FILENAME);
Expand Down Expand Up @@ -266,6 +267,7 @@ function serviceBinCheck() {
settings.set('service_bin', DEFAULT_SERVICE_BIN);
}
}
*/
}

function initSettings() {
Expand All @@ -276,10 +278,12 @@ function initSettings() {
});
settings.set('service_password', crypto.randomBytes(32).toString('hex'));
settings.set('version', SVALINN_VERSION);
serviceBinCheck();
// serviceBinCheck();
/*
fs.unlink(WALLET_CFGFILE, (err) => {
if (err) log.debug(err.code === 'ENOENT' ? 'No stalled wallet config' : err.message);
});
*/
}

app.on('browser-window-created', function (e, window) {
Expand Down
4 changes: 2 additions & 2 deletions src/html/overview_create.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ <h2 class="title">Create new wallet</h2>
<div class="div-input">
<div class="input-wrap">
<h4 class="text-spaced input-required">Select where the wallet file will be stored</h4>
<input required="required" data-fileobj="wallet file"
<input required="required" data-fileobj="wallet file" data-extension="icx" data-object="Wallet"
data-selection="saveFile" data-targetinput="input-create-path"
readonly="readonly" class="text-block path-input-button" id="input-create-path"
placeholder="Required, full path to store this wallet..."
/>
<button data-fileobj="wallet file" data-selection="saveFile" data-targetinput="input-create-path" type="button" class="button-green path-input-button notabindex" id="button-create-browse"><i class="fas fa-folder-open"></i></button>
<button data-fileobj="wallet file" data-extension="icx" data-object="Wallet" data-selection="saveFile" data-targetinput="input-create-path" type="button" class="button-green path-input-button notabindex" id="button-create-browse"><i class="fas fa-folder-open"></i></button>
</div>
<div class="input-wrap">
<h4 class="text-spaced input-required">Set password to open this wallet</h4>
Expand Down
4 changes: 2 additions & 2 deletions src/html/overview_import_key.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ <h2 class="title">Import Private Key</h2>
<div class="div-input">
<div class="input-wrap">
<h4 class="text-spaced input-required">Select where the wallet file will be stored</h4>
<input required="required" data-fileobj="wallet file"
<input required="required" data-fileobj="wallet file" data-extension="icx" data-object="Wallet"
data-selection="saveFile" data-targetinput="input-import-path"
class="text-block path-input-button" id="input-import-path" readonly="readonly"
placeholder="Required, full path to store this wallet..."
/>
<button data-fileobj="wallet file" data-selection="saveFile" data-targetinput="input-import-path" type="button" class="button-green path-input-button notabindex" id="button-import-browse"><i class="fas fa-folder-open"></i></button>
<button data-fileobj="wallet file" data-extension="icx" data-object="Wallet" data-selection="saveFile" data-targetinput="input-import-path" type="button" class="button-green path-input-button notabindex" id="button-import-browse"><i class="fas fa-folder-open"></i></button>
</div>

<div class="input-wrap">
Expand Down
16 changes: 6 additions & 10 deletions src/html/shortcuts.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,24 @@ <h4>Available Keybindings:</h4>
<th scope="col"><kbd>Ctrl</kbd>+<kbd>i</kbd></th>
<td>Switch to <strong>Import wallet from private keys</strong> screen</td>
</tr>
<tr>
<th scope="col"><kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>i</kbd></th>
<td>Switch to <strong>Import wallet from mnemonic seed</strong> screen</td>
</tr>
<tr>
<th scope="col"><kbd>Ctrl</kbd>+<kbd>e</kbd></th>
<td>Switch to <strong>Export private keys/seed</strong> screen (when wallet opened)</td>
<td>Switch to <strong>Export private keys</strong> screen (when wallet opened)</td>
</tr>
<tr>
<th scope="col"><kbd>Ctrl</kbd>+<kbd>t</kbd></th>
<td>Switch to <strong>Transactions</strong> screen (when wallet opened)</td>
<th scope="col"><kbd>Ctrl</kbd>+<kbd>s</kbd></th>
<td>Switch to <strong>Create Transaction</strong> screen (when wallet opened)</td>
</tr>
<tr>
<th scope="col"><kbd>Ctrl</kbd>+<kbd>s</kbd></th>
<td>Switch to <strong>Send/Transfer</strong> screen (when wallet opened)</td>
<th scope="col"><kbd>Ctrl</kbd>+<kbd>t</kbd></th>
<td>Switch to <strong>Send Transactions</strong> screen (when wallet opened)</td>
</tr>
<tr>
<th scope="col"><kbd>Ctrl</kbd>+<kbd>x</kbd></th>
<td>Close wallet</td>
</tr>
<tr>
<th scope="col"><kbd>Ctrl</kbd>+<kbd>\</kbd></th>
<th scope="col"><kbd>Ctrl</kbd>+<kbd>d</kbd></th>
<td>Toggle dark/night mode</td>
</tr>
<tr>
Expand Down
14 changes: 14 additions & 0 deletions src/js/ws_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,20 @@ SvalinnManager.prototype.notifyUpdate = function (msg) {
uiupdater.updateUiState(msg);
};

SvalinnManager.prototype.getBalance = function (address) {

return new Promise ((resolve, reject) => {
try {
const httpProvider = new IconService.HttpProvider ('http://iconation.team:9000/api/v3');
const iconService = new IconService (httpProvider);
const balance = iconService.getBalance (address).execute();
return resolve (balance);
} catch (err) {
return reject (err);
}
});
};

SvalinnManager.prototype.resetState = function () {
return this._reinitSession();
};
Expand Down
33 changes: 29 additions & 4 deletions src/js/wsui_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ const Menu = remote.Menu;
const WS_VERSION = settings.get('version', 'unknown');
const DEFAULT_WALLET_PATH = remote.app.getPath('documents');
const DEFAULT_TRANSACTION_PATH = remote.app.getPath('documents');
const WALLET_REFRESH_INTERVAL = 4 * 1000;

let refreshWalletWorker;


let WALLET_OPEN_IN_PROGRESS = false;
Expand Down Expand Up @@ -1264,11 +1267,28 @@ function handleWalletOpen() {
return false;
}

function balanceUpdate (address) {

wsmanager.getBalance (address).then ((balance) => {
balance = Number.parseFloat (balance / Math.pow(10, 18));
wsmanager.notifyUpdate ({
type: 'balanceUpdated',
data: balance
});
}).catch((err) => {
formMessageSet('load', 'warning', `Cannot get the balance (are you connected to Internet?)`);
});
}

function onSuccess() {
walletOpenInputPath.value = settings.get('recentWallet');
overviewWalletAddress.value = wsession.get('loadedWalletAddress');
balanceUpdate (overviewWalletAddress.value);

refreshWalletWorker = setInterval(() =>{
balanceUpdate (overviewWalletAddress.value);
}, WALLET_REFRESH_INTERVAL);

wsmanager.getNodeFee();
WALLET_OPEN_IN_PROGRESS = false;
changeSection('section-overview');

Expand Down Expand Up @@ -1353,6 +1373,9 @@ function handleWalletClose() {
if (dialog.hasAttribute('open')) dialog.close();
wsmanager.resetState();
wsutil.clearChild(dialog);

clearInterval(refreshWalletWorker);

// Go to welcome page
changeSection("section-welcome");
});
Expand Down Expand Up @@ -1642,7 +1665,7 @@ function handleSendTransfer() {
let fee = sendInputFee.value ? parseFloat(sendInputFee.value) : 0;
let minFee = config.minimumFee;
if (fee < minFee) {
formMessageSet('send', 'error', `Fee can't be less than ${wsutil.amountForMortal(minFee)}`);
formMessageSet('send', 'error', `Fee can't be less than ${config.minimumFee}`);
return;
}

Expand All @@ -1659,14 +1682,16 @@ function handleSendTransfer() {
let tx = {
to: recipientAddress,
from: wsession.get('loadedWalletAddress'),
value: Math.pow (10, 18) * amount, // 1 ICX = 10**18 Loops
value: Math.trunc (Math.pow (10, 18) * amount), // 1 ICX = 10**18 Loops
stepLimit: fee,
nid: 2,
nonce: 0,
version: "0x3",
timestamp: timeStampInMs * 1000
};

console.log(tx);

// if (paymentId.length) tx.paymentId = paymentId;

let tpl = `
Expand Down Expand Up @@ -2428,7 +2453,7 @@ function initKeyBindings() {
return openedDialog.close();
});

Mousetrap.bind([`ctrl+\\`, `command+\\`], () => {
Mousetrap.bind([`ctrl+d`, `command+d`], () => {
setDarkMode(!document.documentElement.classList.contains('dark'));
});
}
Expand Down
93 changes: 11 additions & 82 deletions src/js/wsui_updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,6 @@ function updateSyncProgress(data) {
updateBalance(resetBalance);
break;
case syncStatus.IDLE:
// sync status text
// statusText = 'IDLE';
// syncInfoBar.innerHTML = statusText;
// sync info bar class
// syncDiv.className = '';
// sync status icon
// iconSync.setAttribute('data-icon', 'pause-circle');
// iconSync.classList.remove('fa-spin');
// connection status
// connInfoDiv.classList.remove('conn-warning');
// connInfoDiv.classList.add('empty');
// connInfoDiv.textContent = '';

// sync sess flags
wsession.set('syncStarted', false);
wsession.set('synchronized', false);
Expand All @@ -110,6 +97,11 @@ function updateSyncProgress(data) {
setWinTitle();
// no node connected
wsession.set('connectedNode', '');
let resetBalance = {
availableBalance: 0,
lockedAmount: 0
};
updateBalance(resetBalance);
break;
case syncStatus.RESET:
if (!connInfoDiv.innerHTML.startsWith('Connected')) {
Expand Down Expand Up @@ -219,60 +211,11 @@ function fusionCompleted() {
wsutil.showToast('Optimization completed. You may need to repeat the process until your wallet is fully optimized.', 5000);
}

function updateBalance(data) {
function updateBalance (availableBalance)
{
const balanceAvailableField = document.querySelector('#balance-available > span');
const balanceLockedField = document.querySelector('#balance-locked > span');
const maxSendFormHelp = document.getElementById('sendFormHelp');
const sendMaxAmount = document.getElementById('sendMaxAmount');
let inputSendAmountField = document.getElementById('input-send-amount');

if (!data) return;
let availableBalance = parseFloat(data.availableBalance) || 0;

let bUnlocked = wsutil.amountForMortal(availableBalance);
let bLocked = wsutil.amountForMortal(data.lockedAmount);
let fees = (wsession.get('nodeFee') + config.minimumFee);
let maxSendRaw = (bUnlocked - fees);

if (maxSendRaw <= 0) {
inputSendAmountField.value = 0;
inputSendAmountField.setAttribute('max', '0.00');
inputSendAmountField.setAttribute('disabled', 'disabled');
maxSendFormHelp.innerHTML = "You don't have any funds to be sent.";
sendMaxAmount.dataset.maxsend = 0;
sendMaxAmount.classList.add('hidden');
wsession.set('walletUnlockedBalance', 0);
wsession.set('walletLockedBalance', 0);
if (availableBalance < 0) return;
}

balanceAvailableField.innerHTML = bUnlocked;
balanceLockedField.innerHTML = bLocked;
wsession.set('walletUnlockedBalance', bUnlocked);
wsession.set('walletLockedBalance', bLocked);
// update fusion progress
if (true === wsession.get('fusionProgress')) {
if (wsession.get('fusionStarted') && parseInt(bLocked, 10) <= 0) {
fusionCompleted();
} else {
if (parseInt(bLocked, 10) > 0) {
wsession.set('fusionStarted', true);
}
}
}

let walletFile = require('path').basename(settings.get('recentWallet'));
let wintitle = `(${walletFile}) - ${bUnlocked} ${config.assetTicker}`;
setWinTitle(wintitle);

if (maxSendRaw > 0) {
let maxSend = (maxSendRaw).toFixed(config.decimalPlaces);
inputSendAmountField.setAttribute('max', maxSend);
inputSendAmountField.removeAttribute('disabled');
maxSendFormHelp.innerHTML = `Max. amount is ${maxSend}`;
sendMaxAmount.dataset.maxsend = maxSend;
sendMaxAmount.classList.remove('hidden');
}
balanceAvailableField.innerHTML = availableBalance;
wsession.set ('walletUnlockedBalance', availableBalance);
}

function updateTransactions(result) {
Expand Down Expand Up @@ -377,28 +320,14 @@ function showFeeWarning(fee) {
});
}

function updateQr(address) {
//let backupReminder = document.getElementById('button-overview-showkeys');
function updateQr(address)
{
if (!address) {
triggerTxRefresh();
//backupReminder.classList.remove('connected');
try { clearInterval(window.backupReminderTimer); } catch (_e) { }
return;
}

// window.backupReminderTimer = setInterval(() => {
// if (Math.floor(Math.random() * Math.floor(2)) >= 1) {
// backupReminder.classList.add('connected');
// backupReminder.classList.add('reminder');
// setTimeout(() => {
// backupReminder.classList.remove('reminder');
// }, 2000);
// setTimeout(() => {
// backupReminder.classList.remove('connected');
// }, 2200);
// }
// }, 50000);

let walletHash = wsutil.fnvhash(address);
wsession.set('walletHash', walletHash);

Expand Down

0 comments on commit 90a2548

Please sign in to comment.