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

ui: display relevant accounts #202

Merged
merged 8 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
"@grpc/proto-loader": "^0.7.13",
"@penumbra-labs/registry": "^12.0.0",
"@penumbra-zone/bech32m": "^10.0.0",
"@penumbra-zone/client": "^21.0.0",
"@penumbra-zone/client": "^21.1.0",
"@penumbra-zone/crypto-web": "^30.0.0",
"@penumbra-zone/getters": "^20.0.0",
"@penumbra-zone/perspective": "^40.0.0",
"@penumbra-zone/protobuf": "^6.3.0",
"@penumbra-zone/transport-dom": "^7.5.0",
"@penumbra-zone/types": "^26.3.0",
"@penumbra-zone/ui": "^13.4.2",
"@penumbra-zone/ui": "^13.5.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we have some density issues:

Screenshot 2024-12-11 at 2 28 57 PM

Copy link
Contributor Author

@TalDerei TalDerei Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

density updates from the UI package bump are aggregately addressed in #204 cc @VanishMax

"@penumbra-zone/wasm": "^34.0.0",
"@radix-ui/react-icons": "^1.3.2",
"@rehooks/component-size": "^1.0.3",
Expand Down
40 changes: 20 additions & 20 deletions pnpm-lock.yaml

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

30 changes: 25 additions & 5 deletions src/widgets/header/api/subaccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,29 @@ import {
import { useQuery } from '@tanstack/react-query';
import { ViewService } from '@penumbra-zone/protobuf';
import { penumbra } from '@/shared/const/penumbra';
import { useBalances } from '@/shared/api/balances';
import { BalancesResponse } from '@penumbra-zone/protobuf/penumbra/view/v1/view_pb';

const ACCOUNT_INDEXES = [0, 1, 2, 3, 4, 5];

const fetchQuery = async (): Promise<AddressView[]> => {
const fetchQuery = async (balances: BalancesResponse[]): Promise<AddressView[]> => {
const service = penumbra.service(ViewService);

// Include main account for fresh wallets to display address view
let accountIndexes: number[] = [0];

for (const balance of balances) {
if (
balance.accountAddress?.addressView.case === 'decoded' &&
balance.accountAddress.addressView.value.index?.account !== undefined
) {
accountIndexes.push(balance.accountAddress.addressView.value.index.account);
}
}

// Filter by unique account indices
accountIndexes = accountIndexes.filter((value, index, self) => self.indexOf(value) === index);

return Promise.all(
ACCOUNT_INDEXES.map(async index => {
accountIndexes.map(async index => {
const response = await service.addressByIndex({ addressIndex: { account: index } });

return new AddressView({
Expand All @@ -30,8 +45,13 @@ const fetchQuery = async (): Promise<AddressView[]> => {
};

export const useSubaccounts = () => {
// Query account balances from view service
const { data: balances } = useBalances();

return useQuery({
queryKey: ['view-service-accounts'],
queryFn: fetchQuery,
queryFn: () => {
return fetchQuery(balances!);
TalDerei marked this conversation as resolved.
Show resolved Hide resolved
},
});
};
Loading