Skip to content

Commit

Permalink
disable button and refresh balance
Browse files Browse the repository at this point in the history
  • Loading branch information
Megha-Dev-19 committed Dec 11, 2024
1 parent 3eb16f0 commit 15a6205
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/components/Navbar/components/ButtonConnectWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { useAccount } from 'wagmi';
import { useConnect } from 'wagmi';
import { useDisconnect } from 'wagmi';
import { coinbaseWallet } from 'wagmi/connectors';
import { useGlobalContext } from '@/contexts/GlobalContext';

type Props = {
handleButtonCLick?: () => void;
Expand All @@ -34,8 +35,7 @@ export function ButtonConnectWallet({ handleButtonCLick, text }: Props) {
const { address } = useAccount();
const { disconnect: disconnectBase } = useDisconnect();

const { data: cheddarBalanceData, isLoading: isLoadingCheddarBalance } =
useGetCheddarBalance();
const { cheddarBalance, isCheddarBalanceLoading } = useGlobalContext();

const { isUserNadabotVerfied, isUserHolonymVerified } =
useContext(GameContext);
Expand Down Expand Up @@ -79,10 +79,10 @@ export function ButtonConnectWallet({ handleButtonCLick, text }: Props) {
rightIcon={<ChevronDownIcon />}
>
<Text mr="5px" display="inline-block">
{isLoadingCheddarBalance ? (
{isCheddarBalanceLoading ? (
<Spinner size="sm" />
) : (
yton(`${cheddarBalanceData}`)
yton(`${cheddarBalance}`)
)}
</Text>
<RenderCheddarIcon />
Expand Down
13 changes: 10 additions & 3 deletions src/components/maze/GameboardContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,13 @@ export function GameboardContainer({
pendingCheddarToMint,
} = useContext(GameContext);

const { addresses, isConnected, showConnectionModal, blockchain } =
useGlobalContext();
const {
addresses,
isConnected,
showConnectionModal,
blockchain,
refreshCheddarBalance,
} = useGlobalContext();

const gameboardRef = useRef<HTMLDivElement>(null);
const {
Expand Down Expand Up @@ -415,11 +420,12 @@ export function GameboardContainer({
</div>
<div className={styles.mazeContainer} ref={gameboardRef} tabIndex={0}>
<div className={styles.toolbar}>
{earnedButNotMintedCheddar > 100 && (
{earnedButNotMintedCheddar > 0 && (
<Button
px={{ base: 2, md: 3 }}
_hover={{ bg: 'yellowgreen' }}
isLoading={isClaiming}
isDisabled={earnedButNotMintedCheddar < 100}
onClick={async () => {
if (
blockchain === 'near' &&
Expand All @@ -437,6 +443,7 @@ export function GameboardContainer({
setIsClaiming(false);
setCheddarMintResponse(response);
refetchEarnedButNotMintedCheddar();
refreshCheddarBalance();
}
}}
>
Expand Down
9 changes: 7 additions & 2 deletions src/contexts/GlobalContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface GlobalContextProps {
disconnectWallet: () => void;
cheddarBalance: any;
isCheddarBalanceLoading: boolean;
refreshCheddarBalance: () => void;
cheddarTotalSupply: any;
isCheddarTotalSupplyLoading: boolean;
isConnected: boolean;
Expand All @@ -53,8 +54,11 @@ export const GlobalContextProvider: any = ({ children }: any) => {
const [collapsableNavbar, setCollapsableNavbar] = useState(false);
const { connect } = useConnect();
const { disconnect } = useDisconnect();
const { data: cheddarNearBalance, isLoading: isLoadingCheddarNearBalance } =
useGetCheddarBalance();
const {
data: cheddarNearBalance,
isLoading: isLoadingCheddarNearBalance,
refetch: refreshCheddarBalance,
} = useGetCheddarBalance();
const { data: cheddarBaseBalance, isLoading: isLoadingCheddarBaseBalance } =
useGetCheddarBaseBalance();
const {
Expand Down Expand Up @@ -177,6 +181,7 @@ export const GlobalContextProvider: any = ({ children }: any) => {
toggleCollapsableNavbar,
collapsableNavbarActivated,
setCollapsableNavbarActivated,
refreshCheddarBalance,
}}
>
{children}
Expand Down

0 comments on commit 15a6205

Please sign in to comment.