Skip to content
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

fix: android and detox E2E issue #343

Merged
merged 4 commits into from
Jun 14, 2024
Merged
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
35 changes: 28 additions & 7 deletions src/connections.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { MetaMaskSDK } from '@metamask/sdk';
import { createWeb3Modal, defaultConfig } from '@web3modal/ethers5';
import {
handleNewAccounts,
handleNewProviderDetail,
Expand All @@ -16,12 +15,34 @@ const dappMetadata = {
url: 'https://metamask.github.io/test-dapp/',
};

// eslint-disable-next-line require-unicode-regexp
const isAndroid = /Android/i.test(navigator.userAgent);

const sdk = new MetaMaskSDK({ dappMetadata });

export const walletConnect = createWeb3Modal({
ethersConfig: defaultConfig({ metadata: dappMetadata }),
projectId: 'e6360eaee594162688065f1c70c863b7', // test id
});
export const initializeWeb3Modal = () => {
if (!isAndroid) {
try {
// eslint-disable-next-line node/global-require
const { createWeb3Modal, defaultConfig } = require('@web3modal/ethers5');

const web3Modal = createWeb3Modal({
ethersConfig: defaultConfig({ metadata: dappMetadata }),
vinistevam marked this conversation as resolved.
Show resolved Hide resolved
projectId: 'e6360eaee594162688065f1c70c863b7',
});

console.log('Web3Modal initialized successfully');
return web3Modal;
} catch (error) {
console.error('Error initializing Web3Modal', error);
}
}

console.log('Web3Modal is not initialized');
return null;
};

export const walletConnect = initializeWeb3Modal();

function _setProviderDetail(provider, name, uuid) {
const providerDetail = {
Expand Down Expand Up @@ -51,7 +72,7 @@ export async function handleSdkConnect(name, button, isConnected) {
const provider = sdk.getProvider();
const uuid = sdk.getChannelId();
const providerDetail = _setProviderDetail(provider, name, uuid);
setActiveProviderDetail(providerDetail);
await setActiveProviderDetail(providerDetail);
handleNewProviderDetail(providerDetail);
updateSdkConnectionState(true);
button.innerText = 'Sdk Connect - Disconnect';
Expand Down Expand Up @@ -84,7 +105,7 @@ export async function handleWalletConnect(name, button, isConnected) {
const { provider } = walletConnect.getWalletProvider();
const uuid = provider.signer.uri;
const providerDetail = _setProviderDetail(provider, name, uuid);
setActiveProviderDetail(providerDetail);
await setActiveProviderDetail(providerDetail);
handleNewProviderDetail(providerDetail);
updateWalletConnectState(true);
button.innerText = 'Wallet Connect - Disconnect';
Expand Down
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ const detectEip6963 = () => {
export const setActiveProviderDetail = async (providerDetail) => {
closeProvider();
provider = providerDetail.provider;
initializeProvider();
await initializeProvider();

try {
const newAccounts = await provider.request({
Expand All @@ -574,7 +574,7 @@ export const setActiveProviderDetail = async (providerDetail) => {
updateFormElements();
};

const setActiveProviderDetailWindowEthereum = () => {
const setActiveProviderDetailWindowEthereum = async () => {
const providerDetail = {
info: {
uuid: '',
Expand All @@ -584,7 +584,7 @@ const setActiveProviderDetailWindowEthereum = () => {
provider: window.ethereum,
};

setActiveProviderDetail(providerDetail);
await setActiveProviderDetail(providerDetail);
};

const existsProviderDetail = (newProviderDetail) => {
Expand Down Expand Up @@ -3349,9 +3349,9 @@ const setDeeplinks = () => {
*/

const initialize = async () => {
setActiveProviderDetailWindowEthereum();
await setActiveProviderDetailWindowEthereum();
detectEip6963();
setActiveProviderDetail(providerDetails[0]);
await setActiveProviderDetail(providerDetails[0]);
initializeFormElements();
setDeeplinks();
};
Expand Down
Loading