Skip to content

fix(checkout): Resolve wallet connect issues #2591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export function ConnectLoader({

const isWalletConnected = async (localProvider: WrappedBrowserProvider): Promise<boolean> => {
const { isConnected } = await checkout.checkIsWalletConnected({
provider: localProvider!,
provider: localProvider,
});
if (!isConnected) {
connectLoaderDispatch({
Expand Down Expand Up @@ -207,6 +207,8 @@ export function ConnectLoader({
return;
}
} catch (err) {
// eslint-disable-next-line no-console
console.error(err);
return;
}

Expand All @@ -217,6 +219,8 @@ export function ConnectLoader({
const anonymousId = userData?.anonymousId();
await identifyUser(identify, browserProvider!, { anonymousId });
} catch (err) {
// eslint-disable-next-line no-console
console.error(err);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ export async function identifyUser(
provider: WrappedBrowserProvider,
options?: Record<string, any>,
) {
// WT-1698 Analytics - Identify user here then progress to widget
const walletAddress = (await (await provider.getSigner()).getAddress()).toLowerCase();
const signer = await provider.getSigner();
const address = await signer.getAddress();
const walletAddress = address.toLowerCase();
const isMetaMask = isMetaMaskProvider(provider);
const isPassport = isPassportProvider(provider);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,25 +215,17 @@ export function WalletList(props: WalletListProps) {

const connectCallback = async (ethereumProvider: EthereumProvider) => {
if (ethereumProvider.connected && ethereumProvider.session) {
const browserProvider = new WrappedBrowserProvider(ethereumProvider);
selectBrowserProvider(browserProvider, 'walletconnect');

const { chainId } = await ((await browserProvider.getSigner()).provider.getNetwork());

if (ethereumProvider.chainId !== targetChainId) {
// @ts-ignore allow protected method `switchEthereumChain` to be called
await ethereumProvider.switchEthereumChain(targetChainId);
}

if (chainId as unknown as ChainId !== targetChainId) {
viewDispatch({
payload: {
type: ViewActions.UPDATE_VIEW,
view: { type: ConnectWidgetViews.SWITCH_NETWORK },
},
await ethereumProvider.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId: `0x${targetChainId.toString(16)}` }],
});
}

const browserProvider = new WrappedBrowserProvider(ethereumProvider, 'any');

selectBrowserProvider(browserProvider, 'walletconnect');

viewDispatch({
payload: {
type: ViewActions.UPDATE_VIEW,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ export function SwitchNetworkZkEVM() {
if (!provider || !checkout) return;

const checkCorrectNetwork = async () => {
const currentChainId = await provider.send('eth_chainId', []);
// eslint-disable-next-line radix
const currentChainId = await provider.getNetwork().then((n) => n.chainId);
const parsedChainId = Number(currentChainId.toString());
if (parsedChainId === checkout.config.l2ChainId) {
connectDispatch({
Expand Down Expand Up @@ -151,6 +150,8 @@ export function SwitchNetworkZkEVM() {
},
});
} catch (err: any) {
// eslint-disable-next-line no-console
console.error(err);
setButtonTextKey(t('views.SWITCH_NETWORK.zkEVM.button.retryText'));
}
}, [provider, checkout]);
Expand Down