Skip to content

Commit

Permalink
refactor: normalize validator sorting by slug or moniker
Browse files Browse the repository at this point in the history
  • Loading branch information
grikomsn committed Dec 4, 2023
1 parent 3c4df2d commit af2314b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/types/utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import slugify from "@sindresorhus/slugify";
import { formatUnits } from "ethers";
import { Validator, ValidatorWithStats } from "./base";

export const ValidatorComparer = {
VALIDATOR_ASC: <T extends Validator | ValidatorWithStats>(a: T, b: T) => {
return a.moniker.localeCompare(b.moniker);
const left = "slug" in a ? a.slug : slugify(a.moniker);
const right = "slug" in b ? b.slug : slugify(b.moniker);
return left.localeCompare(right);
},
VALIDATOR_DESC: <T extends Validator | ValidatorWithStats>(a: T, b: T) => {
return b.moniker.localeCompare(a.moniker);
const left = "slug" in a ? a.slug : slugify(a.moniker);
const right = "slug" in b ? b.slug : slugify(b.moniker);
return right.localeCompare(left);
},
AVERAGE_MEV_ASC: <T extends ValidatorWithStats>(a: T, b: T) => {
const aMev = parseFloat(formatUnits(a.averageMev, 6));
Expand Down

0 comments on commit af2314b

Please sign in to comment.