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

add top holders tab for resources #990

Merged
merged 1 commit into from
Oct 10, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
{
id: 'configuration',
label: 'Configuration'
},
{
id: 'holders',
label: 'Top Holders'
}
]
]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '../../utils'
import { isNFTAddress } from '@utils'
import { redirect } from '@sveltejs/kit'
import { callApi } from '@api/_deprecated/gateway'
import { callApi } from '@api/gateway'
import { andThen, pipe } from 'ramda'
import { handleGatewayResult } from '../../../../utils'
import { getStringMetadata } from '@api/utils/metadata'
Expand Down Expand Up @@ -55,7 +55,13 @@ export const load: LayoutLoad = async ({ params }) => {
? getRedeemableTokens(transformedResource)
: Promise.resolve(undefined)

const holders = pipe(
() => callApi('getResourceHolders', params.resource),
handleGatewayResult()
)()

return {
holders,
address: params.resource,
resource: transformedResource,
promises: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<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 type { ResourceHoldersCollectionItem } from '@common/gateway-sdk'
import { callApi } from '@api/gateway'
import InfiniteScroll from '@components/infinite-scroll/InfiniteScroll.svelte'
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))
const loadMore = async () => {
if (!cursor) return
callApi(
'getResourceHolders',
data.resource.address,
cursor ?? undefined
).map((result) => {
cursor = result.next_cursor ?? undefined
holders = [...holders, ...result.items]
})
}
</script>

<div class="card info-card">
{#await data.holders}
<div class="loading-container">
<div class="loading">
<LoadingSpinner />
</div>
</div>
{:then _}
{#each holders 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}

<InfiniteScroll
on:thresholdReached={() => {
loadMore()
}}
/>
{/await}
</div>

<style>
.loading-container {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
width: 100%;
}
.loading {
height: 5rem;
width: 5rem;
}
.pagination {

Check warning on line 85 in apps/dashboard/src/routes/(search-pages)/resource/[resource]/holders/+page.svelte

View workflow job for this annotation

GitHub Actions / build

Unused CSS selector ".pagination"
margin-top: var(--spacing-lg);
}
</style>
39 changes: 4 additions & 35 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"scripts": {},
"dependencies": {
"@floating-ui/dom": "^1.5.3",
"@radixdlt/babylon-gateway-api-sdk": "^1.7.2",
"@radixdlt/babylon-core-api-sdk": "^1.2.3",
"@radixdlt/babylon-gateway-api-sdk": "^1.7.3",
"@radixdlt/radix-dapp-toolkit": "^2.1.1",
"@radixdlt/radix-engine-toolkit": "^1.0.5",
"@radixdlt/rola": "^2.0.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/src/api/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export const api = {
...extractMethods(gatewayApi.stream),
...extractMethods(gatewayApi.status),
...extractMethods(gatewayApi.transaction),
...extractMethods(gatewayApi.statistics)
...extractMethods(gatewayApi.statistics),
...extractMethods(gatewayApi.extensions)
}

export const callApiWithCache = <T extends keyof typeof api>(
Expand Down
Loading