Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into documentation/general
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-kryha committed Dec 5, 2023
2 parents f3ca702 + a94671d commit b1035ab
Show file tree
Hide file tree
Showing 22 changed files with 234 additions and 265 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@
/.pnp.js

.env*
frontend/**
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,5 @@
"vite-plugin-svgr": "^2.2.1",
"vite-tsconfig-paths": "^3.5.0"
},
"packageManager": "yarn@4.0.0"
"packageManager": "yarn@1.22.19"
}
4 changes: 2 additions & 2 deletions frontend/src/components/asset-card/item-card-inventory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ export const ItemCardInventory: FC<Props> = ({ item, selectItem }) => {
const equipAsset = (event: React.MouseEvent<HTMLButtonElement>) => {
event.stopPropagation();
setShowToast(true);
equipItem.mutate({ item });
equipItem.mutate({ item, callback: {} });
};

const unequipAsset = (event: React.MouseEvent<HTMLButtonElement>) => {
event.stopPropagation();
setShowToast(true);
unequipItem.mutate({ item });
unequipItem.mutate({ item, callback: {} });
};

const sellAsset = (event: React.MouseEvent<HTMLButtonElement>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ export const ItemDetailsInventory: FC<ItemDetailsInventoryProps> = ({ item, sele
if (equipItem.isError || unequipItem.isError) return <ErrorView />;
const equipAsset = () => {
setShowToast(!showToast);
equipItem.mutate({ item });
equipItem.mutate({ item, callback: {} });
};

const unequipAsset = () => {
setShowToast(!showToast);
unequipItem.mutate({ item });
unequipItem.mutate({ item, callback: {} });
};

const sellAsset = () => {
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ export * from "./item-card";
export * from "./input-fields";
export * from "./switch-selector";
export * from "./navigation-tab";
export * from "./menu-card";
export * from "./menu-item";
export * from "./price-in-ist";
export * from "./base-route";
export * from "./equipped-item-card";
Expand Down
18 changes: 13 additions & 5 deletions frontend/src/components/menu-card/menu-card.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FC, useMemo, useState } from "react";
import { Item, Category } from "../../interfaces";
import { Item, Category, MakeOfferCallback } from "../../interfaces";
import { text } from "../../assets";
import {
ArrowContainer,
Expand Down Expand Up @@ -44,8 +44,16 @@ export const MenuCard: FC<MenuCardProps> = ({ title, category, equippedItemProp,
const [showToast, setShowToast] = useState(false);
const [equippedItem, setEquippedItem] = useState(equippedItemProp);

const equipItem = useEquipItem(setEquippedItem);
const unequipItem = useUnequipItem(() => setEquippedItem(undefined));
const equipItem = useEquipItem();
const unequipItem = useUnequipItem();

const handleEquipResult: MakeOfferCallback = {
accepted: setEquippedItem,
};

const handleUnequipResult: MakeOfferCallback = {
accepted: () => setEquippedItem(undefined),
};

const allItems = useMemo(() => {
if (equippedItem) return [equippedItem, ...unequippedItems];
Expand All @@ -58,14 +66,14 @@ export const MenuCard: FC<MenuCardProps> = ({ title, category, equippedItemProp,
event.stopPropagation();
setShowToast(!showToast);
if (!selectedItem) return;
equipItem.mutate({ item: selectedItem });
equipItem.mutate({ item: selectedItem, callback: handleEquipResult });
};

const unequip = (event: React.MouseEvent<HTMLButtonElement>) => {
event.stopPropagation();
setShowToast(!showToast);
if (!equippedItem) return;
unequipItem.mutate({ item: equippedItem });
unequipItem.mutate({ item: equippedItem, callback: handleUnequipResult });
};

const primaryActions = () => {
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/containers/canvas/items-mode/items-mode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ export const ItemsMode: FC = () => {
equipItem.mutate({
item: selected,
currentlyEquipped: equipped.inCategory,
callback: {},
});
}
setOnAssetChange(false);
setShowToast(!showToast);
if (!equipped.inCategory && selected) {
equipItem.mutate({ item: selected });
equipItem.mutate({ item: selected, callback: {} });
}
};

Expand All @@ -72,7 +73,7 @@ export const ItemsMode: FC = () => {
setOnAssetChange(false);
setShowToast(!showToast);
if (equipped.inCategory) {
unequipItem.mutate({ item: equipped.inCategory });
unequipItem.mutate({ item: equipped.inCategory, callback: {} });
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const ListItem: FC<ListItemProps> = ({ item, showToast }) => {

const unequip = () => {
showToast();
unequipItem.mutate({ item });
unequipItem.mutate({ item, callback: {} });
};

return (
Expand Down
21 changes: 19 additions & 2 deletions frontend/src/interfaces/agoric.interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
interface Contracts {
kread: {
instance: any;
}
};
}

interface Status {
Expand Down Expand Up @@ -65,7 +65,6 @@ interface UpdateStatus {
payload: { [key: string]: boolean };
}


interface SetOffers {
type: "SET_OFFERS";
payload: any[];
Expand Down Expand Up @@ -136,3 +135,21 @@ export interface OfferProposal {
give: any;
want: any;
}

export const OFFER_STATUS = {
error: "error",
refunded: "refunded",
accepted: "accepted",
seated: "seated"
};
export type OfferStatusType = keyof typeof OFFER_STATUS

export interface MakeOfferCallback {
accepted?: (args?: any) => void, // offer was successful
refunded?: (args?: any) => void, // strangely seems to behave the same way as accepted
error?: (args?: any) => void, // offer failed
seated?: (args?: any) => void, // returned exclusively by the KREAd sell method, likely has to do with the offer being long-lived
settled?: (args?: any) => void, // gets called when a response is received, regardless of the status
setIsLoading?: React.Dispatch<React.SetStateAction<boolean>>
};

1 change: 0 additions & 1 deletion frontend/src/interfaces/character.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,4 @@ export interface CharacterInMarketBackend {

export interface CharacterCreation {
name: string;
setError?: (error: string) => void
}
2 changes: 1 addition & 1 deletion frontend/src/pages/buy/character-buy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const CharacterBuy = () => {
const handleSubmit = async () => {
if (!id) return;
setIsAwaitingApproval(true);
await buyCharacter.callback();
await buyCharacter.sendOffer({});
};

if (isLoadingCharacter) return <LoadingPage spinner={false} />;
Expand Down
13 changes: 10 additions & 3 deletions frontend/src/pages/buy/item-buy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@ export const ItemBuy = () => {

const handleSubmit = async () => {
setIsAwaitingApproval(true);
await buyItem.callback(() => {
setIsOfferAccepted(true);
setIsAwaitingApproval(false);
await buyItem.sendOffer({
refunded: () => {
setIsOfferAccepted(true);
},
accepted: () => {
setIsOfferAccepted(true);
},
settled: () => {
setIsAwaitingApproval(false);
}
});
};

Expand Down
22 changes: 16 additions & 6 deletions frontend/src/pages/create-character/create-character.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ErrorView, FadeInOut, FormHeader, LoadingPage, NotificationDetail, Over
import { PageContainer } from "../../components/page-container";
import { MINTING_COST, MINT_CHARACTER_FLOW_STEPS, WALLET_INTERACTION_STEP } from "../../constants";
import { useIsMobile, useViewport } from "../../hooks";
import { Character, CharacterCreation } from "../../interfaces";
import { Character, CharacterCreation, MakeOfferCallback } from "../../interfaces";
import { routes } from "../../navigation";
import { useCreateCharacter } from "../../service";
import { Confirmation } from "./confirmation";
Expand Down Expand Up @@ -33,8 +33,8 @@ export const CreateCharacter: FC = () => {
const mobile = useIsMobile(breakpoints.desktop);
const { ist } = useWalletState();

const notEnoughIST = useMemo(()=>{
if(ist < MINTING_COST || !ist) {
const notEnoughIST = useMemo(() => {
if (ist < MINTING_COST || !ist) {
return true;
}
return false;
Expand All @@ -53,14 +53,24 @@ export const CreateCharacter: FC = () => {
setCurrentStep(step);
};

const handleError = (error: string) => {
const errorCallback = (error: string) => {
setError(error);
setShowToast(true);
}
};

const handleResult: MakeOfferCallback = {
error: errorCallback,
accepted: () => {
console.info("MintCharacter call settled");
}
};

const sendOfferHandler = async (): Promise<void> => {
setIsLoading(true);
await createCharacter.mutateAsync({ name: characterData.name, setError: handleError });
await createCharacter.mutateAsync({
name: characterData.name,
callback: handleResult,
});
};

const setData = async (data: CharacterCreation): Promise<void> => {
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/pages/landing/landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
Overlay,
OverviewEmpty,
PageSubTitle,
PageTitle,
SecondaryButton,
} from "../../components";
import { ButtonContainer, CharacterCardWrapper, DetailContainer, ItemCardWrapper } from "./styles";
Expand Down Expand Up @@ -64,14 +63,14 @@ export const Landing: FC = () => {
const equipAsset = () => {
setShowToast(!showToast);
if (item) {
equipItem.mutate({ item });
equipItem.mutate({ item, callback: {} });
}
};

const unequipAsset = () => {
setShowToast(!showToast);
if (item) {
unequipItem.mutate({ item });
unequipItem.mutate({ item, callback: {} });
}
};

Expand Down
13 changes: 11 additions & 2 deletions frontend/src/pages/sell/character-sell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { ErrorView } from "../../components";
import { useMyCharacter, useSellCharacter } from "../../service";
import { Sell } from "./sell";
import { SellData } from "./types";
import { MakeOfferCallback } from "../../interfaces";
import { useUserStateDispatch } from "../../context/user";

export const CharacterSell = () => {
const { id } = useParams<"id">();
Expand All @@ -13,13 +15,20 @@ export const CharacterSell = () => {
const sellCharacter = useSellCharacter(Number(idString));
const [character] = useMyCharacter(Number(idString));
const [characterCopy] = useState(character);
const userDispatch = useUserStateDispatch();

const [isPlacedInShop, setIsPlacedInShop] = useState(false);
const [data, setData] = useState<SellData>({ price: 0 });

const handleResult: MakeOfferCallback = {
seated: () => {
setIsPlacedInShop(true);
userDispatch({ type: "SET_SELECTED", payload: "" });
},
};

const sendOfferHandler = async (data: SellData) => {
if (data.price < 1) return; // We don't want to sell for free in case someone managed to fool the frontend
await sellCharacter.callback(data.price, () => setIsPlacedInShop(true));
await sellCharacter.sendOffer(data.price, handleResult);
};

const characterName = useMemo(() => character?.nft.name, [character]);
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/pages/sell/item-sell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ import { ErrorView } from "../../components";
import { useSellItem } from "../../service";
import { Sell } from "./sell";
import { SellData } from "./types";
import { Category, isItemCategory } from "../../interfaces";
import { Category, MakeOfferCallback, isItemCategory } from "../../interfaces";

export const ItemSell = () => {
const { name, category } = useParams<"category" | "name">();
const [isPlacedInShop, setIsPlacedInShop] = useState(false);
const sellItem = useSellItem(name, category as Category);
const [data, setData] = useState<SellData>({ price: 0 });

const handleResult: MakeOfferCallback = {
settled: () => setIsPlacedInShop(true),
};

const sendOfferHandler = async (data: SellData) => {
if (data.price < 1) return; // We don't want to sell for free in case someone managed to fool the frontend
await sellItem.callback(data.price, () => setIsPlacedInShop(true) );
await sellItem.sendOffer(data.price, handleResult);
};

if (!data || !isItemCategory(category)) return <ErrorView />;
Expand Down
Loading

0 comments on commit b1035ab

Please sign in to comment.