Skip to content

Commit

Permalink
Split getters package (#674)
Browse files Browse the repository at this point in the history
  • Loading branch information
turbocrime authored Mar 5, 2024
1 parent 0ce36ea commit 820037c
Show file tree
Hide file tree
Showing 67 changed files with 106 additions and 68 deletions.
1 change: 1 addition & 0 deletions apps/webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@penumbra-zone/client": "workspace:*",
"@penumbra-zone/constants": "workspace:*",
"@penumbra-zone/crypto-web": "workspace:*",
"@penumbra-zone/getters": "workspace:*",
"@penumbra-zone/transport-dom": "workspace:*",
"@penumbra-zone/ui": "workspace:*",
"@radix-ui/react-icons": "^1.3.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/components/shared/select-token-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { cn } from '@penumbra-zone/ui/lib/utils';
import { AssetIcon } from '@penumbra-zone/ui/components/ui/tx/view/asset-icon';
import { ValueViewComponent } from '@penumbra-zone/ui/components/ui/tx/view/value';
import { getAddressIndex, getDisplayDenomFromView, getMetadata } from '@penumbra-zone/types';
import { getAddressIndex, getDisplayDenomFromView, getMetadata } from '@penumbra-zone/getters';
import { BalancesResponse } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/view/v1/view_pb';

interface SelectTokenModalProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ValueView } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core
import { ValidatorInfoComponent } from './validator-info-component';
import { ValueViewComponent } from '@penumbra-zone/ui/components/ui/tx/view/value';
import { StakingActions } from './staking-actions';
import { getValidatorInfoFromValueView } from '@penumbra-zone/types';
import { getValidatorInfoFromValueView } from '@penumbra-zone/getters';

/**
* Renders a `ValueView` that contains a delegation token, along with the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getIdentityKey } from '@penumbra-zone/types';
import { getIdentityKey } from '@penumbra-zone/getters';
import {
Dialog,
DialogContent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Button } from '@penumbra-zone/ui';
import { useStore } from '../../../../../state';
import { stakingSelector } from '../../../../../state/staking';
import { ValidatorInfo } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/stake/v1/stake_pb';
import { getAmount, getValidator, joinLoHiAmount } from '@penumbra-zone/types';
import { getAmount, getValidator } from '@penumbra-zone/getters';
import { joinLoHiAmount } from '@penumbra-zone/types';
import { ValueView } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb';
import { FormDialog } from './form-dialog';
import { useMemo } from 'react';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { ValidatorInfo } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/stake/v1/stake_pb';
import {
bech32IdentityKey,
calculateCommissionAsPercentage,
getIdentityKeyFromValidatorInfo,
getValidator,
} from '@penumbra-zone/types';
import { bech32IdentityKey, calculateCommissionAsPercentage } from '@penumbra-zone/types';
import { getIdentityKeyFromValidatorInfo, getValidator } from '@penumbra-zone/getters';
import {
Identicon,
IdentityKeyComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getDisplayDenomFromView } from '@penumbra-zone/types';
import { getDisplayDenomFromView } from '@penumbra-zone/getters';
import {
Card,
CardContent,
Expand Down
7 changes: 2 additions & 5 deletions apps/webapp/src/components/staking/account/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import {
VotingPowerAsIntegerPercentage,
bech32IdentityKey,
getIdentityKeyFromValueView,
} from '@penumbra-zone/types';
import { VotingPowerAsIntegerPercentage, bech32IdentityKey } from '@penumbra-zone/types';
import { getIdentityKeyFromValueView } from '@penumbra-zone/getters';
import { useStore } from '../../../state';
import { stakingSelector } from '../../../state/staking';
import { DelegationValueView } from './delegation-value-view';
Expand Down
3 changes: 2 additions & 1 deletion apps/webapp/src/components/staking/validator-info-row.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ValidatorInfo } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/stake/v1/stake_pb';
import { calculateCommissionAsPercentage, getValidator } from '@penumbra-zone/types';
import { getValidator } from '@penumbra-zone/getters';
import { calculateCommissionAsPercentage } from '@penumbra-zone/types';
import { TableRow, TableCell } from '@penumbra-zone/ui';
import { ReactNode } from 'react';
import { Oval } from 'react-loader-spinner';
Expand Down
3 changes: 2 additions & 1 deletion apps/webapp/src/components/staking/validators-table.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@penumbra-zone/ui';
import { VotingPowerAsIntegerPercentage, getValidator } from '@penumbra-zone/types';
import { getValidator } from '@penumbra-zone/getters';
import { VotingPowerAsIntegerPercentage } from '@penumbra-zone/types';
import { Oval } from 'react-loader-spinner';
import { ValidatorInfoRow } from './validator-info-row';
import { ValidatorInfo } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/stake/v1/stake_pb';
Expand Down
8 changes: 2 additions & 6 deletions apps/webapp/src/components/swap/swap-loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ import {
import { Metadata } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb';
import { fetchUnclaimedSwaps } from '../../fetchers/unclaimed-swaps';
import { viewClient } from '../../clients';
import {
getDisplayDenomFromView,
getSwapAsset1,
getSwapAsset2,
uint8ArrayToBase64,
} from '@penumbra-zone/types';
import { getDisplayDenomFromView, getSwapAsset1, getSwapAsset2 } from '@penumbra-zone/getters';
import { uint8ArrayToBase64 } from '@penumbra-zone/types';
import { assetPatterns, localAssets } from '@penumbra-zone/constants';

export interface UnclaimedSwapsWithMetadata {
Expand Down
3 changes: 2 additions & 1 deletion apps/webapp/src/components/swap/unclaimed-swaps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Button, Card } from '@penumbra-zone/ui';
import { useLoaderData, useRevalidator } from 'react-router-dom';
import { SwapLoaderResponse, UnclaimedSwapsWithMetadata } from './swap-loader';
import { AssetIcon } from '@penumbra-zone/ui/components/ui/tx/view/asset-icon';
import { getSwapRecordCommitment, uint8ArrayToBase64 } from '@penumbra-zone/types';
import { getSwapRecordCommitment } from '@penumbra-zone/getters';
import { uint8ArrayToBase64 } from '@penumbra-zone/types';
import { useStore } from '../../state';
import { unclaimedSwapsSelector } from '../../state/unclaimed-swaps';

Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/fetchers/balances/by-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
} from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/keys/v1/keys_pb';
import { getBalances } from '.';
import { BalancesResponse } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/view/v1/view_pb';
import { getAddress, getAddressIndex } from '@penumbra-zone/types';
import { getAddress, getAddressIndex } from '@penumbra-zone/getters';

export interface BalancesByAccount {
index: AddressIndex;
Expand Down
3 changes: 2 additions & 1 deletion apps/webapp/src/fetchers/balances/by-asset.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ValueView } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb';
import { addAmounts, getAssetIdFromValueView } from '@penumbra-zone/types';
import { addAmounts } from '@penumbra-zone/types';
import { getAssetIdFromValueView } from '@penumbra-zone/getters';
import { BalancesResponse } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/view/v1/view_pb';

const hasMatchingAssetId = (vA: ValueView, vB: ValueView) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/fetchers/simulate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { simulateClient } from '../clients';
import { SimulateTradeRequest } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/dex/v1/dex_pb';
import { getAssetId } from '@penumbra-zone/types';
import { getAssetId } from '@penumbra-zone/getters';
import {
Metadata,
Value,
Expand Down
6 changes: 3 additions & 3 deletions apps/webapp/src/fetchers/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import {
} from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/keys/v1/keys_pb';
import { stakeClient, viewClient } from '../clients';
import { ValueView } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb';
import { bech32IdentityKey, customizeSymbol } from '@penumbra-zone/types';

import {
bech32IdentityKey,
customizeSymbol,
getDisplayDenomFromView,
getIdentityKeyFromValidatorInfo,
getValidatorInfo,
} from '@penumbra-zone/types';
} from '@penumbra-zone/getters';
import { DelegationCaptureGroups, assetPatterns } from '@penumbra-zone/constants';
import { Any } from '@bufbuild/protobuf';
import { ValidatorInfo } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/stake/v1/stake_pb';
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/fetchers/unclaimed-swaps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { viewClient } from '../clients';
import { streamToPromise } from './stream';
import { getUnclaimedSwaps } from '@penumbra-zone/types';
import { getUnclaimedSwaps } from '@penumbra-zone/getters';
import { SwapRecord } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/view/v1/view_pb';

export const fetchUnclaimedSwaps = async (): Promise<SwapRecord[]> => {
Expand Down
5 changes: 2 additions & 3 deletions apps/webapp/src/state/ibc.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Chain, toBaseUnit } from '@penumbra-zone/types';
import {
Chain,
getAddressIndex,
getDisplayDenomExponentFromValueView,
getMetadata,
toBaseUnit,
} from '@penumbra-zone/types';
} from '@penumbra-zone/getters';
import { AllSlices, SliceCreator } from '.';
import {
BalancesResponse,
Expand Down
6 changes: 2 additions & 4 deletions apps/webapp/src/state/send.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { AllSlices, SliceCreator } from '.';
import {
fromValueView,
getAddress,
getAddressIndex,
getAssetIdFromValueView,
getDisplayDenomExponentFromValueView,
isPenumbraAddr,
toBaseUnit,
} from '@penumbra-zone/types';
} from '@penumbra-zone/getters';
import { fromValueView, isPenumbraAddr, toBaseUnit } from '@penumbra-zone/types';
import {
BalancesResponse,
TransactionPlannerRequest,
Expand Down
3 changes: 2 additions & 1 deletion apps/webapp/src/state/staking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
Metadata,
ValueView,
} from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb';
import { bech32IdentityKey, getValidatorInfoFromValueView } from '@penumbra-zone/types';
import { bech32IdentityKey } from '@penumbra-zone/types';
import { getValidatorInfoFromValueView } from '@penumbra-zone/getters';
import {
AddressView,
IdentityKey,
Expand Down
6 changes: 4 additions & 2 deletions apps/webapp/src/state/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ import { ValidatorInfo } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/
import { AllSlices, SliceCreator } from '.';
import { getDelegationsForAccount } from '../fetchers/staking';
import {
VotingPowerAsIntegerPercentage,
getAmount,
getAssetIdFromValueView,
getDisplayDenomExponent,
getDisplayDenomExponentFromValueView,
getDisplayDenomFromView,
getRateData,
getValidatorInfoFromValueView,
getVotingPowerByValidatorInfo,
getVotingPowerFromValidatorInfo,
} from '@penumbra-zone/getters';
import {
VotingPowerAsIntegerPercentage,
getVotingPowerByValidatorInfo,
isDelegationTokenForValidator,
joinLoHiAmount,
toBaseUnit,
Expand Down
4 changes: 2 additions & 2 deletions apps/webapp/src/state/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import {
getAssetIdFromValueView,
getDisplayDenomExponentFromValueView,
getSwapCommitmentFromTx,
toBaseUnit,
} from '@penumbra-zone/types';
} from '@penumbra-zone/getters';
import { toBaseUnit } from '@penumbra-zone/types';
import { BigNumber } from 'bignumber.js';
import { getAddressByIndex } from '../fetchers/address';
import { StateCommitment } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/crypto/tct/v1/tct_pb';
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/state/unclaimed-swaps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AllSlices, SliceCreator } from '.';
import { SwapRecord } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/view/v1/view_pb';
import { getSwapRecordCommitment } from '@penumbra-zone/types';
import { getSwapRecordCommitment } from '@penumbra-zone/getters';
import { issueSwapClaim } from './swap';

type SwapCommitmentId = string;
Expand Down
8 changes: 8 additions & 0 deletions packages/getters/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
root: true,
extends: ['custom'],
parserOptions: {
project: true,
tsconfigRootDir: __dirname,
},
};
File renamed without changes.
1 change: 1 addition & 0 deletions packages/getters/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './src';
13 changes: 13 additions & 0 deletions packages/getters/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "@penumbra-zone/getters",
"version": "1.0.0",
"description": "Convenience getters for the deeply nested optionals of Penumbra's protobuf types",
"type": "module",
"scripts": {
"lint": "eslint \"**/*.ts*\"",
"test": "vitest run"
},
"dependencies": {
"bech32": "^2.0.0"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
export * from './asset';
export * from './address-view';
export * from './funding-stream';
export * from './metadata';
export * from './rate-data';
export * from './swap';
export * from './swap-record';
export * from './spendable-note-record';
export * from './trading-pair';
export * from './transaction';
export * from './unclaimed-swaps-response';
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ValueView } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb';
import { createGetter } from './utils/create-getter';
import { getDisplayDenomExponent } from './metadata';
import { bech32AssetId } from '../asset';
import { bech32AssetId } from './asset';
import { Any } from '@bufbuild/protobuf';
import { ValidatorInfo } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/stake/v1/stake_pb';
import { getIdentityKeyFromValidatorInfo } from './validator-info';
Expand Down
5 changes: 5 additions & 0 deletions packages/getters/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "tsconfig/base.json",
"include": ["."],
"exclude": ["node_modules"]
}
1 change: 1 addition & 0 deletions packages/router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"dependencies": {
"@penumbra-zone/constants": "workspace:*",
"@penumbra-zone/crypto-web": "workspace:*",
"@penumbra-zone/getters": "workspace:*",
"@penumbra-zone/polyfills": "workspace:*",
"@penumbra-zone/query": "workspace:*",
"@penumbra-zone/services": "workspace:*",
Expand Down
3 changes: 2 additions & 1 deletion packages/router/src/grpc/custody/authorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import type { Impl } from '.';
import { approverCtx, extLocalCtx, extSessionCtx, servicesCtx } from '../../ctx';
import { authorizePlan, generateSpendKey } from '@penumbra-zone/wasm';
import { Key } from '@penumbra-zone/crypto-web';
import { bech32AssetId, Box, Jsonified } from '@penumbra-zone/types';
import { bech32AssetId } from '@penumbra-zone/getters';
import { Box, Jsonified } from '@penumbra-zone/types';
import { Code, ConnectError, HandlerContext } from '@connectrpc/connect';
import { Metadata } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb';
import { viewTransactionPlan } from './view-transaction-plan';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb';
import { Address } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/keys/v1/keys_pb';
import { Jsonified } from '@penumbra-zone/types';
import { bech32AssetId } from '@penumbra-zone/types/src/asset';
import { bech32AssetId } from '@penumbra-zone/getters/src/asset';
import { bech32ToUint8Array } from '@penumbra-zone/types/src/address';
import {
BatchSwapOutputData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
ActionPlan,
ActionView,
} from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/transaction/v1/transaction_pb';
import { bech32AssetId } from '@penumbra-zone/types/src/asset';
import { bech32AssetId } from '@penumbra-zone/getters';
import {
Metadata,
Value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ import {
} from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/view/v1/view_pb';

import { createContextValues, createHandlerContext, HandlerContext } from '@connectrpc/connect';
import {
base64ToUint8Array,
getAddressIndex,
getAssetIdFromValueView,
getMetadata,
} from '@penumbra-zone/types';
import { base64ToUint8Array } from '@penumbra-zone/types';
import { getAddressIndex, getAssetIdFromValueView, getMetadata } from '@penumbra-zone/getters';

import { beforeEach, describe, expect, test, vi } from 'vitest';
import { Services } from '@penumbra-zone/services';
Expand Down
4 changes: 2 additions & 2 deletions packages/router/src/grpc/view-protocol-server/balances.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { Impl } from '.';
import { servicesCtx } from '../../ctx';

import { addLoHi, Base64Str, getAmount, uint8ArrayToBase64 } from '@penumbra-zone/types';
import { addLoHi, Base64Str, uint8ArrayToBase64 } from '@penumbra-zone/types';
import { getAmount, getAssetIdFromRecord } from '@penumbra-zone/getters';

import {
AssetId,
Expand All @@ -18,7 +19,6 @@ import {
BalancesResponse,
SpendableNoteRecord,
} from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/view/v1/view_pb';
import { getAssetIdFromRecord } from '@penumbra-zone/types/src/getters/spendable-note-record';
import { HandlerContext } from '@connectrpc/connect';
import { assetMetadataById } from './asset-metadata-by-id';
import { addressByIndex } from './address-by-index';
Expand Down
1 change: 1 addition & 0 deletions packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"dependencies": {
"@penumbra-zone/constants": "workspace:*",
"@penumbra-zone/getters": "workspace:*",
"@types/chrome": "0.0.260",
"bech32": "^2.0.0",
"bignumber.js": "^9.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/amount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Amount } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/nu
import { fromBaseUnit, joinLoHi, splitLoHi } from './lo-hi';
import { BigNumber } from 'bignumber.js';
import { ValueView_KnownAssetId } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb';
import { getDisplayDenomExponent } from './getters';
import { getDisplayDenomExponent } from '@penumbra-zone/getters';

export const joinLoHiAmount = (amount: Amount): bigint => {
return joinLoHi(amount.lo, amount.hi);
Expand Down
2 changes: 0 additions & 2 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export * from './environment';
export * from './box';
export * from './wallet';
export * from './utility';
export * from './asset';
export * from './transaction';
export * from './translators';
export * from './hex';
Expand All @@ -22,7 +21,6 @@ export * from './chain';
export * from './jsonified';
export * from './schemas';
export * from './type-predicates';
export * from './getters';
export * from './staking';
export * from './identity-key';
export * from './customize-symbol';
Loading

0 comments on commit 820037c

Please sign in to comment.