Skip to content

Commit

Permalink
fix: allow callback on chain switch success
Browse files Browse the repository at this point in the history
  • Loading branch information
aramalipoor committed Jan 8, 2023
1 parent 7c853ef commit 0ee2048
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/react/src/core/wallet/components/SwitchChainButton.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
import React from 'react';
import { useNetwork, useSwitchNetwork } from 'wagmi';
import { Chain, useNetwork, useSwitchNetwork } from 'wagmi';

import { BareComponentProps, useChainInfo } from '../../../common';

type Props = BareComponentProps & {
label?: React.ReactNode;
children?: React.ReactNode;
requiredChainId: number;
onSuccess?: (chain: Chain) => void;
};

export const SwitchChainButton = ({
as,
label,
children,
requiredChainId,
onSuccess,
...attributes
}: Props) => {
const { chain } = useNetwork();
const { switchNetwork } = useSwitchNetwork();
const { switchNetwork } = useSwitchNetwork({
throwForSwitchChainNotSupported: false,
onSuccess(data, variables, context) {
if (data.id.toString() == requiredChainId.toString()) {
onSuccess?.(data);
}
},
});
const requiredChain = useChainInfo(Number(requiredChainId));

const Component = as || 'button';
Expand Down

0 comments on commit 0ee2048

Please sign in to comment.