Skip to content

Commit

Permalink
jesse comments
Browse files Browse the repository at this point in the history
  • Loading branch information
TalDerei committed Jul 4, 2024
1 parent 7b60848 commit ef8992c
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 107 deletions.
4 changes: 2 additions & 2 deletions apps/minifront/src/components/ibc/ibc-out/ibc-out-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const IbcOutForm = () => {
setAmount,
selection,
setSelection,
SetIsSendingMax,
setIsSendingMax,
chain,
} = useStore(ibcOutSelector);
const filteredBalances = filterBalancesPerChain(
Expand All @@ -50,7 +50,7 @@ export const IbcOutForm = () => {
className='mb-1'
selection={selection}
setSelection={setSelection}
SetIsSendingMax={SetIsSendingMax}
setIsSendingMax={setIsSendingMax}
value={amount}
onInputChange={amount => {
if (Number(amount) < 0) return;
Expand Down
4 changes: 2 additions & 2 deletions apps/minifront/src/components/send/send-form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const SendForm = () => {
setFeeTier,
setMemo,
sendTx,
SetIsSendingMax,
setIsSendingMax,
txInProgress,
} = useStore(sendSelector);

Expand Down Expand Up @@ -68,7 +68,7 @@ export const SendForm = () => {
className='mb-1'
selection={selection}
setSelection={setSelection}
SetIsSendingMax={SetIsSendingMax}
setIsSendingMax={setIsSendingMax}
value={amount}
onInputChange={amount => {
if (Number(amount) < 0) return;
Expand Down
6 changes: 3 additions & 3 deletions apps/minifront/src/components/shared/input-token.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface InputTokenProps {
setSelection: (selection: BalancesResponse) => void;
validations?: Validation[];
balances: BalancesResponse[];
SetIsSendingMax: (isSendingMax: boolean) => void;
setIsSendingMax: (isSendingMax: boolean) => void;
onInputChange: (amount: string) => void;
loading?: boolean;
}
Expand All @@ -32,7 +32,7 @@ export default function InputToken({
inputClassName,
setSelection,
balances,
SetIsSendingMax,
setIsSendingMax,
onInputChange,
loading,
}: InputTokenProps) {
Expand All @@ -42,7 +42,7 @@ export default function InputToken({
const formattedAmt = getFormattedAmtFromValueView(match.balanceView);
onInputChange(formattedAmt);
// Track internal state for sending the maximum balance
SetIsSendingMax(true);
setIsSendingMax(true);
}
};

Expand Down
4 changes: 2 additions & 2 deletions apps/minifront/src/state/ibc-out.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface IbcOutSlice {
setChain: (chain: Chain | undefined) => void;
sendIbcWithdraw: () => Promise<void>;
txInProgress: boolean;
SetIsSendingMax: (isSendingMax: boolean) => void;
setIsSendingMax: (isSendingMax: boolean) => void;
}

export const createIbcOutSlice = (): SliceCreator<IbcOutSlice> => (set, get) => {
Expand All @@ -67,7 +67,7 @@ export const createIbcOutSlice = (): SliceCreator<IbcOutSlice> => (set, get) =>
state.ibcOut.selection = selection;
});
},
SetIsSendingMax: isSendingMax => {
setIsSendingMax: isSendingMax => {
set(state => {
state.send.isSendingMax = isSendingMax;
});
Expand Down
62 changes: 18 additions & 44 deletions apps/minifront/src/state/send/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { AllSlices, Middleware, SliceCreator, useStore } from '..';
import {
BalancesResponse,
TransactionPlannerRequest,
TransactionPlannerRequest_Output,
TransactionPlannerRequest_Spend,
} from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/view/v1/view_pb';
import { BigNumber } from 'bignumber.js';
import { MemoPlaintext } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/transaction/v1/transaction_pb';
Expand All @@ -20,6 +22,7 @@ import { getAddress, getAddressIndex } from '@penumbra-zone/getters/address-view
import { toBaseUnit } from '@penumbra-zone/types/lo-hi';
import { isAddress } from '@penumbra-zone/bech32m/penumbra';
import { transferableBalancesResponsesSelector } from './helpers';
import { PartialMessage } from '@bufbuild/protobuf';

export interface SendSlice {
selection: BalancesResponse | undefined;
Expand All @@ -37,7 +40,7 @@ export interface SendSlice {
sendTx: () => Promise<void>;
txInProgress: boolean;
isSendingMax: boolean;
SetIsSendingMax: (isSendingMax: boolean) => void;
setIsSendingMax: (isSendingMax: boolean) => void;
}

export const createSendSlice = (): SliceCreator<SendSlice> => (set, get) => {
Expand All @@ -55,7 +58,7 @@ export const createSendSlice = (): SliceCreator<SendSlice> => (set, get) => {
state.send.amount = amount;
});
},
SetIsSendingMax: isSendingMax => {
setIsSendingMax: isSendingMax => {
set(state => {
state.send.isSendingMax = isSendingMax;
});
Expand Down Expand Up @@ -127,49 +130,21 @@ const assembleRequest = ({
memo,
isSendingMax,
}: SendSlice) => {
if (isSendingMax) {
return new TransactionPlannerRequest({
spends: [
{
address: { altBech32m: recipient },
value: {
amount: toBaseUnit(
BigNumber(amount),
getDisplayDenomExponentFromValueView.optional()(selection?.balanceView),
),
assetId: getAssetIdFromValueView(selection?.balanceView),
},
},
],
source: getAddressIndex(selection?.accountAddress),

// Note: we currently don't provide a UI for setting the fee manually. Thus,
// a `feeMode` of `manualFee` is not supported here.
feeMode:
typeof feeTier === 'undefined'
? { case: undefined }
: {
case: 'autoFee',
value: { feeTier },
},
});
}

const spendOrOutput:
| PartialMessage<TransactionPlannerRequest_Spend>
| PartialMessage<TransactionPlannerRequest_Output> = {
address: { altBech32m: recipient },
value: {
amount: toBaseUnit(
BigNumber(amount),
getDisplayDenomExponentFromValueView.optional()(selection?.balanceView),
),
assetId: getAssetIdFromValueView(selection?.balanceView),
},
};
return new TransactionPlannerRequest({
outputs: [
{
address: { altBech32m: recipient },
value: {
amount: toBaseUnit(
BigNumber(amount),
getDisplayDenomExponentFromValueView.optional()(selection?.balanceView),
),
assetId: getAssetIdFromValueView(selection?.balanceView),
},
},
],
...(isSendingMax ? { spends: [spendOrOutput] } : { outputs: [spendOrOutput] }),
source: getAddressIndex(selection?.accountAddress),

// Note: we currently don't provide a UI for setting the fee manually. Thus,
// a `feeMode` of `manualFee` is not supported here.
feeMode:
Expand All @@ -179,7 +154,6 @@ const assembleRequest = ({
case: 'autoFee',
value: { feeTier },
},

memo: new MemoPlaintext({
returnAddress: getAddress(selection?.accountAddress),
text: memo,
Expand Down
25 changes: 6 additions & 19 deletions packages/services/src/view-service/fees.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@
import { AssetId } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb';
import { TransactionPlannerRequest } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/view/v1/view_pb';

// Attempts to extract a fee token from the assets used in the actions of the planner request
// Priority in descending order
// Attempts to extract a fee token, with priority in descending order, from the assets used
// in the actions of the planner request.
// TODO: expand functionality for other action types like auctions, IBC, governance, etc.
export const extractAltFee = (request: TransactionPlannerRequest): AssetId => {
const outputAsset = request.outputs.map(o => o.value?.assetId).find(Boolean);
if (outputAsset) return outputAsset;

const spendAsset = request.spends.map(o => o.value?.assetId).find(Boolean);
if (spendAsset) return spendAsset;

const swapAsset = request.swaps.map(assetIn => assetIn.value?.assetId).find(Boolean);
if (swapAsset) return swapAsset;

const auctionScheduleAsset = request.dutchAuctionScheduleActions
.map(a => a.description?.outputId)
.find(Boolean);
if (auctionScheduleAsset) return auctionScheduleAsset;

const auctionEndAsset = request.dutchAuctionEndActions.map(a => a.auctionId?.inner).find(Boolean);
if (auctionEndAsset) {
return new AssetId({ inner: auctionEndAsset });
}

const auctionWithdrawAsset = request.dutchAuctionWithdrawActions
.map(a => a.auctionId?.inner)
.find(Boolean);
if (auctionWithdrawAsset) {
return new AssetId({ inner: auctionWithdrawAsset });
}

throw new Error('Could not extract alternative fee assetId from TransactionPlannerRequest');

Check failure on line 17 in packages/services/src/view-service/fees.ts

View workflow job for this annotation

GitHub Actions / test

src/view-service/fees.test.ts > extractAltFee > extracts the fee from dutchAuctionScheduleActions

Error: Could not extract alternative fee assetId from TransactionPlannerRequest ❯ Module.extractAltFee src/view-service/fees.ts:17:9 ❯ src/view-service/fees.test.ts:105:20

Check failure on line 17 in packages/services/src/view-service/fees.ts

View workflow job for this annotation

GitHub Actions / test

src/view-service/fees.test.ts > extractAltFee > extracts the fee from dutchAuctionEndActions

Error: Could not extract alternative fee assetId from TransactionPlannerRequest ❯ Module.extractAltFee src/view-service/fees.ts:17:9 ❯ src/view-service/fees.test.ts:119:20

Check failure on line 17 in packages/services/src/view-service/fees.ts

View workflow job for this annotation

GitHub Actions / test

src/view-service/fees.test.ts > extractAltFee > extracts the fee from dutchAuctionWithdrawActions

Error: Could not extract alternative fee assetId from TransactionPlannerRequest ❯ Module.extractAltFee src/view-service/fees.ts:17:9 ❯ src/view-service/fees.test.ts:133:20
};
34 changes: 0 additions & 34 deletions packages/services/src/view-service/transaction-planner/fees.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Code, ConnectError } from '@connectrpc/connect';
import { assertSwapAssetsAreNotTheSame } from './assert-swap-assets-are-not-the-same';
import { TransactionPlannerRequest } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/view/v1/view_pb';
import { fvkCtx } from '../../ctx/full-viewing-key';
import { extractAltFee } from './fees';
import { extractAltFee } from '../fees';

export const transactionPlanner: Impl['transactionPlanner'] = async (req, ctx) => {
assertValidRequest(req);
Expand Down

0 comments on commit ef8992c

Please sign in to comment.