Skip to content
This repository has been archived by the owner on Jun 7, 2023. It is now read-only.

Commit

Permalink
Desktop: Realm Database implementation Desktop fixes (#874)
Browse files Browse the repository at this point in the history
* Desktop related fixes:
- Fix balance setting in `Balance` and `Sidebar` components
- Fix latest address retrieval
- Fix notification function
- Fix List component transaction list retrieval

* Remove `reverse` from account address list

* Mobile: Resolve lint errors

* Revert 5291972 and fix eslint config (see eslint/eslint#11231)
  • Loading branch information
rihardsgravis authored and laumair committed Jan 3, 2019
1 parent 3723658 commit ea5d79d
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 75 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yml
Expand Up @@ -78,6 +78,7 @@ rules:
no-throw-literal: 2
no-unmodified-loop-condition: 2
no-unused-expressions: [2, { "allowShortCircuit": true, "allowTernary": true }]
no-unused-vars: ["error", { "vars": "all", "args": "after-used", "ignoreRestSiblings": true, "argsIgnorePattern": "^_" }]
no-useless-call: 2
no-useless-concat: 2
no-var: 2
Expand Down
8 changes: 3 additions & 5 deletions src/desktop/native/preload/Electron.js
Expand Up @@ -438,16 +438,14 @@ const Electron = {
* @param {string} accountName - target account name
* @param {array} transactions - new transactions
* @param {array} confirmations - recently confirmed transactions
* @param {object} settings - wallet settings
*/
notify: (accountName, transactions, confirmations) => {
notify: (accountName, transactions, confirmations, settings) => {
if (!transactions.length && !confirmations.length) {
return;
}

const data = electronSettings.get('reduxPersist:settings');
const settings = JSON.parse(data);

if (!settings.notifications.general) {
if (!settings.notifications || !settings.notifications.general) {
return;
}

Expand Down
18 changes: 13 additions & 5 deletions src/desktop/src/ui/components/Balance.js
Expand Up @@ -6,6 +6,7 @@ import { withI18n } from 'react-i18next';
import { getAccountNamesFromState } from 'selectors/accounts';

import { formatValue, formatUnit } from 'libs/iota/utils';
import { accumulateBalance } from 'libs/iota/addresses';
import { round, roundDown } from 'libs/utils';
import { getCurrencySymbol } from 'libs/currency';

Expand Down Expand Up @@ -77,15 +78,22 @@ class Balance extends React.PureComponent {

const accountName = summary && index === -1 ? t('totalBalance') : accountNames[summary ? index : seedIndex];

const accountBalance =
const balances =
summary && index === -1
? Object.entries(accounts.accountInfo).reduce((total, account) => total + account[1].balance, 0)
: accounts.accountInfo[accountName].balance;
? Object.entries(accounts.accountInfo).reduce(
(total, [_accountName, accountData]) =>
total.concat(accountData.addressData.map((addressData) => addressData.balance)),
[],
)
: accounts.accountInfo[accountName].addressData.map((addressData) => addressData.balance);

const accountBalance = accumulateBalance(balances);

const currencySymbol = getCurrencySymbol(settings.currency);
const fiatBalance = round(accountBalance * marketData.usdPrice / 1000000 * settings.conversionRate, 2).toFixed(
const fiatBalance = round(
((accountBalance * marketData.usdPrice) / 1000000) * settings.conversionRate,
2,
);
).toFixed(2);

const balance = !balanceIsShort
? formatValue(accountBalance)
Expand Down
78 changes: 39 additions & 39 deletions src/desktop/src/ui/components/List.js
Expand Up @@ -42,7 +42,7 @@ class List extends React.PureComponent {
/** Toggle hide empty transactions */
toggleEmptyTransactions: PropTypes.func.isRequired,
/** Transaction history */
transfers: PropTypes.array.isRequired,
transactions: PropTypes.array.isRequired,
/** Promotes bundle
* @param {string} bundle - bundle hash
* @param {func} powFn - local Proof of Work function
Expand Down Expand Up @@ -147,7 +147,7 @@ class List extends React.PureComponent {
hideEmptyTransactions,
toggleEmptyTransactions,
updateAccount,
transfers,
transactions,
setItem,
currentItem,
t,
Expand All @@ -163,19 +163,19 @@ class List extends React.PureComponent {
Pending: 0,
};

const historyTx = orderBy(transfers, 'timestamp', ['desc']).filter((transfer) => {
const isReceived = transfer.incoming;
const isConfirmed = transfer.persistence;
const filteredTransactions = orderBy(transactions, 'timestamp', ['desc']).filter((transaction) => {
const isReceived = transaction.incoming;
const isConfirmed = transaction.persistence;

if (hideEmptyTransactions && transfer.transferValue === 0) {
if (hideEmptyTransactions && transaction.transferValue === 0) {
return false;
}

if (
search.length &&
transfer.message.toLowerCase().indexOf(search.toLowerCase()) < 0 &&
transfer.bundle.toLowerCase().indexOf(search.toLowerCase()) !== 0 &&
(!/^\+?\d+$/.test(search) || transfer.transferValue < parseInt(search))
transaction.message.toLowerCase().indexOf(search.toLowerCase()) < 0 &&
transaction.bundle.toLowerCase().indexOf(search.toLowerCase()) !== 0 &&
(!/^\+?\d+$/.test(search) || transaction.transferValue < parseInt(search))
) {
return false;
}
Expand All @@ -202,15 +202,15 @@ class List extends React.PureComponent {
return filter === 'All';
});

const activeTransfer = currentItem ? historyTx.filter((tx) => tx.bundle === currentItem)[0] : null;
const isActiveFailed = activeTransfer && activeTransfer.broadcasted === false;
const activeTx = currentItem ? filteredTransactions.filter((tx) => tx.bundle === currentItem)[0] : null;
const isActiveFailed = activeTx && activeTx.broadcasted === false;

return (
<React.Fragment>
<nav className={css.nav}>
<ul>
<a key="active" onClick={() => this.switchFilter(filter)}>
{t(filter.toLowerCase())} <small>({historyTx.length})</small>
{t(filter.toLowerCase())} <small>({filteredTransactions.length})</small>
<Icon icon="chevronDown" size={8} />
</a>
{loaded ? (
Expand Down Expand Up @@ -264,15 +264,15 @@ class List extends React.PureComponent {
<hr />
<div className={css.list}>
<Scrollbar>
{historyTx && historyTx.length ? (
historyTx.map((transfer, key) => {
const isReceived = transfer.incoming;
const isConfirmed = transfer.persistence;
{filteredTransactions.length ? (
filteredTransactions.map((transaction, key) => {
const isReceived = transaction.incoming;
const isConfirmed = transaction.persistence;

return (
<a
key={key}
onClick={() => setItem(transfer.bundle)}
onClick={() => setItem(transaction.bundle)}
className={classNames(
isConfirmed ? css.confirmed : css.pending,
isReceived ? css.received : css.sent,
Expand All @@ -288,7 +288,7 @@ class List extends React.PureComponent {
{formatTime(
navigator.language,
detectedTimezone,
convertUnixTimeToJSDate(transfer.timestamp),
convertUnixTimeToJSDate(transaction.timestamp),
)}
</span>
<span>
Expand All @@ -297,86 +297,86 @@ class List extends React.PureComponent {
: isReceived ? t('received') : t('sent')}
</span>
<span>
{transfer.transferValue === 0 ? '' : isReceived ? '+' : '-'}
{round(formatValue(transfer.transferValue), 1)}{' '}
{formatUnit(transfer.transferValue)}
{transaction.transferValue === 0 ? '' : isReceived ? '+' : '-'}
{round(formatValue(transaction.transferValue), 1)}{' '}
{formatUnit(transaction.transferValue)}
</span>
</div>
</a>
);
})
) : (
<p className={css.empty}>
{!transfers.length ? t('noTransactions') : t('history:noTransactionsFound')}
{!transactions.length ? t('noTransactions') : t('history:noTransactionsFound')}
</p>
)}
</Scrollbar>
</div>
<div className={classNames(css.popup, activeTransfer ? css.on : null)} onClick={() => setItem(null)}>
<div className={classNames(css.popup, activeTx ? css.on : null)} onClick={() => setItem(null)}>
<div>
{activeTransfer ? (
{activeTx ? (
<div
className={classNames(
activeTransfer.incoming ? css.received : css.sent,
activeTransfer.persistence ? css.confirmed : css.pending,
activeTx.incoming ? css.received : css.sent,
activeTx.persistence ? css.confirmed : css.pending,
)}
>
<p>
<strong>
{activeTransfer.incoming ? t('history:receive') : t('history:send')}{' '}
{activeTx.incoming ? t('history:receive') : t('history:send')}{' '}
<span>
{round(formatValue(activeTransfer.transferValue), 1)}{' '}
{formatUnit(activeTransfer.transferValue)}
{round(formatValue(activeTx.transferValue), 1)}{' '}
{formatUnit(activeTx.transferValue)}
</span>
</strong>
<small>
{!activeTransfer.persistence
{!activeTx.persistence
? t('pending')
: activeTransfer.incoming ? t('received') : t('sent')}
: activeTx.incoming ? t('received') : t('sent')}
<em>
{formatModalTime(
navigator.language,
detectedTimezone,
convertUnixTimeToJSDate(activeTransfer.timestamp),
convertUnixTimeToJSDate(activeTx.timestamp),
)}
</em>
</small>
</p>
<h6>{t('bundleHash')}:</h6>
<p className={css.hash}>
<Clipboard
text={activeTransfer.bundle}
text={activeTx.bundle}
title={t('history:bundleHashCopied')}
success={t('history:bundleHashCopiedExplanation')}
/>
</p>
{mode === 'Advanced' && this.listAddresses(activeTransfer)}
{mode === 'Advanced' && this.listAddresses(activeTx)}
<div className={css.message}>
<strong>{t('send:message')}:</strong>
<Scrollbar>
<Clipboard
text={activeTransfer.message}
text={activeTx.message}
title={t('history:messageCopied')}
success={t('history:messageCopiedExplanation')}
/>
</Scrollbar>
</div>
{!activeTransfer.persistence && (
{!activeTx.persistence && (
<nav>
{isActiveFailed && (
<Button
className="small"
loading={isRetryingFailedTransaction}
onClick={(e) => this.retryFailedTransaction(e, activeTransfer.bundle)}
onClick={(e) => this.retryFailedTransaction(e, activeTx.bundle)}
>
{t('retry')}
</Button>
)}
{!isActiveFailed && (
<Button
className="small"
loading={currentlyPromotingBundleHash === activeTransfer.bundle}
onClick={(e) => this.promoteTransaction(e, activeTransfer.bundle)}
loading={currentlyPromotingBundleHash === activeTx.bundle}
onClick={(e) => this.promoteTransaction(e, activeTx.bundle)}
>
{t('retry')}
</Button>
Expand Down
2 changes: 1 addition & 1 deletion src/desktop/src/ui/global/Alerts.js
Expand Up @@ -80,7 +80,7 @@ class Alerts extends React.PureComponent {
) : (
<div
onClick={() => dismissAlert()}
className={classNames(alerts.category.length ? css.visible : null, css[`${alerts.category}`])}
className={classNames(alerts.category && alerts.category.length ? css.visible : null, css[`${alerts.category}`])}
>
<span>
<Icon icon="cross" size={14} />
Expand Down
17 changes: 8 additions & 9 deletions src/desktop/src/ui/views/settings/account/Addresses.js
Expand Up @@ -28,27 +28,26 @@ class Addresses extends PureComponent {
<fieldset>
<ul className={css.addresses}>
<Scrollbar>
{Object.keys(account.addresses)
.reverse()
.map((item) => {
const address = item + account.addresses[item].checksum;
{account.addressData
.map((addressData) => {
const address = addressData.address + addressData.checksum;
return (
<li key={address}>
<p className={isSpent(account.addresses[item]) ? css.spent : null}>
<p className={isSpent(addressData) ? css.spent : null}>
<Clipboard
text={address}
title={t('receive:addressCopied')}
success={t('receive:addressCopiedExplanation')}
>
{item.match(/.{1,3}/g).join(' ')}{' '}
{addressData.address.match(/.{1,3}/g).join(' ')}{' '}
<mark>
{account.addresses[item].checksum.match(/.{1,3}/g).join(' ')}
{addressData.checksum.match(/.{1,3}/g).join(' ')}
</mark>
</Clipboard>
</p>
<strong>
{formatValue(account.addresses[item].balance)}
{formatUnit(account.addresses[item].balance)}
{formatValue(addressData.balance)}
{formatUnit(addressData.balance)}
</strong>
</li>
);
Expand Down
6 changes: 6 additions & 0 deletions src/desktop/src/ui/views/settings/account/addresses.scss
Expand Up @@ -4,6 +4,12 @@
margin: 0px;
padding: 0;

> div {
display: flex;
justify-content: flex-end;
flex-direction: column-reverse;
}

p {
font-family: 'SourceCodePro';
font-size: 12px;
Expand Down
5 changes: 3 additions & 2 deletions src/desktop/src/ui/views/wallet/Receive.js
Expand Up @@ -16,8 +16,9 @@ import { generateNewAddress, addressValidationRequest, addressValidationSuccess

import SeedStore from 'libs/SeedStore';
import { randomBytes } from 'libs/crypto';
import { byteToChar } from 'libs/iota/converter';
import Errors from 'libs/errors';
import { byteToChar } from 'libs/iota/converter';
import { getLatestAddress } from 'libs/iota/addresses';
import { ADDRESS_LENGTH } from 'libs/iota/utils';

import Button from 'ui/components/Button';
Expand Down Expand Up @@ -130,7 +131,7 @@ class Receive extends React.PureComponent {
generateAlert('info', t('ledger:checkAddress'), t('ledger:checkAddressExplanation'), 20000);
}
this.props.addressValidationRequest();
await seedStore.validateAddress(Object.keys(account.addresses).length - 1);
await seedStore.validateAddress(getLatestAddress(account.addressData));
this.props.addressValidationSuccess();
} catch (err) {
this.props.addressValidationSuccess();
Expand Down

0 comments on commit ea5d79d

Please sign in to comment.