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

Fixed showing loading indicator for fiat amount endlessly #1455

Merged
merged 1 commit into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 13 additions & 4 deletions components/Amount.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import { TouchableOpacity, View } from 'react-native';
import { inject, observer } from 'mobx-react';
import FiatStore from '../stores/FiatStore';
import UnitsStore from '../stores/UnitsStore';
import SettingsStore from '../stores/SettingsStore';
import PrivacyUtils from '../utils/PrivacyUtils';
Expand All @@ -24,6 +25,7 @@ interface AmountDisplayProps {
jumboText?: boolean;
color?: 'text' | 'success' | 'warning' | 'highlight' | 'secondaryText';
pending?: boolean;
fiatRatesLoading?: boolean;
}

function AmountDisplay({
Expand All @@ -36,7 +38,8 @@ function AmountDisplay({
space = false,
jumboText = false,
color = undefined,
pending = false
pending = false,
fiatRatesLoading = false
}: AmountDisplayProps) {
if (unit === 'fiat' && !symbol) {
console.error('Must include a symbol when rendering fiat');
Expand Down Expand Up @@ -95,7 +98,7 @@ function AmountDisplay({
<Row align="flex-end">
<Body jumbo={jumboText} color={color}>
{negative ? '-' : ''}
{amount === 'N/A' ? (
{amount === 'N/A' && fiatRatesLoading ? (
<LoadingIndicator size={20} />
) : (
amount.toString()
Expand All @@ -114,7 +117,7 @@ function AmountDisplay({
{space ? <TextSpace /> : <Spacer width={1} />}
<Body jumbo={jumboText} color={color}>
{negative ? '-' : ''}
{amount === 'N/A' ? (
{amount === 'N/A' && fiatRatesLoading ? (
<LoadingIndicator size={20} />
) : (
amount.toString()
Expand All @@ -127,6 +130,7 @@ function AmountDisplay({
}

interface AmountProps {
FiatStore?: FiatStore;
UnitsStore?: UnitsStore;
SettingsStore?: SettingsStore;
sats: number | string;
Expand All @@ -142,7 +146,7 @@ interface AmountProps {
pending?: boolean;
}

@inject('UnitsStore', 'SettingsStore')
@inject('FiatStore', 'UnitsStore', 'SettingsStore')
@observer
export default class Amount extends React.Component<AmountProps, {}> {
render() {
Expand All @@ -158,6 +162,7 @@ export default class Amount extends React.Component<AmountProps, {}> {
color = undefined,
pending = false
} = this.props;
const FiatStore = this.props.FiatStore!;
const UnitsStore = this.props.UnitsStore!;
const SettingsStore = this.props.SettingsStore!;
const lurkerMode =
Expand Down Expand Up @@ -193,6 +198,7 @@ export default class Amount extends React.Component<AmountProps, {}> {
negative={false}
jumboText={jumboText}
pending={pending}
fiatRatesLoading={FiatStore.loading}
/>
</TouchableOpacity>
);
Expand All @@ -206,6 +212,7 @@ export default class Amount extends React.Component<AmountProps, {}> {
negative={false}
jumboText={jumboText}
pending={pending}
fiatRatesLoading={FiatStore.loading}
/>
);
}
Expand Down Expand Up @@ -246,6 +253,7 @@ export default class Amount extends React.Component<AmountProps, {}> {
jumboText={jumboText}
color={textColor}
pending={pending}
fiatRatesLoading={FiatStore.loading}
/>
</TouchableOpacity>
);
Expand All @@ -260,6 +268,7 @@ export default class Amount extends React.Component<AmountProps, {}> {
jumboText={jumboText}
color={textColor}
pending={pending}
fiatRatesLoading={FiatStore.loading}
/>
);
}
Expand Down
2 changes: 1 addition & 1 deletion components/Conversion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Amount from '../components/Amount';
import { Row } from '../components/layout/Row';
import { getSatAmount } from '../components/AmountInput';

import FiatStore from '../stores/UnitsStore';
import FiatStore from '../stores/FiatStore';
import UnitsStore from '../stores/UnitsStore';
import SettingsStore, { DEFAULT_FIAT } from '../stores/SettingsStore';

Expand Down
2 changes: 1 addition & 1 deletion stores/FiatStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,8 @@ export default class FiatStore {
const status = response.info().status;
if (status == 200) {
const data = response.json();
this.loading = false;
this.fiatRates = data;
this.loading = false;
} else {
this.loading = false;
}
Expand Down