From c20c62c058279c64d8257bf62de74da7a0dc536a Mon Sep 17 00:00:00 2001 From: MickWang <1244134672@qq.com> Date: Tue, 30 Jul 2024 18:13:39 +0800 Subject: [PATCH] update balance after upgrade nft --- .../DashboardS2/DailyRoulette/DailyDrawModal.tsx | 6 +++--- .../Tabs/PortfolioComponents/LynksNFT.tsx | 12 ++++++------ src/hooks/useUpdateNftBalanceStore.ts | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/components/DashboardS2/DailyRoulette/DailyDrawModal.tsx b/src/components/DashboardS2/DailyRoulette/DailyDrawModal.tsx index f1005215..75c299ec 100644 --- a/src/components/DashboardS2/DailyRoulette/DailyDrawModal.tsx +++ b/src/components/DashboardS2/DailyRoulette/DailyDrawModal.tsx @@ -74,7 +74,7 @@ const DailyDrawModal: React.FC = (props: IProps) => { const [mintStatus, setMintStatus] = useState(); const [failMessage, setFailMessage] = useState(""); const { switchChain } = useSwitchChain(); - const { updateFactory } = useUpdateNftBalanceStore(); + const { updateFactor } = useUpdateNftBalanceStore(); const { sendTrademarkMintTx } = useNovaNFT(); const { modalInstance, onDrawed, remain } = props; @@ -159,7 +159,7 @@ const DailyDrawModal: React.FC = (props: IProps) => { mintResultModal.onOpen(); onDrawed(); // update remain times after mint tx setMintParams(undefined); - updateFactory(); + updateFactor(); } catch (e) { console.log(e); setMintStatus(MintStatus.Failed); @@ -178,7 +178,7 @@ const DailyDrawModal: React.FC = (props: IProps) => { mintResultModal, onDrawed, sendTrademarkMintTx, - updateFactory, + updateFactor, ]); const handleSkip = async () => { diff --git a/src/components/DashboardS2/Tabs/PortfolioComponents/LynksNFT.tsx b/src/components/DashboardS2/Tabs/PortfolioComponents/LynksNFT.tsx index 0507c8a4..bf505194 100644 --- a/src/components/DashboardS2/Tabs/PortfolioComponents/LynksNFT.tsx +++ b/src/components/DashboardS2/Tabs/PortfolioComponents/LynksNFT.tsx @@ -8,17 +8,15 @@ import { Abi } from "viem"; import SbtUpgradeModal from "@/components/Dashboard/NovaCharacterComponents/SbtUpgradeModal"; import { useUpdateNftBalanceStore } from "@/hooks/useUpdateNftBalanceStore"; - export default function SbtNFT() { const { address } = useAccount(); const [lynksBalance, setLynksBalance] = useState(0); const { publicClient, trademarkNFT } = useNovaNFT(); const { getLynksNFT } = useNovaNFT(); const { nft, loading: mintLoading, fetchLoading } = useSbtNft(); - const [update, setUpdate] = useState(0); const upgradeModal = useDisclosure(); const [upgradable, setUpgradable] = useState(false); - const { factor } = useUpdateNftBalanceStore(); + const { factor, updateFactor } = useUpdateNftBalanceStore(); useEffect(() => { (async () => { @@ -49,7 +47,7 @@ export default function SbtNFT() { } } })(); - }, [address, getLynksNFT, publicClient, trademarkNFT, update,factor]); + }, [address, getLynksNFT, publicClient, trademarkNFT, factor]); useEffect(() => { (async () => { @@ -65,7 +63,7 @@ export default function SbtNFT() { setLynksBalance(balance); } })(); - }, [address, getLynksNFT]); + }, [address, getLynksNFT, factor]); const handleMintNow = useCallback(() => { if (fetchLoading) { @@ -112,7 +110,9 @@ export default function SbtNFT() { nft={nft} mintLoading={mintLoading} upgradeModal={upgradeModal} - onUpgraded={() => setUpdate((v) => v + 1)} + onUpgraded={() => { + updateFactor(); + }} /> ); diff --git a/src/hooks/useUpdateNftBalanceStore.ts b/src/hooks/useUpdateNftBalanceStore.ts index bc908374..07ecb547 100644 --- a/src/hooks/useUpdateNftBalanceStore.ts +++ b/src/hooks/useUpdateNftBalanceStore.ts @@ -2,12 +2,12 @@ import { create } from "zustand"; interface UpdateNftBalanceStore { factor: number; - updateFactory: () => void; + updateFactor: () => void; } export const useUpdateNftBalanceStore = create( (set) => ({ factor: 0, - updateFactory: () => set((state) => ({ factor: state.factor + 1 })), + updateFactor: () => set((state) => ({ factor: state.factor + 1 })), }) );