Skip to content

Commit

Permalink
Get rid of old gas price code
Browse files Browse the repository at this point in the history
  • Loading branch information
jessepinho committed Jan 10, 2024
1 parent f71d92e commit f6b43c2
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 61 deletions.
12 changes: 2 additions & 10 deletions apps/webapp/src/components/send/send-form/index.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import { Button } from '@penumbra-zone/ui';
import { useStore } from '../../../state/index.ts';
import { totalGasPriceSelector, sendSelector, sendValidationErrors } from '../../../state/send.ts';
import { sendSelector, sendValidationErrors } from '../../../state/send.ts';
import { useToast } from '@penumbra-zone/ui/components/ui/use-toast';
import { InputBlock } from '../../shared/input-block.tsx';
import InputToken from '../../shared/input-token.tsx';
import { LoaderFunction, useLoaderData } from 'react-router-dom';
import { AccountBalance, getBalancesByAccount } from '../../../fetchers/balances.ts';
import { useMemo } from 'react';
import { penumbraAddrValidation } from '../helpers.ts';
import { getGasPrices } from '../../../fetchers/gas-prices.ts';
import { useRefreshFee } from './use-refresh-fee.ts';

export const SendAssetBalanceLoader: LoaderFunction = async (): Promise<AccountBalance[]> => {
const [balancesByAccount, gasPrices] = await Promise.all([
getBalancesByAccount(),
getGasPrices(),
]);

useStore.getState().send.setGasPrices(gasPrices);
const balancesByAccount = await getBalancesByAccount();

if (balancesByAccount[0]) {
// set initial account if accounts exist and asset if account has asset list
Expand Down Expand Up @@ -49,7 +43,6 @@ export const SendForm = () => {
sendTx,
txInProgress,
} = useStore(sendSelector);
const totalGasPrice = useStore(totalGasPriceSelector);

useRefreshFee();

Expand Down Expand Up @@ -93,7 +86,6 @@ export const SendForm = () => {
},
]}
balances={accountBalances}
totalGasPrice={totalGasPrice}
fee={fee}
/>
<InputBlock
Expand Down
4 changes: 1 addition & 3 deletions apps/webapp/src/components/shared/input-token.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ interface InputTokenProps extends InputProps {
setSelection: (selection: Selection) => void;
validations?: Validation[];
balances: AccountBalance[];
totalGasPrice: bigint | undefined;
fee: bigint | undefined;
}

Expand All @@ -47,7 +46,6 @@ export default function InputToken({
inputClassName,
setSelection,
balances,
totalGasPrice,
fee,
...props
}: InputTokenProps) {
Expand Down Expand Up @@ -93,7 +91,7 @@ export default function InputToken({
<div className='flex items-start gap-2'>
{feeAsString && (
<>
<img src='/fuel.svg' alt='Gas price' className='h-5 w-5' />
<img src='/fuel.svg' alt='Gas fee' className='h-5 w-5' />
<p className='font-bold text-muted-foreground'>{feeAsString}</p>
</>
)}
Expand Down
26 changes: 1 addition & 25 deletions apps/webapp/src/state/send.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { beforeEach, describe, expect, test } from 'vitest';
import { create, StoreApi, UseBoundStore } from 'zustand';
import { AllSlices, initializeStore } from './index.ts';
import { Amount } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/num/v1alpha1/num_pb';
import { sendValidationErrors, getTotalGasPriceFromGasPrices } from './send.ts';
import { sendValidationErrors } from './send.ts';
import { AssetId } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1alpha1/asset_pb';
import { GasPrices } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/fee/v1alpha1/fee_pb';

describe('Send Slice', () => {
const selectionExample = {
Expand Down Expand Up @@ -136,27 +135,4 @@ describe('Send Slice', () => {
expect(useStore.getState().send.selection).toStrictEqual(selectionExample);
});
});

describe('getTotalGasPriceFromGasPrices()', () => {
test('returns `undefined` if `gasPrices` is `undefined`', () => {
expect(getTotalGasPriceFromGasPrices(undefined)).toBeUndefined();
});

test("returns the sum of each dimension's price", () => {
const gasPrices = new GasPrices({
blockSpacePrice: 1n,
compactBlockSpacePrice: 2n,
executionPrice: 3n,
verificationPrice: 4n,
});

const sum =
gasPrices.blockSpacePrice +
gasPrices.compactBlockSpacePrice +
gasPrices.executionPrice +
gasPrices.verificationPrice;

expect(getTotalGasPriceFromGasPrices(gasPrices)).toBe(sum);
});
});
});
23 changes: 0 additions & 23 deletions apps/webapp/src/state/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { Selection } from './types';
import { MemoPlaintext } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/transaction/v1alpha1/transaction_pb';
import { viewClient, custodyClient } from '../clients/grpc';
import { getAddressByIndex } from '../fetchers/address.ts';
import { GasPrices } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/fee/v1alpha1/fee_pb';

export interface SendSlice {
selection: Selection | undefined;
Expand All @@ -29,8 +28,6 @@ export interface SendSlice {
setMemo: (txt: string) => void;
fee: bigint | undefined;
refreshFee: () => Promise<void>;
gasPrices: GasPrices | undefined;
setGasPrices: (gasPrices: GasPrices | undefined) => void;
sendTx: (toastFn: typeof toast) => Promise<void>;
txInProgress: boolean;
}
Expand All @@ -42,7 +39,6 @@ export const createSendSlice = (): SliceCreator<SendSlice> => (set, get) => {
recipient: '',
memo: '',
fee: undefined,
gasPrices: undefined,
txInProgress: false,
setAmount: amount => {
set(state => {
Expand All @@ -64,11 +60,6 @@ export const createSendSlice = (): SliceCreator<SendSlice> => (set, get) => {
state.send.memo = txt;
});
},
setGasPrices: gasPrices => {
set(state => {
state.send.gasPrices = gasPrices;
});
},
refreshFee: async () => {
const { amount, recipient, selection, memo } = get().send;

Expand Down Expand Up @@ -198,17 +189,3 @@ export const sendValidationErrors = (
};

export const sendSelector = (state: AllSlices) => state.send;

export const getTotalGasPriceFromGasPrices = (gasPrices: GasPrices | undefined) => {
if (!gasPrices) return undefined;

return (
gasPrices.blockSpacePrice +
gasPrices.compactBlockSpacePrice +
gasPrices.verificationPrice +
gasPrices.executionPrice
);
};

export const totalGasPriceSelector = (state: AllSlices) =>
getTotalGasPriceFromGasPrices(state.send.gasPrices);

0 comments on commit f6b43c2

Please sign in to comment.