-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add collectibles widget, ref leather-io/issues#222
- Loading branch information
1 parent
498a1db
commit 64beb49
Showing
59 changed files
with
1,499 additions
and
509 deletions.
There are no files selected for viewing
2 changes: 0 additions & 2 deletions
2
apps/mobile/src/components/add-wallet/add-wallet-list-item.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
apps/mobile/src/components/widgets/accounts/accounts-header.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
apps/mobile/src/components/widgets/accounts/accounts-widget.layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
apps/mobile/src/components/widgets/collectibles/collectibles-header.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
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> | ||
); | ||
} |
60 changes: 60 additions & 0 deletions
60
apps/mobile/src/components/widgets/collectibles/collectibles-serializer.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { mockCollectibles } from '@leather.io/ui/native'; | ||
|
||
import { serializeCollectibles } from './collectibles-serializer'; | ||
|
||
describe('serializeCollectibles', () => { | ||
it('should correctly serialize collectibles', () => { | ||
const serializedCollectibles = serializeCollectibles(mockCollectibles); | ||
|
||
expect(serializedCollectibles).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ | ||
id: expect.any(String), | ||
title: expect.any(String), | ||
imageUrl: expect.any(String), | ||
collection: expect.any(String), | ||
type: expect.stringMatching(/^(ordinal|stacks)$/), | ||
}), | ||
]) | ||
); | ||
}); | ||
|
||
it('should handle empty input', () => { | ||
const serializedCollectibles = serializeCollectibles([]); | ||
expect(serializedCollectibles).toEqual([]); | ||
}); | ||
|
||
it('should correctly serialize Ordinals', () => { | ||
const ordinals = mockCollectibles.filter(c => 'name' in c && 'mimeType' in c); | ||
const serializedOrdinals = serializeCollectibles(ordinals); | ||
|
||
serializedOrdinals.forEach(ordinal => { | ||
expect(ordinal).toEqual( | ||
expect.objectContaining({ | ||
type: 'inscription', | ||
id: expect.any(String), | ||
title: expect.any(String), | ||
imageUrl: expect.any(String), | ||
collection: expect.any(String), | ||
}) | ||
); | ||
}); | ||
}); | ||
|
||
it('should correctly serialize StacksNfts', () => { | ||
const stacksNfts = mockCollectibles.filter(c => 'metadata' in c); | ||
const serializedStacksNfts = serializeCollectibles(stacksNfts); | ||
|
||
serializedStacksNfts.forEach(nft => { | ||
expect(nft).toEqual( | ||
expect.objectContaining({ | ||
type: 'stacks', | ||
id: expect.any(String), | ||
title: expect.any(String), | ||
imageUrl: expect.any(String), | ||
collection: expect.any(String), | ||
}) | ||
); | ||
}); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
apps/mobile/src/components/widgets/collectibles/collectibles-serializer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { type Collectible, type CollectibleCardProps } from '@leather.io/ui/native'; | ||
|
||
export function serializeCollectibles(collectibles: Collectible[]): CollectibleCardProps[] { | ||
return collectibles.map(collectible => { | ||
const isOrdinal = 'name' in collectible && 'mimeType' in collectible; | ||
if (isOrdinal) { | ||
return { | ||
type: 'inscription', | ||
name: collectible.title, | ||
src: collectible.src, | ||
mimeType: collectible.mimeType, | ||
}; | ||
} | ||
return { | ||
type: 'stacks', | ||
name: collectible.metadata.name, | ||
src: collectible.metadata.cached_image, | ||
mimeType: null, | ||
}; | ||
}); | ||
} |
30 changes: 30 additions & 0 deletions
30
apps/mobile/src/components/widgets/collectibles/collectibles-widget.layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
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> | ||
); | ||
} |
33 changes: 33 additions & 0 deletions
33
apps/mobile/src/components/widgets/collectibles/collectibles-widget.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React, { useRef } from 'react'; | ||
|
||
import { CollectibleCard, CollectibleCardProps, SheetRef } from '@leather.io/ui/native'; | ||
|
||
import { TokenBalance } from '../components/balance/token-balance'; | ||
import { CollectiblesHeader } from './collectibles-header'; | ||
import { CollectiblesWidgetLayout } from './collectibles-widget.layout'; | ||
|
||
interface CollectiblesWidgetProps { | ||
collectibles: CollectibleCardProps[]; | ||
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: CollectibleCardProps, index) => ( | ||
<CollectibleCard key={index} {...collectible} /> | ||
))} | ||
</CollectiblesWidgetLayout> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { mockCollectibles } from '@leather.io/ui/native'; | ||
export { CollectiblesWidget } from './collectibles-widget'; | ||
export { serializeCollectibles } from './collectibles-serializer'; |
2 changes: 0 additions & 2 deletions
2
apps/mobile/src/components/widgets/components/balance/token-balance.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { TokensWidget } from './tokens-widget'; | ||
export { getMockTokens } from './tokens.mocks'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
apps/mobile/src/components/widgets/tokens/tokens-widget.layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import React from 'react'; | ||
|
||
import { Box } from '@leather.io/ui/native'; | ||
|
||
interface WidgetProps { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.