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

fix(suite-native): show fiat balance skeleton while graph is loading #16217

Merged
merged 1 commit into from
Jan 9, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion suite-native/graph/src/components/GraphFiatBalance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type GraphFiatBalanceProps = BalanceProps & {
percentageChangeAtom: Atom<number>;
hasPriceIncreasedAtom: Atom<boolean>;
showChange?: boolean;
isLoading?: boolean;
};

const wrapperStyle = prepareNativeStyle(_ => ({
Expand Down Expand Up @@ -50,11 +51,12 @@ export const GraphFiatBalance = ({
percentageChangeAtom,
hasPriceIncreasedAtom,
showChange = true,
isLoading = false,
}: GraphFiatBalanceProps) => {
const { applyStyle } = useNativeStyles();
const firstGraphPoint = useAtomValue(referencePointAtom);

if (!firstGraphPoint) {
if (isLoading || !firstGraphPoint) {
return <Skeleton />;
}

Expand Down
Copy link
Member

Choose a reason for hiding this comment

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

This change is not related to fiat balance skeleton, right? Or is it somehow needed because of the other changes in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's related to PortfolioHeader in a way and was discovered during testing. @shenkys wanted the button to appear once discovery finishes.

We may do that in a separate PR if you insist.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useSelector } from 'react-redux';

import { useNavigation } from '@react-navigation/native';

import { selectHasDeviceDiscovery } from '@suite-common/wallet-core';
import { selectHasDeviceDiscovery, selectIsDeviceAuthorized } from '@suite-common/wallet-core';
import { Button, VStack } from '@suite-native/atoms';
import { Assets } from '@suite-native/assets';
import {
Expand All @@ -18,7 +18,9 @@ import { PortfolioGraph, PortfolioGraphRef } from './PortfolioGraph';
export const PortfolioContent = forwardRef<PortfolioGraphRef>((_props, ref) => {
const navigation = useNavigation<StackNavigationProps<RootStackParamList, RootStackRoutes>>();

const isDeviceAuthorized = useSelector(selectIsDeviceAuthorized);
const hasDiscovery = useSelector(selectHasDeviceDiscovery);
const showReceiveButton = isDeviceAuthorized && !hasDiscovery;

const handleReceive = () => {
navigation.navigate(RootStackRoutes.ReceiveModal, { closeActionType: 'back' });
Expand All @@ -28,7 +30,7 @@ export const PortfolioContent = forwardRef<PortfolioGraphRef>((_props, ref) => {
<VStack spacing="sp32" marginTop="sp8">
<PortfolioGraph ref={ref} />
<VStack spacing="sp24" marginHorizontal="sp16">
{!hasDiscovery && (
{showReceiveButton && (
<Button
data-testID="@home/portolio/recieve-button"
onPress={handleReceive}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ export const PortfolioGraph = forwardRef<PortfolioGraphRef>((_props, ref) => {
[refetch],
);

const showHeader = isAnyMainnetAccountPresent || isLoading;
const showGraph = hasDeviceHistoryEnabledAccounts || hasDeviceDiscovery;

return (
<VStack spacing="sp24" testID="@home/portfolio/graph">
{isAnyMainnetAccountPresent ? <PortfolioHeader /> : null}

{showHeader && <PortfolioHeader isLoading={isLoading} />}
{showGraph && (
<Graph
points={graphPoints}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useSelector } from 'react-redux';

import { Box, VStack } from '@suite-native/atoms';
import { GraphFiatBalance, selectHasDeviceHistoryEnabledAccounts } from '@suite-native/graph';
import { selectHasDeviceDiscovery, selectIsDeviceAuthorized } from '@suite-common/wallet-core';

import {
hasPriceIncreasedAtom,
Expand All @@ -11,24 +10,24 @@ import {
selectedPointAtom,
} from '../portfolioGraphAtoms';

export const PortfolioHeader = () => {
const hasDiscovery = useSelector(selectHasDeviceDiscovery);
const isDeviceAuthorized = useSelector(selectIsDeviceAuthorized);
type PortfolioHeaderProps = {
isLoading: boolean;
};

export const PortfolioHeader = ({ isLoading }: PortfolioHeaderProps) => {
const hasDeviceHistoryEnabledAccounts = useSelector(selectHasDeviceHistoryEnabledAccounts);
const isLoading = hasDiscovery || !isDeviceAuthorized;

return (
<Box testID="@home/portfolio/header">
<VStack spacing="sp4" alignItems="center">
{!isLoading && (
<GraphFiatBalance
selectedPointAtom={selectedPointAtom}
referencePointAtom={referencePointAtom}
percentageChangeAtom={percentageChangeAtom}
hasPriceIncreasedAtom={hasPriceIncreasedAtom}
showChange={hasDeviceHistoryEnabledAccounts}
/>
)}
<GraphFiatBalance
selectedPointAtom={selectedPointAtom}
referencePointAtom={referencePointAtom}
percentageChangeAtom={percentageChangeAtom}
hasPriceIncreasedAtom={hasPriceIncreasedAtom}
showChange={hasDeviceHistoryEnabledAccounts}
isLoading={isLoading}
/>
</VStack>
</Box>
);
Expand Down
Loading