Skip to content
Open
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/sage-api/src/records/nft_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ pub struct NftCollectionRecord {
pub visible: bool,
pub name: Option<String>,
pub icon: Option<String>,
pub nft_count: u32,
}
11 changes: 8 additions & 3 deletions crates/sage-database/src/tables/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct CollectionRow {
pub banner_url: Option<String>,
pub description: Option<String>,
pub is_visible: bool,
pub nft_count: u32,
}

impl Database {
Expand Down Expand Up @@ -46,7 +47,8 @@ impl DatabaseTx<'_> {
async fn collection(conn: impl SqliteExecutor<'_>, hash: Bytes32) -> Result<Option<CollectionRow>> {
let hash_ref = hash.as_ref();
let row = query!(
"SELECT id, hash, uuid, minter_hash, name, icon_url, banner_url, description, is_visible
"SELECT id, hash, uuid, minter_hash, name, icon_url, banner_url, description, is_visible,
(SELECT COUNT(*) FROM owned_nfts WHERE owned_nfts.collection_id = collections.id AND asset_is_visible = 1) AS \"nft_count!: i64\"
FROM collections
WHERE hash = ?",
hash_ref
Expand All @@ -64,6 +66,7 @@ async fn collection(conn: impl SqliteExecutor<'_>, hash: Bytes32) -> Result<Opti
banner_url: row.banner_url,
description: row.description,
is_visible: row.is_visible,
nft_count: row.nft_count.try_into()?,
})
})
.transpose()
Expand All @@ -77,8 +80,9 @@ async fn collections(
) -> Result<(Vec<CollectionRow>, u32)> {
// we only return collections that have nfts
let rows = query!(
"SELECT collections.hash, uuid, collections.minter_hash, collections.name, collections.icon_url,
collections.banner_url, collections.description, collections.is_visible, COUNT(*) OVER() as total_count
"SELECT collections.hash, uuid, collections.minter_hash, collections.name, collections.icon_url,
collections.banner_url, collections.description, collections.is_visible, COUNT(*) OVER() as total_count,
(SELECT COUNT(*) FROM owned_nfts WHERE owned_nfts.collection_id = collections.id AND asset_is_visible = 1) AS \"nft_count!: i64\"
FROM collections
WHERE 1=1
AND EXISTS (SELECT 1 FROM owned_nfts WHERE owned_nfts.collection_id = collections.id)
Expand Down Expand Up @@ -109,6 +113,7 @@ async fn collections(
banner_url: row.banner_url,
description: row.description,
is_visible: row.is_visible,
nft_count: row.nft_count.try_into()?,
})
})
.collect::<Result<Vec<_>>>()?;
Expand Down
2 changes: 2 additions & 0 deletions crates/sage-wallet/src/utils/offchain_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ pub fn compute_nft_info(did_id: Option<Bytes32>, blob: &[u8]) -> ComputedNftInfo
}
}),
is_visible: true,
// Computed on read paths only; insert_collection ignores this field.
nft_count: 0,
})
} else {
None
Expand Down
3 changes: 3 additions & 0 deletions crates/sage/src/endpoints/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ impl Sage {
name: row.name,
icon: row.icon_url,
visible: row.is_visible,
nft_count: row.nft_count,
})
})
.collect::<Result<Vec<_>>>()?;
Expand Down Expand Up @@ -598,6 +599,7 @@ impl Sage {
visible: collection.is_visible,
name: collection.name,
icon: collection.icon_url,
nft_count: collection.nft_count,
}
} else {
NftCollectionRecord {
Expand All @@ -607,6 +609,7 @@ impl Sage {
visible: true,
name: Some("Uncategorized".to_string()),
icon: None,
nft_count: 0,
}
};

Expand Down
5 changes: 4 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
SupportedLanguage,
useLanguage,
} from './contexts/LanguageContext';
import { NftPriceProvider } from './contexts/NftPriceContext';
import { PeerProvider } from './contexts/PeerContext';
import { PriceProvider } from './contexts/PriceContext';
import { SafeAreaProvider } from './contexts/SafeAreaContext';
Expand Down Expand Up @@ -193,7 +194,9 @@ function AppInner() {
<PeerProvider>
<WalletConnectProvider>
<PriceProvider>
<RouterProvider router={router} />
<NftPriceProvider>
<RouterProvider router={router} />
</NftPriceProvider>
</PriceProvider>
</WalletConnectProvider>
</PeerProvider>
Expand Down
2 changes: 1 addition & 1 deletion src/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1915,7 +1915,7 @@ kind: NftUriKind;
* The URI to add
*/
uri: string }
export type NftCollectionRecord = { collection_id: string; did_id: string; metadata_collection_id: string; visible: boolean; name: string | null; icon: string | null }
export type NftCollectionRecord = { collection_id: string; did_id: string; metadata_collection_id: string; visible: boolean; name: string | null; icon: string | null; nft_count: number }
export type NftData = { blob: string | null; mime_type: string | null; hash_matches: boolean; metadata_json: string | null; metadata_hash_matches: boolean }
/**
* Individual NFT to mint
Expand Down
40 changes: 40 additions & 0 deletions src/components/NftGroupCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import {
NftRecord,
commands,
} from '@/bindings';
import { NumberFormat } from '@/components/NumberFormat';
import { NO_COLLECTION_ID } from '@/hooks/useNftData';
import { NftGroupMode } from '@/hooks/useNftParams';
import { useNetwork } from '@/hooks/useNetwork';
import { useNftPrices } from '@/hooks/useNftPrices';
import useOfferStateWithDefault from '@/hooks/useOfferStateWithDefault';
import { usePrices } from '@/hooks/usePrices';
import { mintGardenCollectionUrl, mintGardenDidUrl } from '@/lib/urls';
//import { getMintGardenProfile } from '@/lib/marketplaces';
import { t } from '@lingui/core/macro';
Expand Down Expand Up @@ -71,6 +75,8 @@ export function NftGroupCard({
}: NftGroupCardProps) {
const navigate = useNavigate();
const { isTestnet } = useNetwork();
const { collectionValues } = useNftPrices();
const { getPriceInUsd } = usePrices();
const [offerState, setOfferState] = useOfferStateWithDefault();
const isCollection = type === 'collection';

Expand Down Expand Up @@ -282,6 +288,40 @@ export function NftGroupCard({
</TooltipContent>
</Tooltip>
</TooltipProvider>

{isCollectionRecord(item) &&
item.collection_id !== NO_COLLECTION_ID &&
(() => {
const value = collectionValues[item.collection_id];
if (!value) return null;

if (value.floorXch === null) {
return (
<p className='text-xs text-muted-foreground truncate'>
<Trans>No listings</Trans>
</p>
);
}

return (
<p className='text-xs text-muted-foreground truncate'>
<Trans>
Floor{' '}
<NumberFormat
value={value.floorXch}
maximumFractionDigits={3}
/>{' '}
XCH · ~
<NumberFormat
value={value.valueXch * getPriceInUsd(null)}
style='currency'
currency='USD'
maximumFractionDigits={2}
/>
</Trans>
</p>
);
})()}
</span>

<DropdownMenu>
Expand Down
Loading