-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat: collectibles widget #481
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 CollectiblesWidgetLayoutProps { | ||
balance?: React.ReactNode; | ||
children: React.ReactNode; | ||
header?: React.ReactNode; | ||
sheetRef?: React.RefObject<SheetRef>; | ||
} | ||
|
||
export function CollectiblesWidgetLayout({ children, header }: CollectiblesWidgetLayoutProps) { | ||
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this as a way to just get only the data we need to display from the mocks.
Later I found
createBestInSlotInscription
which is actually giving us this data and more.I will investigate more when hooking up APIs but maybe it could be good to have a BE proxy for this type of stuff - data we need for App Home for example.