Skip to content

Commit

Permalink
Remove window.web3 (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptickoan authored Apr 21, 2022
1 parent 049296b commit f2f2da7
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 23 deletions.
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

1 comment on commit f2f2da7

@vercel
Copy link

@vercel vercel bot commented on f2f2da7 Apr 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.