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

display name instead of holder addr in collection #27

Merged
merged 3 commits into from
Oct 20, 2023
Merged
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
36 changes: 21 additions & 15 deletions frontend/src/app/home/Pet/Collection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export type CollectionResponse = {
export function Collection() {
const { account, network } = useWallet();
const [collection, setCollection] = useState<Collection>();
const [collectionHolders, setCollectionHolders] =
useState<CollectionHolder[]>();
const [firstFewAptogotchiName, setFirstFewAptogotchiName] =
useState<string[]>();

const fetchCollection = useCallback(async () => {
if (!account?.address) return;
Expand All @@ -49,6 +49,7 @@ export function Collection() {
query: `
query MyQuery($collection_id: String) {
current_collections_v2(
limit: 3
where: { collection_id: { _eq: $collection_id } }
) {
collection_id
Expand Down Expand Up @@ -81,10 +82,18 @@ export function Collection() {
const collectionResponse: CollectionResponse =
await provider.indexerClient.queryIndexer(getCollectionDataGql);

setCollection(collectionResponse.current_collections_v2[0]);
setCollectionHolders(
collectionResponse.current_collection_ownership_v2_view
const firstFewAptogotchi = await Promise.all(
collectionResponse.current_collection_ownership_v2_view.map((holder) =>
provider.view({
function: `${process.env.NEXT_PUBLIC_CONTRACT_ADDRESS}::main::get_aptogotchi`,
type_arguments: [],
arguments: [holder.owner_address],
})
)
);

setCollection(collectionResponse.current_collections_v2[0]);
setFirstFewAptogotchiName(firstFewAptogotchi.map((x) => x[0] as string));
}, [account?.address]);

useEffect(() => {
Expand All @@ -96,18 +105,15 @@ export function Collection() {
const collectionComponent = (
<div className="nes-field">
<label htmlFor="owner_field">
Aptogotchi Minted: {collection?.current_supply}
Total Aptogotchi Minted: {collection?.current_supply}
</label>
<label htmlFor="owner_field">All Holders</label>
<label htmlFor="owner_field">Fellow Aptogotchis:</label>
<ul className="nes-list is-disc">
<label>
{/* we should paginate this if there are lots of holders */}
{JSON.stringify(
collectionHolders?.map(
(holder) => holder.owner_address.substring(0, 5) + "..."
)
)}
</label>
<label>{`${firstFewAptogotchiName?.join(", ")}${
(firstFewAptogotchiName?.length || 0) < collection?.current_supply
? "... and more"
: ""
} `}</label>
</ul>
</div>
);
Expand Down