-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0740975
commit 16765c3
Showing
6 changed files
with
137 additions
and
36 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -27,6 +27,10 @@ | |
{ | ||
id: 'configuration', | ||
label: 'Configuration' | ||
}, | ||
{ | ||
id: 'holders', | ||
label: 'Top Holders' | ||
} | ||
] | ||
]} | ||
|
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
109 changes: 109 additions & 0 deletions
109
apps/dashboard/src/routes/(search-pages)/resource/[resource]/holders/+page.svelte
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,109 @@ | ||
<script lang="ts"> | ||
import Row from '@components/info-box/Row.svelte' | ||
import Link from '@components/_base/link/Link.svelte' | ||
import type { PageData } from './$types' | ||
import LoadingSpinner from '@components/_base/button/loading-spinner/LoadingSpinner.svelte' | ||
import { formatTokenValue } from '@utils' | ||
import Pagination from '@components/_base/table/basic-table/Pagination.svelte' | ||
import { gatewayApi } from '@stores' | ||
import type { ResourceHoldersCollectionItem } from '@common/gateway-sdk' | ||
export let data: PageData | ||
let holders: ResourceHoldersCollectionItem[][] = [] | ||
data.holders.then(({ items }) => { | ||
holders = [...holders, items] | ||
}) | ||
let cursor: string | undefined | ||
data.holders.then((holders) => (cursor = holders.next_cursor ?? undefined)) | ||
let currentPage = 0 | ||
let disabledNext = true | ||
$: if (currentPage < holders.length - 1 || cursor) { | ||
disabledNext = false | ||
} else { | ||
disabledNext = true | ||
} | ||
const loadNextPage = async () => { | ||
if (currentPage < holders.length - 1) { | ||
currentPage++ | ||
return | ||
} | ||
if (!cursor) return | ||
if (currentPage === holders.length - 1) { | ||
const items = await $gatewayApi!.extensions | ||
.getResourceHolders(data.resource.address, cursor ?? undefined) | ||
.then((holders) => { | ||
cursor = holders.next_cursor ?? undefined | ||
return holders.items | ||
}) | ||
holders = [...holders, items] | ||
currentPage++ | ||
} else { | ||
currentPage++ | ||
} | ||
} | ||
</script> | ||
|
||
<div class="card info-card"> | ||
{#await data.holders} | ||
<div class="loading-container"> | ||
<div class="loading"> | ||
<LoadingSpinner /> | ||
</div> | ||
</div> | ||
{:then _} | ||
{#each holders[currentPage] as holder} | ||
<Row> | ||
<div slot="left"> | ||
<Link | ||
url="/account/{holder.holder_address}" | ||
text={holder.holder_address} | ||
/> | ||
</div> | ||
|
||
<div slot="right"> | ||
{holder.type === 'FungibleResource' | ||
? formatTokenValue(holder.amount).displayValue | ||
: holder.non_fungible_ids_count} | ||
</div> | ||
</Row> | ||
{/each} | ||
|
||
<div class="pagination"> | ||
<Pagination | ||
disabledPrevious={currentPage === 0} | ||
{disabledNext} | ||
on:next={loadNextPage} | ||
on:previous={() => currentPage--} | ||
/> | ||
</div> | ||
{/await} | ||
</div> | ||
|
||
<style> | ||
.loading-container { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100%; | ||
width: 100%; | ||
} | ||
.loading { | ||
height: 5rem; | ||
width: 5rem; | ||
} | ||
.pagination { | ||
margin-top: var(--spacing-lg); | ||
} | ||
</style> |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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