1
1
import { JsonRpcSigner } from '@ethersproject/providers/src.ts/json-rpc-provider' ;
2
- import React from 'react' ;
3
- import { ethers } from 'ethers' ;
2
+ import { ledgerProviderOptions } from '@rsksmart/rlogin-ledger-provider' ;
4
3
import WalletConnectProvider from '@walletconnect/web3-provider' ;
5
- import Web3Modal from 'web3modal' ;
4
+ import { ethers } from 'ethers' ;
5
+ import React from 'react' ;
6
+ import WalletLink from 'walletlink' ;
7
+ import Web3Modal , { IProviderOptions } from 'web3modal' ;
6
8
7
9
export interface Web3ContextType {
8
10
connectWallet ?: ( ) => void ;
@@ -29,15 +31,33 @@ export interface ProviderProps {
29
31
* @type string
30
32
*/
31
33
infuraId ?: string ;
34
+ /**
35
+ * @dev An array of extra Wallet Providers you want to support.
36
+ * @type [
37
+ [id: string]: {
38
+ package: any;
39
+ options?: any;
40
+ connector?: Connector;
41
+ display?: Partial<IProviderDisplay>;
42
+ };
43
+ ]
44
+ */
45
+ extraWalletProviders ?: [ IProviderOptions ] ;
32
46
}
33
47
34
48
/**
35
49
* @dev The global provider that handles and stores all the web3 connections. Wrap your entire App with this component.
36
50
* @param children Your app.
37
51
* @param network The network you want to connect to.
38
52
* @param infuraId Your Infura project ID. This is required if you want to support WalletConnect.
53
+ * @param extraWalletProviders An array of extra Wallet Providers you want to support.
39
54
*/
40
- export const Provider : React . FC < ProviderProps > = ( { children, network, infuraId } ) => {
55
+ export const Provider : React . FC < ProviderProps > = ( {
56
+ children,
57
+ network,
58
+ infuraId,
59
+ extraWalletProviders = [ ] ,
60
+ } ) => {
41
61
const [ signer , setSigner ] = React . useState < null | JsonRpcSigner > ( ) ;
42
62
const [ provider , setProvider ] = React . useState < ethers . providers . Web3Provider | null > ( ) ;
43
63
const [ userAddress , setUserAddress ] = React . useState < null | string > ( ) ;
@@ -48,15 +68,49 @@ export const Provider: React.FC<ProviderProps> = ({ children, network, infuraId
48
68
const [ connection , setConnection ] = React . useState < any > ( ) ;
49
69
50
70
const connectWallet = React . useCallback ( async ( ) => {
51
- const web3Modal = new Web3Modal ( {
52
- providerOptions : {
53
- walletconnect : {
54
- package : WalletConnectProvider ,
55
- options : {
56
- infuraId,
71
+ // Coinbase walletLink init
72
+ const walletLink = new WalletLink ( {
73
+ appName : 'coinbase' ,
74
+ } ) ;
75
+
76
+ // WalletLink provider
77
+ const walletLinkProvider = walletLink . makeWeb3Provider (
78
+ `https://eth-mainnet.alchemyapi.io/v2/${ infuraId } ` ,
79
+ 1
80
+ ) ;
81
+
82
+ const defaulProviderOptions = {
83
+ walletconnect : {
84
+ package : WalletConnectProvider ,
85
+ options : {
86
+ bridge : 'https://polygon.bridge.walletconnect.org' ,
87
+ infuraId,
88
+ rpc : {
89
+ 1 : `https://eth-mainnet.alchemyapi.io/v2/${ infuraId } ` , // mainnet // For more WalletConnect providers: https://docs.walletconnect.org/quick-start/dapps/web3-provider#required
90
+ 42 : `https://kovan.infura.io/v3/${ infuraId } ` ,
91
+ 100 : 'https://dai.poa.network' , // xDai
57
92
} ,
58
93
} ,
59
94
} ,
95
+ 'custom-walletlink' : {
96
+ display : {
97
+ logo : 'https://play-lh.googleusercontent.com/PjoJoG27miSglVBXoXrxBSLveV6e3EeBPpNY55aiUUBM9Q1RCETKCOqdOkX2ZydqVf0' ,
98
+ name : 'Coinbase' ,
99
+ description : 'Connect to Coinbase Wallet' ,
100
+ } ,
101
+ package : walletLinkProvider ,
102
+ connector : async ( provider , options ) => {
103
+ await provider . enable ( ) ;
104
+ return provider ;
105
+ } ,
106
+ } ,
107
+ 'custom-ledger' : {
108
+ ...ledgerProviderOptions ,
109
+ } ,
110
+ } ;
111
+
112
+ const web3Modal = new Web3Modal ( {
113
+ providerOptions : Object . assign ( defaulProviderOptions , ...extraWalletProviders ) ,
60
114
} ) ;
61
115
setWeb3Modal ( web3Modal ) ;
62
116
const connection = await web3Modal . connect ( ) ;
0 commit comments