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: balance placeholders #2242

Merged
merged 5 commits into from
Dec 19, 2024
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
3 changes: 3 additions & 0 deletions src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ export const App = observer(() => {
}, [AppStore.networkLoggerEnabled]);

useEffect(() => {
if (AppStore.isInitialized) {
return;
}
const splashTimer = setTimeout(() => {
hideModal(ModalType.splash);
}, SPLASH_TIMEOUT_MS);
Expand Down
45 changes: 28 additions & 17 deletions src/components/account-info/account-info-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {Balance} from '@app/services/balance';
import {WalletType} from '@app/types';

import {StackedVestedTokens} from '../stacked-vested-tokens';
import {Placeholder} from '../ui/placeholder';

const CARD_WIDTH = 78;
const CARD_RADIUS = 8;
Expand All @@ -34,6 +35,7 @@ export type AccountInfoProps = {
total: Balance;
vested: Balance;
unlock: Date;
isBalanceLoading: boolean;
onPressInfo: () => void;
onSend: () => void;
onReceive: () => void;
Expand All @@ -46,10 +48,11 @@ export const AccountInfoHeader = ({
total,
vested,
available,
unlock,
isBalanceLoading,
onPressInfo,
onSend,
onReceive,
unlock,
}: AccountInfoProps) => {
const formattedAddress = useMemo(
() => shortAddress(wallet.providerSpecificAddress, '•'),
Expand All @@ -68,10 +71,20 @@ export const AccountInfoHeader = ({
colorPattern={wallet.colorPattern}
/>
<View style={styles.headerContent}>
<Text
variant={TextVariant.t3}
children={total.toFiat({useDefaultCurrency: true})}
/>
<First>
{isBalanceLoading && (
<>
<Placeholder opacity={0.8}>
<Placeholder.Item width={140} height={28} />
</Placeholder>
<Spacer height={10} />
</>
)}
<Text
variant={TextVariant.t3}
children={total.toFiat({useDefaultCurrency: true})}
/>
</First>
<CopyMenu wallet={wallet} style={styles.copyButton} withSettings>
<Text variant={TextVariant.t14} color={Color.textBase2}>
{formattedAddress}
Expand All @@ -85,18 +98,16 @@ export const AccountInfoHeader = ({
</CopyMenu>
</View>
</View>
<First>
<StackedVestedTokens
totalBalance={total}
availableBalance={available}
lockedBalance={locked}
vestedBalance={vested}
stakingBalance={staked}
onPressInfo={onPressInfo}
unlock={unlock}
/>
<Spacer height={24} />
</First>
<StackedVestedTokens
totalBalance={total}
availableBalance={available}
lockedBalance={locked}
vestedBalance={vested}
stakingBalance={staked}
unlock={unlock}
isBalanceLoading={isBalanceLoading}
onPressInfo={onPressInfo}
/>
<Inline gap={12} style={styles.iconButtons}>
<IconButton
disabled={wallet.type === WalletType.watchOnly}
Expand Down
3 changes: 3 additions & 0 deletions src/components/account-info/account-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export type AccountInfoProps = {
vested: Balance;
unlock: Date;
tokens: Record<AddressEthereum, IToken[]>;
isBalanceLoading: boolean;
onPressInfo: () => void;
onSend: () => void;
onReceive: () => void;
Expand All @@ -57,6 +58,7 @@ export const AccountInfo = observer(
unlock,
vested,
tokens,
isBalanceLoading,
onPressInfo,
onSend,
onReceive,
Expand Down Expand Up @@ -87,6 +89,7 @@ export const AccountInfo = observer(
total={total}
unlock={unlock}
vested={vested}
isBalanceLoading={isBalanceLoading}
onPressInfo={onPressInfo}
onSend={onSend}
onReceive={onReceive}
Expand Down
111 changes: 75 additions & 36 deletions src/components/stacked-vested-tokens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,28 @@ import {I18N, getText} from '@app/i18n';
import {Balance} from '@app/services/balance';

import {DashedLine} from './dashed-line';
import {Icon, IconButton, IconsName, Spacer, Text, TextVariant} from './ui';
import {
First,
Icon,
IconButton,
IconsName,
Spacer,
Text,
TextVariant,
} from './ui';
import {BarChart} from './ui/bar-chart';
import {BarChartItem} from './ui/bar-chart/bar-chart-item';
import {Placeholder} from './ui/placeholder';

export interface StackedVestedTokensProps {
lockedBalance?: Balance;
vestedBalance?: Balance;
stakingBalance?: Balance;
availableBalance?: Balance;
unlock: Date;
onPressInfo(): void;
totalBalance?: Balance;
isBalanceLoading: boolean;
onPressInfo(): void;
}

const calculateDistanceToNow = (endDate: Date) => {
Expand All @@ -36,9 +46,10 @@ export function StackedVestedTokens({
lockedBalance = Balance.Empty,
stakingBalance = Balance.Empty,
vestedBalance = Balance.Empty,
onPressInfo,
unlock,
totalBalance,
isBalanceLoading,
onPressInfo,
}: StackedVestedTokensProps) {
const {width} = useWindowDimensions();
const vestedUnlockDescription = useMemo(() => {
Expand Down Expand Up @@ -86,17 +97,26 @@ export function StackedVestedTokens({
<View style={styles.row}>
<Icon i20 color={Color.graphicBase1} name={IconsName.islm} />
<Spacer width={4} />
<Text
variant={TextVariant.t10}
color={Color.textBase1}
i18n={I18N.totalAvailable}
i18params={{count: totalBalance?.toFloatString() ?? '0'}}
/>
<Text
variant={TextVariant.t10}
color={Color.textBase2}
children={' ' + totalBalance?.currency}
/>
<First>
{isBalanceLoading && (
<Placeholder opacity={0.8}>
<Placeholder.Item width={150} height={22} />
</Placeholder>
)}
<>
<Text
variant={TextVariant.t10}
color={Color.textBase1}
i18n={I18N.totalAvailable}
i18params={{count: totalBalance?.toFloatString() ?? '0'}}
/>
<Text
variant={TextVariant.t10}
color={Color.textBase2}
children={' ' + totalBalance?.currency}
/>
</>
</First>
</View>
<DashedLine
style={styles.separator}
Expand All @@ -108,17 +128,26 @@ export function StackedVestedTokens({
<View style={styles.row}>
<Icon i20 color={Color.graphicBase1} name={IconsName.coin} />
<Spacer width={4} />
<Text
variant={TextVariant.t10}
color={Color.textBase1}
i18n={I18N.lockedTokensAvailable}
i18params={{count: availableBalance?.toFloatString() ?? '0'}}
/>
<Text
variant={TextVariant.t10}
color={Color.textBase2}
children={' ' + availableBalance.currency}
/>
<First>
{isBalanceLoading && (
<Placeholder opacity={0.8}>
<Placeholder.Item width={130} height={22} />
</Placeholder>
)}
<>
<Text
variant={TextVariant.t10}
color={Color.textBase1}
i18n={I18N.lockedTokensAvailable}
i18params={{count: availableBalance?.toFloatString() ?? '0'}}
/>
<Text
variant={TextVariant.t10}
color={Color.textBase2}
children={' ' + availableBalance.currency}
/>
</>
</First>
</View>
{lockedBalance?.isPositive() && (
<>
Expand All @@ -130,17 +159,27 @@ export function StackedVestedTokens({
<View style={styles.row}>
<Icon i20 color={Color.graphicBase1} name={IconsName.lock} />
<Spacer width={4} />
<Text
variant={TextVariant.t10}
color={Color.textBase1}
i18n={I18N.lockedTokensLocked}
i18params={{count: lockedBalance.toFloatString()}}
/>
<Text
variant={TextVariant.t10}
color={Color.textBase2}
children={' ' + lockedBalance.currency}
/>
<First>
{isBalanceLoading && (
<Placeholder opacity={0.8}>
<Placeholder.Item width={110} height={22} />
</Placeholder>
)}
<>
<Text
variant={TextVariant.t10}
color={Color.textBase1}
i18n={I18N.lockedTokensLocked}
i18params={{count: lockedBalance.toFloatString()}}
/>
<Text
variant={TextVariant.t10}
color={Color.textBase2}
children={' ' + lockedBalance.currency}
/>
</>
</First>

<Spacer width={4} />
<IconButton onPress={onPressInfo}>
<Icon i20 color={Color.graphicBase2} name={IconsName.info} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {Color} from '@app/colors';
import {First, Spacer, Text, TextVariant} from '@app/components/ui';
import {createTheme} from '@app/helpers';
import {I18N} from '@app/i18n';
import {BalanceModel} from '@app/models/wallet';
import {BalanceModel, Wallet} from '@app/models/wallet';

import {StackedVestedTokens} from '../stacked-vested-tokens';

Expand Down Expand Up @@ -49,6 +49,7 @@ export const TotalValueInfoHeader = ({
stakingBalance={balance?.staked}
onPressInfo={onPressInfo}
unlock={balance?.nextVestingUnlockDate}
isBalanceLoading={Wallet.isBalancesLoading}
/>
</First>
</>
Expand Down
13 changes: 9 additions & 4 deletions src/components/wallet-card/balance-info-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,26 @@ import {
import {Placeholder} from '@app/components/ui/placeholder';
import {createTheme} from '@app/helpers';
import {I18N} from '@app/i18n';
import {Wallet} from '@app/models/wallet';
import {Balance} from '@app/services/balance';

type BalanceInfoDetailsProps = {
total?: Balance;
locked?: Balance;
showLockedTokens: boolean;
isBalanceLoading: boolean;
};

export const BalanceInfoDetails = observer(
({total, locked, showLockedTokens}: BalanceInfoDetailsProps) => {
({
total,
locked,
showLockedTokens,
isBalanceLoading,
}: BalanceInfoDetailsProps) => {
return (
<View style={styles.row}>
<First>
{Wallet.isBalancesLoading && (
{isBalanceLoading && (
<>
<Spacer height={8} />
<Placeholder opacity={0.6}>
Expand All @@ -50,7 +55,7 @@ export const BalanceInfoDetails = observer(
{!!total?.toFiat() && <Spacer width={10} />}
{showLockedTokens && (
<First>
{Wallet.isBalancesLoading && (
{isBalanceLoading && (
<>
<Spacer height={8} />
<Placeholder opacity={0.6}>
Expand Down
Loading