Fixes
This commit is contained in:
parent
637da6ae69
commit
1b8ddfe488
|
@ -4,14 +4,11 @@ import { useHistory } from "react-router-dom";
|
||||||
import { useSnackbar } from "notistack";
|
import { useSnackbar } from "notistack";
|
||||||
import AppBar from "@material-ui/core/AppBar";
|
import AppBar from "@material-ui/core/AppBar";
|
||||||
import Toolbar from "@material-ui/core/Toolbar";
|
import Toolbar from "@material-ui/core/Toolbar";
|
||||||
import Select from "@material-ui/core/Select";
|
|
||||||
import Menu from "@material-ui/core/Menu";
|
import Menu from "@material-ui/core/Menu";
|
||||||
import Link from "@material-ui/core/Link";
|
import Link from "@material-ui/core/Link";
|
||||||
import Typography from "@material-ui/core/Typography";
|
import Typography from "@material-ui/core/Typography";
|
||||||
import IconButton from "@material-ui/core/IconButton";
|
import IconButton from "@material-ui/core/IconButton";
|
||||||
import ExitToAppIcon from "@material-ui/icons/ExitToApp";
|
|
||||||
import Button from "@material-ui/core/Button";
|
import Button from "@material-ui/core/Button";
|
||||||
import PersonIcon from "@material-ui/icons/Person";
|
|
||||||
import BubbleChartIcon from "@material-ui/icons/BubbleChart";
|
import BubbleChartIcon from "@material-ui/icons/BubbleChart";
|
||||||
import RefreshIcon from "@material-ui/icons/Refresh";
|
import RefreshIcon from "@material-ui/icons/Refresh";
|
||||||
import CircularProgress from "@material-ui/core/CircularProgress";
|
import CircularProgress from "@material-ui/core/CircularProgress";
|
||||||
|
@ -20,7 +17,8 @@ import {
|
||||||
WalletDisconnectButton,
|
WalletDisconnectButton,
|
||||||
WalletMultiButton,
|
WalletMultiButton,
|
||||||
} from "@solana/wallet-adapter-material-ui";
|
} 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 { refreshAccounts } from "./BootstrapProvider";
|
||||||
import { networks } from "../../store/config";
|
import { networks } from "../../store/config";
|
||||||
import {
|
import {
|
||||||
|
@ -287,15 +285,12 @@ export function WalletConnectButton(): ReactElement {
|
||||||
});
|
});
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const { wallet, lockupClient } = useWallet();
|
const { wallet, lockupClient } = useWallet();
|
||||||
|
const { connected } = useSolana();
|
||||||
const { enqueueSnackbar } = useSnackbar();
|
const { enqueueSnackbar } = useSnackbar();
|
||||||
|
|
||||||
// Wallet connection event listeners.
|
// Wallet connection event listeners.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
wallet.on("disconnect", () => {
|
if (!connected) {
|
||||||
enqueueSnackbar("Disconnected from wallet", {
|
|
||||||
variant: "info",
|
|
||||||
autoHideDuration: 2500,
|
|
||||||
});
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ActionType.CommonWalletDidDisconnect,
|
type: ActionType.CommonWalletDidDisconnect,
|
||||||
item: {},
|
item: {},
|
||||||
|
@ -304,18 +299,19 @@ export function WalletConnectButton(): ReactElement {
|
||||||
type: ActionType.CommonTriggerShutdown,
|
type: ActionType.CommonTriggerShutdown,
|
||||||
item: {},
|
item: {},
|
||||||
});
|
});
|
||||||
});
|
} else {
|
||||||
wallet.on("connect", async () => {
|
if (wallet.publicKey) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ActionType.CommonWalletDidConnect,
|
type: ActionType.CommonWalletDidConnect,
|
||||||
item: {},
|
item: {},
|
||||||
});
|
});
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ActionType.CommonTriggerBootstrap,
|
type: ActionType.CommonTriggerBootstrap,
|
||||||
item: {},
|
item: {},
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
}, [wallet, dispatch, enqueueSnackbar, lockupClient.provider.connection]);
|
}
|
||||||
|
}, [connected, wallet, wallet.publicKey, dispatch, enqueueSnackbar, lockupClient.provider.connection]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<WalletDialogProvider>
|
<WalletDialogProvider>
|
||||||
|
@ -325,12 +321,10 @@ export function WalletConnectButton(): ReactElement {
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
flexDirection: "column",
|
flexDirection: "column",
|
||||||
}}
|
}}
|
||||||
onClick={() => wallet.disconnect()}
|
|
||||||
>
|
>
|
||||||
<WalletDisconnectButton />
|
<WalletDisconnectButton />
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
onClick={() => wallet.connect()}
|
|
||||||
style={{
|
style={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
|
|
|
@ -60,13 +60,14 @@ export default function WalletProvider(
|
||||||
}
|
}
|
||||||
|
|
||||||
function WalletProviderInner(props: PropsWithChildren<ReactNode>) {
|
function WalletProviderInner(props: PropsWithChildren<ReactNode>) {
|
||||||
const { wallet: solWallet } = useSolana();
|
const { wallet: solWallet, connected, publicKey } = useSolana();
|
||||||
const { walletProvider, network } = useSelector((state: StoreState) => {
|
const { walletProvider, network } = useSelector((state: StoreState) => {
|
||||||
return {
|
return {
|
||||||
walletProvider: state.common.walletProvider,
|
walletProvider: state.common.walletProvider,
|
||||||
network: state.common.network,
|
network: state.common.network,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
console.log('adapter', publicKey?.toString(), solWallet?.adapter());
|
||||||
const { wallet, lockupClient, registryClient, multisigClient } =
|
const { wallet, lockupClient, registryClient, multisigClient } =
|
||||||
useMemo(() => {
|
useMemo(() => {
|
||||||
const opts: ConfirmOptions = {
|
const opts: ConfirmOptions = {
|
||||||
|
@ -74,7 +75,7 @@ function WalletProviderInner(props: PropsWithChildren<ReactNode>) {
|
||||||
commitment: "recent",
|
commitment: "recent",
|
||||||
};
|
};
|
||||||
const connection = new Connection(network.url, opts.preflightCommitment);
|
const connection = new Connection(network.url, opts.preflightCommitment);
|
||||||
const wallet = new Wallet(solWallet ? solWallet.adapter() : undefined);
|
const wallet = new Wallet(solWallet?.adapter());
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const provider = new Provider(connection, wallet, opts);
|
const provider = new Provider(connection, wallet, opts);
|
||||||
|
|
||||||
|
@ -99,7 +100,7 @@ function WalletProviderInner(props: PropsWithChildren<ReactNode>) {
|
||||||
registryClient,
|
registryClient,
|
||||||
multisigClient,
|
multisigClient,
|
||||||
};
|
};
|
||||||
}, [solWallet, walletProvider, network]);
|
}, [connected, solWallet, walletProvider, network]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<WalletContext.Provider
|
<WalletContext.Provider
|
||||||
|
@ -112,8 +113,9 @@ function WalletProviderInner(props: PropsWithChildren<ReactNode>) {
|
||||||
|
|
||||||
class Wallet {
|
class Wallet {
|
||||||
get publicKey(): PublicKey | undefined {
|
get publicKey(): PublicKey | undefined {
|
||||||
|
console.log('adapt:', this.adapter?.publicKey);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return this.adapter ? this.adapter.publicKey : undefined;
|
return this.adapter?.publicKey
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(readonly adapter: WalletAdapter | undefined) {}
|
constructor(readonly adapter: WalletAdapter | undefined) {}
|
||||||
|
|
Loading…
Reference in New Issue