Skip to content

Commit

Permalink
remove isLoading from hooks and move any logic possible to view compo…
Browse files Browse the repository at this point in the history
…nents
  • Loading branch information
Pandelis Symeonidis committed Nov 29, 2023
1 parent 10107ea commit 3ef02c5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 42 deletions.
3 changes: 3 additions & 0 deletions frontend/src/pages/sell/character-sell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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 @@ -14,6 +15,7 @@ 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 });
Expand All @@ -23,6 +25,7 @@ export const CharacterSell = () => {
// Currently calling this logic on settled due to an issue with the status returned by the sell method,
// TODO: move this logic to a more specific callback
setIsPlacedInShop(true);
userDispatch({ type: "SET_SELECTED", payload: "" });
},
};

Expand Down
15 changes: 0 additions & 15 deletions frontend/src/service/character.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ export const useSellCharacter = (characterId: number) => {
const [service] = useAgoricContext();
const wallet = useWalletState();
const [characters] = useMyCharacters();
const userDispatch = useUserStateDispatch();
const [isLoading, setIsLoading] = useState(false);
const instance = service.contracts.kread.instance;
const charBrand = service.tokenInfo.character.brand;
Expand All @@ -195,10 +194,6 @@ export const useSellCharacter = (characterId: number) => {
},
callback: {
...callback,
settled: () => {
if (callback.settled) callback.settled();
userDispatch({ type: "SET_SELECTED", payload: "" });
},
setIsLoading: setIsLoading
}
});
Expand Down Expand Up @@ -243,16 +238,6 @@ export const useBuyCharacter = (characterId: string) => {
},
callback: {
...callback,
refunded: () => {
console.info("BuyCharacter call settled");
if (callback.refunded) callback.refunded();
setIsLoading(false);
},
accepted: () => {
console.info("BuyCharacter call settled");
if (callback.accepted) callback.accepted();
setIsLoading(false);
},
setIsLoading: setIsLoading,
},
});
Expand Down
29 changes: 2 additions & 27 deletions frontend/src/service/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,6 @@ export const useSellItem = (itemName: string | undefined, itemCategory: Category
},
callback: {
...callback,
seated: () => {
console.info("SellItem call settled");
if (callback.seated) callback.seated();
setIsLoading(false);
},
setIsLoading: setIsLoading
}
});
Expand Down Expand Up @@ -214,16 +209,6 @@ export const useBuyItem = (itemToBuy: ItemInMarket | undefined) => {
},
callback: {
...callback,
refunded: () => {
console.info("BuyItem call settled");
if (callback.refunded) callback.refunded();
setIsLoading(false);
},
accepted: () => {
console.info("BuyItem call settled");
if (callback.accepted) callback.accepted();
setIsLoading(false);
},
setIsLoading: setIsLoading
}
});
Expand Down Expand Up @@ -273,10 +258,6 @@ export const useEquipItem = () => {
},
callback: {
...body.callback,
seated: () => {
console.info("Swap call settled");
if (body.callback.seated) body.callback.seated();
},
settled: () => {
setTimeout(() => userStateDispatch({ type: "END_INVENTORY_CALL" }), INVENTORY_CALL_FETCH_DELAY);
}
Expand All @@ -294,11 +275,8 @@ export const useEquipItem = () => {
},
callback: {
...body.callback,
seated: () => {
console.info("Equip call settled");
if (body.callback.seated) body.callback.seated();
},
settled: () => {
if (body.callback.settled) body.callback.settled();
setTimeout(() => userStateDispatch({ type: "END_INVENTORY_CALL" }), INVENTORY_CALL_FETCH_DELAY);
}
},
Expand Down Expand Up @@ -337,11 +315,8 @@ export const useUnequipItem = () => {
},
callback: {
...body.callback,
seated: () => {
console.info("Unequip call settled");
if (body.callback.seated) body.callback.seated();
},
settled: () => {
if (body.callback.settled) body.callback.settled();
setTimeout(() => userStateDispatch({ type: "END_INVENTORY_CALL" }), INVENTORY_CALL_FETCH_DELAY);
}
}
Expand Down

0 comments on commit 3ef02c5

Please sign in to comment.