From bc5bfb241a2a91e1f56f0cdf7f73d36f3802f8f9 Mon Sep 17 00:00:00 2001 From: turbocrime Date: Tue, 20 Aug 2024 17:02:21 -0700 Subject: [PATCH] use optional access instead of call --- .../dashboard/assets-table/equivalent-values.tsx | 2 +- .../src/components/dashboard/assets-table/index.tsx | 2 +- apps/minifront/src/components/shared/input-token.tsx | 4 +--- .../src/components/shared/non-native-fee-warning.tsx | 12 ++++++------ .../src/components/shared/selectors/balance-item.tsx | 4 ++-- .../src/components/shared/selectors/helpers.ts | 8 ++++---- .../components/shared/selectors/search-filters.ts | 2 +- .../validator-info-component.tsx | 2 +- .../output/estimated-output-explanation.tsx | 4 ++-- .../src/components/swap/swap-form/price-history.tsx | 2 +- .../swap/swap-form/simulate-swap-result/index.tsx | 4 ++-- .../simulate-swap-result/traces/trace/price.tsx | 4 ++-- .../components/swap/swap-form/token-swap-input.tsx | 6 +++--- .../assets-page/equivalent-values.tsx | 2 +- apps/minifront/src/fetchers/auction-infos.ts | 4 ++-- .../src/fetchers/balances/by-priority-score.ts | 8 ++++---- apps/minifront/src/state/helpers.ts | 6 +++--- apps/minifront/src/state/ibc-out.ts | 2 +- apps/minifront/src/state/send/index.ts | 2 +- .../swap/dutch-auction/assemble-schedule-request.ts | 2 +- apps/minifront/src/state/swap/dutch-auction/index.ts | 4 ++-- apps/minifront/src/state/swap/getters.ts | 4 ++-- apps/minifront/src/state/swap/query-params.ts | 4 ++-- .../src/state/swap/swap-balances-middleware.ts | 4 ++-- docs/adrs/001-getters.md | 2 +- packages/getters/README.md | 2 +- packages/perspective/src/plan/view-action-plan.ts | 4 ++-- packages/services/src/view-service/balances.ts | 2 +- .../unbonding-tokens-by-address-index/helpers.ts | 4 ++-- .../unbonding-tokens-by-address-index/index.ts | 2 +- packages/types/src/swap.ts | 8 ++++---- packages/types/src/value-view.ts | 2 +- packages/ui/components/ui/asset-icon/index.tsx | 2 +- .../ui/components/ui/balance-value-view/index.tsx | 4 ++-- .../expanded-details/get-price.ts | 2 +- .../expanded-details/index.tsx | 4 ++-- .../ui/tx/actions-views/delegator-vote.tsx | 4 ++-- .../ui/components/ui/tx/actions-views/swap/index.tsx | 4 ++-- .../ui/tx/actions-views/swap/one-way-swap.tsx | 2 +- .../ui/tx/actions-views/swap/swap-claim.tsx | 8 ++++---- packages/ui/src/AssetIcon/index.tsx | 2 +- .../MetadataOrBalancesResponse/Balance.tsx | 4 ++-- .../MetadataOrBalancesResponse/index.tsx | 2 +- packages/ui/src/AssetSelector/index.tsx | 2 +- packages/ui/src/ValueViewComponent/index.tsx | 2 +- 45 files changed, 82 insertions(+), 84 deletions(-) diff --git a/apps/minifront/src/components/dashboard/assets-table/equivalent-values.tsx b/apps/minifront/src/components/dashboard/assets-table/equivalent-values.tsx index 0770ded5c..22dd16aa3 100644 --- a/apps/minifront/src/components/dashboard/assets-table/equivalent-values.tsx +++ b/apps/minifront/src/components/dashboard/assets-table/equivalent-values.tsx @@ -4,7 +4,7 @@ import { getDisplayDenomFromView, getEquivalentValues } from '@penumbra-zone/get import { ValueViewComponent } from '@repo/ui/components/ui/value'; export const EquivalentValues = ({ valueView }: { valueView?: ValueView }) => { - const equivalentValuesAsValueViews = (getEquivalentValues.optional()(valueView) ?? []).map( + const equivalentValuesAsValueViews = (getEquivalentValues.optional(valueView) ?? []).map( asValueView, ); diff --git a/apps/minifront/src/components/dashboard/assets-table/index.tsx b/apps/minifront/src/components/dashboard/assets-table/index.tsx index d5ab4ec7d..204830d04 100644 --- a/apps/minifront/src/components/dashboard/assets-table/index.tsx +++ b/apps/minifront/src/components/dashboard/assets-table/index.tsx @@ -22,7 +22,7 @@ import { shouldDisplay } from '../../../fetchers/balances/should-display'; import { sortByPriorityScore } from '../../../fetchers/balances/by-priority-score'; const getTradeLink = (balance: BalancesResponse): string => { - const metadata = getMetadataFromBalancesResponse.optional()(balance); + const metadata = getMetadataFromBalancesResponse.optional(balance); const accountIndex = getAddressIndex(balance.accountAddress).account; const accountQuery = accountIndex ? `&account=${accountIndex}` : ''; return metadata ? `${PagePath.SWAP}?from=${metadata.symbol}${accountQuery}` : PagePath.SWAP; diff --git a/apps/minifront/src/components/shared/input-token.tsx b/apps/minifront/src/components/shared/input-token.tsx index d185685bd..a00450cd1 100644 --- a/apps/minifront/src/components/shared/input-token.tsx +++ b/apps/minifront/src/components/shared/input-token.tsx @@ -38,9 +38,7 @@ export default function InputToken({ loading, }: InputTokenProps) { const tokenExponent = useMemo(() => { - return getDisplayDenomExponent.optional()( - getMetadataFromBalancesResponse.optional()(selection), - ); + return getDisplayDenomExponent.optional(getMetadataFromBalancesResponse.optional(selection)); }, [selection]); const setInputToBalanceMax = () => { diff --git a/apps/minifront/src/components/shared/non-native-fee-warning.tsx b/apps/minifront/src/components/shared/non-native-fee-warning.tsx index 4c150c749..afc9dc69b 100644 --- a/apps/minifront/src/components/shared/non-native-fee-warning.tsx +++ b/apps/minifront/src/components/shared/non-native-fee-warning.tsx @@ -24,7 +24,7 @@ const hasTokenBalance = ({ gasPrices: GasPrices[]; stakingAssetMetadata?: Metadata; }): boolean => { - const account = getAddressIndex.optional()(source)?.account; + const account = getAddressIndex.optional(source).account; if (typeof account === 'undefined') { return false; } @@ -33,9 +33,9 @@ const hasTokenBalance = ({ const hasStakingToken = balancesResponses.some( asset => getAssetIdFromValueView - .optional()(asset.balanceView) - ?.equals(getAssetId.optional()(stakingAssetMetadata)) && - getAddressIndex.optional()(asset)?.account === account, + .optional(asset.balanceView) + .equals(getAssetId.optional(stakingAssetMetadata)) && + getAddressIndex.optional(asset).account === account, ); if (hasStakingToken) { @@ -43,7 +43,7 @@ const hasTokenBalance = ({ } const accountAssets = balancesResponses.filter( - balance => getAddressIndex.optional()(balance)?.account === account, + balance => getAddressIndex.optional(balance).account === account, ); // Finds the alt tokens in the user's account balances that can be used for fees const hasAltTokens = accountAssets.some(balance => { @@ -54,7 +54,7 @@ const hasTokenBalance = ({ } return gasPrices.some(price => - price.assetId?.equals(getAssetIdFromBalancesResponse.optional()(balance)), + price.assetId?.equals(getAssetIdFromBalancesResponse.optional(balance)), ); }); diff --git a/apps/minifront/src/components/shared/selectors/balance-item.tsx b/apps/minifront/src/components/shared/selectors/balance-item.tsx index dc088cbe0..e5d43791d 100644 --- a/apps/minifront/src/components/shared/selectors/balance-item.tsx +++ b/apps/minifront/src/components/shared/selectors/balance-item.tsx @@ -19,8 +19,8 @@ export const BalanceItem = ({ asset, value, onSelect }: BalanceItemProps) => { const account = isBalance(asset) ? getAddressIndex(asset.accountAddress).account : undefined; const metadataFromAsset = isMetadata(asset) ? asset - : getMetadataFromBalancesResponse.optional()(asset); - const metadataFromValue = getMetadataFromBalancesResponse.optional()(value); + : getMetadataFromBalancesResponse.optional(asset); + const metadataFromValue = getMetadataFromBalancesResponse.optional(value); const isSelected = useMemo(() => { if (!value) { diff --git a/apps/minifront/src/components/shared/selectors/helpers.ts b/apps/minifront/src/components/shared/selectors/helpers.ts index c3c76ca88..e6f588c0b 100644 --- a/apps/minifront/src/components/shared/selectors/helpers.ts +++ b/apps/minifront/src/components/shared/selectors/helpers.ts @@ -22,7 +22,7 @@ export const mergeBalancesAndAssets = ( ): BalanceOrMetadata[] => { const filteredAssets = assets.filter(asset => { return !balances.some(balance => { - const balanceMetadata = getMetadataFromBalancesResponse.optional()(balance); + const balanceMetadata = getMetadataFromBalancesResponse.optional(balance); return balanceMetadata?.equals(asset); }); }); @@ -43,10 +43,10 @@ export const useSyncSelectedBalance = ({ if (value) { const matchedValue = balances?.find(balance => { return ( - getAddressIndex.optional()(balance)?.equals(getAddressIndex.optional()(value)) && + getAddressIndex.optional(balance)?.equals(getAddressIndex.optional(value)) && getMetadataFromBalancesResponse - .optional()(balance) - ?.equals(getMetadataFromBalancesResponse.optional()(value)) + .optional(balance) + ?.equals(getMetadataFromBalancesResponse.optional(value)) ); }); if (matchedValue && !matchedValue.equals(value)) { diff --git a/apps/minifront/src/components/shared/selectors/search-filters.ts b/apps/minifront/src/components/shared/selectors/search-filters.ts index cb9a879e8..91f3f4ae9 100644 --- a/apps/minifront/src/components/shared/selectors/search-filters.ts +++ b/apps/minifront/src/components/shared/selectors/search-filters.ts @@ -7,7 +7,7 @@ import { getValueViewCaseFromBalancesResponse } from '@penumbra-zone/getters/bal export const balanceBySearch = (search: string) => (balancesResponse: BalancesResponse): boolean => - getValueViewCaseFromBalancesResponse.optional()(balancesResponse) === 'knownAssetId' && + getValueViewCaseFromBalancesResponse.optional(balancesResponse) === 'knownAssetId' && (getDisplayDenomFromView(balancesResponse.balanceView) .toLocaleLowerCase() .includes(search.toLocaleLowerCase()) || diff --git a/apps/minifront/src/components/staking/account/delegation-value-view/validator-info-component.tsx b/apps/minifront/src/components/staking/account/delegation-value-view/validator-info-component.tsx index 83a141152..ca545323f 100644 --- a/apps/minifront/src/components/staking/account/delegation-value-view/validator-info-component.tsx +++ b/apps/minifront/src/components/staking/account/delegation-value-view/validator-info-component.tsx @@ -35,7 +35,7 @@ export const ValidatorInfoComponent = ({ const showTooltips = useStore(state => !state.staking.loading); const validator = getValidator(validatorInfo); const identityKey = getIdentityKeyFromValidatorInfo(validatorInfo); - const state = getValidatorState.optional()(validatorInfo); + const state = getValidatorState.optional(validatorInfo); return ( diff --git a/apps/minifront/src/components/swap/swap-form/output/estimated-output-explanation.tsx b/apps/minifront/src/components/swap/swap-form/output/estimated-output-explanation.tsx index 54ad934a5..cd7399e5f 100644 --- a/apps/minifront/src/components/swap/swap-form/output/estimated-output-explanation.tsx +++ b/apps/minifront/src/components/swap/swap-form/output/estimated-output-explanation.tsx @@ -24,9 +24,9 @@ export const EstimatedOutputExplanation = () => { const formattedAmount = formatAmount({ amount: estimatedOutput, - exponent: getDisplayDenomExponent.optional()(assetOut), + exponent: getDisplayDenomExponent.optional(assetOut), }); - const assetInSymbol = getSymbolFromValueView.optional()(assetIn?.balanceView); + const assetInSymbol = getSymbolFromValueView.optional(assetIn?.balanceView); return (
diff --git a/apps/minifront/src/components/swap/swap-form/price-history.tsx b/apps/minifront/src/components/swap/swap-form/price-history.tsx index 3591ba311..a7c1c52b5 100644 --- a/apps/minifront/src/components/swap/swap-form/price-history.tsx +++ b/apps/minifront/src/components/swap/swap-form/price-history.tsx @@ -12,7 +12,7 @@ import { useStoreShallow } from '../../../utils/use-store-shallow'; import { Button } from '@repo/ui/components/ui/button'; const priceHistorySelector = (state: AllSlices) => ({ - startMetadata: getMetadataFromBalancesResponse.optional()(state.swap.assetIn), + startMetadata: getMetadataFromBalancesResponse.optional(state.swap.assetIn), endMetadata: state.swap.assetOut, historyLimit: state.swap.priceHistory.historyLimit, historyStart: state.swap.priceHistory.historyStart, diff --git a/apps/minifront/src/components/swap/swap-form/simulate-swap-result/index.tsx b/apps/minifront/src/components/swap/swap-form/simulate-swap-result/index.tsx index 0d5248c8d..de582de1c 100644 --- a/apps/minifront/src/components/swap/swap-form/simulate-swap-result/index.tsx +++ b/apps/minifront/src/components/swap/swap-form/simulate-swap-result/index.tsx @@ -25,9 +25,9 @@ const simulateSwapResultSelector = (state: AllSlices) => ({ value: { amount: toBaseUnit( new BigNumber(state.swap.amount || 0), - getDisplayDenomExponentFromValueView.optional()(state.swap.assetIn?.balanceView), + getDisplayDenomExponentFromValueView.optional(state.swap.assetIn?.balanceView), ), - metadata: getMetadata.optional()(state.swap.assetIn?.balanceView), + metadata: getMetadata.optional(state.swap.assetIn?.balanceView), }, }, }), diff --git a/apps/minifront/src/components/swap/swap-form/simulate-swap-result/traces/trace/price.tsx b/apps/minifront/src/components/swap/swap-form/simulate-swap-result/traces/trace/price.tsx index e9c2689e7..74dd6bc4e 100644 --- a/apps/minifront/src/components/swap/swap-form/simulate-swap-result/traces/trace/price.tsx +++ b/apps/minifront/src/components/swap/swap-form/simulate-swap-result/traces/trace/price.tsx @@ -21,8 +21,8 @@ export const Price = ({ const lastValueMetadata = metadataByAssetId[bech32mAssetId(outputValue.assetId)]; if (firstValueMetadata?.symbol && lastValueMetadata?.symbol) { - const inputDisplayDenomExponent = getDisplayDenomExponent.optional()(firstValueMetadata) ?? 0; - const outputDisplayDenomExponent = getDisplayDenomExponent.optional()(lastValueMetadata) ?? 0; + const inputDisplayDenomExponent = getDisplayDenomExponent.optional(firstValueMetadata) ?? 0; + const outputDisplayDenomExponent = getDisplayDenomExponent.optional(lastValueMetadata) ?? 0; const formattedInputAmount = formatAmount({ amount: inputValue.amount, exponent: inputDisplayDenomExponent, diff --git a/apps/minifront/src/components/swap/swap-form/token-swap-input.tsx b/apps/minifront/src/components/swap/swap-form/token-swap-input.tsx index 631a06c77..2eca3ee4b 100644 --- a/apps/minifront/src/components/swap/swap-form/token-swap-input.tsx +++ b/apps/minifront/src/components/swap/swap-form/token-swap-input.tsx @@ -43,7 +43,7 @@ const getAssetOutBalance = ( getAddressIndex(assetIn.accountAddress), assetOut, ); - const matchedBalance = getBalanceView.optional()(match); + const matchedBalance = getBalanceView.optional(match); return matchedBalance ?? zeroValueView(assetOut); }; @@ -70,10 +70,10 @@ export const TokenSwapInput = () => { useStoreShallow(tokenSwapInputSelector); const assetOutBalance = getAssetOutBalance(balancesResponses?.data, assetIn, assetOut); const assetInExponent = useMemo(() => { - return getDisplayDenomExponent.optional()(getMetadataFromBalancesResponse.optional()(assetIn)); + return getDisplayDenomExponent.optional(getMetadataFromBalancesResponse.optional(assetIn)); }, [assetIn]); - const maxAmount = getAmount.optional()(assetIn); + const maxAmount = getAmount.optional(assetIn); const maxAmountAsString = maxAmount ? joinLoHiAmount(maxAmount).toString() : undefined; const setInputToBalanceMax = () => { diff --git a/apps/minifront/src/components/v2/dashboard-layout/assets-page/equivalent-values.tsx b/apps/minifront/src/components/v2/dashboard-layout/assets-page/equivalent-values.tsx index 738d0e6a6..821dd56fa 100644 --- a/apps/minifront/src/components/v2/dashboard-layout/assets-page/equivalent-values.tsx +++ b/apps/minifront/src/components/v2/dashboard-layout/assets-page/equivalent-values.tsx @@ -4,7 +4,7 @@ import { getDisplayDenomFromView, getEquivalentValues } from '@penumbra-zone/get import { ValueViewComponent } from '@repo/ui/ValueViewComponent'; export const EquivalentValues = ({ valueView }: { valueView?: ValueView }) => { - const equivalentValuesAsValueViews = (getEquivalentValues.optional()(valueView) ?? []).map( + const equivalentValuesAsValueViews = (getEquivalentValues.optional(valueView) ?? []).map( asValueView, ); diff --git a/apps/minifront/src/fetchers/auction-infos.ts b/apps/minifront/src/fetchers/auction-infos.ts index b83d32ec5..b3f491488 100644 --- a/apps/minifront/src/fetchers/auction-infos.ts +++ b/apps/minifront/src/fetchers/auction-infos.ts @@ -31,8 +31,8 @@ export const getAuctionInfos = async function* ({ const auction = DutchAuction.fromBinary(response.auction.value); - const inputAssetId = getInputAssetId.optional()(auction); - const outputAssetId = getOutputAssetId.optional()(auction); + const inputAssetId = getInputAssetId.optional(auction); + const outputAssetId = getOutputAssetId.optional(auction); const inputMetadataPromise = inputAssetId ? penumbra.service(ViewService).assetMetadataById({ assetId: inputAssetId }) diff --git a/apps/minifront/src/fetchers/balances/by-priority-score.ts b/apps/minifront/src/fetchers/balances/by-priority-score.ts index 72771ba3c..8760f3b10 100644 --- a/apps/minifront/src/fetchers/balances/by-priority-score.ts +++ b/apps/minifront/src/fetchers/balances/by-priority-score.ts @@ -6,11 +6,11 @@ import { import { multiplyAmountByNumber, joinLoHiAmount } from '@penumbra-zone/types/amount'; export const sortByPriorityScore = (a: BalancesResponse, b: BalancesResponse) => { - const aScore = getMetadataFromBalancesResponse.optional()(a)?.priorityScore ?? 1n; - const bScore = getMetadataFromBalancesResponse.optional()(b)?.priorityScore ?? 1n; + const aScore = getMetadataFromBalancesResponse.optional(a)?.priorityScore ?? 1n; + const bScore = getMetadataFromBalancesResponse.optional(b)?.priorityScore ?? 1n; - const aAmount = getAmount.optional()(a); - const bAmount = getAmount.optional()(b); + const aAmount = getAmount.optional(a); + const bAmount = getAmount.optional(b); const aPriority = aAmount ? joinLoHiAmount(multiplyAmountByNumber(aAmount, Number(aScore))) diff --git a/apps/minifront/src/state/helpers.ts b/apps/minifront/src/state/helpers.ts index 1646258dd..be2aba600 100644 --- a/apps/minifront/src/state/helpers.ts +++ b/apps/minifront/src/state/helpers.ts @@ -200,8 +200,8 @@ export const isIncorrectDecimal = ( throw new Error('Missing balanceView'); } - const exponent = getDisplayDenomExponent.optional()( - getMetadataFromBalancesResponse.optional()(asset), + const exponent = getDisplayDenomExponent.optional( + getMetadataFromBalancesResponse.optional(asset), ); const fraction = amountInDisplayDenom.split('.')[1]?.length; return typeof exponent !== 'undefined' && typeof fraction !== 'undefined' && fraction > exponent; @@ -213,4 +213,4 @@ export const isValidAmount = (amount: string, assetIn?: BalancesResponse) => (!assetIn || !isIncorrectDecimal(assetIn, amount)); export const isKnown = (balancesResponse: BalancesResponse) => - getValueViewCaseFromBalancesResponse.optional()(balancesResponse) === 'knownAssetId'; + getValueViewCaseFromBalancesResponse.optional(balancesResponse) === 'knownAssetId'; diff --git a/apps/minifront/src/state/ibc-out.ts b/apps/minifront/src/state/ibc-out.ts index 0ccfb55e1..860428935 100644 --- a/apps/minifront/src/state/ibc-out.ts +++ b/apps/minifront/src/state/ibc-out.ts @@ -282,7 +282,7 @@ export const filterBalancesPerChain = ( registryAssets: Metadata[], stakingTokenMetadata?: Metadata, ): BalancesResponse[] => { - const penumbraAssetId = getAssetId.optional()(stakingTokenMetadata); + const penumbraAssetId = getAssetId.optional(stakingTokenMetadata); const assetsWithMatchingChannel = registryAssets .filter(a => { const match = assetPatterns.ibc.capture(a.base); diff --git a/apps/minifront/src/state/send/index.ts b/apps/minifront/src/state/send/index.ts index 1f7235cb2..58782df2c 100644 --- a/apps/minifront/src/state/send/index.ts +++ b/apps/minifront/src/state/send/index.ts @@ -133,7 +133,7 @@ const assembleRequest = ({ amount, feeTier, recipient, selection, memo }: SendSl value: { amount: toBaseUnit( BigNumber(amount), - getDisplayDenomExponentFromValueView.optional()(selection?.balanceView), + getDisplayDenomExponentFromValueView.optional(selection?.balanceView), ), assetId: getAssetIdFromValueView(selection?.balanceView), }, diff --git a/apps/minifront/src/state/swap/dutch-auction/assemble-schedule-request.ts b/apps/minifront/src/state/swap/dutch-auction/assemble-schedule-request.ts index dd8eb3b68..8cc72d151 100644 --- a/apps/minifront/src/state/swap/dutch-auction/assemble-schedule-request.ts +++ b/apps/minifront/src/state/swap/dutch-auction/assemble-schedule-request.ts @@ -13,7 +13,7 @@ export const assembleScheduleRequest = async ({ duration, }: Pick & Pick): Promise => { - const source = getAddressIndex.optional()(assetIn); + const source = getAddressIndex.optional(assetIn); return new TransactionPlannerRequest({ dutchAuctionScheduleActions: await getSubAuctions({ diff --git a/apps/minifront/src/state/swap/dutch-auction/index.ts b/apps/minifront/src/state/swap/dutch-auction/index.ts index 0b7fc3110..03ec8128b 100644 --- a/apps/minifront/src/state/swap/dutch-auction/index.ts +++ b/apps/minifront/src/state/swap/dutch-auction/index.ts @@ -122,7 +122,7 @@ export const createDutchAuctionSlice = (): SliceCreator => (s swap.dutchAuction.minOutput = ''; } else { const minMinOutput = getSmallestPossibleAmountAboveZero(get().swap.assetOut); - const exponent = getDisplayDenomExponent.optional()(get().swap.assetOut) ?? 0; + const exponent = getDisplayDenomExponent.optional(get().swap.assetOut) ?? 0; const minOutputAsBaseUnit = Number(minOutput) * 10 ** exponent; const outputLimitAsDisplayUnit = (OUTPUT_LIMIT / 10 ** exponent).toString(); @@ -144,7 +144,7 @@ export const createDutchAuctionSlice = (): SliceCreator => (s swap.dutchAuction.maxOutput = ''; } else { const minMaxOutput = getSmallestPossibleAmountAboveZero(get().swap.assetOut); - const exponent = getDisplayDenomExponent.optional()(get().swap.assetOut) ?? 0; + const exponent = getDisplayDenomExponent.optional(get().swap.assetOut) ?? 0; const maxOutputAsBaseUnit = Number(maxOutput) * 10 ** exponent; const outputLimitAsDisplayUnit = (OUTPUT_LIMIT / 10 ** exponent).toString(); diff --git a/apps/minifront/src/state/swap/getters.ts b/apps/minifront/src/state/swap/getters.ts index 8dea64b51..e3a33b7f1 100644 --- a/apps/minifront/src/state/swap/getters.ts +++ b/apps/minifront/src/state/swap/getters.ts @@ -8,7 +8,7 @@ import { getMetadata } from '@penumbra-zone/getters/value-view'; export const balancesResponseAndMetadataAreSameAsset = ( balancesResponse?: BalancesResponse, metadata?: Metadata, -) => getMetadata.optional()(balancesResponse?.balanceView)?.equals(metadata); +) => getMetadata.optional(balancesResponse?.balanceView)?.equals(metadata); export const getFirstBalancesResponseNotMatchingMetadata = ( balancesResponses: BalancesResponse[], @@ -38,7 +38,7 @@ export const getBalanceByMatchingMetadataAndAddressIndex = ( metadata: Metadata, ) => { return balances.find(balance => { - const balanceViewMetadata = getMetadataFromBalancesResponse.optional()(balance); + const balanceViewMetadata = getMetadataFromBalancesResponse.optional(balance); return ( getAddressIndex(balance.accountAddress).account === addressIndex.account && diff --git a/apps/minifront/src/state/swap/query-params.ts b/apps/minifront/src/state/swap/query-params.ts index 93edd3ece..ce6663026 100644 --- a/apps/minifront/src/state/swap/query-params.ts +++ b/apps/minifront/src/state/swap/query-params.ts @@ -31,9 +31,9 @@ export const getSwapQueryParams = (): SwapQueryParams => { * Sets the swap query parameters in the URL hash based on the store state */ export const setSwapQueryParams = (state: AllSlices): void => { - const fromSymbol = getMetadataFromBalancesResponse.optional()(state.swap.assetIn)?.symbol; + const fromSymbol = getMetadataFromBalancesResponse.optional(state.swap.assetIn)?.symbol; const toSymbol = state.swap.assetOut?.symbol; - const accountIndex = getAddressIndex.optional()(state.swap.assetIn)?.account; + const accountIndex = getAddressIndex.optional(state.swap.assetIn)?.account; const searchParams = new URLSearchParams(); if (fromSymbol) { diff --git a/apps/minifront/src/state/swap/swap-balances-middleware.ts b/apps/minifront/src/state/swap/swap-balances-middleware.ts index cf8a571d6..d13e38bd5 100644 --- a/apps/minifront/src/state/swap/swap-balances-middleware.ts +++ b/apps/minifront/src/state/swap/swap-balances-middleware.ts @@ -32,7 +32,7 @@ const getAssetIn = (state: AllSlices, from?: string, account?: number) => { if (from) { const matchingBalancesResponse = filteredSwappableBalancesResponses.find( - balance => getMetadataFromBalancesResponse.optional()(balance)?.symbol === from, + balance => getMetadataFromBalancesResponse.optional(balance)?.symbol === from, ); if (matchingBalancesResponse) { return matchingBalancesResponse; @@ -73,7 +73,7 @@ const getAssetOut = (state: AllSlices, to?: string, assetIn?: BalancesResponse) return state.swap.assetOut; } - if (getMetadataFromBalancesResponse.optional()(assetIn)?.equals(swappableAssets[0])) { + if (getMetadataFromBalancesResponse.optional(assetIn)?.equals(swappableAssets[0])) { return swappableAssets[1]; } diff --git a/docs/adrs/001-getters.md b/docs/adrs/001-getters.md index 19e9a38de..afbd15fda 100644 --- a/docs/adrs/001-getters.md +++ b/docs/adrs/001-getters.md @@ -60,7 +60,7 @@ If we want to allow `undefined`, we can add a call to `.optional()`: required because we called `.optional()`. Otherwise, TypeScript would have guaranteed that the return value of `getAddressIndex()` was an actual `AddressIndex`. */} - {getAddressIndex.optional()(addressView)?.account} + {getAddressIndex.optional(addressView)?.account}
``` diff --git a/packages/getters/README.md b/packages/getters/README.md index 0b5c7cba1..dcaf93ba0 100644 --- a/packages/getters/README.md +++ b/packages/getters/README.md @@ -83,7 +83,7 @@ At this point, it's worth mentioning that getters are _required by default_. If What if the value you're getting _is_ optional, though? What if you don't want your getter to throw if either the value it's passed, or the value it returns, is `undefined`? That's what the `.optional()` property on the getter is for: ```tsx -const addressView = getAddressView.optional()(memoView) +const addressView = getAddressView.optional(memoView)
{addressView && } diff --git a/packages/perspective/src/plan/view-action-plan.ts b/packages/perspective/src/plan/view-action-plan.ts index 4551427e4..9f054f051 100644 --- a/packages/perspective/src/plan/view-action-plan.ts +++ b/packages/perspective/src/plan/view-action-plan.ts @@ -324,8 +324,8 @@ export const viewActionPlan = }); case 'actionDutchAuctionSchedule': { - const inputAssetId = getInputAssetId.optional()(actionPlan.action.value.description); - const outputAssetId = getOutputAssetId.optional()(actionPlan.action.value.description); + const inputAssetId = getInputAssetId.optional(actionPlan.action.value.description); + const outputAssetId = getOutputAssetId.optional(actionPlan.action.value.description); const [inputMetadata, outputMetadata] = await Promise.all([ inputAssetId ? await denomMetadataByAssetId(inputAssetId) : undefined, outputAssetId ? await denomMetadataByAssetId(outputAssetId) : undefined, diff --git a/packages/services/src/view-service/balances.ts b/packages/services/src/view-service/balances.ts index fb22a2717..8e91326db 100644 --- a/packages/services/src/view-service/balances.ts +++ b/packages/services/src/view-service/balances.ts @@ -156,7 +156,7 @@ class BalancesAggregator { * of the equivalent value and the `amount` of the `ValueView`. */ private async aggregateEquivalentValues(valueView: ValueView, toAdd: SpendableNoteRecord) { - const assetId = getAssetIdFromRecord.optional()(toAdd); + const assetId = getAssetIdFromRecord.optional(toAdd); if (!assetId?.inner) { return; } diff --git a/packages/services/src/view-service/unbonding-tokens-by-address-index/helpers.ts b/packages/services/src/view-service/unbonding-tokens-by-address-index/helpers.ts index 3280c7665..0e1bb2f12 100644 --- a/packages/services/src/view-service/unbonding-tokens-by-address-index/helpers.ts +++ b/packages/services/src/view-service/unbonding-tokens-by-address-index/helpers.ts @@ -11,7 +11,7 @@ import { status } from '../status.js'; import { appParameters } from '../app-parameters.js'; export const isUnbondingTokenBalance = (balancesResponse: PartialMessage) => { - const display = getDisplayFromBalancesResponse.optional()(new BalancesResponse(balancesResponse)); + const display = getDisplayFromBalancesResponse.optional(new BalancesResponse(balancesResponse)); return display ? assetPatterns.unbondingToken.matches(display) : false; }; @@ -40,7 +40,7 @@ export const getIsClaimable = async ( return false; } - const display = getDisplayFromBalancesResponse.optional()(new BalancesResponse(balancesResponse)); + const display = getDisplayFromBalancesResponse.optional(new BalancesResponse(balancesResponse)); if (!display) { return false; } diff --git a/packages/services/src/view-service/unbonding-tokens-by-address-index/index.ts b/packages/services/src/view-service/unbonding-tokens-by-address-index/index.ts index d0805e0de..6da3b4032 100644 --- a/packages/services/src/view-service/unbonding-tokens-by-address-index/index.ts +++ b/packages/services/src/view-service/unbonding-tokens-by-address-index/index.ts @@ -44,7 +44,7 @@ export const unbondingTokensByAddressIndex: Impl['unbondingTokensByAddressIndex' } const regexResult = assetPatterns.unbondingToken.capture( - getDisplayFromBalancesResponse.optional()(new BalancesResponse(balancesResponse)) ?? '', + getDisplayFromBalancesResponse.optional(new BalancesResponse(balancesResponse)) ?? '', ); if (!regexResult) { throw new Error('expected delegation token identity key not present'); diff --git a/packages/types/src/swap.ts b/packages/types/src/swap.ts index 1be3bd260..a39765e7b 100644 --- a/packages/types/src/swap.ts +++ b/packages/types/src/swap.ts @@ -35,8 +35,8 @@ const getUnfilledAmount = (swapView: SwapView): ValueView | undefined => { const delta1I = getDelta1IFromSwapView(swapView); const delta2I = getDelta2IFromSwapView(swapView); - const output1Value = getOutput1Value.optional()(swapView); - const output2Value = getOutput2Value.optional()(swapView); + const output1Value = getOutput1Value.optional(swapView); + const output2Value = getOutput2Value.optional(swapView); const is1To2Swap = isZero(delta2I); const is2To1Swap = isZero(delta1I); @@ -69,8 +69,8 @@ export const getOneWaySwapValues = ( ); } - const output1 = getOutput1Value.optional()(swapView); - const output2 = getOutput2Value.optional()(swapView); + const output1 = getOutput1Value.optional(swapView); + const output2 = getOutput2Value.optional(swapView); const delta1I = getDelta1IFromSwapView(swapView); const delta2I = getDelta2IFromSwapView(swapView); diff --git a/packages/types/src/value-view.ts b/packages/types/src/value-view.ts index 1e3162589..28e257eb7 100644 --- a/packages/types/src/value-view.ts +++ b/packages/types/src/value-view.ts @@ -13,7 +13,7 @@ export const getFormattedAmtFromValueView = (v: ValueView, commas = false): stri if (v.valueView.case === 'knownAssetId' && v.valueView.value.metadata) { const { amount = new Amount(), metadata } = v.valueView.value; - const exponent = getDisplayDenomExponent.optional()(metadata); + const exponent = getDisplayDenomExponent.optional(metadata); return formatAmount({ amount, exponent, commas }); } else { const { amount = new Amount() } = v.valueView.value; diff --git a/packages/ui/components/ui/asset-icon/index.tsx b/packages/ui/components/ui/asset-icon/index.tsx index 9e6ca82e1..9acc5218f 100644 --- a/packages/ui/components/ui/asset-icon/index.tsx +++ b/packages/ui/components/ui/asset-icon/index.tsx @@ -22,7 +22,7 @@ export const AssetIcon = ({ size === 'sm' && 'size-6', size === 'lg' && 'size-12', ); - const display = getDisplay.optional()(metadata); + const display = getDisplay.optional(metadata); const isDelegationToken = display ? assetPatterns.delegationToken.matches(display) : false; const isUnbondingToken = display ? assetPatterns.unbondingToken.matches(display) : false; diff --git a/packages/ui/components/ui/balance-value-view/index.tsx b/packages/ui/components/ui/balance-value-view/index.tsx index 53cb0157b..69e6092a4 100644 --- a/packages/ui/components/ui/balance-value-view/index.tsx +++ b/packages/ui/components/ui/balance-value-view/index.tsx @@ -18,8 +18,8 @@ export const BalanceValueView = ({ error?: boolean; onClick?: (valueView: ValueView) => void; }) => { - const exponent = getDisplayDenomExponentFromValueView.optional()(valueView); - const amount = getAmount.optional()(valueView) ?? new Amount({ hi: 0n, lo: 0n }); + const exponent = getDisplayDenomExponentFromValueView.optional(valueView); + const amount = getAmount.optional(valueView) ?? new Amount({ hi: 0n, lo: 0n }); const formattedAmount = formatAmount({ amount, exponent, commas: true }); return ( diff --git a/packages/ui/components/ui/dutch-auction-component/expanded-details/get-price.ts b/packages/ui/components/ui/dutch-auction-component/expanded-details/get-price.ts index de8cbd821..7405a591d 100644 --- a/packages/ui/components/ui/dutch-auction-component/expanded-details/get-price.ts +++ b/packages/ui/components/ui/dutch-auction-component/expanded-details/get-price.ts @@ -46,7 +46,7 @@ export const getPrice = ( // The input, scaled up by `step_count` to match. const inputScaled = (stepCount - 1n) * input; - const inputDisplayDenomExponent = getDisplayDenomExponent.optional()(inputMetadata); + const inputDisplayDenomExponent = getDisplayDenomExponent.optional(inputMetadata); const multiplier = 10 ** (inputDisplayDenomExponent ?? 0); const price = Math.round((Number(targetOutputScaled) / Number(inputScaled)) * multiplier); diff --git a/packages/ui/components/ui/dutch-auction-component/expanded-details/index.tsx b/packages/ui/components/ui/dutch-auction-component/expanded-details/index.tsx index caac99a5b..5921a7b53 100644 --- a/packages/ui/components/ui/dutch-auction-component/expanded-details/index.tsx +++ b/packages/ui/components/ui/dutch-auction-component/expanded-details/index.tsx @@ -45,8 +45,8 @@ export const ExpandedDetails = ({ fullSyncHeight >= description.startHeight && fullSyncHeight <= description.endHeight; - const inputExponent = getDisplayDenomExponent.optional()(inputMetadata); - const outputExponent = getDisplayDenomExponent.optional()(outputMetadata); + const inputExponent = getDisplayDenomExponent.optional(inputMetadata); + const outputExponent = getDisplayDenomExponent.optional(outputMetadata); return (
diff --git a/packages/ui/components/ui/tx/actions-views/delegator-vote.tsx b/packages/ui/components/ui/tx/actions-views/delegator-vote.tsx index c0912ab6c..de2b6ade3 100644 --- a/packages/ui/components/ui/tx/actions-views/delegator-vote.tsx +++ b/packages/ui/components/ui/tx/actions-views/delegator-vote.tsx @@ -54,11 +54,11 @@ const umValueView = (amount?: Amount) => { }; export const DelegatorVoteComponent = ({ value }: { value: DelegatorVoteView }) => { - const body = getDelegatorVoteBody.optional()(value); + const body = getDelegatorVoteBody.optional(value); if (value.delegatorVote.case === 'visible') { const note = value.delegatorVote.value.note; - const address = getAddress.optional()(note); + const address = getAddress.optional(note); return ( { if (value.swapView.case === 'visible') { - const claimTx = getClaimTx.optional()(value); - const addressView = getAddressView.optional()(value); + const claimTx = getClaimTx.optional(value); + const addressView = getAddressView.optional(value); const oneWaySwap = isOneWaySwap(value) ? getOneWaySwapValues(value) : undefined; // The 'Fee' protobuf definition does not include assetMetadata. diff --git a/packages/ui/components/ui/tx/actions-views/swap/one-way-swap.tsx b/packages/ui/components/ui/tx/actions-views/swap/one-way-swap.tsx index c7aaf3b1a..6fa0c7f7d 100644 --- a/packages/ui/components/ui/tx/actions-views/swap/one-way-swap.tsx +++ b/packages/ui/components/ui/tx/actions-views/swap/one-way-swap.tsx @@ -10,7 +10,7 @@ import { getAmount } from '@penumbra-zone/getters/value-view'; * 1.23INPUT -> 4.56OUTPUT */ export const OneWaySwap = ({ input, output }: { input: ValueView; output: ValueView }) => { - const outputAmount = getAmount.optional()(output); + const outputAmount = getAmount.optional(output); return (
diff --git a/packages/ui/components/ui/tx/actions-views/swap/swap-claim.tsx b/packages/ui/components/ui/tx/actions-views/swap/swap-claim.tsx index 6bcb34de3..749d109ca 100644 --- a/packages/ui/components/ui/tx/actions-views/swap/swap-claim.tsx +++ b/packages/ui/components/ui/tx/actions-views/swap/swap-claim.tsx @@ -30,10 +30,10 @@ const getClaimLabel = ( export const SwapClaimViewComponent = ({ value }: { value: SwapClaimView }) => { if (value.swapClaimView.case === 'visible') { const swapTxId = value.swapClaimView.value.swapTx; - const output1Value = getOutput1Value.optional()(value); - const output2Value = getOutput2Value.optional()(value); - const output1Amount = getAmount.optional()(output1Value); - const output2Amount = getAmount.optional()(output2Value); + const output1Value = getOutput1Value.optional(value); + const output2Value = getOutput2Value.optional(value); + const output1Amount = getAmount.optional(output1Value); + const output2Amount = getAmount.optional(output2Value); const claimLabel = getClaimLabel(output1Amount, output2Amount); return ( diff --git a/packages/ui/src/AssetIcon/index.tsx b/packages/ui/src/AssetIcon/index.tsx index 1b77b3f59..a5475dbc3 100644 --- a/packages/ui/src/AssetIcon/index.tsx +++ b/packages/ui/src/AssetIcon/index.tsx @@ -26,7 +26,7 @@ export const AssetIcon = ({ metadata }: AssetIcon) => { // Image default is "" and thus cannot do nullish-coalescing // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const icon = metadata?.images[0]?.png || metadata?.images[0]?.svg; - const display = getDisplay.optional()(metadata); + const display = getDisplay.optional(metadata); const isDelegationToken = display ? assetPatterns.delegationToken.matches(display) : false; const isUnbondingToken = display ? assetPatterns.unbondingToken.matches(display) : false; diff --git a/packages/ui/src/AssetSelector/AssetSelectorDialogContent/MetadataOrBalancesResponse/Balance.tsx b/packages/ui/src/AssetSelector/AssetSelectorDialogContent/MetadataOrBalancesResponse/Balance.tsx index 1309f7543..55129b7a9 100644 --- a/packages/ui/src/AssetSelector/AssetSelectorDialogContent/MetadataOrBalancesResponse/Balance.tsx +++ b/packages/ui/src/AssetSelector/AssetSelectorDialogContent/MetadataOrBalancesResponse/Balance.tsx @@ -15,8 +15,8 @@ export interface BalanceProps { } export const Balance = ({ balancesResponse }: BalanceProps) => { - const addressIndexAccount = getAddressIndex.optional()(balancesResponse)?.account; - const valueView = getBalanceView.optional()(balancesResponse); + const addressIndexAccount = getAddressIndex.optional(balancesResponse)?.account; + const valueView = getBalanceView.optional(balancesResponse); return ( {valueView && {getFormattedAmtFromValueView(valueView, true)}} diff --git a/packages/ui/src/AssetSelector/AssetSelectorDialogContent/MetadataOrBalancesResponse/index.tsx b/packages/ui/src/AssetSelector/AssetSelectorDialogContent/MetadataOrBalancesResponse/index.tsx index 38d18a043..007c647fc 100644 --- a/packages/ui/src/AssetSelector/AssetSelectorDialogContent/MetadataOrBalancesResponse/index.tsx +++ b/packages/ui/src/AssetSelector/AssetSelectorDialogContent/MetadataOrBalancesResponse/index.tsx @@ -44,7 +44,7 @@ export const MetadataOrBalancesResponse = ({ isSelected, onSelect, }: MetadataOrBalancesResponseProps) => { - const metadata = isMetadata(value) ? value : getMetadataFromBalancesResponse.optional()(value); + const metadata = isMetadata(value) ? value : getMetadataFromBalancesResponse.optional(value); const isParentAnimating = useIsAnimating(); const [scope, animate] = useAnimate(); const animationControls = useRef(); diff --git a/packages/ui/src/AssetSelector/index.tsx b/packages/ui/src/AssetSelector/index.tsx index e783f76fe..76e7efc65 100644 --- a/packages/ui/src/AssetSelector/index.tsx +++ b/packages/ui/src/AssetSelector/index.tsx @@ -60,7 +60,7 @@ export const AssetSelector = ) => { const layoutId = useId(); const density = useDensity(); - const metadata = isMetadata(value) ? value : getMetadataFromBalancesResponse.optional()(value); + const metadata = isMetadata(value) ? value : getMetadataFromBalancesResponse.optional(value); const [isOpen, setIsOpen] = useState(false); diff --git a/packages/ui/src/ValueViewComponent/index.tsx b/packages/ui/src/ValueViewComponent/index.tsx index dff24fb55..58fe2803e 100644 --- a/packages/ui/src/ValueViewComponent/index.tsx +++ b/packages/ui/src/ValueViewComponent/index.tsx @@ -89,7 +89,7 @@ export const ValueViewComponent = ( } const formattedAmount = getFormattedAmtFromValueView(valueView, true); - const metadata = getMetadata.optional()(valueView); + const metadata = getMetadata.optional(valueView); // Symbol default is "" and thus cannot do nullish coalescing // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const symbol = metadata?.symbol || 'Unknown';