-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat(extension): #252: add assets table to the main popup screen * chore: changeset * fix: #252: fix review comments * fix: possible height fix
- Loading branch information
Showing
7 changed files
with
207 additions
and
17 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,6 @@ | ||
--- | ||
'chrome-extension': minor | ||
'@repo/ui': minor | ||
--- | ||
|
||
Add AssetsTable to the home screen of the extension |
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,88 @@ | ||
import { | ||
Table, | ||
TableBody, | ||
TableCell, | ||
TableHead, | ||
TableHeader, | ||
TableRow, | ||
} from '@repo/ui/components/ui/table'; | ||
import { ValueViewComponent } from '@repo/ui/components/ui/value'; | ||
import { ValueView } from '@penumbra-zone/protobuf/penumbra/core/asset/v1/asset_pb'; | ||
import { getDisplayDenomFromView, getEquivalentValues } from '@penumbra-zone/getters/value-view'; | ||
import { getMetadataFromBalancesResponse } from '@penumbra-zone/getters/balances-response'; | ||
import { asValueView } from '@penumbra-zone/getters/equivalent-value'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { viewClient } from '../../../clients'; | ||
|
||
const EquivalentValues = ({ valueView }: { valueView?: ValueView }) => { | ||
const equivalentValuesAsValueViews = (getEquivalentValues.optional(valueView) ?? []).map( | ||
asValueView, | ||
); | ||
|
||
return ( | ||
<div className='flex flex-wrap gap-2'> | ||
{equivalentValuesAsValueViews.map(equivalentValueAsValueView => ( | ||
<ValueViewComponent | ||
key={getDisplayDenomFromView(equivalentValueAsValueView)} | ||
view={equivalentValueAsValueView} | ||
variant='equivalent' | ||
/> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export interface AssetsTableProps { | ||
account: number; | ||
} | ||
|
||
export const AssetsTable = ({ account }: AssetsTableProps) => { | ||
const { | ||
data: balances, | ||
isLoading, | ||
error, | ||
} = useQuery({ | ||
queryKey: ['balances', account], | ||
staleTime: Infinity, | ||
queryFn: async () => { | ||
try { | ||
const balances = await Array.fromAsync(viewClient.balances({ accountFilter: { account } })); | ||
balances.sort((a, b) => { | ||
const aScore = getMetadataFromBalancesResponse.optional(a)?.priorityScore ?? 0n; | ||
const bScore = getMetadataFromBalancesResponse.optional(b)?.priorityScore ?? 0n; | ||
return Number(bScore - aScore); | ||
}); | ||
return balances; | ||
} catch (_) { | ||
return []; | ||
} | ||
}, | ||
}); | ||
|
||
if (isLoading || error || !balances?.length) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Table> | ||
<TableHeader className='group'> | ||
<TableRow> | ||
<TableHead>Balance</TableHead> | ||
<TableHead>Value</TableHead> | ||
</TableRow> | ||
</TableHeader> | ||
<TableBody> | ||
{balances.map((assetBalance, index) => ( | ||
<TableRow className='group' key={index}> | ||
<TableCell> | ||
<ValueViewComponent view={assetBalance.balanceView} /> | ||
</TableCell> | ||
<TableCell> | ||
<EquivalentValues valueView={assetBalance.balanceView} /> | ||
</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</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
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,81 @@ | ||
import * as React from 'react'; | ||
import { cn } from '../../../lib/utils'; | ||
|
||
const Table = React.forwardRef<HTMLTableElement, React.HTMLAttributes<HTMLTableElement>>( | ||
({ className, ...props }, ref) => ( | ||
<table ref={ref} className={cn('w-full caption-bottom text-sm', className)} {...props} /> | ||
), | ||
); | ||
Table.displayName = 'Table'; | ||
|
||
const TableHeader = React.forwardRef< | ||
HTMLTableSectionElement, | ||
React.HTMLAttributes<HTMLTableSectionElement> | ||
>(({ className, ...props }, ref) => ( | ||
<thead ref={ref} className={cn('[&_tr]:border-b', className)} {...props} /> | ||
)); | ||
TableHeader.displayName = 'TableHeader'; | ||
|
||
const TableBody = React.forwardRef< | ||
HTMLTableSectionElement, | ||
React.HTMLAttributes<HTMLTableSectionElement> | ||
>(({ className, ...props }, ref) => ( | ||
<tbody ref={ref} className={cn('[&_tr:last-child]:border-0', className)} {...props} /> | ||
)); | ||
TableBody.displayName = 'TableBody'; | ||
|
||
const TableFooter = React.forwardRef< | ||
HTMLTableSectionElement, | ||
React.HTMLAttributes<HTMLTableSectionElement> | ||
>(({ className, ...props }, ref) => ( | ||
<tfoot | ||
ref={ref} | ||
className={cn('bg-primary font-medium text-primary-foreground', className)} | ||
{...props} | ||
/> | ||
)); | ||
TableFooter.displayName = 'TableFooter'; | ||
|
||
const TableRow = React.forwardRef<HTMLTableRowElement, React.HTMLAttributes<HTMLTableRowElement>>( | ||
({ className, ...props }, ref) => ( | ||
<tr ref={ref} className={cn('border-b border-border-secondary', className)} {...props} /> | ||
), | ||
); | ||
TableRow.displayName = 'TableRow'; | ||
|
||
const TableHead = React.forwardRef< | ||
HTMLTableCellElement, | ||
React.ThHTMLAttributes<HTMLTableCellElement> | ||
>(({ className, ...props }, ref) => ( | ||
<th | ||
ref={ref} | ||
className={cn( | ||
'py-4 text-left align-top text-lg leading-[26px] font-headline font-semibold [&:has([role=checkbox])]:pr-0', | ||
className, | ||
)} | ||
{...props} | ||
/> | ||
)); | ||
TableHead.displayName = 'TableHead'; | ||
|
||
const TableCell = React.forwardRef< | ||
HTMLTableCellElement, | ||
React.TdHTMLAttributes<HTMLTableCellElement> | ||
>(({ className, ...props }, ref) => ( | ||
<td | ||
ref={ref} | ||
className={cn('py-4 align-middle text-base [&:has([role=checkbox])]:pr-0', className)} | ||
{...props} | ||
/> | ||
)); | ||
TableCell.displayName = 'TableCell'; | ||
|
||
const TableCaption = React.forwardRef< | ||
HTMLTableCaptionElement, | ||
React.HTMLAttributes<HTMLTableCaptionElement> | ||
>(({ className, ...props }, ref) => ( | ||
<caption ref={ref} className={cn('mt-4 text-sm text-muted-foreground', className)} {...props} /> | ||
)); | ||
TableCaption.displayName = 'TableCaption'; | ||
|
||
export { Table, TableHeader, TableBody, TableFooter, TableHead, TableRow, TableCell, TableCaption }; |