Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentine1898 committed Jun 26, 2024
1 parent 7810d94 commit 8a3ede4
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 20 deletions.
9 changes: 9 additions & 0 deletions apps/extension/src/routes/popup/settings/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { passwordSelector } from '../../../state/password';
import { usePopupNav } from '../../../utils/navigate';
import { PopupPath } from '../paths';
import { SettingsScreen } from './settings-screen';
import { useChainIdQuery } from '../../../hooks/chain-id';
import { getNumeraireFromRegistry } from '../../../utils/get-numeraires-from-registry';

const links = [
{
Expand All @@ -39,6 +41,7 @@ const links = [
title: 'Price denomination',
icon: <BarChartIcon className='size-5 text-muted-foreground' />,
href: PopupPath.SETTINGS_NUMERAIRES,
disabled: false,
},
{
title: 'Advanced',
Expand All @@ -51,6 +54,11 @@ export const Settings = () => {
const navigate = usePopupNav();
const { clearSessionPassword } = useStore(passwordSelector);

const { chainId } = useChainIdQuery();
const numeraires = getNumeraireFromRegistry(chainId);

console.log(chainId, numeraires);

return (
<SettingsScreen title='Settings'>
<div className='flex grow flex-col justify-between'>
Expand All @@ -61,6 +69,7 @@ export const Settings = () => {
title={i.title}
icon={i.icon}
onClick={() => navigate(i.href)}
disabled={i.href === PopupPath.SETTINGS_NUMERAIRES && numeraires.length === 0}
/>
))}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ interface DisplayedFrontend {
}

const getFrontendsFromRegistry = (selectedRpc?: string): DisplayedFrontend[] => {
const registryClient = new ChainRegistryClient();
const { frontends } = registryClient.globals();

const registeredFrontends = frontends.map(frontend => ({
title: extractDomain(frontend),
url: frontend,
}));
let registeredFrontends: DisplayedFrontend[] = [];
try {
const registryClient = new ChainRegistryClient();
const { frontends } = registryClient.globals();
registeredFrontends = frontends.map(frontend => ({
title: extractDomain(frontend),
url: frontend,
}));
} catch (e) {
console.error('Registry globals is not available', e);
}

if (selectedRpc) {
registeredFrontends.push({ title: 'Embedded RPC frontend', url: `${selectedRpc}/app/` });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ const useSaveGrpcEndpointSelector = (state: AllSlices) => ({
});

const getRpcsFromRegistry = () => {
const registryClient = new ChainRegistryClient();
const { rpcs } = registryClient.globals();
return rpcs.toSorted(randomSort);
try {
const registryClient = new ChainRegistryClient();
const { rpcs } = registryClient.globals();
return rpcs.toSorted(randomSort);
} catch (e) {
console.error('Registry globals is not available', e);
return [];
}
};

export const useGrpcEndpointForm = () => {
Expand Down
4 changes: 3 additions & 1 deletion apps/extension/src/shared/components/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ interface LinkProps {
icon: ReactElement;
title: string;
onClick: () => void;
disabled?: boolean;
}

export const CustomLink = ({ icon, title, onClick }: LinkProps) => {
export const CustomLink = ({ icon, title, onClick, disabled }: LinkProps) => {
return (
<Button
variant='ghost'
disabled={disabled}
className='flex w-full items-center justify-start gap-2 p-[10px] text-left hover:bg-transparent hover:opacity-50'
onClick={onClick}
>
Expand Down
15 changes: 6 additions & 9 deletions apps/extension/src/shared/components/numeraires-form.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ChainRegistryClient } from '@penumbra-labs/registry';
import { AllSlices, useStore } from '../../state';
import { useChainIdQuery } from '../../hooks/chain-id';
import { useMemo, useState } from 'react';
Expand All @@ -7,14 +6,7 @@ import { SelectList } from '@repo/ui/components/ui/select';
import { bech32mAssetId } from '@penumbra-zone/bech32m/passet';
import { getAssetId } from '@penumbra-zone/getters/metadata';
import { Button } from '@repo/ui/components/ui/button';
import { Metadata } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb';

const getNumeraireFromRegistry = (chainId?: string): Metadata[] => {
if (!chainId) return [];
const registryClient = new ChainRegistryClient();
const registry = registryClient.get(chainId);
return registry.numeraires.map(n => registry.getMetadata(n));
};
import { getNumeraireFromRegistry } from '../../utils/get-numeraires-from-registry';

const useNumerairesSelector = (state: AllSlices) => {
return {
Expand All @@ -40,6 +32,11 @@ export const NumeraireForm = ({
// this forces you to use two sources to guarantee 'chainId' for both settings and onboarding
const numeraires = useMemo(() => getNumeraireFromRegistry(chainId ?? networkChainId), [chainId]);

if (numeraires.length === 0) {
void (async function () {
await onSuccess();
})();
}
const [loading, setLoading] = useState(false);

const handleSubmit = () => {
Expand Down
14 changes: 14 additions & 0 deletions apps/extension/src/utils/get-numeraires-from-registry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Metadata } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb';
import { ChainRegistryClient } from '@penumbra-labs/registry';

export const getNumeraireFromRegistry = (chainId?: string): Metadata[] => {
if (!chainId) return [];
try {
const registryClient = new ChainRegistryClient();
const registry = registryClient.get(chainId);
return registry.numeraires.map(n => registry.getMetadata(n));
} catch (error) {
console.error('Registry numeraires is not available', error);
return [];
}
};

0 comments on commit 8a3ede4

Please sign in to comment.