Skip to content

Commit

Permalink
Merge f35494b into 98f3a77
Browse files Browse the repository at this point in the history
  • Loading branch information
pbca26 authored Mar 1, 2022
2 parents 98f3a77 + f35494b commit f6a3715
Show file tree
Hide file tree
Showing 17 changed files with 89 additions and 47 deletions.
2 changes: 1 addition & 1 deletion electron/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "hw-kmd-wallet-electron",
"version": "0.3.1",
"version": "0.3.2",
"description": "Komodo Hardware Wallet Electron App",
"main": "main.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hw-kmd-wallet",
"version": "0.3.1",
"version": "0.3.2",
"author": "Luke Childs <[email protected]> (http://lukechilds.co.uk), Komodo Platform (https://komodoplatform.com)",
"repository": "pbca26/hw-kmd-wallet",
"homepage": "https://pbca26.github.io/hw-kmd-wallet",
Expand Down
11 changes: 9 additions & 2 deletions src/Accounts.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import Transactions from './Transactions';
import SendCoinButton from './SendCoinButton';
import {TX_FEE} from './constants';
import {TX_FEE, CACHE_MAX_LIFETIME} from './constants';
import humanReadableSatoshis from './lib/human-readable-satoshis';
import ClaimRewardsButton from './ClaimRewardsButton';
import CoinSettingsModal from './CoinSettingsModal';
Expand All @@ -16,6 +16,7 @@ import {
import {writeLog} from './Debug';
import {getLocalStorageVar} from './lib/localstorage-util';
import coinsList from './lib/coins';
import {checkTimestamp} from './lib/time';

class Account extends React.Component {
state = this.initialState;
Expand Down Expand Up @@ -115,6 +116,7 @@ const Accounts = ({
activeAccount,
removeCoin,
enableAccount,
checkTipTime,
}) => (
<div className="container content">
<div className="accounts-block">
Expand Down Expand Up @@ -183,7 +185,12 @@ const Accounts = ({
coin={coin}
tiptime={tiptime}
isClaimRewardsOnly={true}
claimableAmount={coins[activeCoin].accounts[activeAccount].claimableAmount} />
disabled={
!coins[activeCoin].lastChecked ||
(coins[activeCoin].lastChecked && checkTimestamp(coins[activeCoin].lastChecked) > CACHE_MAX_LIFETIME)
}
claimableAmount={coins[activeCoin].accounts[activeAccount].claimableAmount}
checkTipTime={checkTipTime} />
}
<UtxosModal
utxos={coins[activeCoin].accounts[activeAccount].utxos}
Expand Down
21 changes: 11 additions & 10 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ class App extends React.Component {

const currentTimestamp = Date.now() / 1000;
const secondsDiff = Math.floor(Number(currentTimestamp) - Number(tiptime));

if (Math.abs(secondsDiff) < MAX_TIP_TIME_DIFF) {
return tiptime;
} else {
Expand Down Expand Up @@ -341,10 +341,6 @@ class App extends React.Component {
this.setState({
explorerEndpointOverride,
});

setTimeout(() => {
console.warn(this.state);
}, 100)
}

checkExplorerEndpoints = async () => {
Expand Down Expand Up @@ -392,7 +388,7 @@ class App extends React.Component {
if (clearData &&
clearData !== 'logout') {
resetLocalStorage();
document.getElementById('body').removeEventListener('click');
document.getElementById('body').removeEventListener('click', null);
} else if (
clearData &&
clearData === 'logout') {
Expand Down Expand Up @@ -578,7 +574,7 @@ class App extends React.Component {
this.handleScanData({
coins: balances,
tiptime,
})
});
}
}
});
Expand All @@ -592,6 +588,7 @@ class App extends React.Component {

for (var i = 0; i < newCoins.length; i++) {
coins[newCoins[i].coin] = newCoins[i];
coins[newCoins[i].coin].lastChecked = Date.now();
}

for (let coin in coins) {
Expand Down Expand Up @@ -689,7 +686,8 @@ class App extends React.Component {
closeLoginModal={this.closeLoginModal}
resetState={this.resetState}
isClosed={this.state.loginModalClosed}
isAuth={this.state.isAuth} />
isAuth={this.state.isAuth}
triggerSidebarSizeChange={this.triggerSidebarSizeChange} />
<Header>
<div className="navbar-brand">
<div className="navbar-item">
Expand Down Expand Up @@ -810,7 +808,9 @@ class App extends React.Component {
isAuth={this.state.isAuth}
resetState={this.resetState}
triggerSidebarSizeChange={this.triggerSidebarSizeChange}
updateExplorerEndpoint={this.updateExplorerEndpoint} />
updateExplorerEndpoint={this.updateExplorerEndpoint}
coins={this.state.coins}
checkTipTime={this.checkTipTime} />

{this.state.explorerEndpoint === false &&
<ConnectionError />
Expand Down Expand Up @@ -929,7 +929,8 @@ class App extends React.Component {
syncData={this.syncData}
removeCoin={this.removeCoin}
enableAccount={this.enableAccount}
addAccount={this.addAccount} />
addAccount={this.addAccount}
checkTipTime={this.checkTipTime} />
}
</React.Fragment>
)}
Expand Down
4 changes: 4 additions & 0 deletions src/ClaimRewardsButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const ClaimRewardsButton = ({
coin,
tiptime,
claimableAmount,
disabled,
checkTipTime,
}) => (
<SendCoinButton
account={account}
Expand All @@ -19,6 +21,8 @@ const ClaimRewardsButton = ({
coin={coin}
isClaimRewardsOnly={true}
tiptime={tiptime}
disabled={disabled}
checkTipTime={checkTipTime}
className="claim-rewards-btn">
<i className="fa fa-donate"></i> Claim {humanReadableSatoshis(Math.max(0, claimableAmount))} rewards
</SendCoinButton>
Expand Down
2 changes: 1 addition & 1 deletion src/DashboardOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DashboardOperations extends React.Component {
<span className="date">{item.date}</span>
</div>
<div className="item-right-pane">
<span className="amount">{item.amount}</span>
<span className={item.type === 'received' || item.type === 'rewards' ? 'amount-increase' : 'amount-decrease'}>{item.type === 'received' || item.type === 'rewards' ? '+' + item.amount : '-' + item.amount}</span>
</div>
</div>
))}
Expand Down
1 change: 1 addition & 0 deletions src/LoginModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class LoginModal extends React.Component {
<SettingsModal
resetState={this.props.resetState}
isAuth={this.state.isAuth}
triggerSidebarSizeChange={this.props.triggerSidebarSizeChange}
coin="KMD" />
Password <input
style={{'marginLeft': '10px','padding': '5px', 'width': 'calc(100% - 100px)'}}
Expand Down
2 changes: 0 additions & 2 deletions src/SelectCoinModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ class SelectCoinModal extends React.Component {
}

render() {
console.warn(this.state.selectedCoins);

return (
<React.Fragment>
<div
Expand Down
23 changes: 14 additions & 9 deletions src/SendCoinButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,15 @@ class SendCoinButton extends React.Component {

if (!isUserInputValid) {
const {coin} = this.props;

const tiptime = await blockchain[blockchainAPI].getTipTime();

//tiptime = this.props.checkTipTime(tiptime);

let tiptime = await blockchain[blockchainAPI].getTipTime();
tiptime = this.props.checkTipTime(this.props.tiptime);

let currentAction;
try {
if (coin === 'KMD' && !tiptime) {
throw new Error('Unable to get tiptime!');
}

currentAction = 'connect';
updateActionState(this, currentAction, 'loading');
const hwIsAvailable = await hw[this.props.vendor].isAvailable();
Expand Down Expand Up @@ -353,7 +355,7 @@ class SendCoinButton extends React.Component {
[{address: txData.outputAddress, value: txData.value}, {address: txData.changeAddress, value: txData.change + txData.totalInterest - (isClaimRewardsOnly ? 0 : TX_FEE * 2), derivationPath}] : [{address: txData.outputAddress, value: txData.value}]);

writeLog('rawtx', rawtx);
if (!rawtx) {
if (!rawtx || typeof rawtx !== 'string') {
throw new Error(`${VENDOR[this.props.vendor]} failed to generate a valid transaction`);
}
updateActionState(this, currentAction, true);
Expand Down Expand Up @@ -502,7 +504,7 @@ class SendCoinButton extends React.Component {

const {isClaimingRewards} = this.state;
const isNoBalace = this.props.isClaimRewardsOnly ? Number(this.props.balance) <= 0 : Number(this.props.accounts[this.state.accountIndex].balance || 0) <= 0;
let {coin, isClaimRewardsOnly, balance} = this.props;
let {coin, isClaimRewardsOnly, balance, disabled} = this.props;

if (!this.props.isClaimRewardsOnly) {
balance = this.props.accounts[this.state.accountIndex].balance || 0;
Expand All @@ -518,6 +520,7 @@ class SendCoinButton extends React.Component {
<button
className={`button is-primary${this.props.className ? ' ' + this.props.className : ''}`}
disabled={
disabled ||
isNoBalace ||
(coin === 'KMD' && this.props.account.claimableAmount < KMD_REWARDS_MIN_THRESHOLD && isClaimRewardsOnly)
}
Expand All @@ -526,7 +529,9 @@ class SendCoinButton extends React.Component {
</button>
}
{!this.props.isClaimRewardsOnly &&
<li onClick={this.initSendCoinForm}>
<li
onClick={disabled && coin === 'KMD' ? null : this.initSendCoinForm}
className={disabled && coin === 'KMD' ? 'disabled': ''}>
<i className="fa fa-paper-plane"></i>
{this.props.sidebarSize === 'full' &&
<span className="sidebar-item-title">Send</span>
Expand Down Expand Up @@ -607,7 +612,7 @@ class SendCoinButton extends React.Component {
Send change to
<select
style={{'marginLeft': '10px'}}
className="account-index-selector"
className="account-index-selector minimal"
name="address"
value={this.state.address}
onChange={(event) => this.updateInput(event)}>
Expand Down
9 changes: 8 additions & 1 deletion src/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
shell,
} from './Electron';
import {getLocalStorageVar} from './lib/localstorage-util';
import {CACHE_MAX_LIFETIME} from './constants';
import {checkTimestamp} from './lib/time';

class Sidebar extends React.Component {
state = this.initialState;
Expand Down Expand Up @@ -53,7 +55,12 @@ class Sidebar extends React.Component {
vendor={this.props.vendor}
syncData={this.props.syncData}
coin={this.props.activeCoin}
sidebarSize={sidebarSize}>
sidebarSize={sidebarSize}
checkTipTime={this.props.checkTipTime}
disabled={
(this.props.activeCoin === 'KMD' && !this.props.coins.KMD.lastChecked) ||
(this.props.activeCoin === 'KMD' && this.props.coins.KMD.lastChecked && checkTimestamp(this.props.coins.KMD.lastChecked) > CACHE_MAX_LIFETIME)
}>
Send
</SendCoinButton>
}
Expand Down
4 changes: 2 additions & 2 deletions src/TransactionViewModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class TransactionDetailsModal extends React.Component {
<i className={`fa fa-long-arrow-alt-${tx.type === 'sent' ? 'up' : 'down'}`}></i>
{Number(tx.height) === -1 || Number(tx.height) === 0 || Number(tx.confirmations) === 0 ? 'pending' : tx.type}
</div>
<div className={`amount ${tx.type === 'received' ? 'amount-increase' : 'amount-decrease'}`}>
{tx.type === 'received' ? '+' + tx.amount : '-' + tx.amount} {coin}
<div className={`amount ${tx.type === 'received' || tx.type === 'rewards' ? 'amount-increase' : 'amount-decrease'}`}>
{tx.type === 'received' || tx.type === 'rewards' ? '+' + tx.amount : '-' + tx.amount} {coin}
</div>
</div>
<table className="table">
Expand Down
2 changes: 1 addition & 1 deletion src/Transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class Transactions extends React.Component {
{coin} {tx.accountIndex + 1}
</td>
}
<td className={tx.type === 'received' ? 'amount-increase' : 'amount-decrease'}>{tx.type === 'received' ? '+' + tx.amount : '-' + tx.amount}</td>
<td className={tx.type === 'received' || tx.type === 'rewards' ? 'amount-increase' : 'amount-decrease'}>{tx.type === 'received' || tx.type === 'rewards' ? '+' + tx.amount : '-' + tx.amount}</td>
{/*<td>{tx.confirmations}</td>*/}
</tr>
))}
Expand Down
3 changes: 2 additions & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,5 @@ export const SETTINGS = {
1800: '30 min',
3200: '60 min',
},
};
};
export const CACHE_MAX_LIFETIME = 10 * 60;
9 changes: 4 additions & 5 deletions src/lib/account-discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,12 @@ const getAddressUtxos = async addresses => {
}));
};

const getAddressHistory = async addresses => {
const getAddressHistory = async (addresses, coin) => {
const history = await blockchain[blockchainAPI].getHistory(addresses.map(a => a.address));

return {
addresses: addresses,
allTxs: history.items,
historyParsed: parseHistory(history.items, addresses.map(a => a.address)),
historyParsed: parseHistory(history.items, addresses.map(a => a.address), {coin}),
};
};

Expand Down Expand Up @@ -242,7 +241,7 @@ const accountDiscovery = async (vendor, coin, _accounts) => {
accounts.push(account);
} else {
account.utxos = await getAddressUtxos(account.addresses);
account.history = await getAddressHistory(account.addresses);
account.history = await getAddressHistory(account.addresses, coin);
account.accountIndex = accountIndex;
account.enabled = true;
}
Expand Down Expand Up @@ -274,7 +273,7 @@ const accountDiscovery = async (vendor, coin, _accounts) => {
if (config.accountIndex === 0 && accountIndex >= 2) break;
} else {
account.utxos = await getAddressUtxos(account.addresses);
account.history = await getAddressHistory(account.addresses);
account.history = await getAddressHistory(account.addresses, coin);
account.accountIndex = accountIndex;
account.enabled = _accounts && _accounts[accountIndex] ? _accounts[accountIndex].enabled : true;
accounts.push(account);
Expand Down
18 changes: 14 additions & 4 deletions src/lib/history-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import {writeLog} from '../Debug';
const parse = ([txs, addr, options]) => {
let txHistory = [];
let addresses = [];
let myOutAddress = false;

if (options && options.hasOwnProperty('debug')) {
writeLog('parsehistory txs', txs);
}

for (let i = 0; i < txs.length; i++) {
let tx = {};
let vinSum = 0, voutSum = 0;
let vinSum = 0, voutSum = 0, txVin = 0, txVout = 0;

if (options && options.hasOwnProperty('debug')) {
writeLog('--- vin -->');
Expand All @@ -23,6 +24,8 @@ const parse = ([txs, addr, options]) => {
}

for (let j = 0; j < txs[i].vin.length; j++) {
if (txs[i].vin[j].value) txVin += Number(txs[i].vin[j].value);

if (addresses.indexOf(txs[i].vin[j].addr) === -1) {
addresses.push(txs[i].vin[j].addr);
}
Expand All @@ -33,13 +36,16 @@ const parse = ([txs, addr, options]) => {
}

for (let j = 0; j < txs[i].vout.length; j++) {
if (txs[i].vout[j].value) txVout += Number(txs[i].vout[j].value);

if (addresses.indexOf(txs[i].vout[j].scriptPubKey.addresses[0]) === -1) {
addresses.push(txs[i].vout[j].scriptPubKey.addresses[0]);
}

if (addr.indexOf(txs[i].vout[j].scriptPubKey.addresses[0]) > -1) {
voutSum += Number(txs[i].vout[j].value);
writeLog('vout', JSON.stringify(txs[i].vout[j]));
myOutAddress = true;
}
}

Expand All @@ -59,9 +65,13 @@ const parse = ([txs, addr, options]) => {
};

// TODO: dectect send to self txs
if /*(vinSum && voutSum) {
tx.type = 'self';
} else if */(vinSum && !voutSum) {
if (options &&
options.coin &&
options.coin.toUpperCase() === 'KMD' &&
(Number(txVin - txVout) < 0) &&
myOutAddress) {
tx.type = 'rewards';
} else if (vinSum && !voutSum) {
tx.type = 'sent';
} else if (!vinSum && voutSum) {
tx.type = 'received';
Expand Down
Loading

0 comments on commit f6a3715

Please sign in to comment.