This commit is contained in:
armaniferrante 2021-08-20 13:06:39 -07:00
parent 637da6ae69
commit 1b8ddfe488
No known key found for this signature in database
GPG Key ID: 58BEF301E91F7828
2 changed files with 23 additions and 27 deletions

View File

@ -4,14 +4,11 @@ import { useHistory } from "react-router-dom";
import { useSnackbar } from "notistack";
import AppBar from "@material-ui/core/AppBar";
import Toolbar from "@material-ui/core/Toolbar";
import Select from "@material-ui/core/Select";
import Menu from "@material-ui/core/Menu";
import Link from "@material-ui/core/Link";
import Typography from "@material-ui/core/Typography";
import IconButton from "@material-ui/core/IconButton";
import ExitToAppIcon from "@material-ui/icons/ExitToApp";
import Button from "@material-ui/core/Button";
import PersonIcon from "@material-ui/icons/Person";
import BubbleChartIcon from "@material-ui/icons/BubbleChart";
import RefreshIcon from "@material-ui/icons/Refresh";
import CircularProgress from "@material-ui/core/CircularProgress";
@ -20,7 +17,8 @@ import {
WalletDisconnectButton,
WalletMultiButton,
} from "@solana/wallet-adapter-material-ui";
import { Popper, MenuList, MenuItem, Grow } from "@material-ui/core";
import { MenuItem } from "@material-ui/core";
import { useWallet as useSolana } from "@solana/wallet-adapter-react";
import { refreshAccounts } from "./BootstrapProvider";
import { networks } from "../../store/config";
import {
@ -287,15 +285,12 @@ export function WalletConnectButton(): ReactElement {
});
const dispatch = useDispatch();
const { wallet, lockupClient } = useWallet();
const { connected } = useSolana();
const { enqueueSnackbar } = useSnackbar();
// Wallet connection event listeners.
useEffect(() => {
wallet.on("disconnect", () => {
enqueueSnackbar("Disconnected from wallet", {
variant: "info",
autoHideDuration: 2500,
});
if (!connected) {
dispatch({
type: ActionType.CommonWalletDidDisconnect,
item: {},
@ -304,18 +299,19 @@ export function WalletConnectButton(): ReactElement {
type: ActionType.CommonTriggerShutdown,
item: {},
});
});
wallet.on("connect", async () => {
dispatch({
type: ActionType.CommonWalletDidConnect,
item: {},
});
dispatch({
type: ActionType.CommonTriggerBootstrap,
item: {},
});
});
}, [wallet, dispatch, enqueueSnackbar, lockupClient.provider.connection]);
} else {
if (wallet.publicKey) {
dispatch({
type: ActionType.CommonWalletDidConnect,
item: {},
});
dispatch({
type: ActionType.CommonTriggerBootstrap,
item: {},
});
}
}
}, [connected, wallet, wallet.publicKey, dispatch, enqueueSnackbar, lockupClient.provider.connection]);
return (
<WalletDialogProvider>
@ -325,12 +321,10 @@ export function WalletConnectButton(): ReactElement {
justifyContent: "center",
flexDirection: "column",
}}
onClick={() => wallet.disconnect()}
>
<WalletDisconnectButton />
</div>
<div
onClick={() => wallet.connect()}
style={{
display: "flex",
justifyContent: "center",

View File

@ -60,13 +60,14 @@ export default function WalletProvider(
}
function WalletProviderInner(props: PropsWithChildren<ReactNode>) {
const { wallet: solWallet } = useSolana();
const { wallet: solWallet, connected, publicKey } = useSolana();
const { walletProvider, network } = useSelector((state: StoreState) => {
return {
walletProvider: state.common.walletProvider,
network: state.common.network,
};
});
console.log('adapter', publicKey?.toString(), solWallet?.adapter());
const { wallet, lockupClient, registryClient, multisigClient } =
useMemo(() => {
const opts: ConfirmOptions = {
@ -74,7 +75,7 @@ function WalletProviderInner(props: PropsWithChildren<ReactNode>) {
commitment: "recent",
};
const connection = new Connection(network.url, opts.preflightCommitment);
const wallet = new Wallet(solWallet ? solWallet.adapter() : undefined);
const wallet = new Wallet(solWallet?.adapter());
// @ts-ignore
const provider = new Provider(connection, wallet, opts);
@ -99,7 +100,7 @@ function WalletProviderInner(props: PropsWithChildren<ReactNode>) {
registryClient,
multisigClient,
};
}, [solWallet, walletProvider, network]);
}, [connected, solWallet, walletProvider, network]);
return (
<WalletContext.Provider
@ -112,8 +113,9 @@ function WalletProviderInner(props: PropsWithChildren<ReactNode>) {
class Wallet {
get publicKey(): PublicKey | undefined {
console.log('adapt:', this.adapter?.publicKey);
// @ts-ignore
return this.adapter ? this.adapter.publicKey : undefined;
return this.adapter?.publicKey
}
constructor(readonly adapter: WalletAdapter | undefined) {}