Skip to content

Commit

Permalink
feat: remove isWSX instances, update filters to include only supporte…
Browse files Browse the repository at this point in the history
…d currencies
  • Loading branch information
robhyrk committed May 22, 2024
1 parent f782b30 commit 1b026d0
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 49 deletions.
9 changes: 1 addition & 8 deletions components/portfolio/CurrenciesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { ChainName, CHAIN_IMAGES } from "lib/constants/chains";
import TransferButton from "./TransferButton";
import { AssetId } from "@zeitgeistpm/sdk";
import { convertDecimals } from "lib/util/convert-decimals";
import { isWSX } from "lib/constants";
import { useMemo } from "react";
import { usePrevious } from "lib/hooks/usePrevious";
import { isNotNull } from "@zeitgeistpm/utility/dist/null";
Expand Down Expand Up @@ -125,16 +124,10 @@ const MoveButton = ({
};

const CurrenciesTable = ({ address }: { address: string }) => {
const { data: allBalances, isFetched } = useCurrencyBalances(address);
const { data: balances, isFetched } = useCurrencyBalances(address);
const { data: constants } = useChainConstants();
const wasFetched = usePrevious(isFetched);

const balances = useMemo(() => {
return isWSX
? allBalances?.filter((b) => b.symbol === "WSX")
: allBalances?.filter((b) => b.symbol !== "WSX");
}, [isWSX, allBalances]);

// set sort order only once when data is first fetched
// sort by balance descending, but keep sorting on subsequent renders/balance updates.
const sorting = useMemo(() => {
Expand Down
14 changes: 0 additions & 14 deletions lib/constants/foreign-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,6 @@ const BATTERY_STATION_FOREIGN_ASSET_METADATA: ForeignAssetMetadata = {
coinGeckoId: "polkadot",
tokenSymbol: "ROC",
},
3: {
//todo: add WSX logo
image: "/currencies/ausd.jpg",
withdrawSupported: false,
coinGeckoId: "polkadot",
tokenSymbol: "WSX",
},
4: {
//todo: add NTT logo
image: "/currencies/ausd.jpg",
withdrawSupported: false,
coinGeckoId: "polkadot",
tokenSymbol: "NTT",
},
};

const PROD_FOREIGN_ASSET_METADATA: ForeignAssetMetadata = {
Expand Down
9 changes: 4 additions & 5 deletions lib/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import resolveTailwindConfig from "tailwindcss/resolveConfig";
import tailwindConfig from "../../tailwind.config";
import { EndpointOption, Environment } from "../types";

// IMPORTANT: this should be false for all other branches other than the wsx branch.
export const isWSX = false;

export const wsxID = process.env.NEXT_PUBLIC_VERCEL_ENV === "staging" ? 3 : 2;
export const wsxAssetIdString = `{"foreignAsset":${wsxID}}`;
//for campaign assets
export const campaignAssetID =
process.env.NEXT_PUBLIC_VERCEL_ENV === "staging" ? 0 : 0; //may need to change ID on mainnet
export const campaignAssetIdString = `{"foreignAsset":${campaignAssetID}}`;

export const ZTG = 10 ** 10;

Expand Down
12 changes: 12 additions & 0 deletions lib/constants/supported-currencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ export const supportedCurrencies = [
} satisfies CurrencyMetadata,
] as const;

export const supportedCurrenciesFilter = supportedCurrencies.map((currency) => {
const assetKey = Object.keys(currency.assetId)[0];
const assetValue = currency.assetId[assetKey];
return assetValue === null ? assetKey : `{ "${assetKey}": ${assetValue} }`;
});

export const supportedCurrenciesFilterString = `[${supportedCurrenciesFilter
.map((item) => {
return `"${item.replace(/"/g, '\\"')}"`;

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding High

This does not escape backslash characters in the input.
})
.join(", ")}]`;

export type SupportedCurrencyTag = Unpacked<
typeof supportedCurrencies
>[number]["name"];
Expand Down
6 changes: 2 additions & 4 deletions lib/gql/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { isWSX, wsxID } from "lib/constants";
import { supportedCurrenciesFilterString } from "lib/constants/supported-currencies";

export const marketMetaFilter = isWSX
? `question_not_eq: "", question_isNull: false, categories_isNull: false, hasValidMetaCategories_eq: true, scoringRule_not_eq: Parimutuel, baseAsset_eq: "{\\"foreignAsset\\":${wsxID}}"`
: `question_not_eq: "", question_isNull: false, categories_isNull: false, hasValidMetaCategories_eq: true, scoringRule_not_eq: Parimutuel, baseAsset_not_eq: "{\\"foreignAsset\\":${wsxID}}"`;
export const marketMetaFilter = `question_not_eq: "", question_isNull: false, categories_isNull: false, hasValidMetaCategories_eq: true, scoringRule_not_eq: Parimutuel, baseAsset_in: ${supportedCurrenciesFilterString}`;
15 changes: 3 additions & 12 deletions lib/hooks/queries/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,16 @@ import {
MarketWhereInput,
HistoricalSwapWhereInput,
} from "@zeitgeistpm/indexer";
import { isWSX, wsxAssetIdString, wsxID } from "lib/constants";
import { supportedCurrenciesFilter } from "../../constants/supported-currencies";

export const marketMetaFilter: MarketWhereInput = {
question_isNull: false,
question_not_eq: "",
categories_isNull: false,
hasValidMetaCategories_eq: true,
...(isWSX ? { baseAsset_eq: wsxAssetIdString } : {}),
...(!isWSX ? { baseAsset_not_eq: wsxAssetIdString } : {}),
baseAsset_in: supportedCurrenciesFilter,
};

export const swapsMetaFilter: HistoricalSwapWhereInput = {
...(isWSX
? {
assetIn_eq: wsxAssetIdString,
assetOut_eq: wsxAssetIdString,
}
: {
assetIn_not_eq: wsxAssetIdString,
assetOut_not_eq: wsxAssetIdString,
}),
assetIn_in: supportedCurrenciesFilter,
};
7 changes: 4 additions & 3 deletions lib/hooks/queries/useInfiniteMarkets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { FullCmsMarketMetadata } from "lib/cms/markets";
import { marketCmsDatakeyForMarket } from "./cms/useMarketCmsMetadata";
import { marketMetaFilter } from "./constants";
import { marketsRootQuery } from "./useMarket";
import { supportedCurrenciesFilter } from "../../constants/supported-currencies";

import { tryCatch } from "@zeitgeistpm/utility/dist/either";
import { WHITELISTED_TRUSTED_CREATORS } from "lib/constants/whitelisted-trusted-creators";

export const rootKey = "markets-filtered";
Expand Down Expand Up @@ -68,7 +68,7 @@ export const useInfiniteMarkets = (
const statuses = filters.status as MarketStatus[];
const tags = filters.tag;
const currencies = filters.currency;

console.log(currencies);
const markets: Market<IndexerContext>[] = await sdk.model.markets.list({
where: {
AND: [
Expand All @@ -77,7 +77,8 @@ export const useInfiniteMarkets = (
status_not_in: [MarketStatus.Destroyed],
status_in: statuses.length === 0 ? undefined : statuses,
tags_containsAny: tags?.length === 0 ? undefined : tags,
baseAsset_in: currencies?.length !== 0 ? currencies : undefined,
baseAsset_in:
currencies?.length !== 0 ? currencies : supportedCurrenciesFilter,
scoringRule_not_eq: ScoringRule.Parimutuel,
},
{
Expand Down
5 changes: 2 additions & 3 deletions lib/hooks/queries/useMarketSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { useQuery } from "@tanstack/react-query";
import { MarketOrderByInput, ZeitgeistIndexer } from "@zeitgeistpm/indexer";
import { isIndexedSdk } from "@zeitgeistpm/sdk";
import Fuse from "fuse.js";
import { isWSX, wsxID } from "lib/constants";
import { useDebounce } from "use-debounce";
import { useSdkv2 } from "../useSdkv2";
import { supportedCurrenciesFilter } from "lib/constants/supported-currencies";

export const marketSearchKey = "market-search";

Expand Down Expand Up @@ -41,8 +41,7 @@ export const searchMarketsText = async (
where: {
AND: [
{
baseAsset_eq: isWSX ? `{"foreignAsset":${wsxID}}` : undefined,
baseAsset_not_eq: !isWSX ? `{"foreignAsset":${wsxID}}` : undefined,
baseAsset_in: supportedCurrenciesFilter,
},
{
OR: search,
Expand Down

0 comments on commit 1b026d0

Please sign in to comment.