@@ -3,7 +3,7 @@ import {groupBy} from 'lodash-es';
33import { observer } from 'mobx-react' ;
44import React , { useEffect , useRef , useState } from 'react' ;
55
6- import { WalletType } from '@/core/config/createWallets' ;
6+ import { BraveWallet , WalletType } from '@/core/config/createWallets' ;
77import { transactionStore } from '@/core/stores/transactionStore' ;
88import { uiStore , WalletTab } from '@/core/stores/uiStore' ;
99import { walletStore } from '@/core/stores/walletStore' ;
@@ -154,23 +154,26 @@ const WalletItem: React.FC<{
154154} > = observer ( ( { wallet} ) => {
155155 const mobile = isMobile ( ) ;
156156
157- if ( wallet . type === 'Brave' || ( wallet . type === ' Core' && mobile ) ) {
157+ if ( wallet . type === 'Core' && mobile ) {
158158 // https://github.com/telosnetwork/telos-bridge/issues/20
159159 return null ;
160160 }
161161
162162 let buttonText ;
163+ const win = window as any ;
163164
164- const isSafePal = ( window as any ) . ethereum . isSafePal ;
165+ const isSafePal = win . ethereum ?. isSafePal ;
166+ const isBraveBrowser = win . navigator . brave ;
167+ const isBraveWallet = win . ethereum ?. isBraveWallet ;
165168
166169 if ( wallet . isConnecting ) {
167170 buttonText = 'Connecting...' ;
168171 } else if ( wallet . isConnected && wallet . address ) {
169172 buttonText = `${ formatAddress ( wallet . address , 16 ) } ` ;
170173 // handle safepal extension conflict
171- } else if ( wallet . type === WalletType . METAMASK && isSafePal ) {
174+ } else if ( wallet . type === WalletType . METAMASK && isSafePal ) {
172175 buttonText = `Get MetaMask Wallet` ;
173- } else if ( wallet . isAvailable ) {
176+ } else if ( wallet . isAvailable || ( wallet . type === WalletType . BRAVE && isBraveWallet ) ) {
174177 buttonText = `Connect ${ wallet . type } ` ;
175178 } else if ( ! mobile ) {
176179 buttonText = `Get ${ wallet . type } Wallet` ;
@@ -188,7 +191,10 @@ const WalletItem: React.FC<{
188191 window . open ( 'https://metamask.app.link/dapp/bridge.telos.net' ) ;
189192 return ;
190193 }
191- if ( wallet . isAvailable ) {
194+ if ( isBraveBrowser && isBraveWallet ) {
195+ ( wallet as BraveWallet ) . setProvider ( WalletType . BRAVE , win . ethereum ) ;
196+ }
197+ if ( wallet . isAvailable || isBraveWallet ) {
192198 wallet . connect ( ) ;
193199 return ;
194200 }
@@ -201,6 +207,8 @@ const WalletItem: React.FC<{
201207 window . open ( 'https://phantom.app/ul/' ) ;
202208 } else if ( wallet . type === WalletType . SAFEPAL ) {
203209 window . open ( 'https://www.safepal.com/en/download' ) ;
210+ } else if ( wallet . type === WalletType . BRAVE ) {
211+ window . open ( ( wallet as any ) . url ) ;
204212 }
205213 }
206214
0 commit comments