Skip to content

Commit

Permalink
Add closeModalAfterSwitchingNetwork. (#84)
Browse files Browse the repository at this point in the history
* feat: Setting `reloadOnDisconnect` = false in default for coinbaseWallet

* docs: Add changeset log

* feat: Add `closeModalAfterSwitchingNetwork`
  • Loading branch information
wenty22 authored Dec 18, 2023
1 parent 00527b8 commit a6de228
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/fifty-fans-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@totejs/walletkit': patch
---

Add `closeModalAfterSwitchingNetwork`.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface WalletKitOptions {
hideOfficialWalletConnectCTA?: boolean;

closeModalAfterConnected?: boolean;
closeModalAfterSwitchingNetwork?: boolean;
closeModalOnEsc?: boolean;
closeModalOnOverlayClick?: boolean;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export function getDefaultProviderOptions(options: WalletKitOptions) {
hideNoWalletCTA: false,
hideOfficialWalletConnectCTA: false,

closeModalAfterSwitchingNetwork: false,
closeModalAfterConnected: true,
closeModalOnEsc: true,
closeModalOnOverlayClick: true,
Expand Down
14 changes: 11 additions & 3 deletions packages/walletkit/src/pages/SwitchNetwork/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ import {
import { ModalFooter } from '@/base/components/Modal/ModalFooter';

export function SwitchNetworkPage() {
const { supportedChains, log } = useWalletKitContext();
const { isLoading, switchNetwork, pendingChainId } = useWalletKitSwitchNetwork();
const { supportedChains, log, options } = useWalletKitContext();

const { chain } = useNetwork();
const { isClosable } = useModal();
const { isClosable, onClose } = useModal();

const { isLoading, switchNetwork, pendingChainId } = useWalletKitSwitchNetwork({
onSuccess() {
if (options.closeModalAfterSwitchingNetwork) {
onClose();
}
},
});

const onSwitchNetwork = (chainId: number) => {
log('[switch network page]', 'switchNetwork:', switchNetwork, ', isLoading:', isLoading);
Expand Down
2 changes: 1 addition & 1 deletion packages/walletkit/src/wallets/coinbaseWallet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function coinbaseWallet(props: CoinbaseWalletProps = {}): WalletProps {
options: {
appName,
headlessMode: true,
reloadOnDisconnect: false,
// reloadOnDisconnect: false,
...connectorOptions,
},
});
Expand Down
1 change: 1 addition & 0 deletions website/src/pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ interface WalletKitOptions {
hideOfficialWalletConnectCTA?: boolean;

closeModalAfterConnected?: boolean;
closeModalAfterSwitchingNetwork?: boolean;
closeModalOnEsc?: boolean;
closeModalOnOverlayClick?: boolean;

Expand Down

0 comments on commit a6de228

Please sign in to comment.