@@ -3,8 +3,14 @@ import { EnvironmentAccessorService } from '@/common/services/enviroment-accesso
3
3
import WalletConnectProvider from '@walletconnect/web3-provider' ;
4
4
import { trezorProviderOptions } from '@rsksmart/rlogin-trezor-provider' ;
5
5
import { ledgerProviderOptions } from '@rsksmart/rlogin-ledger-provider' ;
6
+ import * as constants from '@/common/store/constants' ;
7
+ import {
8
+ Browser , Feature , FeatureNames , SupportedBrowsers ,
9
+ } from '../types' ;
10
+ import { getBrowserName } from './utils' ;
6
11
7
- export function getRloginInstance ( ) : RLogin {
12
+ export function getRloginInstance ( features : Array < Feature > ) : RLogin {
13
+ const currentBrowser = getBrowserName ( ) as Browser ;
8
14
const rpcUrls = { } ;
9
15
const customLedgerProviderOptions = ledgerProviderOptions ;
10
16
customLedgerProviderOptions . connector = async ( ProviderPackage , options ) => {
@@ -14,6 +20,16 @@ export function getRloginInstance(): RLogin {
14
20
await provider . connect ( ) ;
15
21
return provider ;
16
22
} ;
23
+ const customTrezorProviderOptions = {
24
+ ...trezorProviderOptions ,
25
+ options : {
26
+ dPath : "m/44'/37310'/0'/0/0" ,
27
+ manifestEmail : EnvironmentAccessorService
28
+ . getEnvironmentVariables ( ) . vueAppManifestEmail ,
29
+ manifestAppUrl : EnvironmentAccessorService
30
+ . getEnvironmentVariables ( ) . vueAppManifestAppUrl ,
31
+ } ,
32
+ } ;
17
33
const { vueAppRskNodeHost, chainId } = EnvironmentAccessorService . getEnvironmentVariables ( ) ;
18
34
Object
19
35
. defineProperty ( rpcUrls , chainId , {
@@ -23,30 +39,34 @@ export function getRloginInstance(): RLogin {
23
39
enumerable : true ,
24
40
} ) ;
25
41
const supportedChains = Object . keys ( rpcUrls ) . map ( Number ) ;
26
- const rLoginSetup = new RLogin ( {
42
+ const rLoginOptions = {
27
43
cacheProvider : false ,
28
- defaultTheme : 'dark' ,
44
+ defaultTheme : 'dark' as 'dark' | 'light' ,
29
45
providerOptions : {
30
46
walletconnect : {
31
47
package : WalletConnectProvider ,
32
48
options : {
33
49
rpc : rpcUrls ,
34
50
} ,
35
51
} ,
36
- 'custom-ledger' : customLedgerProviderOptions ,
37
- 'custom-trezor' : {
38
- ...trezorProviderOptions ,
39
- options : {
40
- dPath : "m/44'/37310'/0'/0/0" ,
41
- manifestEmail : EnvironmentAccessorService
42
- . getEnvironmentVariables ( ) . vueAppManifestEmail ,
43
- manifestAppUrl : EnvironmentAccessorService
44
- . getEnvironmentVariables ( ) . vueAppManifestAppUrl ,
45
- } ,
46
- } ,
47
52
} ,
48
53
rpcUrls,
49
54
supportedChains,
50
- } ) ;
55
+ } ;
56
+ const ledgerFeature = features . find ( ( feature ) => feature . name === FeatureNames . WALLET_LEDGER ) ;
57
+ if ( ledgerFeature ?. value === constants . ENABLED
58
+ && ledgerFeature . supportedBrowsers [ currentBrowser . toLowerCase ( ) as keyof SupportedBrowsers ] ) {
59
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
60
+ // @ts -ignore
61
+ rLoginOptions . providerOptions [ 'custom-ledger' ] = customLedgerProviderOptions ;
62
+ }
63
+ const trezorFeature = features . find ( ( feature ) => feature . name === FeatureNames . WALLET_TREZOR ) ;
64
+ if ( trezorFeature ?. value === constants . ENABLED
65
+ && trezorFeature . supportedBrowsers [ currentBrowser . toLowerCase ( ) as keyof SupportedBrowsers ] ) {
66
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
67
+ // @ts -ignore
68
+ rLoginOptions . providerOptions [ 'custom-trezor' ] = customTrezorProviderOptions ;
69
+ }
70
+ const rLoginSetup = new RLogin ( rLoginOptions ) ;
51
71
return rLoginSetup ;
52
72
}
0 commit comments