-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #970 from alleslabs/feat/account-detail-lite
Feat: Implement Account Details Page
- Loading branch information
Showing
36 changed files
with
872 additions
and
554 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
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
127 changes: 0 additions & 127 deletions
127
src/lib/pages/account-details/components/tables/InstantiatedContractsTable.tsx
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export * from "./txs"; | ||
export * from "./AdminContractsTable"; | ||
export * from "./InstantiatedContractsTable"; | ||
export * from "./instantiated-contracts"; | ||
export * from "./OpenedProposalsTable"; | ||
export * from "./StoredCodesTable"; |
118 changes: 118 additions & 0 deletions
118
src/lib/pages/account-details/components/tables/instantiated-contracts/Full.tsx
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,118 @@ | ||
import { Box } from "@chakra-ui/react"; | ||
import type { ChangeEvent } from "react"; | ||
|
||
import { useInternalNavigate, useMobile } from "lib/app-provider"; | ||
import { Pagination } from "lib/components/pagination"; | ||
import { usePaginator } from "lib/components/pagination/usePaginator"; | ||
import { EmptyState, ErrorFetching } from "lib/components/state"; | ||
import { | ||
ContractsTable, | ||
MobileTitle, | ||
TableTitle, | ||
ViewMore, | ||
} from "lib/components/table"; | ||
import { useAccountContracts } from "lib/pages/account-details/data"; | ||
import type { BechAddr32 } from "lib/types"; | ||
|
||
import type { InstantiatedContractsTableProps } from "./types"; | ||
|
||
export const InstantiatedContractsTableFull = ({ | ||
address, | ||
scrollComponentId, | ||
totalData, | ||
refetchCount, | ||
onViewMore, | ||
}: InstantiatedContractsTableProps) => { | ||
const isMobile = useMobile(); | ||
const navigate = useInternalNavigate(); | ||
const onRowSelect = (contract: BechAddr32) => | ||
navigate({ | ||
pathname: "/contracts/[contract]", | ||
query: { contract }, | ||
}); | ||
|
||
const { | ||
pagesQuantity, | ||
currentPage, | ||
setCurrentPage, | ||
pageSize, | ||
setPageSize, | ||
offset, | ||
} = usePaginator({ | ||
total: totalData, | ||
initialState: { | ||
pageSize: 10, | ||
currentPage: 1, | ||
isDisabled: false, | ||
}, | ||
}); | ||
const { contracts, isLoading } = useAccountContracts( | ||
address, | ||
offset, | ||
onViewMore ? 5 : pageSize | ||
); | ||
|
||
const onPageChange = (nextPage: number) => { | ||
refetchCount(); | ||
setCurrentPage(nextPage); | ||
}; | ||
|
||
const onPageSizeChange = (e: ChangeEvent<HTMLSelectElement>) => { | ||
const size = Number(e.target.value); | ||
refetchCount(); | ||
setPageSize(size); | ||
setCurrentPage(1); | ||
}; | ||
|
||
const isMobileOverview = isMobile && !!onViewMore; | ||
return ( | ||
<Box mt={{ base: 4, md: 8 }}> | ||
{isMobileOverview ? ( | ||
<MobileTitle | ||
title="Contract Instances" | ||
count={totalData} | ||
onViewMore={onViewMore} | ||
/> | ||
) : ( | ||
<> | ||
<TableTitle | ||
title="Contract Instances" | ||
count={totalData} | ||
helperText="This account instantiated the following contracts" | ||
mb={2} | ||
/> | ||
<ContractsTable | ||
contracts={contracts} | ||
isLoading={isLoading} | ||
emptyState={ | ||
!contracts ? ( | ||
<ErrorFetching dataName="contracts" /> | ||
) : ( | ||
<EmptyState | ||
message="No contracts have been instantiated by this account before." | ||
withBorder | ||
/> | ||
) | ||
} | ||
onRowSelect={onRowSelect} | ||
/> | ||
</> | ||
)} | ||
{!!totalData && | ||
(onViewMore | ||
? totalData > 5 && !isMobile && <ViewMore onClick={onViewMore} /> | ||
: totalData > 10 && ( | ||
<Pagination | ||
currentPage={currentPage} | ||
pagesQuantity={pagesQuantity} | ||
offset={offset} | ||
totalData={totalData} | ||
scrollComponentId={scrollComponentId} | ||
pageSize={pageSize} | ||
onPageChange={onPageChange} | ||
onPageSizeChange={onPageSizeChange} | ||
/> | ||
))} | ||
</Box> | ||
); | ||
}; |
71 changes: 71 additions & 0 deletions
71
src/lib/pages/account-details/components/tables/instantiated-contracts/Lite.tsx
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 { Box } from "@chakra-ui/react"; | ||
|
||
import { useInternalNavigate, useMobile } from "lib/app-provider"; | ||
import { EmptyState, ErrorFetching } from "lib/components/state"; | ||
import { | ||
ContractsTable, | ||
MobileTitle, | ||
TableTitle, | ||
ViewMore, | ||
} from "lib/components/table"; | ||
import { useAccountContractsLcd } from "lib/pages/account-details/data"; | ||
import type { BechAddr32 } from "lib/types"; | ||
|
||
import type { InstantiatedContractsTableProps } from "./types"; | ||
|
||
export const InstantiatedContractsTableLite = ({ | ||
address, | ||
onViewMore, | ||
}: InstantiatedContractsTableProps) => { | ||
const isMobile = useMobile(); | ||
const navigate = useInternalNavigate(); | ||
const onRowSelect = (contract: BechAddr32) => | ||
navigate({ | ||
pathname: "/contracts/[contract]", | ||
query: { contract }, | ||
}); | ||
const { contracts, isLoading } = useAccountContractsLcd(address); | ||
|
||
const contractsCount = contracts?.length; | ||
const isMobileOverview = isMobile && !!onViewMore; | ||
return ( | ||
<Box mt={{ base: 4, md: 8 }}> | ||
{isMobileOverview ? ( | ||
<MobileTitle | ||
title="Contract Instances" | ||
count={contractsCount} | ||
onViewMore={onViewMore} | ||
/> | ||
) : ( | ||
<> | ||
<TableTitle | ||
title="Contract Instances" | ||
count={contractsCount} | ||
helperText="This account instantiated the following contracts" | ||
mb={2} | ||
/> | ||
<ContractsTable | ||
contracts={onViewMore ? contracts?.slice(0, 5) : contracts} | ||
isLoading={isLoading} | ||
emptyState={ | ||
!contracts ? ( | ||
<ErrorFetching dataName="contracts" /> | ||
) : ( | ||
<EmptyState | ||
message="No contracts have been instantiated by this account before." | ||
withBorder | ||
/> | ||
) | ||
} | ||
onRowSelect={onRowSelect} | ||
showLastUpdate={false} | ||
/> | ||
</> | ||
)} | ||
{!!contractsCount && | ||
(onViewMore | ||
? contractsCount > 5 && !isMobile && <ViewMore onClick={onViewMore} /> | ||
: null)} | ||
</Box> | ||
); | ||
}; |
19 changes: 19 additions & 0 deletions
19
src/lib/pages/account-details/components/tables/instantiated-contracts/index.tsx
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,19 @@ | ||
import { observer } from "mobx-react-lite"; | ||
|
||
import { useTierConfig } from "lib/app-provider"; | ||
|
||
import { InstantiatedContractsTableFull } from "./Full"; | ||
import { InstantiatedContractsTableLite } from "./Lite"; | ||
import type { InstantiatedContractsTableProps } from "./types"; | ||
|
||
export const InstantiatedContractsTable = observer( | ||
(props: InstantiatedContractsTableProps) => { | ||
const isFullTier = useTierConfig() === "full"; | ||
|
||
return isFullTier ? ( | ||
<InstantiatedContractsTableFull {...props} /> | ||
) : ( | ||
<InstantiatedContractsTableLite {...props} /> | ||
); | ||
} | ||
); |
9 changes: 9 additions & 0 deletions
9
src/lib/pages/account-details/components/tables/instantiated-contracts/types.ts
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,9 @@ | ||
import type { BechAddr, Option } from "lib/types"; | ||
|
||
export interface InstantiatedContractsTableProps { | ||
address: BechAddr; | ||
scrollComponentId: string; | ||
totalData: Option<number>; | ||
refetchCount: () => void; | ||
onViewMore?: () => void; | ||
} |
Oops, something went wrong.