Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update filters for supported currencies only #2425

Open
wants to merge 3 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 10 additions & 0 deletions lib/constants/supported-currencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ 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.charAt(0).toLowerCase()}${assetKey.slice(
1,
)}": ${assetValue} }`;
});

export type SupportedCurrencyTag = Unpacked<
typeof supportedCurrencies
>[number]["name"];
Expand Down
8 changes: 4 additions & 4 deletions lib/gql/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isWSX, wsxID } from "lib/constants";
import { supportedCurrenciesFilter } 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: ${JSON.stringify(
supportedCurrenciesFilter,
)}`;
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,
};
5 changes: 3 additions & 2 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 @@ -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
Loading