Skip to content

Commit

Permalink
Remove use of lodash/chain
Browse files Browse the repository at this point in the history
  • Loading branch information
robknight committed Sep 15, 2024
1 parent d2dead1 commit 5b14489
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
import { ErrorMessage, Separator } from "@pcd/passport-ui";
import { SerializedPCD } from "@pcd/pcd-types";
import { getErrorMessage } from "@pcd/util";
import chain from "lodash/chain";
import upperFirst from "lodash/upperFirst";
import prettyMilliseconds from "pretty-ms";
import { useEffect, useMemo, useState } from "react";
Expand Down Expand Up @@ -293,7 +292,10 @@ export function DataTable({
}));
const keys =
data.length > 0
? chain(data).map(Object.keys).flatten().uniq().value()
? data
.map(Object.keys)
.flat()
.filter((key, index, self) => self.indexOf(key) === index)
: [];

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
import { ErrorMessage, Separator } from "@pcd/passport-ui";
import { SerializedPCD } from "@pcd/pcd-types";
import { getErrorMessage } from "@pcd/util";
import chain from "lodash/chain";
import { Dispatch, SetStateAction, useEffect, useState } from "react";
// react-table-lite does not have types
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down Expand Up @@ -277,7 +276,10 @@ export function DataTable({
}): JSX.Element {
const keys =
data.length > 0
? chain(data).map(Object.keys).flatten().uniq().value()
? data
.map(Object.keys)
.flat()
.filter((key, index, self) => self.indexOf(key) === index)
: [];

const dataWithChecked = data.map((row) => ({
Expand Down
10 changes: 5 additions & 5 deletions apps/passport-client/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
} from "@pcd/passport-interface";
import { splitPath } from "@pcd/pcd-collection";
import { sleep } from "@pcd/util";
import chain from "lodash/chain";
import { v4 as uuid } from "uuid";
import { Dispatcher } from "./dispatch";

Expand Down Expand Up @@ -78,10 +77,11 @@ function getVerifyUrlPrefixes(): string[] {
// Given an input string, check if there exists a ticket verify URL within it.
// If so, return the last occurance of a verify URL. If not, return null.
export function getLastValidVerifyUrl(inputString: string): string | null {
const lastValidUrlStartIdx = chain(getVerifyUrlPrefixes())
.map((verifyUrlPrefix) => inputString.lastIndexOf(verifyUrlPrefix))
.max()
.value();
const lastValidUrlStartIdx = Math.max(
...getVerifyUrlPrefixes().map((verifyUrlPrefix) =>
inputString.lastIndexOf(verifyUrlPrefix)
)
);
if (lastValidUrlStartIdx !== -1) {
return inputString.slice(lastValidUrlStartIdx);
}
Expand Down
11 changes: 5 additions & 6 deletions apps/passport-server/src/database/queries/frogcrypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
FrogCryptoScore
} from "@pcd/passport-interface";
import { PCDPermissionType } from "@pcd/pcd-collection";
import chain from "lodash/chain";
import omit from "lodash/omit";
import unzip from "lodash/unzip";
import { Client } from "pg";
import { Pool } from "postgres-pool";
import { parseFrogEnum } from "../../util/frogcrypto";
Expand Down Expand Up @@ -191,12 +191,11 @@ export async function sampleFrogData(
pool: Pool,
biomes: FrogCryptoFeedBiomeConfigs
): Promise<FrogCryptoFrogData | undefined> {
const [biomeKeys, scalingFactors] = chain(biomes)
.toPairs()
const biomePairs = Object.entries(biomes);
const filteredPairs = biomePairs
.map(([biome, config]) => [biome, config?.dropWeightScaler])
.filter(([, scalingFactor]) => !!scalingFactor)
.unzip()
.value();
.filter(([, scalingFactor]) => !!scalingFactor);
const [biomeKeys, scalingFactors] = unzip(filteredPairs);

const result = await sqlQuery(
pool,
Expand Down

0 comments on commit 5b14489

Please sign in to comment.