From 63d91133e57a952065cf0a4f35596849e17ba53f Mon Sep 17 00:00:00 2001 From: rashid Date: Fri, 17 Mar 2023 18:17:27 +0300 Subject: [PATCH 1/6] refactor toastify --- packages/client/src/index.tsx | 3 +- packages/client/src/mud/hooks/skill.ts | 3 +- packages/client/src/mud/utils/toast.ts | 59 ++++++++++++++++++-------- 3 files changed, 45 insertions(+), 20 deletions(-) diff --git a/packages/client/src/index.tsx b/packages/client/src/index.tsx index 8706d60..de5d612 100644 --- a/packages/client/src/index.tsx +++ b/packages/client/src/index.tsx @@ -8,7 +8,6 @@ import { MUDProvider } from "./mud/MUDContext"; import { ComponentBrowser } from "./ComponentBrowser"; import "../index.css"; import { WandererProvider } from "./contexts/WandererContext"; -import { defaultToastOptions } from "./mud/utils/toast"; const rootElement = document.getElementById("react-root"); if (!rootElement) throw new Error("React root not found"); @@ -20,7 +19,7 @@ setup().then((result) => { - + {import.meta.env.DEV ? : null} diff --git a/packages/client/src/mud/hooks/skill.ts b/packages/client/src/mud/hooks/skill.ts index 4c12d1a..eb7ba8d 100644 --- a/packages/client/src/mud/hooks/skill.ts +++ b/packages/client/src/mud/hooks/skill.ts @@ -3,6 +3,7 @@ import { EntityIndex, Has } from "@latticexyz/recs"; import { useCallback, useMemo } from "react"; import { useMUD } from "../MUDContext"; import { getSkill } from "../utils/skill"; +import { toastCalling } from "../utils/toast"; export const useSkill = (entity: EntityIndex | undefined) => { const { world, components } = useMUD(); @@ -66,7 +67,7 @@ export const useLearnCycleSkill = (wandererEntity: EntityIndex | undefined) => { world.entities[wandererEntity], world.entities[skillEntity] ); - await tx.wait(); + await toastCalling(tx.wait(), "skill learning", "skill learned"); }, [world, systems, wandererEntity] ); diff --git a/packages/client/src/mud/utils/toast.ts b/packages/client/src/mud/utils/toast.ts index bde374b..c620efb 100644 --- a/packages/client/src/mud/utils/toast.ts +++ b/packages/client/src/mud/utils/toast.ts @@ -1,18 +1,43 @@ -import { ToastContent } from "react-toastify"; +import { toast } from "react-toastify"; -export const defaultToastOptions = { - style: { - borderRadius: "0", - padding: "10px", - border: "1px solid #3c3c3c", - backgroundColor: "#252526", - }, - icon: false, - position: "bottom-right", - autoClose: 2500, - hideProgressBar: true, - closeOnClick: true, - pauseOnHover: true, - draggable: false, - theme: "dark", -} as const; +export const toastCalling = async ( + promise: Promise | (() => Promise), + loadingRender: string, + successRender: string +) => { + await toast.promise(promise, { + pending: { + style: { + borderRadius: "0", + padding: "10px", + border: "1px solid #3c3c3c", + backgroundColor: "#252526", + }, + render: loadingRender, + icon: false, + position: "bottom-right", + autoClose: 500, + closeOnClick: true, + pauseOnHover: true, + draggable: false, + theme: "dark", + }, + success: { + style: { + borderRadius: "0", + padding: "10px", + border: "1px solid #3c3c3c", + backgroundColor: "#252526", + }, + render: successRender, + icon: false, + position: "bottom-right", + autoClose: 2000, + closeOnClick: true, + pauseOnHover: true, + draggable: false, + theme: "dark", + }, + error: "error", + }); +}; From d34d18e5bc4365603b71e946c4136a703e2780fb Mon Sep 17 00:00:00 2001 From: rashid Date: Mon, 20 Mar 2023 16:50:11 +0300 Subject: [PATCH 2/6] add toastify to skills --- packages/client/index.css | 2 +- packages/client/src/mud/hooks/skill.ts | 21 ++++++++++++--------- packages/client/src/mud/utils/toast.ts | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/client/index.css b/packages/client/index.css index afc43d5..41d8723 100644 --- a/packages/client/index.css +++ b/packages/client/index.css @@ -8,6 +8,6 @@ :root { --toastify-toast-background: #343434; - --toastify-color-progress-success: #c586c0; + --toastify-color-progress-success: #343434; --toastify-text-color-dark: #969696; } diff --git a/packages/client/src/mud/hooks/skill.ts b/packages/client/src/mud/hooks/skill.ts index eb7ba8d..b774692 100644 --- a/packages/client/src/mud/hooks/skill.ts +++ b/packages/client/src/mud/hooks/skill.ts @@ -58,7 +58,7 @@ export const useLearnedSkillEntities = (targetEntity: EntityIndex | undefined) = }; export const useLearnCycleSkill = (wandererEntity: EntityIndex | undefined) => { - const { world, systems } = useMUD(); + const { world, systems, components } = useMUD(); return useCallback( async (skillEntity: EntityIndex) => { @@ -67,14 +67,15 @@ export const useLearnCycleSkill = (wandererEntity: EntityIndex | undefined) => { world.entities[wandererEntity], world.entities[skillEntity] ); - await toastCalling(tx.wait(), "skill learning", "skill learned"); + const skill = getSkill(world, components, skillEntity); + await toastCalling(tx.wait(), `learning ${skill.name}`, `${skill.name} learned`); }, - [world, systems, wandererEntity] + [world, systems, components, wandererEntity] ); }; export const usePermSkill = (wandererEntity: EntityIndex | undefined) => { - const { world, systems } = useMUD(); + const { world, systems, components } = useMUD(); return useCallback( async (skillEntity: EntityIndex) => { @@ -83,14 +84,15 @@ export const usePermSkill = (wandererEntity: EntityIndex | undefined) => { world.entities[wandererEntity], world.entities[skillEntity] ); - await tx.wait(); + const skill = getSkill(world, components, skillEntity); + await toastCalling(tx.wait(), `use ${skill.name}`, `${skill.name} used`); }, - [world, systems, wandererEntity] + [world, systems, components, wandererEntity] ); }; export const useExecuteNoncombatSkill = () => { - const { world, systems } = useMUD(); + const { world, systems, components } = useMUD(); return useCallback( async (cycleEntity: EntityIndex, skillEntity: EntityIndex) => { @@ -98,8 +100,9 @@ export const useExecuteNoncombatSkill = () => { world.entities[cycleEntity], world.entities[skillEntity] ); - await tx.wait(); + const skill = getSkill(world, components, skillEntity); + await toastCalling(tx.wait(), `use execute ${skill.name}`, `used execute ${skill.name}`); }, - [world, systems] + [world, systems, components] ); }; diff --git a/packages/client/src/mud/utils/toast.ts b/packages/client/src/mud/utils/toast.ts index c620efb..8549c65 100644 --- a/packages/client/src/mud/utils/toast.ts +++ b/packages/client/src/mud/utils/toast.ts @@ -16,7 +16,7 @@ export const toastCalling = async ( render: loadingRender, icon: false, position: "bottom-right", - autoClose: 500, + autoClose: 0, closeOnClick: true, pauseOnHover: true, draggable: false, From 6db849945a88d8af43f70303691dd9a50e8bbce1 Mon Sep 17 00:00:00 2001 From: rashid Date: Mon, 20 Mar 2023 17:15:47 +0300 Subject: [PATCH 3/6] add more toatify for Promise functions --- packages/client/src/components/info/ClaimTurnsButton.tsx | 3 ++- packages/client/src/components/info/PassTurnButton.tsx | 3 ++- packages/client/src/mud/hooks/combat.ts | 9 +++++---- packages/client/src/mud/hooks/cycle.ts | 5 +++-- packages/client/src/mud/hooks/skill.ts | 6 +++--- packages/client/src/mud/hooks/transfer.ts | 7 ++++++- packages/client/src/mud/hooks/useChangeCycleEquipment.ts | 3 ++- packages/client/src/mud/hooks/useWandererSpawn.ts | 3 ++- 8 files changed, 25 insertions(+), 14 deletions(-) diff --git a/packages/client/src/components/info/ClaimTurnsButton.tsx b/packages/client/src/components/info/ClaimTurnsButton.tsx index a6858ac..8a5131a 100644 --- a/packages/client/src/components/info/ClaimTurnsButton.tsx +++ b/packages/client/src/components/info/ClaimTurnsButton.tsx @@ -2,6 +2,7 @@ import { useCallback, useState } from "react"; import { useWandererContext } from "../../contexts/WandererContext"; import { useMUD } from "../../mud/MUDContext"; import CustomButton from "../UI/Button/CustomButton"; +import { toastCalling } from "../../mud/utils/toast"; export default function ClaimTurnsButton({ claimableTurns }: { claimableTurns: number }) { const { world, systems } = useMUD(); @@ -14,7 +15,7 @@ export default function ClaimTurnsButton({ claimableTurns }: { claimableTurns: n } setIsBusy(true); const tx = await systems["system.ClaimCycleTurns"].executeTyped(world.entities[selectedWandererEntity]); - await tx.wait(); + await toastCalling(tx.wait(), `Claim Turns `, `Claimed Turns `); setIsBusy(false); }, [world, systems, selectedWandererEntity]); diff --git a/packages/client/src/components/info/PassTurnButton.tsx b/packages/client/src/components/info/PassTurnButton.tsx index f16cccf..289653e 100644 --- a/packages/client/src/components/info/PassTurnButton.tsx +++ b/packages/client/src/components/info/PassTurnButton.tsx @@ -3,6 +3,7 @@ import { useWandererContext } from "../../contexts/WandererContext"; import { useCycleTurns } from "../../mud/hooks/turns"; import { useMUD } from "../../mud/MUDContext"; import CustomButton from "../UI/Button/CustomButton"; +import { toastCalling } from "../../mud/utils/toast"; export default function PassTurnButton() { const { world, systems } = useMUD(); @@ -16,7 +17,7 @@ export default function PassTurnButton() { if (selectedWandererEntity === undefined) throw new Error("No wanderer selected"); setIsBusy(true); const tx = await systems["system.PassCycleTurn"].executeTyped(world.entities[selectedWandererEntity]); - await tx.wait(); + await toastCalling(tx.wait(), `Pass turn... `, `Turn is passed`); setIsBusy(false); }, [world, systems, selectedWandererEntity]); diff --git a/packages/client/src/mud/hooks/combat.ts b/packages/client/src/mud/hooks/combat.ts index 245b994..74df108 100644 --- a/packages/client/src/mud/hooks/combat.ts +++ b/packages/client/src/mud/hooks/combat.ts @@ -14,6 +14,7 @@ import { useMUD } from "../MUDContext"; import { useEntityQuery } from "../useEntityQuery"; import { CombatAction } from "../utils/combat"; import { parsePStats } from "../utils/experience"; +import { toastCalling } from "../utils/toast"; export const useActiveCombat = (entity: EntityIndex | undefined) => { const mud = useMUD(); @@ -41,7 +42,7 @@ export const useActivateCycleCombat = () => { world.entities[wandererEntity], world.entities[mapEntity] ); - await tx.wait(); + await toastCalling(tx.wait(), `Activate map...`, `Map is active`); }, [world, systems] ); @@ -53,7 +54,7 @@ export const useExecuteCycleCombatRound = () => { return useCallback( async (wandererEntity: EntityIndex, actions: CombatAction[]) => { const tx = await systems["system.CycleCombat"].executeTyped(world.entities[wandererEntity], actions); - await tx.wait(); + await toastCalling(tx.wait(), `Execute cycle combat round..`, `Combat!`); }, [world, systems] ); @@ -68,7 +69,7 @@ export const useClaimCycleCombatReward = () => { world.entities[wandererEntity], world.entities[requestEntity] ); - await tx.wait(); + await toastCalling(tx.wait(), `Claim combat reward...`, `Claim is rewarded!`); }, [world, systems] ); @@ -83,7 +84,7 @@ export const useCancelCycleCombatReward = () => { world.entities[wandererEntity], world.entities[requestEntity] ); - await tx.wait(); + await toastCalling(tx.wait(), `Cancel claim combat reward...`, `Claim is cancelled!`); }, [world, systems] ); diff --git a/packages/client/src/mud/hooks/cycle.ts b/packages/client/src/mud/hooks/cycle.ts index b36964b..40d2b29 100644 --- a/packages/client/src/mud/hooks/cycle.ts +++ b/packages/client/src/mud/hooks/cycle.ts @@ -1,6 +1,7 @@ import { EntityID, EntityIndex } from "@latticexyz/recs"; import { useCallback, useEffect } from "react"; import { useMUD } from "../MUDContext"; +import { toastCalling } from "../utils/toast"; export const useCompleteCycle = (wandererEntity: EntityIndex | undefined) => { const { world, systems } = useMUD(); @@ -10,7 +11,7 @@ export const useCompleteCycle = (wandererEntity: EntityIndex | undefined) => { const tx = await systems["system.CompleteCycle"].executeTyped(world.entities[wandererEntity], { gasLimit: 5000000, }); - await tx.wait(); + await toastCalling(tx.wait(), `Cycle complete... `, `Cycle completed! `); }, [world, systems, wandererEntity]); }; @@ -26,7 +27,7 @@ export const useStartCycle = (wandererEntity: EntityIndex | undefined) => { world.entities[wheelEntity], { gasLimit: 30000000 } ); - await tx.wait(); + await toastCalling(tx.wait(), `Starts cycle... `, `Cycle started!`); }, [world, systems, wandererEntity] ); diff --git a/packages/client/src/mud/hooks/skill.ts b/packages/client/src/mud/hooks/skill.ts index b774692..8b2a888 100644 --- a/packages/client/src/mud/hooks/skill.ts +++ b/packages/client/src/mud/hooks/skill.ts @@ -68,7 +68,7 @@ export const useLearnCycleSkill = (wandererEntity: EntityIndex | undefined) => { world.entities[skillEntity] ); const skill = getSkill(world, components, skillEntity); - await toastCalling(tx.wait(), `learning ${skill.name}`, `${skill.name} learned`); + await toastCalling(tx.wait(), `Learning ${skill.name}`, `${skill.name} learned!`); }, [world, systems, components, wandererEntity] ); @@ -85,7 +85,7 @@ export const usePermSkill = (wandererEntity: EntityIndex | undefined) => { world.entities[skillEntity] ); const skill = getSkill(world, components, skillEntity); - await toastCalling(tx.wait(), `use ${skill.name}`, `${skill.name} used`); + await toastCalling(tx.wait(), `Use ${skill.name}`, `${skill.name} used`); }, [world, systems, components, wandererEntity] ); @@ -101,7 +101,7 @@ export const useExecuteNoncombatSkill = () => { world.entities[skillEntity] ); const skill = getSkill(world, components, skillEntity); - await toastCalling(tx.wait(), `use execute ${skill.name}`, `used execute ${skill.name}`); + await toastCalling(tx.wait(), `Use execute ${skill.name}`, `Execute ${skill.name} is a used`); }, [world, systems, components] ); diff --git a/packages/client/src/mud/hooks/transfer.ts b/packages/client/src/mud/hooks/transfer.ts index f720367..167bc99 100644 --- a/packages/client/src/mud/hooks/transfer.ts +++ b/packages/client/src/mud/hooks/transfer.ts @@ -1,6 +1,7 @@ import { EntityID } from "@latticexyz/recs"; import { useCallback } from "react"; import { useMUD } from "../../mud/MUDContext"; +import { toastCalling } from "../utils/toast"; export default function useTransferFrom() { const { systems, playerEntityId } = useMUD(); @@ -8,7 +9,11 @@ export default function useTransferFrom() { return useCallback( async (toPlayerEntityId: string, tokenId: EntityID) => { const tx = await systems["system.WNFT"].transferFrom(playerEntityId, toPlayerEntityId, tokenId); - await tx.wait(); + await toastCalling( + tx.wait(), + `Transfer for ${toPlayerEntityId}..`, + `The transfer for ${toPlayerEntityId} is completed` + ); }, [systems, playerEntityId] ); diff --git a/packages/client/src/mud/hooks/useChangeCycleEquipment.ts b/packages/client/src/mud/hooks/useChangeCycleEquipment.ts index 8aecbc4..5d88c47 100644 --- a/packages/client/src/mud/hooks/useChangeCycleEquipment.ts +++ b/packages/client/src/mud/hooks/useChangeCycleEquipment.ts @@ -2,6 +2,7 @@ import { EntityIndex } from "@latticexyz/recs"; import { useCallback } from "react"; import { useWandererContext } from "../../contexts/WandererContext"; import { useMUD } from "../MUDContext"; +import { toastCalling } from "../utils/toast"; export enum EquipmentAction { UNEQUIP, @@ -26,7 +27,7 @@ export const useChangeCycleEquipment = () => { equipmentSlotId, equipmentEntityId ); - await tx.wait(); + await toastCalling(tx.wait(), `Сhange equipment`, `Equipment changed`); }, [world, systems, selectedWandererEntity] ); diff --git a/packages/client/src/mud/hooks/useWandererSpawn.ts b/packages/client/src/mud/hooks/useWandererSpawn.ts index 01a1625..af123cf 100644 --- a/packages/client/src/mud/hooks/useWandererSpawn.ts +++ b/packages/client/src/mud/hooks/useWandererSpawn.ts @@ -1,6 +1,7 @@ import { EntityIndex } from "@latticexyz/recs"; import { useCallback } from "react"; import { useMUD } from "../MUDContext"; +import { toastCalling } from "../utils/toast"; export const useWandererSpawn = () => { const { world, systems } = useMUD(); @@ -8,7 +9,7 @@ export const useWandererSpawn = () => { return useCallback( async (guiseProtoEntity: EntityIndex) => { const tx = await systems["system.WandererSpawn"].executeTyped(world.entities[guiseProtoEntity]); - await tx.wait(); + await toastCalling(tx.wait(), `Generate Wanderer..`, `Wanderer generated`); }, [world, systems] ); From a75175a072ed2d0dfdc484317dc0ac7b1a1782f8 Mon Sep 17 00:00:00 2001 From: rashid Date: Mon, 20 Mar 2023 17:17:53 +0300 Subject: [PATCH 4/6] change color text and change padding for wanderer --- packages/client/index.css | 2 +- packages/client/src/components/Wanderer/index.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/client/index.css b/packages/client/index.css index 41d8723..47c11e8 100644 --- a/packages/client/index.css +++ b/packages/client/index.css @@ -9,5 +9,5 @@ :root { --toastify-toast-background: #343434; --toastify-color-progress-success: #343434; - --toastify-text-color-dark: #969696; + --toastify-text-color-dark: #cccccc; } diff --git a/packages/client/src/components/Wanderer/index.tsx b/packages/client/src/components/Wanderer/index.tsx index 332b8ba..9359d6e 100644 --- a/packages/client/src/components/Wanderer/index.tsx +++ b/packages/client/src/components/Wanderer/index.tsx @@ -7,7 +7,7 @@ export default function Wanderer({ wandererEntity }: { wandererEntity: EntityInd const { selectedWandererEntity, selectWandererEntity } = useWandererContext(); return ( -
+
{wandererEntity === selectedWandererEntity && ( From d4738458af80fa21a4343afba1253f59793b2395 Mon Sep 17 00:00:00 2001 From: rashid Date: Mon, 20 Mar 2023 17:37:03 +0300 Subject: [PATCH 5/6] rename toast function --- .../client/src/components/info/ClaimTurnsButton.tsx | 4 ++-- packages/client/src/components/info/PassTurnButton.tsx | 4 ++-- packages/client/src/mud/hooks/combat.ts | 10 +++++----- packages/client/src/mud/hooks/cycle.ts | 6 +++--- packages/client/src/mud/hooks/skill.ts | 8 ++++---- packages/client/src/mud/hooks/transfer.ts | 4 ++-- .../client/src/mud/hooks/useChangeCycleEquipment.ts | 4 ++-- packages/client/src/mud/hooks/useWandererSpawn.ts | 4 ++-- packages/client/src/mud/utils/toast.ts | 2 +- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/packages/client/src/components/info/ClaimTurnsButton.tsx b/packages/client/src/components/info/ClaimTurnsButton.tsx index 8a5131a..5e18758 100644 --- a/packages/client/src/components/info/ClaimTurnsButton.tsx +++ b/packages/client/src/components/info/ClaimTurnsButton.tsx @@ -2,7 +2,7 @@ import { useCallback, useState } from "react"; import { useWandererContext } from "../../contexts/WandererContext"; import { useMUD } from "../../mud/MUDContext"; import CustomButton from "../UI/Button/CustomButton"; -import { toastCalling } from "../../mud/utils/toast"; +import { toastPromise } from "../../mud/utils/toast"; export default function ClaimTurnsButton({ claimableTurns }: { claimableTurns: number }) { const { world, systems } = useMUD(); @@ -15,7 +15,7 @@ export default function ClaimTurnsButton({ claimableTurns }: { claimableTurns: n } setIsBusy(true); const tx = await systems["system.ClaimCycleTurns"].executeTyped(world.entities[selectedWandererEntity]); - await toastCalling(tx.wait(), `Claim Turns `, `Claimed Turns `); + await toastPromise(tx.wait(), `Claim Turns `, `Claimed Turns `); setIsBusy(false); }, [world, systems, selectedWandererEntity]); diff --git a/packages/client/src/components/info/PassTurnButton.tsx b/packages/client/src/components/info/PassTurnButton.tsx index 289653e..d9210e8 100644 --- a/packages/client/src/components/info/PassTurnButton.tsx +++ b/packages/client/src/components/info/PassTurnButton.tsx @@ -3,7 +3,7 @@ import { useWandererContext } from "../../contexts/WandererContext"; import { useCycleTurns } from "../../mud/hooks/turns"; import { useMUD } from "../../mud/MUDContext"; import CustomButton from "../UI/Button/CustomButton"; -import { toastCalling } from "../../mud/utils/toast"; +import { toastPromise } from "../../mud/utils/toast"; export default function PassTurnButton() { const { world, systems } = useMUD(); @@ -17,7 +17,7 @@ export default function PassTurnButton() { if (selectedWandererEntity === undefined) throw new Error("No wanderer selected"); setIsBusy(true); const tx = await systems["system.PassCycleTurn"].executeTyped(world.entities[selectedWandererEntity]); - await toastCalling(tx.wait(), `Pass turn... `, `Turn is passed`); + await toastPromise(tx.wait(), `Pass turn... `, `Turn is passed`); setIsBusy(false); }, [world, systems, selectedWandererEntity]); diff --git a/packages/client/src/mud/hooks/combat.ts b/packages/client/src/mud/hooks/combat.ts index 74df108..276ab9e 100644 --- a/packages/client/src/mud/hooks/combat.ts +++ b/packages/client/src/mud/hooks/combat.ts @@ -14,7 +14,7 @@ import { useMUD } from "../MUDContext"; import { useEntityQuery } from "../useEntityQuery"; import { CombatAction } from "../utils/combat"; import { parsePStats } from "../utils/experience"; -import { toastCalling } from "../utils/toast"; +import { toastPromise } from "../utils/toast"; export const useActiveCombat = (entity: EntityIndex | undefined) => { const mud = useMUD(); @@ -42,7 +42,7 @@ export const useActivateCycleCombat = () => { world.entities[wandererEntity], world.entities[mapEntity] ); - await toastCalling(tx.wait(), `Activate map...`, `Map is active`); + await toastPromise(tx.wait(), `Activate map...`, `Map is active`); }, [world, systems] ); @@ -54,7 +54,7 @@ export const useExecuteCycleCombatRound = () => { return useCallback( async (wandererEntity: EntityIndex, actions: CombatAction[]) => { const tx = await systems["system.CycleCombat"].executeTyped(world.entities[wandererEntity], actions); - await toastCalling(tx.wait(), `Execute cycle combat round..`, `Combat!`); + await toastPromise(tx.wait(), `Execute cycle combat round..`, `Combat!`); }, [world, systems] ); @@ -69,7 +69,7 @@ export const useClaimCycleCombatReward = () => { world.entities[wandererEntity], world.entities[requestEntity] ); - await toastCalling(tx.wait(), `Claim combat reward...`, `Claim is rewarded!`); + await toastPromise(tx.wait(), `Claim combat reward...`, `Claim is rewarded!`); }, [world, systems] ); @@ -84,7 +84,7 @@ export const useCancelCycleCombatReward = () => { world.entities[wandererEntity], world.entities[requestEntity] ); - await toastCalling(tx.wait(), `Cancel claim combat reward...`, `Claim is cancelled!`); + await toastPromise(tx.wait(), `Cancel claim combat reward...`, `Claim is cancelled!`); }, [world, systems] ); diff --git a/packages/client/src/mud/hooks/cycle.ts b/packages/client/src/mud/hooks/cycle.ts index 40d2b29..527a2a7 100644 --- a/packages/client/src/mud/hooks/cycle.ts +++ b/packages/client/src/mud/hooks/cycle.ts @@ -1,7 +1,7 @@ import { EntityID, EntityIndex } from "@latticexyz/recs"; import { useCallback, useEffect } from "react"; import { useMUD } from "../MUDContext"; -import { toastCalling } from "../utils/toast"; +import { toastPromise } from "../utils/toast"; export const useCompleteCycle = (wandererEntity: EntityIndex | undefined) => { const { world, systems } = useMUD(); @@ -11,7 +11,7 @@ export const useCompleteCycle = (wandererEntity: EntityIndex | undefined) => { const tx = await systems["system.CompleteCycle"].executeTyped(world.entities[wandererEntity], { gasLimit: 5000000, }); - await toastCalling(tx.wait(), `Cycle complete... `, `Cycle completed! `); + await toastPromise(tx.wait(), `Cycle complete... `, `Cycle completed! `); }, [world, systems, wandererEntity]); }; @@ -27,7 +27,7 @@ export const useStartCycle = (wandererEntity: EntityIndex | undefined) => { world.entities[wheelEntity], { gasLimit: 30000000 } ); - await toastCalling(tx.wait(), `Starts cycle... `, `Cycle started!`); + await toastPromise(tx.wait(), `Starts cycle... `, `Cycle started!`); }, [world, systems, wandererEntity] ); diff --git a/packages/client/src/mud/hooks/skill.ts b/packages/client/src/mud/hooks/skill.ts index 8b2a888..183adbd 100644 --- a/packages/client/src/mud/hooks/skill.ts +++ b/packages/client/src/mud/hooks/skill.ts @@ -3,7 +3,7 @@ import { EntityIndex, Has } from "@latticexyz/recs"; import { useCallback, useMemo } from "react"; import { useMUD } from "../MUDContext"; import { getSkill } from "../utils/skill"; -import { toastCalling } from "../utils/toast"; +import { toastPromise } from "../utils/toast"; export const useSkill = (entity: EntityIndex | undefined) => { const { world, components } = useMUD(); @@ -68,7 +68,7 @@ export const useLearnCycleSkill = (wandererEntity: EntityIndex | undefined) => { world.entities[skillEntity] ); const skill = getSkill(world, components, skillEntity); - await toastCalling(tx.wait(), `Learning ${skill.name}`, `${skill.name} learned!`); + await toastPromise(tx.wait(), `Learning ${skill.name}`, `${skill.name} learned!`); }, [world, systems, components, wandererEntity] ); @@ -85,7 +85,7 @@ export const usePermSkill = (wandererEntity: EntityIndex | undefined) => { world.entities[skillEntity] ); const skill = getSkill(world, components, skillEntity); - await toastCalling(tx.wait(), `Use ${skill.name}`, `${skill.name} used`); + await toastPromise(tx.wait(), `Use ${skill.name}`, `${skill.name} used`); }, [world, systems, components, wandererEntity] ); @@ -101,7 +101,7 @@ export const useExecuteNoncombatSkill = () => { world.entities[skillEntity] ); const skill = getSkill(world, components, skillEntity); - await toastCalling(tx.wait(), `Use execute ${skill.name}`, `Execute ${skill.name} is a used`); + await toastPromise(tx.wait(), `Use execute ${skill.name}`, `Execute ${skill.name} is a used`); }, [world, systems, components] ); diff --git a/packages/client/src/mud/hooks/transfer.ts b/packages/client/src/mud/hooks/transfer.ts index 167bc99..25a1470 100644 --- a/packages/client/src/mud/hooks/transfer.ts +++ b/packages/client/src/mud/hooks/transfer.ts @@ -1,7 +1,7 @@ import { EntityID } from "@latticexyz/recs"; import { useCallback } from "react"; import { useMUD } from "../../mud/MUDContext"; -import { toastCalling } from "../utils/toast"; +import { toastPromise } from "../utils/toast"; export default function useTransferFrom() { const { systems, playerEntityId } = useMUD(); @@ -9,7 +9,7 @@ export default function useTransferFrom() { return useCallback( async (toPlayerEntityId: string, tokenId: EntityID) => { const tx = await systems["system.WNFT"].transferFrom(playerEntityId, toPlayerEntityId, tokenId); - await toastCalling( + await toastPromise( tx.wait(), `Transfer for ${toPlayerEntityId}..`, `The transfer for ${toPlayerEntityId} is completed` diff --git a/packages/client/src/mud/hooks/useChangeCycleEquipment.ts b/packages/client/src/mud/hooks/useChangeCycleEquipment.ts index 5d88c47..8c89219 100644 --- a/packages/client/src/mud/hooks/useChangeCycleEquipment.ts +++ b/packages/client/src/mud/hooks/useChangeCycleEquipment.ts @@ -2,7 +2,7 @@ import { EntityIndex } from "@latticexyz/recs"; import { useCallback } from "react"; import { useWandererContext } from "../../contexts/WandererContext"; import { useMUD } from "../MUDContext"; -import { toastCalling } from "../utils/toast"; +import { toastPromise } from "../utils/toast"; export enum EquipmentAction { UNEQUIP, @@ -27,7 +27,7 @@ export const useChangeCycleEquipment = () => { equipmentSlotId, equipmentEntityId ); - await toastCalling(tx.wait(), `Сhange equipment`, `Equipment changed`); + await toastPromise(tx.wait(), `Сhange equipment`, `Equipment changed`); }, [world, systems, selectedWandererEntity] ); diff --git a/packages/client/src/mud/hooks/useWandererSpawn.ts b/packages/client/src/mud/hooks/useWandererSpawn.ts index af123cf..3fda795 100644 --- a/packages/client/src/mud/hooks/useWandererSpawn.ts +++ b/packages/client/src/mud/hooks/useWandererSpawn.ts @@ -1,7 +1,7 @@ import { EntityIndex } from "@latticexyz/recs"; import { useCallback } from "react"; import { useMUD } from "../MUDContext"; -import { toastCalling } from "../utils/toast"; +import { toastPromise } from "../utils/toast"; export const useWandererSpawn = () => { const { world, systems } = useMUD(); @@ -9,7 +9,7 @@ export const useWandererSpawn = () => { return useCallback( async (guiseProtoEntity: EntityIndex) => { const tx = await systems["system.WandererSpawn"].executeTyped(world.entities[guiseProtoEntity]); - await toastCalling(tx.wait(), `Generate Wanderer..`, `Wanderer generated`); + await toastPromise(tx.wait(), `Generate Wanderer..`, `Wanderer generated`); }, [world, systems] ); diff --git a/packages/client/src/mud/utils/toast.ts b/packages/client/src/mud/utils/toast.ts index 8549c65..3108401 100644 --- a/packages/client/src/mud/utils/toast.ts +++ b/packages/client/src/mud/utils/toast.ts @@ -1,6 +1,6 @@ import { toast } from "react-toastify"; -export const toastCalling = async ( +export const toastPromise = async ( promise: Promise | (() => Promise), loadingRender: string, successRender: string From 0d5b6c0c4a7f945c82ef32927b4cd9d10ef5fb2f Mon Sep 17 00:00:00 2001 From: rashid Date: Mon, 20 Mar 2023 17:44:54 +0300 Subject: [PATCH 6/6] add loot name for useChangeCycleEquipment --- packages/client/src/mud/hooks/useChangeCycleEquipment.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/client/src/mud/hooks/useChangeCycleEquipment.ts b/packages/client/src/mud/hooks/useChangeCycleEquipment.ts index 8c89219..36f1e60 100644 --- a/packages/client/src/mud/hooks/useChangeCycleEquipment.ts +++ b/packages/client/src/mud/hooks/useChangeCycleEquipment.ts @@ -3,6 +3,7 @@ import { useCallback } from "react"; import { useWandererContext } from "../../contexts/WandererContext"; import { useMUD } from "../MUDContext"; import { toastPromise } from "../utils/toast"; +import { getLoot } from "../utils/getLoot"; export enum EquipmentAction { UNEQUIP, @@ -10,7 +11,7 @@ export enum EquipmentAction { } export const useChangeCycleEquipment = () => { - const { world, systems } = useMUD(); + const { world, systems, components } = useMUD(); const { selectedWandererEntity } = useWandererContext(); return useCallback( @@ -27,7 +28,8 @@ export const useChangeCycleEquipment = () => { equipmentSlotId, equipmentEntityId ); - await toastPromise(tx.wait(), `Сhange equipment`, `Equipment changed`); + const loot = getLoot(world, components, equipmentEntity); + await toastPromise(tx.wait(), `Equip ${loot.name}...`, `${loot.name} equipped...`); }, [world, systems, selectedWandererEntity] );