Skip to content

Commit

Permalink
fix: use account hook from store and set account state on reconnect (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
addegbenga authored Dec 14, 2024
1 parent f343d27 commit 7620097
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
4 changes: 3 additions & 1 deletion packages/pixel_ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,16 @@ function App({ contractAddress, usernameAddress, nftCanvasAddress }: IApp) {
const {
connectWallet,
startSession,
account, address,
account,
address,
queryAddress,
setConnected,
isSessionable,
disconnectWallet,
usingSessionKeys
} = useWalletStore()


//Connect
useQueryAddressEffect()
useAutoConnect()
Expand Down
11 changes: 9 additions & 2 deletions packages/pixel_ui/src/footer/PixelSelector.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import './PixelSelector.css';
import '../utils/Styles.css';
import { useWalletStore } from '../hooks/useWalletStore';

import React, {useEffect, useState} from 'react';
import {
useAccount,
// useAccount,
// useContract,
// useNetwork,
// useConnect
Expand All @@ -12,13 +13,19 @@ import {
import EraserIcon from '../resources/icons/Eraser.png';

const PixelSelector = (props) => {

//Use account hooks from store.
const {
account,
} = useWalletStore()

// Track when a placement is available

const {account} = useAccount()

const [placementTimer, setPlacementTimer] = useState('XX:XX');
const [placementMode, setPlacementMode] = useState(false);
const [ended, setEnded] = useState(false);

useEffect(() => {
if (props.queryAddress === '0' || !account?.address) {
setPlacementTimer('Login to Play');
Expand Down
10 changes: 8 additions & 2 deletions packages/pixel_ui/src/hooks/useWalletStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ const canSession = (wallet) => {
if (wallet && connectorData && connector) {

const new_account = await connector.account(provider);

console.log(new_account, "sjsjsj")


set({
wallet,
connectorData:{account:connectorData?.account,chainId: connectorData.chainId ? BigInt(connectorData.chainId).toString(): undefined},
Expand Down Expand Up @@ -231,6 +235,7 @@ const canSession = (wallet) => {

export const useAutoConnect = () => {
const {setWallet, setConnector, setConnectorData,connectorData, setIsSessionable,
setAccount,
} = useWalletStore()

useEffect(() => {
Expand All @@ -246,7 +251,8 @@ const canSession = (wallet) => {
icons: []
}
});

const new_account = await connector.account(provider);
setAccount(new_account)
setConnector(connector);
setWallet(connectedWallet)
setIsSessionable(canSession(connectedWallet))
Expand All @@ -266,7 +272,7 @@ const canSession = (wallet) => {
if (!connectorData) {
autoConnect();
}
}, [setConnector, setConnectorData, connectorData, setIsSessionable, setWallet]);
}, [setConnector, setConnectorData, connectorData, setIsSessionable, setWallet, setAccount]);

useEffect(() => {
if (typeof window !== "undefined") {
Expand Down

0 comments on commit 7620097

Please sign in to comment.