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

Remove window.web3 #104

Merged
merged 2 commits into from
Apr 21, 2022
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
Binary file added public/static/brave.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/static/metamask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 7 additions & 19 deletions src/context/RariContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import WalletLink from "walletlink";

async function launchModalLazy(
t: (text: string, extra?: any) => string,
cacheProvider: boolean = true
cacheProvider: boolean = true,
brave: boolean
) {
const [WalletConnectProvider, Web3Modal] = await Promise.all([
import("@walletconnect/web3-provider"),
Expand All @@ -45,6 +46,8 @@ async function launchModalLazy(
const providerOptions = {
injected: {
display: {
logo: brave ? "/static/brave.png" : "/static/metamask.png",
name: brave ? "Brave Wallet" : "Metamask",
description: t("Connect with a browser extension"),
},
package: null,
Expand Down Expand Up @@ -138,23 +141,6 @@ export const RariProvider = ({ children }: { children: ReactNode }) => {
}
}, [requestedAddress])


useEffect(() => {
//toast on brave users
if(typeof navigator !== 'object') return
const isBrave = (navigator as any).brave
if(isBrave){
toast({
title: "Warning",
description: "Brave Users may experience issues connecting. Please use Chrome/FF for now for optimal experience.",
status: "warning",
position: "bottom-right",
duration: 300000,
isClosable: true,
});
}
}, [])

// Check the user's network:
// First render only
useEffect(() => {
Expand Down Expand Up @@ -239,7 +225,9 @@ export const RariProvider = ({ children }: { children: ReactNode }) => {
async (cacheProvider: boolean = true) => {
try {
setIsAttemptingLogin(true);
const providerWeb3Modal = await launchModalLazy(t, cacheProvider);
const clientVersion = await provider.send('web3_clientVersion',[])
const isBrave = clientVersion.split('/')[0] !== 'MetaMask'
const providerWeb3Modal = await launchModalLazy(t, cacheProvider, isBrave);
setWeb3ModalProvider(providerWeb3Modal);
setRariAndAddressFromModal(providerWeb3Modal, "login");
setIsAttemptingLogin(false);
Expand Down
17 changes: 17 additions & 0 deletions src/static/icons/brave.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions src/utils/web3Providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ export function chooseBestWeb3Provider(
): JsonRpcProvider | Web3Provider {

let providerURL = getChainMetadata(chainId).rpcUrl ?? "";
console.log({ chainId, providerURL });
// return new JsonRpcProvider(providerURL);

const isClient = typeof window === "object";
if (!isClient || vaults) {
return new JsonRpcProvider(providerURL);
}

if (window.web3) {
return new Web3Provider(window.web3.currentProvider);
if (window.ethereum) {
// @ts-ignore
return new Web3Provider(window.ethereum)
} else {
return new JsonRpcProvider(providerURL);
}

}

export const initFuseWithProviders = (
Expand Down