Skip to content

Commit

Permalink
fix: use getters and fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
vacekj committed Oct 24, 2024
1 parent 86907a6 commit d2a7ed9
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 45 deletions.
3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
}
},
"linter": {
"enabled": false,
"enabled": true,
"ignore": ["theme.config.jsx"],
"rules": {
"recommended": true,
"style": {
Expand Down
3 changes: 1 addition & 2 deletions components/Balances.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import { useBalances } from '@/components/hooks';
import type { ValueView } from '@penumbra-zone/protobuf/penumbra/core/asset/v1/asset_pb';
import { ValueViewComponent } from '@penumbra-zone/ui/ValueViewComponent';
import type React from 'react';

export function Balances() {
const { data: balances } = useBalances();

return balances
return balances?.every((b) => b.balanceView !== undefined)
? balances.map(({ balanceView }) => (
<BalanceRow key={balanceView!.toJsonString()} balance={balanceView!} />
))
Expand Down
9 changes: 4 additions & 5 deletions components/Deposit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import { ValueViewComponent } from '@penumbra-zone/ui/ValueViewComponent';
import { useQuery } from '@tanstack/react-query';
import { capitalize } from 'es-toolkit';
import { ChevronRightIcon } from 'lucide-react';
import React, { useState } from 'react';
import type React from 'react';
import { useState } from 'react';
import {
useConnect,
useCurrentChainStatus,
useEphemeralAddress,
useNotes,
useSetScanSinceBlock,
useSwaps,
useWalletManifests,
} from './hooks';

Expand All @@ -37,7 +37,6 @@ const Deposit: React.FC = () => {
) ?? [];

const { scanSinceBlockHeight } = useQuestStore();
showOld;
const { data: notesWithMetadata } = useQuery({
queryKey: [
'notesWithMetadata',
Expand All @@ -49,7 +48,6 @@ const Deposit: React.FC = () => {
staleTime: 0,
initialData: [],
queryFn: async () => {
('refetch');
const deposits = await Promise.all(
depositNotes.map(async (note) => {
const metadata = await client.service(ViewService).assetMetadataById({
Expand Down Expand Up @@ -95,6 +93,7 @@ const Deposit: React.FC = () => {
wallets &&
!connected &&
Object.entries(wallets).map(([origin, manifest]) => (
// biome-ignore lint: no need for a type here
<button
key={origin}
onClick={() => onConnect(origin)}
Expand Down Expand Up @@ -193,7 +192,7 @@ const Deposit: React.FC = () => {
id="default-checkbox"
checked={showOld}
type={'checkbox'}
onChange={(e) => setShowOld((old) => !old)}
onChange={() => setShowOld((old) => !old)}
className="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600"
/>
<label
Expand Down
35 changes: 16 additions & 19 deletions components/Staking.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { bech32mIdentityKey } from '@penumbra-zone/bech32m/penumbravalid';
import {
getMetadataFromBalancesResponse,
getValueViewCaseFromBalancesResponse,
} from '@penumbra-zone/getters/balances-response';
import {
getAmount,
getExtendedMetadata,
getSymbolFromValueView,
} from '@penumbra-zone/getters/value-view';
import {
ValueView,
ValueView_KnownAssetId,
} from '@penumbra-zone/protobuf/penumbra/core/asset/v1/asset_pb';
import { ValidatorInfo } from '@penumbra-zone/protobuf/penumbra/core/component/stake/v1/stake_pb';
import { ValueViewComponent } from '@penumbra-zone/ui/ValueViewComponent';
import { ValueComponent } from '@penumbra-zone/ui/components/value/value';

import type React from 'react';
import { useBalances, useDelegations } from './hooks';
Expand All @@ -15,40 +23,29 @@ const Staking: React.FC = () => {
const validators =
delegations
?.filter(
(delegation) =>
delegation?.valueView?.valueView?.value?.amount?.toJsonString() !==
'{}',
(delegation) => getAmount(delegation.valueView).toJsonString() !== '{}',
)
.map((delegation) => {
const valueView = delegation.valueView?.valueView
?.value as ValueView_KnownAssetId;
return ValidatorInfo.fromBinary(
valueView.extendedMetadata?.value as Uint8Array,
);
const extendedMetadata = getExtendedMetadata(delegation.valueView);
return ValidatorInfo.fromBinary(extendedMetadata.value as Uint8Array);
}) ?? [];
const { data: balances } = useBalances();
const delegationTokens =
balances
?.filter(
(balance) =>
balance?.balanceView?.valueView.case === 'knownAssetId' &&
balance?.balanceView?.valueView?.value?.metadata?.base.includes(
'udelegation',
),
getValueViewCaseFromBalancesResponse(balance) === 'knownAssetId' &&
getMetadataFromBalancesResponse(balance).base.includes('udelegation'),
)
.map((balance) => {
const bal = balance;
const symbol = getSymbolFromValueView(bal.balanceView);

(bal.balanceView?.valueView?.value as ValueView_KnownAssetId)!
.metadata!.symbol = truncateMiddle(
(bal.balanceView?.valueView?.value as ValueView_KnownAssetId)!
.metadata!.symbol,
30,
);
.metadata!.symbol = truncateMiddle(symbol, 30);
return bal;
}) ?? [];

delegationTokens.length, balances?.length, balances;
return (
<div className="py-3 flex flex-col gap-8">
<div className="space-y-6">
Expand Down
2 changes: 1 addition & 1 deletion components/Swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function AssetSwapWithFeeMetadataComponent(props: {
txv: TransactionView;
action: ActionView;
}) {
/*The link that's displayed when claimTx is defined doesn't work outside minifront*/
// biome-ignore lint: The link that's displayed when claimTx is defined doesn't work outside minifront
delete (
(props.action.actionView.value as SwapView).swapView
.value as SwapView_Visible
Expand Down
1 change: 1 addition & 0 deletions components/WalletInstall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const WalletInstall: React.FC = () => {
wallets &&
!connected &&
Object.entries(wallets).map(([origin, manifest]) => (
// biome-ignore lint: we don't want or need a type here
<button
key={origin}
onClick={() => onConnect(origin)}
Expand Down
1 change: 0 additions & 1 deletion components/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ export function useSwaps(blockRange: BlockRange) {
action.action?.case === 'swapClaim',
),
);
swaps;
return swaps;
},
});
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@penumbra-labs/registry": "^11.3.1",
"@penumbra-zone/bech32m": "^8.0.0",
"@penumbra-zone/client": "^18.1.0",
"@penumbra-zone/getters": "^19.0.0",
"@penumbra-zone/protobuf": "^6.1.0",
"@penumbra-zone/transport-dom": "^7.5.0",
"@penumbra-zone/ui": "^10.0.2",
Expand Down
Loading

0 comments on commit d2a7ed9

Please sign in to comment.