-
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.
Fixup coin holders page / Add transactinos (#918)
* [holders] Add loading spinner * [transactions] Add coin transactions bare minimum table
- Loading branch information
1 parent
461c57b
commit 59d9ac8
Showing
8 changed files
with
190 additions
and
12 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,48 @@ | ||
import {useQuery as useGraphqlQuery} from "@apollo/client/react/hooks/useQuery"; | ||
import {gql} from "@apollo/client"; | ||
|
||
export type FAActivity = { | ||
transaction_version: number; | ||
transaction_timestamp: string; | ||
owner_address: string; | ||
}; | ||
|
||
export function useGetCoinActivities( | ||
asset: string, | ||
offset?: number, | ||
): { | ||
isLoading: boolean; | ||
error: any; | ||
data: FAActivity[] | undefined; | ||
} { | ||
const {loading, error, data} = useGraphqlQuery<{ | ||
fungible_asset_activities: FAActivity[]; | ||
}>( | ||
// Exclude gas fees from the list | ||
gql` | ||
query GetFungibleAssetActivities($asset: String, $offset: Int) { | ||
fungible_asset_activities( | ||
where: { | ||
asset_type: {_eq: $asset} | ||
type: {_neq: "0x1::aptos_coin::GasFeeEvent"} | ||
} | ||
offset: $offset | ||
limit: 100 | ||
order_by: {transaction_version: desc} | ||
distinct_on: transaction_version | ||
) { | ||
transaction_version | ||
owner_address | ||
transaction_timestamp | ||
} | ||
} | ||
`, | ||
{variables: {asset, offset: offset ?? 0}}, | ||
); | ||
|
||
return { | ||
isLoading: loading, | ||
error, | ||
data: data?.fungible_asset_activities, | ||
}; | ||
} |
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 |
---|---|---|
@@ -1,13 +1,71 @@ | ||
import React from "react"; | ||
import EmptyTabContent from "../../../components/IndividualPageContent/EmptyTabContent"; | ||
import LoadingModal from "../../../components/LoadingModal"; | ||
import Table from "@mui/material/Table"; | ||
import TableHead from "@mui/material/TableHead"; | ||
import TableRow from "@mui/material/TableRow"; | ||
import GeneralTableHeaderCell from "../../../components/Table/GeneralTableHeaderCell"; | ||
import GeneralTableBody from "../../../components/Table/GeneralTableBody"; | ||
import GeneralTableRow from "../../../components/Table/GeneralTableRow"; | ||
import GeneralTableCell from "../../../components/Table/GeneralTableCell"; | ||
import HashButton, {HashType} from "../../../components/HashButton"; | ||
import { | ||
FAActivity, | ||
useGetCoinActivities, | ||
} from "../../../api/hooks/useGetCoinActivities"; | ||
import {CoinData} from "../Components/CoinData"; | ||
|
||
type TransactionsTabProps = { | ||
struct: string; | ||
data: CoinData | undefined; | ||
}; | ||
|
||
export default function TransactionsTab({}: TransactionsTabProps) { | ||
// TODO: Lookup transactions by coin | ||
return <EmptyTabContent />; | ||
export default function TransactionsTab({struct, data}: TransactionsTabProps) { | ||
const holderData = useGetCoinActivities(struct); | ||
if (holderData?.isLoading) { | ||
return <LoadingModal open={true} />; | ||
} | ||
if (!data || Array.isArray(data) || !holderData?.data) { | ||
return <EmptyTabContent />; | ||
} | ||
|
||
return <FAActivityTable data={data} activities={holderData.data} />; | ||
} | ||
|
||
export function FAActivityTable({ | ||
activities, | ||
}: { | ||
activities: FAActivity[]; | ||
data: CoinData; | ||
}) { | ||
return ( | ||
<Table> | ||
<TableHead> | ||
<TableRow> | ||
<GeneralTableHeaderCell header="version" /> | ||
<GeneralTableHeaderCell header="sender" /> | ||
</TableRow> | ||
</TableHead> | ||
<GeneralTableBody> | ||
{activities.map((activity) => { | ||
return ( | ||
<GeneralTableRow> | ||
<GeneralTableCell> | ||
<HashButton | ||
hash={activity.transaction_version.toString()} | ||
type={HashType.TRANSACTION} | ||
/> | ||
</GeneralTableCell> | ||
<GeneralTableCell> | ||
<HashButton | ||
hash={activity.owner_address} | ||
type={HashType.ACCOUNT} | ||
/> | ||
</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 |
---|---|---|
@@ -1,13 +1,71 @@ | ||
import React from "react"; | ||
import EmptyTabContent from "../../../components/IndividualPageContent/EmptyTabContent"; | ||
import {FACombinedData} from "../Index"; | ||
import LoadingModal from "../../../components/LoadingModal"; | ||
import Table from "@mui/material/Table"; | ||
import TableHead from "@mui/material/TableHead"; | ||
import TableRow from "@mui/material/TableRow"; | ||
import GeneralTableHeaderCell from "../../../components/Table/GeneralTableHeaderCell"; | ||
import GeneralTableBody from "../../../components/Table/GeneralTableBody"; | ||
import GeneralTableRow from "../../../components/Table/GeneralTableRow"; | ||
import GeneralTableCell from "../../../components/Table/GeneralTableCell"; | ||
import HashButton, {HashType} from "../../../components/HashButton"; | ||
import { | ||
FAActivity, | ||
useGetCoinActivities, | ||
} from "../../../api/hooks/useGetCoinActivities"; | ||
|
||
type TransactionsTabProps = { | ||
address: string; | ||
data: FACombinedData | undefined; | ||
}; | ||
|
||
export default function TransactionsTab({}: TransactionsTabProps) { | ||
// TODO: Lookup transactions by coin | ||
return <EmptyTabContent />; | ||
export default function TransactionsTab({address, data}: TransactionsTabProps) { | ||
const holderData = useGetCoinActivities(address); | ||
if (holderData?.isLoading) { | ||
return <LoadingModal open={true} />; | ||
} | ||
if (!data || Array.isArray(data) || !holderData?.data) { | ||
return <EmptyTabContent />; | ||
} | ||
|
||
return <FAActivityTable data={data} activities={holderData.data} />; | ||
} | ||
|
||
export function FAActivityTable({ | ||
activities, | ||
}: { | ||
activities: FAActivity[]; | ||
data: FACombinedData; | ||
}) { | ||
return ( | ||
<Table> | ||
<TableHead> | ||
<TableRow> | ||
<GeneralTableHeaderCell header="version" /> | ||
<GeneralTableHeaderCell header="sender" /> | ||
</TableRow> | ||
</TableHead> | ||
<GeneralTableBody> | ||
{activities.map((activity) => { | ||
return ( | ||
<GeneralTableRow> | ||
<GeneralTableCell> | ||
<HashButton | ||
hash={activity.transaction_version.toString()} | ||
type={HashType.TRANSACTION} | ||
/> | ||
</GeneralTableCell> | ||
<GeneralTableCell> | ||
<HashButton | ||
hash={activity.owner_address} | ||
type={HashType.ACCOUNT} | ||
/> | ||
</GeneralTableCell> | ||
</GeneralTableRow> | ||
); | ||
})} | ||
</GeneralTableBody> | ||
</Table> | ||
); | ||
} |