Skip to content

Commit

Permalink
fix(minifront): #1120: sort by account index and priority score
Browse files Browse the repository at this point in the history
  • Loading branch information
VanishMax committed Sep 4, 2024
1 parent cff346e commit e74a03e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions apps/minifront/src/fetchers/balances/by-priority-score.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BalancesResponse } from '@penumbra-zone/protobuf/penumbra/view/v1/view_
import {
getMetadataFromBalancesResponseOptional,
getAmount,
getAddressIndex,
} from '@penumbra-zone/getters/balances-response';
import { multiplyAmountByNumber, joinLoHiAmount } from '@penumbra-zone/types/amount';

Expand All @@ -21,3 +22,14 @@ export const sortByPriorityScore = (a: BalancesResponse, b: BalancesResponse) =>

return Number(bPriority - aPriority);
};

export const sortByPriorityScoreAndAccountIndex = (a: BalancesResponse, b: BalancesResponse) => {
const aIndex = getAddressIndex.optional()(a)?.account ?? Infinity;
const bIndex = getAddressIndex.optional()(b)?.account ?? Infinity;

if (aIndex === bIndex) {
return sortByPriorityScore(a, b);
}

return aIndex - bIndex;
};
4 changes: 2 additions & 2 deletions apps/minifront/src/state/swap/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { isKnown } from '../helpers';
import { AbridgedZQueryState } from '@penumbra-zone/zquery/src/types';
import { penumbra } from '../../prax';
import { DexService, SimulationService } from '@penumbra-zone/protobuf';
import { sortByPriorityScore } from '../../fetchers/balances/by-priority-score.ts';
import { sortByPriorityScoreAndAccountIndex } from '../../fetchers/balances/by-priority-score.ts';

export const sendSimulateTradeRequest = ({
assetIn,
Expand Down Expand Up @@ -173,7 +173,7 @@ export const swappableBalancesResponsesSelector = (
data: zQueryState.data
?.filter(isKnown)
.filter(balance => isSwappable(getMetadata(balance.balanceView)))
.sort(sortByPriorityScore),
.sort(sortByPriorityScoreAndAccountIndex),
});

export const swappableAssetsSelector = (zQueryState: AbridgedZQueryState<Metadata[]>) => ({
Expand Down

0 comments on commit e74a03e

Please sign in to comment.