Skip to content

Commit

Permalink
Attach the entire fee object to the state, rather than just the joine…
Browse files Browse the repository at this point in the history
…d amount
  • Loading branch information
jessepinho committed Jan 10, 2024
1 parent f6b43c2 commit 3975294
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
23 changes: 9 additions & 14 deletions apps/webapp/src/components/shared/input-token.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import { Input, InputProps } from '@penumbra-zone/ui';
import { cn } from '@penumbra-zone/ui/lib/utils';
import { fromBaseUnitAmount } from '@penumbra-zone/types';
import { fromBaseUnitAmount, joinLoHiAmount } from '@penumbra-zone/types';
import SelectTokenModal from './select-token-modal';
import { Validation, validationResult } from './validation-result';
import { AccountBalance, AssetBalance } from '../../fetchers/balances';
import { Selection } from '../../state/types';
import { Fee } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/fee/v1alpha1/fee_pb';

/**
* Each property of the `GasPrices` class has an implicit 1,000 denominator, per
* its docs.
*
* @see `proto/penumbra/penumbra/core/component/fee/v1alpha1/fee.proto` in the
* core repo.
*/
const FEE_DENOMINATOR = 1000;
const PENUMBRA_FEE_DENOMINATOR = 1000;

const getFeeAsString = (fee: bigint | undefined, denomination: string | undefined) =>
typeof fee !== 'undefined' ? `${(Number(fee) / FEE_DENOMINATOR).toString()} ${denomination}` : '';
const getFeeAsString = (fee: Fee | undefined) => {
if (!fee?.amount) return '';
return `${(Number(joinLoHiAmount(fee.amount)) / PENUMBRA_FEE_DENOMINATOR).toString()} penumbra`;
};

const getCurrentBalance = (assetBalance: AssetBalance | undefined) =>
assetBalance
Expand All @@ -33,7 +29,7 @@ interface InputTokenProps extends InputProps {
setSelection: (selection: Selection) => void;
validations?: Validation[];
balances: AccountBalance[];
fee: bigint | undefined;
fee: Fee | undefined;
}

export default function InputToken({
Expand All @@ -52,8 +48,7 @@ export default function InputToken({
const vResult = validationResult(value, validations);

const currentBalance = getCurrentBalance(selection?.asset);
const denomination = selection?.asset?.denom.display;
const feeAsString = getFeeAsString(fee, denomination);
const feeAsString = getFeeAsString(fee);

return (
<div
Expand Down
7 changes: 3 additions & 4 deletions apps/webapp/src/state/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { AllSlices, SliceCreator } from './index';
import {
fromBaseUnitAmount,
isPenumbraAddr,
joinLoHiAmount,
toBaseUnit,
uint8ArrayToHex,
} from '@penumbra-zone/types';
Expand All @@ -16,6 +15,7 @@ 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 { Fee } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/fee/v1alpha1/fee_pb';

export interface SendSlice {
selection: Selection | undefined;
Expand All @@ -26,7 +26,7 @@ export interface SendSlice {
setRecipient: (addr: string) => void;
memo: string;
setMemo: (txt: string) => void;
fee: bigint | undefined;
fee: Fee | undefined;
refreshFee: () => Promise<void>;
sendTx: (toastFn: typeof toast) => Promise<void>;
txInProgress: boolean;
Expand Down Expand Up @@ -72,10 +72,9 @@ export const createSendSlice = (): SliceCreator<SendSlice> => (set, get) => {

const plan = await getPlan({ amount, recipient, selection, memo });
if (!plan?.fee?.amount) return;
const fee = joinLoHiAmount(plan.fee.amount);

set(state => {
state.send.fee = fee;
state.send.fee = plan.fee;
});
},
sendTx: async toastFn => {
Expand Down

0 comments on commit 3975294

Please sign in to comment.