Skip to content

Commit

Permalink
feat: add collectibles widget, ref leather-io/issues#222
Browse files Browse the repository at this point in the history
  • Loading branch information
pete-watters committed Sep 18, 2024
1 parent 69e4377 commit 338a9ac
Show file tree
Hide file tree
Showing 14 changed files with 532 additions and 7 deletions.
6 changes: 6 additions & 0 deletions apps/mobile/src/components/home/home.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { AccountsWidget } from '@/components/widgets/accounts/accounts-widget';
import { CollectiblesWidget } from '@/components/widgets/collectible/collectible-widget';
import { mockCollectibles } from '@/components/widgets/collectible/collectible.mocks';
import { TokensWidget } from '@/components/widgets/tokens/tokens-widget';
import { getMockTokens, mockTotalBalance } from '@/components/widgets/tokens/tokens.mocks';
import { useAccounts } from '@/store/accounts/accounts.read';
Expand All @@ -16,6 +18,10 @@ export function Home() {
<HomeLayout>
<AccountsWidget accounts={accounts.list} wallets={wallets.list} />
<TokensWidget tokens={getMockTokens()} totalBalance={mockTotalBalance.totalUsdBalance} />
<CollectiblesWidget
collectibles={mockCollectibles}
totalBalance={mockTotalBalance.totalUsdBalance}
/>
</HomeLayout>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';

import { t } from '@lingui/macro';

import { Box, ChevronRightIcon, Chip, SheetRef, Text } from '@leather.io/ui/native';

import { FiatBalance } from '../components/balance/fiat-balance';

interface CollectiblesHeaderProps {
collectibleCount: number;
sheetRef: React.RefObject<SheetRef>;
totalBalance: string;
}

function CollectiblesHeaderText() {
return <Text variant="heading05">{t`My collectibles`}</Text>;
}

export function CollectiblesHeader({ collectibleCount, totalBalance }: CollectiblesHeaderProps) {
const hasCollectibles = collectibleCount > 0;
if (!hasCollectibles) return <CollectiblesHeaderText />;
return (
<Box flexDirection="row" gap="1" alignItems="center" marginHorizontal="5">
<CollectiblesHeaderText />
<Chip label={collectibleCount} />
<ChevronRightIcon variant="small" />
<Box flex={1} justifyContent="flex-end" alignItems="flex-end">
<FiatBalance balance={totalBalance} color="ink.text-subdued" />
</Box>
</Box>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import { ScrollView } from 'react-native-gesture-handler';

import { useTheme } from '@shopify/restyle';

import { Box, SheetRef, Theme } from '@leather.io/ui/native';

import { Widget } from '../widget';

interface CollectiblesWidgetProps {
balance?: React.ReactNode;
children: React.ReactNode;
header?: React.ReactNode;
sheetRef?: React.RefObject<SheetRef>;
}

export function CollectiblesWidgetLayout({ children, header }: CollectiblesWidgetProps) {
const theme = useTheme<Theme>();
return (
<Widget>
<Box>{header}</Box>
<ScrollView
showsHorizontalScrollIndicator={false}
horizontal
contentContainerStyle={{ gap: theme.spacing['3'], marginHorizontal: theme.spacing['5'] }}
>
{children}
</ScrollView>
</Widget>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, { useRef } from 'react';

import { SheetRef } from '@leather.io/ui/native';

import { TokenBalance } from '../components/balance/token-balance';
import { CollectiblesHeader } from './collectibles-header';
import { CollectiblesWidgetLayout } from './collectibles-widget.layout';
import { type Collectible } from './collectibles.mocks';
import { CollectiblesCard } from './components/collectible-card';

interface CollectiblesWidgetProps {
collectibles: Collectible[];
totalBalance: string;
}

export function CollectiblesWidget({ collectibles, totalBalance }: CollectiblesWidgetProps) {
const sheetRef = useRef<SheetRef>(null);

return (
<CollectiblesWidgetLayout
header={
<CollectiblesHeader
collectibleCount={collectibles.length}
totalBalance={totalBalance}
sheetRef={sheetRef}
/>
}
balance={collectibles.length > 0 && <TokenBalance balance={totalBalance} />}
>
{collectibles.map((collectible: Collectible) => (
<CollectiblesCard collectible={collectible} />

Check failure on line 31 in apps/mobile/src/components/widgets/collectibles/collectibles-widget.tsx

View workflow job for this annotation

GitHub Actions / lint-eslint

Missing "key" prop for element in iterator
))}
</CollectiblesWidgetLayout>
);
}
Loading

0 comments on commit 338a9ac

Please sign in to comment.