Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions pages/_app.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { useRootStore } from 'src/store/root';
import { SharedDependenciesProvider } from 'src/ui-config/SharedDependenciesProvider';
import { wagmiConfig } from 'src/ui-config/wagmiConfig';
import { WagmiProvider } from 'wagmi';
import { useShallow } from 'zustand/shallow';

import createEmotionCache from '../src/createEmotionCache';
import { AppGlobalStyles } from '../src/layouts/AppGlobalStyles';
Expand Down Expand Up @@ -112,9 +111,7 @@ interface MyAppProps extends AppProps {
export default function MyApp(props: MyAppProps) {
const { Component, emotionCache = clientSideEmotionCache, pageProps } = props;
const getLayout = Component.getLayout ?? ((page: ReactNode) => page);
const [initializeEventsTracking, setWalletType] = useRootStore(
useShallow((store) => [store.initializeEventsTracking, store.setWalletType])
);
const initializeEventsTracking = useRootStore((store) => store.initializeEventsTracking);
const [queryClient] = useState(
() =>
new QueryClient({
Expand Down Expand Up @@ -155,10 +152,7 @@ export default function MyApp(props: MyAppProps) {
<LanguageProvider>
<WagmiProvider config={wagmiConfig}>
<QueryClientProvider client={queryClient}>
<ConnectKitProvider
onDisconnect={cleanLocalStorage}
onConnect={({ connectorId }) => setWalletType(connectorId)}
>
<ConnectKitProvider onDisconnect={cleanLocalStorage}>
<Web3ContextProvider>
<AppGlobalStyles>
<ComplianceProvider>
Expand Down
21 changes: 18 additions & 3 deletions src/libs/web3-data-provider/Web3Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ let didAutoConnectForCypress = false;
export const Web3ContextProvider: React.FC<{ children: ReactElement }> = ({ children }) => {
const { switchChainAsync } = useSwitchChain();
const { watchAssetAsync } = useWatchAsset();
const { chainId, address } = useAccount();
const { chainId, address, status, connector } = useAccount();
const { connect, connectors } = useConnect();

const [readOnlyModeAddress, setReadOnlyModeAddress] = useState<string | undefined>();
const [switchNetworkError, setSwitchNetworkError] = useState<Error>();
const [setAccount, setConnectedAccountIsContract] = useRootStore(
useShallow((store) => [store.setAccount, store.setConnectedAccountIsContract])
const [setAccount, setConnectedAccountIsContract, setWalletType] = useRootStore(
useShallow((store) => [
store.setAccount,
store.setConnectedAccountIsContract,
store.setWalletType,
])
);

const account = address;
Expand Down Expand Up @@ -203,6 +207,17 @@ export const Web3ContextProvider: React.FC<{ children: ReactElement }> = ({ chil
setAccount(account?.toLowerCase());
}, [account, setAccount]);

// Drive walletType from wagmi's account state so it survives page reloads.
// ConnectKit's `onConnect` prop only fires on fresh connect (not on reconnect),
// which caused most transaction events to be tracked with walletType=undefined.
useEffect(() => {
if (status === 'connected' && connector?.id) {
setWalletType(connector.id);
} else if (status === 'disconnected') {
setWalletType(undefined);
}
}, [status, connector?.id, setWalletType]);

useEffect(() => {
if (readOnlyModeAddress) {
setAccount(readOnlyModeAddress.toLowerCase());
Expand Down
Loading