Skip to content

Commit

Permalink
WT-1948 fix: Only show loading shimmer once balance API request start…
Browse files Browse the repository at this point in the history
…ed (#1359)
  • Loading branch information
dreamoftrees authored Jan 18, 2024
1 parent bf052ad commit f69d346
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export function WalletWidget(props: WalletWidgetInputs) {
<LoadingView loadingText={loadingText} />
)}
{viewState.view.type === WalletWidgetViews.WALLET_BALANCES && (
<WalletBalances balancesLoading={balancesLoading} setBalancesLoading={setBalancesLoading} />
<WalletBalances balancesLoading={balancesLoading} />
)}
{viewState.view.type === WalletWidgetViews.SETTINGS && <Settings />}
{viewState.view.type === WalletWidgetViews.COIN_INFO && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('Network Menu', () => {
<ConnectLoaderTestComponent
initialStateOverride={connectLoaderState}
>
<NetworkMenu setBalancesLoading={() => {}} />
<NetworkMenu />
</ConnectLoaderTestComponent>
</ViewContextTestComponent>,
);
Expand All @@ -75,7 +75,7 @@ describe('Network Menu', () => {
<WalletContext.Provider
value={{ walletState, walletDispatch: () => {} }}
>
<NetworkMenu setBalancesLoading={() => {}} />
<NetworkMenu />
</WalletContext.Provider>
</ConnectLoaderTestComponent>
</ViewContextTestComponent>,
Expand Down Expand Up @@ -119,7 +119,7 @@ describe('Network Menu', () => {
<WalletContext.Provider
value={{ walletState, walletDispatch: () => {} }}
>
<NetworkMenu setBalancesLoading={() => {}} />
<NetworkMenu />
</WalletContext.Provider>
</ConnectLoaderTestComponent>
</ViewContextTestComponent>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ import {
import { EventTargetContext } from '../../../../context/event-target-context/EventTargetContext';
import { UserJourney, useAnalytics } from '../../../../context/analytics-provider/SegmentAnalyticsProvider';

export interface NetworkMenuProps {
setBalancesLoading: (loading: boolean) => void;
}

export function NetworkMenu({ setBalancesLoading }: NetworkMenuProps) {
export function NetworkMenu() {
const { t } = useTranslation();
const { connectLoaderState } = useContext(ConnectLoaderContext);
const { eventTargetState: { eventTarget } } = useContext(EventTargetContext);
Expand All @@ -65,16 +61,13 @@ export function NetworkMenu({ setBalancesLoading }: NetworkMenuProps) {
});

try {
setBalancesLoading(true);

const switchNetworkResult = await checkout.switchNetwork({
provider,
chainId,
} as SwitchNetworkParams);

sendNetworkSwitchEvent(eventTarget, switchNetworkResult.provider, switchNetworkResult.network);
} catch (err: any) {
setBalancesLoading(false);
if (err.type === CheckoutErrorType.USER_REJECTED_REQUEST_ERROR) {
// ignore error
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe('WalletBalances', () => {
initialStateOverride={baseWalletState}
cryptoConversionsOverride={cryptoConversions}
>
<WalletBalances balancesLoading={false} setBalancesLoading={() => {}} />
<WalletBalances balancesLoading={false} />
</WalletWidgetTestComponent>
</ConnectLoaderTestComponent>
</ViewContextTestComponent>,
Expand All @@ -123,7 +123,7 @@ describe('WalletBalances', () => {
initialStateOverride={baseWalletState}
cryptoConversionsOverride={cryptoConversions}
>
<WalletBalances balancesLoading setBalancesLoading={() => {}} />
<WalletBalances balancesLoading />
</WalletWidgetTestComponent>
</ConnectLoaderTestComponent>
</ViewContextTestComponent>,
Expand All @@ -145,7 +145,7 @@ describe('WalletBalances', () => {
initialStateOverride={baseWalletState}
cryptoConversionsOverride={cryptoConversions}
>
<WalletBalances balancesLoading={false} setBalancesLoading={() => {}} />
<WalletBalances balancesLoading={false} />
</WalletWidgetTestComponent>
</ConnectLoaderTestComponent>
</ViewContextTestComponent>,
Expand All @@ -167,7 +167,7 @@ describe('WalletBalances', () => {
initialStateOverride={{ ...baseWalletState, tokenBalances: [] }}
cryptoConversionsOverride={cryptoConversions}
>
<WalletBalances balancesLoading={false} setBalancesLoading={() => {}} />
<WalletBalances balancesLoading={false} />
</WalletWidgetTestComponent>
</ConnectLoaderTestComponent>
</ViewContextTestComponent>,
Expand Down Expand Up @@ -225,7 +225,7 @@ describe('WalletBalances', () => {
initialStateOverride={baseWalletState}
cryptoConversionsOverride={cryptoConversions}
>
<WalletBalances balancesLoading={false} setBalancesLoading={() => {}} />
<WalletBalances balancesLoading={false} />
</WalletWidgetTestComponent>
</ConnectLoaderTestComponent>
</ViewContextTestComponent>,
Expand Down Expand Up @@ -287,7 +287,7 @@ describe('WalletBalances', () => {
initialStateOverride={walletState}
cryptoConversionsOverride={cryptoConversions}
>
<WalletBalances balancesLoading={false} setBalancesLoading={() => {}} />
<WalletBalances balancesLoading={false} />
</WalletWidgetTestComponent>
</ConnectLoaderTestComponent>
</ViewContextTestComponent>,
Expand Down Expand Up @@ -348,7 +348,7 @@ describe('WalletBalances', () => {
initialStateOverride={walletState}
cryptoConversionsOverride={cryptoConversions}
>
<WalletBalances balancesLoading={false} setBalancesLoading={() => {}} />
<WalletBalances balancesLoading={false} />
</WalletWidgetTestComponent>
</ConnectLoaderTestComponent>
</ViewContextTestComponent>,
Expand Down Expand Up @@ -417,7 +417,7 @@ describe('WalletBalances', () => {
<WalletContext.Provider
value={{ walletState: testWalletState, walletDispatch: () => {} }}
>
<WalletBalances balancesLoading={false} setBalancesLoading={() => {}} />
<WalletBalances balancesLoading={false} />
</WalletContext.Provider>
</ConnectLoaderTestComponent>
</ViewContextTestComponent>
Expand Down Expand Up @@ -445,7 +445,7 @@ describe('WalletBalances', () => {
<WalletContext.Provider
value={{ walletState: testWalletState, walletDispatch: () => {} }}
>
<WalletBalances balancesLoading={false} setBalancesLoading={() => {}} />
<WalletBalances balancesLoading={false} />
</WalletContext.Provider>
</ConnectLoaderTestComponent>
</ViewContextTestComponent>
Expand Down Expand Up @@ -479,7 +479,7 @@ describe('WalletBalances', () => {
<WalletContext.Provider
value={{ walletState, walletDispatch: () => {} }}
>
<WalletBalances balancesLoading={false} setBalancesLoading={() => {}} />
<WalletBalances balancesLoading={false} />
</WalletContext.Provider>
</ConnectLoaderTestComponent>
</ViewContextTestComponent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,9 @@ import { BalanceInfo, mapTokenBalancesWithConversions } from '../functions/token

type WalletBalancesProps = {
balancesLoading: boolean;
setBalancesLoading: (balances: boolean) => void;
};
export function WalletBalances({
balancesLoading,
setBalancesLoading,
}: WalletBalancesProps) {
const { t } = useTranslation();
const { connectLoaderState } = useContext(ConnectLoaderContext);
Expand Down Expand Up @@ -236,7 +234,7 @@ export function WalletBalances({
sx={walletBalanceOuterContainerStyles}
>
<Box sx={walletBalanceContainerStyles}>
{showNetworkMenu && <NetworkMenu setBalancesLoading={setBalancesLoading} />}
{showNetworkMenu && <NetworkMenu />}
<TotalTokenBalance totalBalance={totalFiatAmount} loading={balancesLoading} />
<Box
sx={walletBalanceListContainerStyles(showNetworkMenu, showAddCoins)}
Expand Down

0 comments on commit f69d346

Please sign in to comment.