Skip to content

Commit

Permalink
Remove all unused code from the sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
xbtmatt committed Dec 4, 2024
1 parent 3d7cf44 commit 5ffc857
Show file tree
Hide file tree
Showing 19 changed files with 9 additions and 334 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { startTransition, useCallback, useEffect, useRef, useState } from "react
import { useSearchParams } from "next/navigation";
import { getEmojisInString } from "@sdk/emoji_data";
import { useAptos } from "context/wallet-context/AptosContextProvider";
import { revalidateTagAction } from "lib/queries/cache-utils/revalidate";
import { TAGS } from "lib/queries/cache-utils/tags";
import { ROUTES } from "router/routes";
import { useRouter } from "next/navigation";
import path from "path";
Expand Down Expand Up @@ -69,14 +67,6 @@ const ClientLaunchEmojicoinPage = () => {
const handleLoading = useCallback(async () => {
const marketRegistrationEvent = lastResponse.current;
if (marketRegistrationEvent) {
// NOTE: revalidateTagAction may cause a flicker in the loading animation because the server
// rerenders and sends the RSC components again. To avoid this we'll probably need to finish the animation
// orchestration with a different animation or cover it up somehow, otherwise I'm not sure how to fix it in a
// clean way.

// Revalidate the registered markets tag.
revalidateTagAction(TAGS.RegisteredMarkets);

startTransition(() => {
// Parse the emojis from the market registration event.
// We do this in case the emojis are somehow cleared before the response is received. This ensures that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
import { useEventStore } from "context/event-store-context";
import { type TypeTagInput } from "@sdk/emojicoin_dot_fun";
import { DEFAULT_TOAST_CONFIG } from "const";
import { sleep, UnitOfTime } from "@sdk/utils";
import { sleep } from "@sdk/utils";
import { useWalletBalance } from "lib/hooks/queries/use-wallet-balance";
import {
getAptBalanceFromChanges,
Expand Down Expand Up @@ -217,9 +217,7 @@ export function AptosContextProvider({ children }: PropsWithChildren) {
error: null,
});
setLastResponseStoredAt(Date.now());
sleep(DEFAULT_TOAST_CONFIG.autoClose, UnitOfTime.Milliseconds).then(() => {
setStatus("idle");
});
sleep(DEFAULT_TOAST_CONFIG.autoClose).then(() => setStatus("idle"));
}
} catch (e: unknown) {
if (e instanceof AptosApiError) {
Expand Down
5 changes: 2 additions & 3 deletions src/typescript/frontend/src/lib/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ export type Links = {

const network = process.env.NEXT_PUBLIC_APTOS_NETWORK;
const APTOS_NETWORK = network as Network;
// NOTE: We must check it this way instead of with `NetworkToNetworkName[APTOS_NETWORK]` because
// otherwise the @aptos-labs/ts-sdk package is included in the middleware.ts function and the edge
// runtime won't build properly.
// NOTE: Don't use `NetworkToNetworkName[APTOS_NETWORK]` here or the @aptos-labs/ts-sdk package is
// included in the middleware.ts function in the frontend and the edge runtime won't build properly.
if (!["local", "devnet", "testnet", "mainnet", "custom"].includes(APTOS_NETWORK)) {
throw new Error(`Invalid network: ${network}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import { useAptos } from "context/wallet-context/AptosContextProvider";
import { useEffect, useMemo, useState } from "react";

// -------------------------------------------------------------------------------------------------
//
// Utilities for calculating the number of seconds left.
//
// -------------------------------------------------------------------------------------------------
const nowSeconds = () => Math.floor(new Date().getTime() / 1000);

Expand All @@ -26,9 +24,7 @@ const formattedTimeLeft = (secondsRemaining: number) => {
};

// -------------------------------------------------------------------------------------------------
//
// Hook to force the component to re-render on an interval basis.
//
// -------------------------------------------------------------------------------------------------
const useDisplayTimeLeft = (marketRegistrationTime?: bigint) => {
const [timeLeft, setTimeLeft] = useState<ReturnType<typeof formattedTimeLeft>>();
Expand All @@ -51,9 +47,7 @@ const useDisplayTimeLeft = (marketRegistrationTime?: bigint) => {
};

// -------------------------------------------------------------------------------------------------
//
// `useQuery` hook that fetches the grace period status on an interval basis.
//
// -------------------------------------------------------------------------------------------------
const useGracePeriod = (symbol: string, hasSwaps: boolean) => {
const { aptos } = useAptos();
Expand All @@ -80,9 +74,7 @@ const useGracePeriod = (symbol: string, hasSwaps: boolean) => {
};

// -------------------------------------------------------------------------------------------------
//
// The actual hook to be used in a component to display the amount of seconds left.
//
// -------------------------------------------------------------------------------------------------
export const useCanTradeMarket = (symbol: string) => {
const { account } = useAptos();
Expand Down
4 changes: 0 additions & 4 deletions src/typescript/frontend/src/lib/queries/cache-utils/cached.ts

This file was deleted.

This file was deleted.

8 changes: 0 additions & 8 deletions src/typescript/frontend/src/lib/queries/cache-utils/tags.ts

This file was deleted.

8 changes: 0 additions & 8 deletions src/typescript/frontend/src/lib/queries/graphql/README.md

This file was deleted.

27 changes: 0 additions & 27 deletions src/typescript/frontend/src/lib/queries/initial/cache-helper.ts

This file was deleted.

31 changes: 0 additions & 31 deletions src/typescript/frontend/src/lib/queries/sorting/types.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,11 @@
import { DEFAULT_SORT_BY, SortMarketsBy } from "@sdk/indexer-v2/types/common";
import { type ORDER_BY } from "@sdk/queries/const";
import { type ValueOf } from "@sdk/utils/utility-types";

export type MarketDataSortByHomePage =
| SortMarketsBy.MarketCap
| SortMarketsBy.BumpOrder
| SortMarketsBy.DailyVolume
| SortMarketsBy.AllTimeVolume;

export type GetSortedMarketDataQueryArgs = {
limit?: number;
page: number;
orderBy: ValueOf<typeof ORDER_BY>;
sortBy: SortMarketsBy | SortByPostgrestQueryParams;
inBondingCurve?: boolean;
exactCount?: boolean;
searchBytes?: string;
};

export type GetMySortedMarketDataQueryArgs = Omit<
GetSortedMarketDataQueryArgs,
"exactCount" | "inBondingCurve"
> & {
account?: string;
};

export const sortByFilters = {
[SortMarketsBy.MarketCap]: {
forPageQueryParams: "market_cap",
Expand Down Expand Up @@ -73,18 +54,6 @@ export type SortByPostgrestQueryParams =
| "one_day_tvl_per_lp_coin_growth_q64"
| "cpamm_real_reserves_quote";

export const toPageQueryParam = (
sortBy: SortByPostgrestQueryParams | SortMarketsBy | SortByPageQueryParams
): SortByPageQueryParams => {
return sortByFilters[sortBy].forPageQueryParams ?? sortBy;
};

export const toPostgrestQueryParam = (
sortBy: SortByPageQueryParams | SortMarketsBy | SortByPostgrestQueryParams
): SortByPostgrestQueryParams => {
return sortByFilters[sortBy]?.forPostgrestQuery ?? sortBy;
};

export const toMarketDataSortBy = (
sortBy?: SortByPostgrestQueryParams | SortMarketsBy | SortByPageQueryParams
): SortMarketsBy => {
Expand Down
24 changes: 0 additions & 24 deletions src/typescript/frontend/src/lib/store/market-data.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/typescript/frontend/src/lib/utils/prettify-emoji-name.ts

This file was deleted.

16 changes: 0 additions & 16 deletions src/typescript/sdk/src/indexer-v2/queries/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import {
type PostgrestBuilder,
type PostgrestTransformBuilder,
} from "@supabase/postgrest-js";
import { type Account, type AccountAddressInput } from "@aptos-labs/ts-sdk";
import { type AnyNumberString } from "../../types/types";
import { type DatabaseJsonType, postgresTimestampToDate, TableName } from "../types/json-types";
import { toAccountAddress } from "../../utils";
import { postgrest } from "./client";
import { type DatabaseModels } from "../types";

Expand Down Expand Up @@ -203,17 +201,3 @@ export function queryHelperWithCount<

return query;
}

/**
* Strip leading zeroes from an address.
*
* @param address either the account object, an account address, or a string.
* @returns the address without any leading zeroes, still prefixed with "0x".
*
*/
/* eslint-disable-next-line import/no-unused-modules */
export const stripLeadingZeroes = <T extends Account>(address: T | AccountAddressInput) =>
// prettier-ignore
toAccountAddress(address)
.toString()
.replace(/^0x0+/, "0x");
39 changes: 0 additions & 39 deletions src/typescript/sdk/src/queries/client-utils/candlestick.ts

This file was deleted.

14 changes: 0 additions & 14 deletions src/typescript/sdk/src/queries/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,3 @@ export const toOrderBy = (input: OrderByStrings | OrderBy) => {
throw new Error(`Invalid order by value: ${input}`);
}
};

export const toOrderByString = (input: OrderByStrings | OrderBy): OrderByStrings => {
if (typeof input === "string") {
return input;
}
switch (input) {
case ORDER_BY.ASC:
return "asc";
case ORDER_BY.DESC:
return "desc";
default:
return "desc";
}
};
4 changes: 0 additions & 4 deletions src/typescript/sdk/src/utils/aptos-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import {
} from "@aptos-labs/ts-sdk";
import { sha3_256 } from "@noble/hashes/sha3";

export function toAptos(aptos: Aptos | AptosConfig): Aptos {
return aptos instanceof Aptos ? aptos : new Aptos(aptos);
}

export function toConfig(aptos: Aptos | AptosConfig): AptosConfig {
return aptos instanceof Aptos ? aptos.config : aptos;
}
Expand Down
Loading

0 comments on commit 5ffc857

Please sign in to comment.