-
Notifications
You must be signed in to change notification settings - Fork 103
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
652df02
commit 461c57b
Showing
10 changed files
with
215 additions
and
15 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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import {useQuery as useGraphqlQuery} from "@apollo/client/react/hooks/useQuery"; | ||
import {gql} from "@apollo/client"; | ||
|
||
export type CoinHolder = { | ||
owner_address: string; | ||
amount: number; | ||
}; | ||
|
||
export function useGetCoinHolders(coin_type: string): { | ||
isLoading: boolean; | ||
error: any; | ||
data: CoinHolder[] | undefined; | ||
} { | ||
const {loading, error, data} = useGraphqlQuery<{ | ||
current_fungible_asset_balances: CoinHolder[]; | ||
}>( | ||
gql` | ||
query GetFungibleAssetBalances($coin_type: String!) { | ||
current_fungible_asset_balances( | ||
where: {asset_type: {_eq: $coin_type}} | ||
limit: 100 | ||
order_by: {amount: desc} | ||
) { | ||
owner_address | ||
amount | ||
} | ||
} | ||
`, | ||
{variables: {coin_type}}, | ||
); | ||
|
||
return { | ||
isLoading: loading, | ||
error, | ||
data: data?.current_fungible_asset_balances, | ||
}; | ||
} |
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
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
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
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,71 @@ | ||
import React from "react"; | ||
import EmptyTabContent from "../../../components/IndividualPageContent/EmptyTabContent"; | ||
import {CoinData} from "../Components/CoinData"; | ||
import { | ||
CoinHolder, | ||
useGetCoinHolders, | ||
} from "../../../api/hooks/useGetCoinHolders"; | ||
import Table from "@mui/material/Table"; | ||
import TableHead from "@mui/material/TableHead"; | ||
import TableRow from "@mui/material/TableRow"; | ||
import GeneralTableBody from "../../../components/Table/GeneralTableBody"; | ||
import GeneralTableHeaderCell from "../../../components/Table/GeneralTableHeaderCell"; | ||
import GeneralTableRow from "../../../components/Table/GeneralTableRow"; | ||
import GeneralTableCell from "../../../components/Table/GeneralTableCell"; | ||
import HashButton, {HashType} from "../../../components/HashButton"; | ||
import {getFormattedBalanceStr} from "../../../components/IndividualPageContent/ContentValue/CurrencyValue"; | ||
|
||
type HoldersTabProps = { | ||
struct: string; | ||
data: CoinData | undefined; | ||
}; | ||
|
||
export default function HoldersTab({struct, data}: HoldersTabProps) { | ||
const holderData = useGetCoinHolders(struct); | ||
if (!data || Array.isArray(data) || !holderData?.data) { | ||
return <EmptyTabContent />; | ||
} | ||
|
||
return <HoldersTable data={data} holders={holderData.data} />; | ||
} | ||
|
||
export function HoldersTable({ | ||
data, | ||
holders, | ||
}: { | ||
holders: CoinHolder[]; | ||
data: CoinData; | ||
}) { | ||
return ( | ||
<Table> | ||
<TableHead> | ||
<TableRow> | ||
<GeneralTableHeaderCell header="address" /> | ||
<GeneralTableHeaderCell header="amount" textAlignRight={true} /> | ||
</TableRow> | ||
</TableHead> | ||
<GeneralTableBody> | ||
{holders.map((holder) => { | ||
return ( | ||
<GeneralTableRow> | ||
<GeneralTableCell> | ||
<HashButton | ||
hash={holder.owner_address} | ||
type={HashType.ACCOUNT} | ||
/> | ||
</GeneralTableCell> | ||
<GeneralTableCell align={"right"}> | ||
{getFormattedBalanceStr( | ||
holder.amount.toString(), | ||
data.data.decimals, | ||
) + | ||
" " + | ||
data.data.symbol} | ||
</GeneralTableCell> | ||
</GeneralTableRow> | ||
); | ||
})} | ||
</GeneralTableBody> | ||
</Table> | ||
); | ||
} |
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
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
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,73 @@ | ||
import React from "react"; | ||
import EmptyTabContent from "../../../components/IndividualPageContent/EmptyTabContent"; | ||
import { | ||
CoinHolder, | ||
useGetCoinHolders, | ||
} from "../../../api/hooks/useGetCoinHolders"; | ||
import Table from "@mui/material/Table"; | ||
import TableHead from "@mui/material/TableHead"; | ||
import TableRow from "@mui/material/TableRow"; | ||
import GeneralTableBody from "../../../components/Table/GeneralTableBody"; | ||
import GeneralTableHeaderCell from "../../../components/Table/GeneralTableHeaderCell"; | ||
import GeneralTableRow from "../../../components/Table/GeneralTableRow"; | ||
import GeneralTableCell from "../../../components/Table/GeneralTableCell"; | ||
import HashButton, {HashType} from "../../../components/HashButton"; | ||
import {getFormattedBalanceStr} from "../../../components/IndividualPageContent/ContentValue/CurrencyValue"; | ||
import {FACombinedData} from "../Index"; | ||
|
||
type HoldersTabProps = { | ||
address: string; | ||
data: FACombinedData | undefined; | ||
}; | ||
|
||
export default function HoldersTab({address, data}: HoldersTabProps) { | ||
const holderData = useGetCoinHolders(address); | ||
if (!data || Array.isArray(data) || !holderData?.data) { | ||
return <EmptyTabContent />; | ||
} | ||
|
||
return <HoldersTable data={data} holders={holderData.data} />; | ||
} | ||
|
||
export function HoldersTable({ | ||
data, | ||
holders, | ||
}: { | ||
holders: CoinHolder[]; | ||
data: FACombinedData; | ||
}) { | ||
return ( | ||
<Table> | ||
<TableHead> | ||
<TableRow> | ||
<GeneralTableHeaderCell header="rank" /> | ||
<GeneralTableHeaderCell header="holder address" /> | ||
<GeneralTableHeaderCell header="amount" textAlignRight={true} /> | ||
</TableRow> | ||
</TableHead> | ||
<GeneralTableBody> | ||
{holders.map((holder, i) => { | ||
return ( | ||
<GeneralTableRow> | ||
<GeneralTableCell>{i}</GeneralTableCell> | ||
<GeneralTableCell> | ||
<HashButton | ||
hash={holder.owner_address} | ||
type={HashType.ACCOUNT} | ||
/> | ||
</GeneralTableCell> | ||
<GeneralTableCell align={"right"}> | ||
{getFormattedBalanceStr( | ||
holder.amount.toString(), | ||
data.coinData?.decimals, | ||
) + | ||
" " + | ||
data.coinData?.symbol} | ||
</GeneralTableCell> | ||
</GeneralTableRow> | ||
); | ||
})} | ||
</GeneralTableBody> | ||
</Table> | ||
); | ||
} |
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
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