Skip to content

Commit

Permalink
feat: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
grothem committed Dec 12, 2024
1 parent dcefa4e commit 815ae2f
Show file tree
Hide file tree
Showing 20 changed files with 43 additions and 858 deletions.
10 changes: 8 additions & 2 deletions pages/_app.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ interface MyAppProps extends AppProps {
export default function MyApp(props: MyAppProps) {
const { Component, emotionCache = clientSideEmotionCache, pageProps } = props;
const getLayout = Component.getLayout ?? ((page: ReactNode) => page);
const initializeMixpanel = useRootStore((store) => store.initializeMixpanel);
const [initializeMixpanel, setWalletType] = useRootStore((store) => [
store.initializeMixpanel,
store.setWalletType,
]);
const [queryClient] = useState(
() =>
new QueryClient({
Expand Down Expand Up @@ -137,7 +140,10 @@ export default function MyApp(props: MyAppProps) {
<LanguageProvider>
<WagmiProvider config={wagmiConfig}>
<QueryClientProvider client={queryClient}>
<ConnectKitProvider onDisconnect={cleanLocalStorage}>
<ConnectKitProvider
onDisconnect={cleanLocalStorage}
onConnect={({ connectorId }) => setWalletType(connectorId)}
>
<Web3ContextProvider>
<AppGlobalStyles>
<AddressBlocked>
Expand Down
4 changes: 2 additions & 2 deletions pages/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { DashboardContentWrapper } from '../src/modules/dashboard/DashboardConte
import { DashboardTopPanel } from '../src/modules/dashboard/DashboardTopPanel';

export default function Home() {
const { currentAccount, loading: web3Loading } = useWeb3Context();
const { currentAccount } = useWeb3Context();
const { currentMarket } = useProtocolDataContext();
const trackEvent = useRootStore((store) => store.trackEvent);

Expand Down Expand Up @@ -63,7 +63,7 @@ export default function Home() {
{currentAccount ? (
<DashboardContentWrapper isBorrow={mode === 'borrow'} />
) : (
<ConnectWalletPaper loading={web3Loading} />
<ConnectWalletPaper />
)}
</ContentContainer>
</>
Expand Down
3 changes: 1 addition & 2 deletions pages/v3-migration.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const selectableMarkets = [
];

export default function V3Migration() {
const { currentAccount, loading: web3Loading } = useWeb3Context();
const { currentAccount } = useWeb3Context();
const router = useRouter();
const [fromMarketData, setFromMarketData] = useState<MarketDataType>(() => {
if (router.query.market) {
Expand Down Expand Up @@ -255,7 +255,6 @@ export default function V3Migration() {
</ContentContainer>
) : (
<ConnectWalletPaper
loading={web3Loading}
description={<Trans> Please connect your wallet to see migration tool.</Trans>}
/>
)}
Expand Down
6 changes: 4 additions & 2 deletions src/components/AddressBlocked.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ import { useAddressAllowed } from 'src/hooks/useAddressAllowed';
import { MainLayout } from 'src/layouts/MainLayout';
import { useWeb3Context } from 'src/libs/hooks/useWeb3Context';
import { ENABLE_TESTNET } from 'src/utils/marketsAndNetworksConfig';
import { useDisconnect } from 'wagmi';

import { AddressBlockedModal } from './AddressBlockedModal';

export const AddressBlocked = ({ children }: { children: ReactNode }) => {
const { currentAccount, disconnectWallet, readOnlyMode, loading } = useWeb3Context();
const { currentAccount, readOnlyMode, loading } = useWeb3Context();
const { disconnect } = useDisconnect();
const screenAddress = readOnlyMode || loading || ENABLE_TESTNET ? '' : currentAccount;
const { isAllowed } = useAddressAllowed(screenAddress);

if (!isAllowed) {
return (
<MainLayout>
<AddressBlockedModal address={currentAccount} onDisconnectWallet={disconnectWallet} />;
<AddressBlockedModal address={currentAccount} onDisconnectWallet={() => disconnect()} />;
</MainLayout>
);
}
Expand Down
15 changes: 7 additions & 8 deletions src/components/ConnectWalletPaper.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import { Trans } from '@lingui/macro';
import { Box, CircularProgress, Paper, PaperProps, Typography } from '@mui/material';
import { useModal } from 'connectkit';
import { ReactNode } from 'react';
import { useWeb3Context } from 'src/libs/hooks/useWeb3Context';

import LandingGhost from '/public/resting-gho-hat-purple.svg';

import { ConnectWalletButton } from './WalletConnection/ConnectWalletButton';

interface ConnectWalletPaperProps extends PaperProps {
loading?: boolean;
description?: ReactNode;
}

export const ConnectWalletPaper = ({
loading,
description,
sx,
...rest
}: ConnectWalletPaperProps) => {
export const ConnectWalletPaper = ({ description, sx, ...rest }: ConnectWalletPaperProps) => {
const { open } = useModal();
const { loading } = useWeb3Context();

return (
<Paper
{...rest}
Expand All @@ -35,7 +34,7 @@ export const ConnectWalletPaper = ({
<LandingGhost />
</Box>
<>
{loading ? (
{open || loading ? (
<CircularProgress />
) : (
<>
Expand Down
7 changes: 4 additions & 3 deletions src/components/UserDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useMemo } from 'react';
import useGetEns from 'src/libs/hooks/use-get-ens';
import { useWeb3Context } from 'src/libs/hooks/useWeb3Context';
import { useRootStore } from 'src/store/root';
import { useAccount } from 'wagmi';
import { shallow } from 'zustand/shallow';

import { Avatar, AvatarProps } from './Avatar';
Expand All @@ -27,12 +28,12 @@ export const UserDisplay: React.FC<UserDisplayProps> = ({
withLink,
funnel,
}) => {
const { account, defaultDomain, domainsLoading, accountLoading } = useRootStore(
const { isConnecting } = useAccount();
const { account, defaultDomain, domainsLoading } = useRootStore(
(state) => ({
account: state.account,
defaultDomain: state.defaultDomain,
domainsLoading: state.domainsLoading,
accountLoading: state.accountLoading,
}),
shallow
);
Expand All @@ -41,7 +42,7 @@ export const UserDisplay: React.FC<UserDisplayProps> = ({
() => (account ? blo(account as `0x${string}`) : undefined),
[account]
);
const loading = domainsLoading || accountLoading;
const loading = domainsLoading || isConnecting;

return (
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2 }}>
Expand Down
3 changes: 2 additions & 1 deletion src/components/WalletConnection/ConnectWalletButton.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Trans } from '@lingui/macro';
import { Button } from '@mui/material';
import { ConnectKitButton } from 'connectkit';
import { useWalletModalContext } from 'src/hooks/useWalletModal';
import { useRootStore } from 'src/store/root';
import { AUTH } from 'src/utils/mixPanelEvents';

Expand All @@ -10,6 +9,7 @@ import { UserDisplay } from '../UserDisplay';

export interface ConnectWalletProps {
funnel?: string;
onIsConnecting?: (isConnecting: boolean) => void;
}

export const ConnectWalletButton: React.FC<ConnectWalletProps> = ({ funnel }) => {
Expand All @@ -24,6 +24,7 @@ export const ConnectWalletButton: React.FC<ConnectWalletProps> = ({ funnel }) =>
variant={isConnected ? 'surface' : 'gradient'}
onClick={() => {
show && show();
trackEvent(AUTH.CONNECT_WALLET, { funnel: funnel });
}}
>
{isConnected ? (
Expand Down
8 changes: 1 addition & 7 deletions src/components/WalletConnection/ReadOnlyModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,14 @@ import { useEffect, useState } from 'react';
import { ReadOnlyModeTooltip } from 'src/components/infoTooltips/ReadOnlyModeTooltip';
import { ModalType, useModalContext } from 'src/hooks/useModal';
import { useWeb3Context } from 'src/libs/hooks/useWeb3Context';
import { WalletType } from 'src/libs/web3-data-provider/WalletOptions';
import { useRootStore } from 'src/store/root';
import { getENSProvider } from 'src/utils/marketsAndNetworksConfig';
import { AUTH } from 'src/utils/mixPanelEvents';
import { mock, useConnect } from 'wagmi';

import { BasicModal } from '../primitives/BasicModal';
import { Warning } from '../primitives/Warning';
import { TxModalTitle } from '../transactions/FlowCommons/TxModalTitle';
import { mock, useConnect } from 'wagmi';

export type WalletRowProps = {
walletName: string;
walletType: WalletType;
};

export enum ErrorType {
UNSUPORTED_CHAIN,
Expand Down
14 changes: 0 additions & 14 deletions src/components/WalletConnection/WalletModal.tsx

This file was deleted.

Loading

0 comments on commit 815ae2f

Please sign in to comment.