Skip to content

Commit

Permalink
Hotfix/hair item filter (#54)
Browse files Browse the repository at this point in the history
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 <[email protected]>
Co-authored-by: Xabier Almazor <[email protected]>
Co-authored-by: Wietze <[email protected]>
Co-authored-by: Xabier Almazor Telek <[email protected]>
Co-authored-by: Pandelis Symeonidis <[email protected]>
Co-authored-by: Axel Verheul <[email protected]>
Co-authored-by: Pandelis Symeonidis <[email protected]>
  • Loading branch information
8 people authored Oct 18, 2023
1 parent 564d72b commit 44196a4
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 24 deletions.
43 changes: 43 additions & 0 deletions azure-pipelines-emerynet.yml
Original file line number Diff line number Diff line change
@@ -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 [email protected] --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
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ spec:
spec:
containers:
- name: ui
image: "eu.gcr.io/web3-335312/kread/frontend-staging/frontend:latest"
image: "eu.gcr.io/web3-335312/kread/frontend-staging/frontend:latest"
7 changes: 7 additions & 0 deletions frontend/src/constants.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down
62 changes: 39 additions & 23 deletions frontend/src/pages/shop/items-shop.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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<string>("");
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 (
<>
<AssetHeaderContainer>
Expand All @@ -51,8 +67,8 @@ export const ItemsShop: FC = () => {
<AssetFilterCount customColor={color.darkGrey}>Market: {text.param.amountOfItems(assetsCount)}</AssetFilterCount>
<HorizontalDivider />
{selectedId && item && <ItemDetailsMarket itemInMarket={item} selectItemInMarket={(id: string) => setSelectedId(id)} />}
{items.length > 0 ? (
<ItemCardsMarket itemsInMarket={items} isLoading={fetched} selectItemInMarketId={(id: string) => setSelectedId(id)} />
{filteredItems.length > 0 ? (
<ItemCardsMarket itemsInMarket={filteredItems} isLoading={fetched} selectItemInMarketId={(id: string) => setSelectedId(id)} />
) : (
<OverviewContainer>
<OverviewEmpty
Expand Down

0 comments on commit 44196a4

Please sign in to comment.