From 44196a4856678892acc3df00ed76e1876b927623 Mon Sep 17 00:00:00 2001 From: carlos-kryha <97608823+carlos-kryha@users.noreply.github.com> Date: Wed, 18 Oct 2023 12:03:27 +0200 Subject: [PATCH] Hotfix/hair item filter (#54) This enebles us to exclude certain category/rarity combinations from the item shop. Currently excluding legendary hair items due to #53 - [x] cleaned up item-shop data - [x] added const for filtering out by `[[Category, Rarity[]]]` - [x] implemented filters in item-shop - [x] update view --------- Co-authored-by: Xabier Almazor Co-authored-by: Xabier Almazor Co-authored-by: Wietze Co-authored-by: Xabier Almazor Telek Co-authored-by: Pandelis Symeonidis Co-authored-by: Axel Verheul Co-authored-by: Pandelis Symeonidis <54764628+Pandelissym@users.noreply.github.com> --- azure-pipelines-emerynet.yml | 43 +++++++++++++ .../workloads/config/ui-config.template.yaml | 2 +- frontend/src/constants.ts | 7 +++ frontend/src/pages/shop/items-shop.tsx | 62 ++++++++++++------- 4 files changed, 90 insertions(+), 24 deletions(-) create mode 100644 azure-pipelines-emerynet.yml diff --git a/azure-pipelines-emerynet.yml b/azure-pipelines-emerynet.yml new file mode 100644 index 000000000..356a4def9 --- /dev/null +++ b/azure-pipelines-emerynet.yml @@ -0,0 +1,43 @@ +trigger: + - develop + +pool: + vmImage: "ubuntu-latest" + +stages: + - stage: build_and_deploy + displayName: Build and Deploy + dependsOn: [] + condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) + jobs: + - job: build_and_deploy + displayName: Build Docker images and deploy through Kubernetes + steps: + - script: curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64 && sudo install skaffold /usr/local/bin/ + displayName: Install Skaffold + - task: Docker@2 + displayName: Login to Container Registry + inputs: + command: login + containerRegistry: $(CONTAINER_REGISTRY_SERVICE_CONNECTION) + - task: DownloadSecureFile@1 + name: authkey + displayName: "Download Service Account Key" + inputs: + secureFile: web3-agoric.json + retryCount: "2" + - script: gcloud auth activate-service-account web3-agoric-0@web3-335312.iam.gserviceaccount.com --key-file=$(authkey.secureFilePath) + displayName: Activate Service Account + - task: Kubernetes@1 + inputs: + connectionType: "Kubernetes Service Connection" + kubernetesServiceEndpoint: "gke-service-connection" + namespace: "agoric-makefile-automation" + command: "login" + - script: | + cd frontend + export $(grep -v '^#' .env.emerynet | xargs) + envsubst < ../deployment/emerynet/workloads/config/ui-config.template.yaml > ../deployment/emerynet/workloads/config/ui-config.yaml + envsubst < skaffold.emerynet.template.yaml > skaffold.emerynet.yaml + skaffold run --filename skaffold.emerynet.yaml + displayName: Build and push docker images diff --git a/deployment/emerynet/workloads/config/ui-config.template.yaml b/deployment/emerynet/workloads/config/ui-config.template.yaml index 8dc80fbd5..993f43460 100644 --- a/deployment/emerynet/workloads/config/ui-config.template.yaml +++ b/deployment/emerynet/workloads/config/ui-config.template.yaml @@ -10,4 +10,4 @@ spec: spec: containers: - name: ui - image: "eu.gcr.io/web3-335312/kread/frontend-staging/frontend:latest" \ No newline at end of file + image: "eu.gcr.io/web3-335312/kread/frontend-staging/frontend:latest" diff --git a/frontend/src/constants.ts b/frontend/src/constants.ts index 29b684396..faee09959 100644 --- a/frontend/src/constants.ts +++ b/frontend/src/constants.ts @@ -1,3 +1,5 @@ +import { Category, Rarity } from "./interfaces"; + export const GO_BACK = -1 as const; export const BASE_URL = import.meta.env.VITE_BASE_URL || "http://localhost:5001"; export const MIN_PRICE = 0 as const; @@ -92,6 +94,11 @@ export const METRICS_CHARACTER = [ ]; export const METRICS_ITEM = ["sales", "collection size", "floor price", "avg. item price", "avg. item level", "avg. marketplace level"]; + +export const EXCLUDE_ITEMS_SHOP = [ + ["hair", ["legendary"]], +] as [[Category, Rarity[]]]; + /***************************************************************************/ export const AGORIC_LINK = "https://agoric.com/" as const; diff --git a/frontend/src/pages/shop/items-shop.tsx b/frontend/src/pages/shop/items-shop.tsx index 95db7394c..5fcf253e1 100644 --- a/frontend/src/pages/shop/items-shop.tsx +++ b/frontend/src/pages/shop/items-shop.tsx @@ -1,6 +1,6 @@ -import React, { FC, useState } from "react"; -import { METRICS_ITEM, SECTION } from "../../constants"; -import { useGetItemInShopById, useGetItemMarketMetrics, useGetItemsInShop } from "../../service"; +import React, { FC, useMemo, useState } from "react"; +import { EXCLUDE_ITEMS_SHOP, METRICS_ITEM, SECTION } from "../../constants"; +import { getRarityString, useGetItemInShopById, useGetItemMarketMetrics, useGetItemsInShop } from "../../service"; import { routes } from "../../navigation"; import { AssetItemFilters } from "../../components/asset-item-filters/asset-item-filters"; import { ItemDetailsMarket } from "../../components/asset-details/item-details-market"; @@ -12,36 +12,52 @@ import { AssetFilterCount, AssetHeader, AssetHeaderContainer } from "../../compo import { color } from "../../design"; import { MarketplaceMetrics } from "../../components/marketplace-metrics/marketplace-metrics"; import { findAverageValue, findMinimumValue, toTwoDecimals, uISTToIST } from "../../util"; +import { ItemInMarket } from "../../interfaces"; export const ItemsShop: FC = () => { const [selectedId, setSelectedId] = useState(""); const [items, fetched] = useGetItemsInShop(); const metrics = useGetItemMarketMetrics(); const [item] = useGetItemInShopById(selectedId); - const assetsCount = items.length; - let metricsData: any = []; + const filteredItems = useMemo(()=>{ + let toRemove = [] as ItemInMarket[]; + let filtered = items; + if(EXCLUDE_ITEMS_SHOP.length){ + for(const filter of EXCLUDE_ITEMS_SHOP){ + toRemove = [...toRemove, items.filter(({ item }) => filter[0] === item.category && filter[1].includes(getRarityString(item.rarity)))]; + } + filtered = items.filter((entry) => !toRemove.includes(entry)); + }; + return filtered; + }, [items]); - if (metrics) { - let itemAverage = 0; - let itemMinimum = 0; - if (items.length != 0) { - itemMinimum = findMinimumValue(items.map((x) => uISTToIST(Number(x.sell.price)))); - itemAverage = findAverageValue(items.map((x) => uISTToIST(Number(x.sell.price)))); + const metricsData = useMemo(()=>{ + if (metrics) { + let itemAverage = 0; + let itemMinimum = 0; + + if (filteredItems.length != 0) { + itemMinimum = findMinimumValue(filteredItems.map((x) => uISTToIST(Number(x.sell.price)))); + itemAverage = findAverageValue(filteredItems.map((x) => uISTToIST(Number(x.sell.price)))); + } + + return [ + metrics.amountSold, + metrics.collectionSize, + toTwoDecimals(itemMinimum), + toTwoDecimals(itemAverage), + toTwoDecimals(metrics.averageLevel), + toTwoDecimals(metrics.marketplaceAverageLevel), + ]; } + return []; + }, [filteredItems]); - metricsData = [ - metrics.amountSold, - metrics.collectionSize, - toTwoDecimals(itemMinimum), - toTwoDecimals(itemAverage), - toTwoDecimals(metrics.averageLevel), - toTwoDecimals(metrics.marketplaceAverageLevel), - ]; - } + if (!filteredItems) return <>; + const assetsCount = filteredItems.length; - if (!items) return <>; return ( <> @@ -51,8 +67,8 @@ export const ItemsShop: FC = () => { Market: {text.param.amountOfItems(assetsCount)} {selectedId && item && setSelectedId(id)} />} - {items.length > 0 ? ( - setSelectedId(id)} /> + {filteredItems.length > 0 ? ( + setSelectedId(id)} /> ) : (