Skip to content

Commit

Permalink
chore: clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
pete-watters committed Sep 26, 2024
1 parent dc1879f commit 96ce700
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 204 deletions.
12 changes: 7 additions & 5 deletions apps/mobile/src/components/home/home.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { AccountsWidget } from '@/components/widgets/accounts/accounts-widget';
import { CollectiblesWidget } from '@/components/widgets/collectibles/collectibles-widget';
import { mockCollectibles } from '@/components/widgets/collectibles/collectibles.mocks';
import { TokensWidget } from '@/components/widgets/tokens/tokens-widget';
import { getMockTokens, mockTotalBalance } from '@/components/widgets/tokens/tokens.mocks';
import {
CollectiblesWidget,
mockCollectibles,
serializeCollectibles,
} from '@/components/widgets/collectibles';
import { TokensWidget, getMockTokens, mockTotalBalance } from '@/components/widgets/tokens';
import { useAccounts } from '@/store/accounts/accounts.read';
import { useWallets } from '@/store/wallets/wallets.read';
import { useLingui } from '@lingui/react';
Expand All @@ -19,7 +21,7 @@ export function Home() {
<AccountsWidget accounts={accounts.list} wallets={wallets.list} />
<TokensWidget tokens={getMockTokens()} totalBalance={mockTotalBalance.totalUsdBalance} />
<CollectiblesWidget
collectibles={mockCollectibles}
collectibles={serializeCollectibles(mockCollectibles)}
totalBalance={mockTotalBalance.totalUsdBalance}
/>
</HomeLayout>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { CollectibleCardProps } from '@leather.io/ui/native';

import { type Collectible } from './collectibles.mocks';

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,
};
});
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import React, { useRef } from 'react';

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

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

View workflow job for this annotation

GitHub Actions / lint-eslint

'/home/runner/work/mono/mono/apps/mobile/node_modules/@leather.io/ui/native.ts' imported multiple times
import { CollectibleCardProps } from '@leather.io/ui/native';

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

View workflow job for this annotation

GitHub Actions / lint-eslint

'@leather.io/ui/native' import is duplicated

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

View workflow job for this annotation

GitHub Actions / lint-eslint

'/home/runner/work/mono/mono/apps/mobile/node_modules/@leather.io/ui/native.ts' imported multiple times

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

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

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

console.log('PETE collectibles', collectibles);

return (
<CollectiblesWidgetLayout
header={
Expand All @@ -28,24 +26,9 @@ export function CollectiblesWidget({ collectibles, totalBalance }: CollectiblesW
}
balance={collectibles.length > 0 && <TokenBalance balance={totalBalance} />}
>
{collectibles.length &&
collectibles.map((collectible: Collectible) => (
<>
{/* <Text key={`collectible-${index}`}>
{'name' in collectible ? collectible.name : collectible.metadata.name}
</Text> */}
{/*
// TODO: fix this - If I do this then rebuild the app, it crashes
has to be some issue with the collectible-card.native.tsx OR the mock data
it was working ok before the refactor to the collectibles-widget.tsx
maybe map it to sanitise the data first?
*/}
{/* {collectible && ( */}
<CollectibleCard collectible={collectible} />
{/* )} */}
</>
))}
{collectibles.map((collectible: CollectibleCardProps, index) => (
<CollectibleCard key={index} {...collectible} />
))}
</CollectiblesWidgetLayout>
);
}
134 changes: 84 additions & 50 deletions apps/mobile/src/components/widgets/collectibles/collectibles.mocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,60 @@ const mockOrdinals: Ordinal[] = [
name: 'inscription',
src: 'https://ordinals.com/preview/a494e48bf7120c959239e8c544bc821ca4fb5a46e5fff79938943d434f252949i0',
},
// {
// id: '335209b72c452f52199ae09e8ce586a451ce452c73326f01f958d8aa8417e062i0',
// number: 73858867,
// output: '0',
// txid: '335209b72c452f52199ae09e8ce586a451ce452c73326f01f958d8aa8417e062',
// offset: '0',
// address: 'bc1pwz9n62p9dhjpqcpdmfcrewdnz3nk8jcved242vd2lj9fgvtvwnwscvdyre',
// preview:
// 'https://ordinals.hiro.so/inscription/335209b72c452f52199ae09e8ce586a451ce452c73326f01f958d8aa8417e062i0',
// title: 'Inscription 73858867',
// genesisBlockHeight: 855754,
// genesisBlockHash: '000000000000000000021972c2000a8d347dbac1a2540112fadf81219b188796',
// genesisTimestamp: 1723027746,
// value: '546',
// mimeType: 'text',
// name: 'inscription',
// src: 'https://bis-ord-content.fra1.cdn.digitaloceanspaces.com/ordinals/335209b72c452f52199ae09e8ce586a451ce452c73326f01f958d8aa8417e062i0',
// },
// ... (other ordinals)
// on leather dev wallet all seem to be mimeType: 'text' / 'html
{
id: '335209b72c452f52199ae09e8ce586a451ce452c73326f01f958d8aa8417e062i0',
number: 73858867,
output: '0',
txid: '335209b72c452f52199ae09e8ce586a451ce452c73326f01f958d8aa8417e062',
offset: '0',
address: 'bc1pwz9n62p9dhjpqcpdmfcrewdnz3nk8jcved242vd2lj9fgvtvwnwscvdyre',
preview:
'https://ordinals.hiro.so/inscription/335209b72c452f52199ae09e8ce586a451ce452c73326f01f958d8aa8417e062i0',
title: 'Inscription 73858867',
genesisBlockHeight: 855754,
genesisBlockHash: '000000000000000000021972c2000a8d347dbac1a2540112fadf81219b188796',
genesisTimestamp: 1723027746,
value: '546',
mimeType: 'text',
name: 'inscription',
src: 'https://bis-ord-content.fra1.cdn.digitaloceanspaces.com/ordinals/335209b72c452f52199ae09e8ce586a451ce452c73326f01f958d8aa8417e062i0',
},
{
id: 'cd27e71f955e021dd0840aa0544067fc92c3608009f2191a405f9f4910712b78i0',
number: 55549412,
output: '0',
txid: 'cd27e71f955e021dd0840aa0544067fc92c3608009f2191a405f9f4910712b78',
offset: '0',
address: 'bc1pwz9n62p9dhjpqcpdmfcrewdnz3nk8jcved242vd2lj9fgvtvwnwscvdyre',
preview:
'https://ordinals.hiro.so/inscription/cd27e71f955e021dd0840aa0544067fc92c3608009f2191a405f9f4910712b78i0',
title: 'Inscription 55549412',
genesisBlockHeight: 825933,
genesisBlockHash: '00000000000000000002f95317315f9d00b2299eb3499b0f499a707506ad6735',
genesisTimestamp: 1705356588,
value: '600',
mimeType: 'image',
name: 'inscription',
src: 'https://bis-ord-content.fra1.cdn.digitaloceanspaces.com/ordinals/cd27e71f955e021dd0840aa0544067fc92c3608009f2191a405f9f4910712b78i0',
},
{
id: 'e59434da4436cbdcdcf6b7b31fb734d43b304e981a2e3b69092bd6ca83108009i1286',
number: 64484111,
output: '1287',
txid: 'e59434da4436cbdcdcf6b7b31fb734d43b304e981a2e3b69092bd6ca83108009',
offset: '0',
address: 'bc1pwz9n62p9dhjpqcpdmfcrewdnz3nk8jcved242vd2lj9fgvtvwnwscvdyre',
preview:
'https://ordinals.hiro.so/inscription/e59434da4436cbdcdcf6b7b31fb734d43b304e981a2e3b69092bd6ca83108009i1286',
title: 'Inscription 64484111',
genesisBlockHeight: 834795,
genesisBlockHash: '00000000000000000000a3f2c9b0459df8eda99abca3c83f0e94a2a224badaba',
genesisTimestamp: 1710504509,
value: '546',
mimeType: 'gltf',
name: 'inscription',
src: 'https://ordinals.com/preview/e59434da4436cbdcdcf6b7b31fb734d43b304e981a2e3b69092bd6ca83108009i1286',
},
];

export interface StacksNft {
Expand All @@ -90,36 +124,36 @@ export interface StacksNft {
}

const mockStacksNfts: StacksNft[] = [
// {
// token_uri: 'ipfs://ipfs/QmQ63rXC9F7GyLYoYNyqxeiYvbBUvmHmL36PrfYNxpw5sT/90.json',
// metadata: {
// sip: 16,
// name: 'BlockSurvey #90',
// description: 'Worlds First Software License as an NFT',
// image: 'ipfs://QmZXkLMrN2ejpzGv1wk4HgcuL6XbyLVieW3Zm9wyAoDk18/90.png',
// cached_image:
// 'https://assets.hiro.so/api/mainnet/token-metadata-api/SPNWZ5V2TPWGQGVDR6T7B6RQ4XMGZ4PXTEE0VQ0S.blocksurvey/90.png',
// cached_thumbnail_image:
// 'https://assets.hiro.so/api/mainnet/token-metadata-api/SPNWZ5V2TPWGQGVDR6T7B6RQ4XMGZ4PXTEE0VQ0S.blocksurvey/90-thumb.png',
// attributes: [
// {
// trait_type: 'NightBackground',
// value: 'MidnightMoss',
// display_type: '',
// },
// {
// trait_type: 'NightLogo',
// value: 'AtomicTangerine',
// display_type: '',
// },
// {
// trait_type: 'SignatureWhite',
// value: 'SignatureWhite',
// display_type: '',
// },
// ],
// },
// },
{
token_uri: 'ipfs://ipfs/QmQ63rXC9F7GyLYoYNyqxeiYvbBUvmHmL36PrfYNxpw5sT/90.json',
metadata: {
sip: 16,
name: 'BlockSurvey #90',
description: 'Worlds First Software License as an NFT',
image: 'ipfs://QmZXkLMrN2ejpzGv1wk4HgcuL6XbyLVieW3Zm9wyAoDk18/90.png',
cached_image:
'https://assets.hiro.so/api/mainnet/token-metadata-api/SPNWZ5V2TPWGQGVDR6T7B6RQ4XMGZ4PXTEE0VQ0S.blocksurvey/90.png',
cached_thumbnail_image:
'https://assets.hiro.so/api/mainnet/token-metadata-api/SPNWZ5V2TPWGQGVDR6T7B6RQ4XMGZ4PXTEE0VQ0S.blocksurvey/90-thumb.png',
attributes: [
{
trait_type: 'NightBackground',
value: 'MidnightMoss',
display_type: '',
},
{
trait_type: 'NightLogo',
value: 'AtomicTangerine',
display_type: '',
},
{
trait_type: 'SignatureWhite',
value: 'SignatureWhite',
display_type: '',
},
],
},
},
// {
// token_uri: 'ipfs://ipfs/QmWRQyaVxUjHGjBUoZqGcNjL37VN99jcFwmoB1wZnpjJEg/',
// metadata: {
Expand Down
3 changes: 3 additions & 0 deletions apps/mobile/src/components/widgets/collectibles/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { CollectiblesWidget } from './collectibles-widget';
export { serializeCollectibles } from './collectibles-serializer';
export { mockCollectibles } from './collectibles.mocks';
2 changes: 2 additions & 0 deletions apps/mobile/src/components/widgets/tokens/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { TokensWidget } from './tokens-widget';
export { getMockTokens, mockTotalBalance } from './tokens.mocks';
78 changes: 39 additions & 39 deletions packages/ui/src/components/collectibles/collectibles.shared.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
export interface StacksNft {
token_uri: string;
metadata: {
sip: number;
name: string;
description: string;
image: string;
cached_image: string;
cached_thumbnail_image: string;
attributes?: Array<{
trait_type: string;
value: string;
display_type?: string;
}>;
properties?: {
collection?: string;
collectionId?: string;
[key: string]: any;
};
};
}
export interface Ordinal {
id: string;
number: number;
output: string;
txid: string;
offset: string;
address: string;
preview: string;
title: string;
genesisBlockHeight: number;
genesisBlockHash: string;
genesisTimestamp: number;
value: string;
mimeType: string;
name: string;
src: string;
}
// export interface StacksNft {
// token_uri: string;
// metadata: {
// sip: number;
// name: string;
// description: string;
// image: string;
// cached_image: string;
// cached_thumbnail_image: string;
// attributes?: Array<{
// trait_type: string;
// value: string;
// display_type?: string;
// }>;
// properties?: {
// collection?: string;
// collectionId?: string;
// [key: string]: any;
// };
// };
// }
// export interface Ordinal {
// id: string;
// number: number;
// output: string;
// txid: string;
// offset: string;
// address: string;
// preview: string;
// title: string;
// genesisBlockHeight: number;
// genesisBlockHash: string;
// genesisTimestamp: number;
// value: string;
// mimeType: string;
// name: string;
// src: string;
// }

export type Collectible = Ordinal | StacksNft;
// export type Collectible = Ordinal | StacksNft;
Loading

0 comments on commit 96ce700

Please sign in to comment.