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

added optimism support #921

Open
wants to merge 1 commit into
base: v3
Choose a base branch
from
Open
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
51 changes: 19 additions & 32 deletions src/store/main/sagas/connectWeb3Modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@ export function* connectWeb3Modal(): any {
try {
const providerOptions = {
walletconnect: {
package: WalletConnectProvider, // required
package: WalletConnectProvider,
options: {
rpc: {
137: process.env.REACT_APP_RPC_URLS,
10: process.env.REACT_APP_RPC_URLS_CHAIN_ID_10,
},
},
},
walletlink: {
package: WalletLink,
options: {
rpc: process.env.REACT_APP_RPC_URLS,
rpc: {
137: process.env.REACT_APP_RPC_URLS,
10: process.env.REACT_APP_RPC_URLS_CHAIN_ID_10,
},
chainId: 137,
},
},
Expand All @@ -37,57 +41,40 @@ export function* connectWeb3Modal(): any {
},
},
},
// "custom-gnosis": {
// display: {
// logo: "https://gnosis-safe.io/app/static/media/transition-logo.f4f66a24.gif?40",
// name: "Example Provider",
// description: "Connect to your example provider account"
// },
// package: SafeAppProvider,
// options: {
// networkParams: {
// chainId: 137,
// },
// },
// connector: async () => {
// const provider = await getProvider();

// console.log(provider)

// await provider.connect();

// return provider;
// }
// }
torus10: {
package: Torus,
options: {
networkParams: {
chainId: 10,
},
},
},
};
// const web3Modal = new Web3Modal({
// network: 'matic',
// providerOptions,
// cacheProvider: true,
// });

const web3Modal = new SafeAppWeb3Modal({
network: 'matic',
providerOptions,
cacheProvider: true,
});

// const provider = yield call(web3Modal.connect);
const provider = yield call(web3Modal.requestProvider);
const readWeb3 = new Web3(new Web3.providers.HttpProvider(process.env.REACT_APP_API_NODE_URL!));
const web3 = new Web3(provider);
const chainId = yield call(web3.eth.net.getId);
if (chainId === Number(process.env.REACT_APP_CHAIN_ID)) {

if (chainId === 137 || chainId === 10) {
yield put(modalHide());
yield put(mainGetData());
} else {
// Run modal switch network
yield put(modalShow(ModalType.Network));
}

provider?.on('chainChanged', () => store.dispatch(mainCheck()));
provider?.on('accountsChanged', () => store.dispatch(mainGetData()));
yield put(mainSetState({ web3, readWeb3 }));
} catch (e) {
// Ignoring error, since user can reject connection
console.warn(e);
}
}
}