Skip to content

Commit

Permalink
refactor: disable refresh when buying is not confirmed
Browse files Browse the repository at this point in the history
  • Loading branch information
noyyyy committed Oct 16, 2024
1 parent 97ad967 commit 2788cf0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/client/src/ui/features/shop/HeroCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ const rarityBgColor: Record<number, string> = {
interface IHeroCard {
creatureKey: CreatureKey;
altarSlot: number;
setLoading: React.Dispatch<React.SetStateAction<boolean>>;
}

export const HeroCard = ({ creatureKey, altarSlot }: IHeroCard) => {
export const HeroCard = ({ creatureKey, altarSlot, setLoading }: IHeroCard) => {
const {
clientComponents: { GameStatus, Player },
systemCalls: { buyHero, buyAndMerge },
Expand All @@ -50,6 +51,7 @@ export const HeroCard = ({ creatureKey, altarSlot }: IHeroCard) => {
alert("can only buy piece during prepare");
return;
}
setLoading(true);
playClick();

if (mergeAble.canMerge) {
Expand All @@ -64,11 +66,17 @@ export const HeroCard = ({ creatureKey, altarSlot }: IHeroCard) => {
y: mergeAble.onBoardCoord.y,
invSlot: mergeAble.invSlot,
onBoardIdx: mergeAble.boardIdx,
}).then(() => {
playUpgrade();
});
})
.then(() => {
playUpgrade();
})
.finally(() => {
setLoading(false);
});
} else {
buyHero(account, altarSlot, firstEmptyInv);
buyHero(account, altarSlot, firstEmptyInv).finally(() => {
setLoading(false);
});
}
}, [
account,
Expand Down
5 changes: 5 additions & 0 deletions packages/client/src/ui/features/shop/Shop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,34 +85,39 @@ const Shop = () => {
level: 1,
}}
altarSlot={1}
setLoading={setLoading}
/>
<HeroCard
creatureKey={{
id: heroAltar?.slot2,
level: 1,
}}
altarSlot={2}
setLoading={setLoading}
/>
<HeroCard
creatureKey={{
id: heroAltar?.slot3,
level: 1,
}}
altarSlot={3}
setLoading={setLoading}
/>
<HeroCard
creatureKey={{
id: heroAltar?.slot4,
level: 1,
}}
altarSlot={4}
setLoading={setLoading}
/>
<HeroCard
creatureKey={{
id: heroAltar?.slot5,
level: 1,
}}
altarSlot={5}
setLoading={setLoading}
/>
</div>

Expand Down

0 comments on commit 2788cf0

Please sign in to comment.