Skip to content

Commit

Permalink
feat(walletconnect): better switch chain modal, add wallet name
Browse files Browse the repository at this point in the history
  • Loading branch information
simodrws committed May 25, 2023
1 parent 38cdca9 commit 20487c8
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 13 deletions.
14 changes: 11 additions & 3 deletions src/components/masa-interface/pages/switch-chain/switch-chain.tsx
Expand Up @@ -15,6 +15,7 @@ export const InterfaceSwitchChain = (): JSX.Element => {
forceNetwork,
switchNetworkNew,
canProgramaticallySwitchNetwork,
walletName,
} = useMasa();
// const { chain } = useNetwork();
// const { switchNetwork: switchNetworkWagmi } = useSwitchNetwork({
Expand Down Expand Up @@ -64,9 +65,16 @@ export const InterfaceSwitchChain = (): JSX.Element => {
{!canProgramaticallySwitchNetwork && (
<div className="dont-have-a-wallet">
<p>
If you are connected using WalletConnect, please switch the
network in your app as for some apps, it may not be possible to
switch networks from the browser. Tottenham
<b>
It seems that your {walletName} wallet is not able to switch
networks programmatically.{' '}
</b>
</p>
<p>
This means that you have to manually switch networks in your
wallet. Please switch to the <b>{networkData?.chainName}</b> in
your wallet. This window will update automatically once you
switched networks.
</p>
</div>
)}
Expand Down
23 changes: 15 additions & 8 deletions src/provider/masa-context-provider.tsx
Expand Up @@ -82,14 +82,19 @@ export const MasaContextProvider = ({
const { walletAddress, isWalletLoading, hasWalletAddress, reloadWallet } =
useWallet(masaInstance, signer);

const { isConnected, isDisconnected, hasAccountAddress, accountAddress } =
useAccountState({
masa: masaInstance,
walletAddress,
signer,
hasWalletAddress,
reloadWallet,
});
const {
isConnected,
isDisconnected,
hasAccountAddress,
accountAddress,
walletName,
} = useAccountState({
masa: masaInstance,
walletAddress,
signer,
hasWalletAddress,
reloadWallet,
});

// session
const { isLoggedIn, handleLogin, handleLogout, isSessionLoading } =
Expand Down Expand Up @@ -389,6 +394,7 @@ export const MasaContextProvider = ({
isConnected,
isDisconnected,
canProgramaticallySwitchNetwork,
walletName,
};
return masaShape;
}, [
Expand Down Expand Up @@ -487,6 +493,7 @@ export const MasaContextProvider = ({
isConnected,
isDisconnected,
canProgramaticallySwitchNetwork,
walletName,
]);

return (
Expand Down
3 changes: 2 additions & 1 deletion src/provider/masa-shape.ts
Expand Up @@ -123,7 +123,7 @@ export interface MasaShape {
handleAddSBT?: (isCollection: boolean, name: string, address: string) => void;
refetchContracts?: () => void;
isLoadingCustomSBTs?: boolean;

walletName?: string | undefined;
// rainbowkit
useRainbowKit?: boolean;
openConnectModal?: (() => void) | undefined;
Expand All @@ -137,6 +137,7 @@ export interface MasaShape {
switchNetworkNew?: (forcedNetworkParam: NetworkName) => void;
currentNetworkNew?: GetNetworkResult;
canProgramaticallySwitchNetwork?: boolean;

isConnected?: boolean;
isDisconnected?: boolean;
// new-modal
Expand Down
3 changes: 3 additions & 0 deletions src/provider/use-account-state.ts
Expand Up @@ -56,6 +56,8 @@ export const useAccountState = ({
address: wagmiAddress,
} = useAccount();

const walletName = useMemo(() => activeConnector?.name, [activeConnector]);

const provider = useProvider();

const { isLoggingOut, hasLoggedOut } = useLogout({
Expand Down Expand Up @@ -202,5 +204,6 @@ export const useAccountState = ({
hasWalletAddress,
hasAccountAddress,
walletAddress,
walletName,
};
};
4 changes: 3 additions & 1 deletion src/styles.scss
Expand Up @@ -321,12 +321,14 @@

.dont-have-a-wallet {
display: flex;
flex-direction: row;
flex-direction: column;
justify-content: center;

text-align: center;
p {
font-size: 16px;
padding: 8px;
margin: 0;
}
}
.masa-input-container {
Expand Down

0 comments on commit 20487c8

Please sign in to comment.