Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frontend: display offline errors on account summary #1859

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 68 additions & 55 deletions frontends/web/src/routes/account/summary/accountssummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { FiatConversion } from '../../../components/rates/rates';
import { Check } from '../../../components/icon/icon';
import Logo from '../../../components/icon/logo';
import Spinner from '../../../components/spinner/ascii';
import { Spinner as ErrorSpinner } from '../../../components/spinner/Spinner';
import { debug } from '../../../utils/env';
import { Chart } from './chart';
import { AddBuyReceiveOnEmptyBalances } from '../info/buyReceiveCTA';
Expand All @@ -52,6 +53,7 @@ interface State {
exported: string;
balances?: Balances;
syncStatus?: SyncStatus;
offlineErrors: string[];
totalBalancePerCoin?: accountApi.ITotalBalance;
}

Expand All @@ -75,6 +77,7 @@ class AccountsSummary extends Component<Props, State> {
public readonly state: State = {
data: undefined,
exported: '',
offlineErrors: [],
totalBalancePerCoin: undefined,
};
private unsubscribe!: () => void;
Expand Down Expand Up @@ -165,6 +168,10 @@ class AccountsSummary extends Component<Props, State> {

private async onStatusChanged(code: string, initial: boolean = false) {
const status = await accountApi.getStatus(code);
const { offlineErrors } = this.state;
if (status.offlineError && !offlineErrors.includes(status.offlineError)) {
this.setState({ offlineErrors: [...offlineErrors, status.offlineError] });
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could also push status.fatalError && t('account.fatalError') into this array, or replace the array completely if 1 account had fatalError.

On the other hand the offlineError might contain useful information like Tor misconfiguration.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not replace the array in case of fatalError, I agree with you that offlineError could be useful

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if you get online again? this code seems to never reset offlineErrors when back online.

}
if (status.disabled) {
return;
}
Expand Down Expand Up @@ -296,7 +303,7 @@ class AccountsSummary extends Component<Props, State> {

public render() {
const { t, accounts } = this.props;
const { exported, data, balances } = this.state;
const { exported, data, balances, offlineErrors } = this.state;
return (
<div className="contentWithGuide">
<div className="container">
Expand All @@ -322,60 +329,66 @@ class AccountsSummary extends Component<Props, State> {
)}
</Header>
<div className="content padded">
<Chart
data={data}
noDataPlaceholder={
(accounts.length === Object.keys(balances || {}).length) ? (
<AddBuyReceiveOnEmptyBalances balances={balances} />
) : undefined
} />
<div className={style.balanceTable}>
<table className={style.table}>
<colgroup>
<col width="33%" />
<col width="33%" />
<col width="*" />
</colgroup>
<thead>
<tr>
<th>{t('accountSummary.name')}</th>
<th>{t('accountSummary.balance')}</th>
<th>{t('accountSummary.fiatBalance')}</th>
</tr>
</thead>
<tbody>
{ accounts.length > 0 ? (
this.renderAccountSummary()
) : (
<tr>
<td colSpan={3} className={style.noAccount}>
{t('accountSummary.noAccount')}
</td>
</tr>
)}
</tbody>
<tfoot>
<tr>
<th>
<strong>{t('accountSummary.total')}</strong>
</th>
<td colSpan={2}>
{(data && data.formattedChartTotal !== null) ? (
<>
<strong>
{data.formattedChartTotal}
</strong>
{' '}
<span className={style.coinUnit}>
{data.chartFiat}
</span>
</>
) : (<Skeleton />) }
</td>
</tr>
</tfoot>
</table>
</div>
{offlineErrors.length ? (
<ErrorSpinner text={offlineErrors.join('\n')} guideExists={false} />
) : (
<>
<Chart
data={data}
noDataPlaceholder={
(accounts.length === Object.keys(balances || {}).length) ? (
<AddBuyReceiveOnEmptyBalances balances={balances} />
) : undefined
} />
<div className={style.balanceTable}>
<table className={style.table}>
<colgroup>
<col width="33%" />
<col width="33%" />
<col width="*" />
</colgroup>
<thead>
<tr>
<th>{t('accountSummary.name')}</th>
<th>{t('accountSummary.balance')}</th>
<th>{t('accountSummary.fiatBalance')}</th>
</tr>
</thead>
<tbody>
{ accounts.length > 0 ? (
this.renderAccountSummary()
) : (
<tr>
<td colSpan={3} className={style.noAccount}>
{t('accountSummary.noAccount')}
</td>
</tr>
)}
</tbody>
<tfoot>
<tr>
<th>
<strong>{t('accountSummary.total')}</strong>
</th>
<td colSpan={2}>
{(data && data.formattedChartTotal !== null) ? (
<>
<strong>
{data.formattedChartTotal}
</strong>
{' '}
<span className={style.coinUnit}>
{data.chartFiat}
</span>
</>
) : (<Skeleton />) }
</td>
</tr>
</tfoot>
</table>
</div>
</>
)}
</div>
</div>
</div>
Expand Down