@@ -48,6 +48,10 @@ export function matchAndGenerateProviders(
48
48
const all = allProviders ( envs ) ;
49
49
50
50
if ( providers ) {
51
+ /*
52
+ * If `wallets` is included in widget config,
53
+ * allProviders should be filtered based on wallets list
54
+ */
51
55
const selectedProviders : VersionedProviders [ ] = [ ] ;
52
56
53
57
providers . forEach ( ( requestedProvider ) => {
@@ -58,11 +62,17 @@ export function matchAndGenerateProviders(
58
62
*/
59
63
if ( typeof requestedProvider === 'string' ) {
60
64
const result = all . find ( ( provider ) => {
61
- const versionedProvider =
62
- pickSingleProviderVersionWithFallbackToLegacy (
63
- provider ,
64
- options ?. experimentalWallet
65
- ) ;
65
+ /*
66
+ * To find a provider in allProviders,
67
+ * a version of each provider should be picked
68
+ * and validated based on that version scheme.
69
+ * If the corresponding provider to a wallet was found in allProvider,
70
+ * it will be add to selected providers.
71
+ */
72
+ const versionedProvider = pickProviderVersionWithFallbackToLegacy (
73
+ provider ,
74
+ options
75
+ ) ;
66
76
if ( versionedProvider instanceof Provider ) {
67
77
return versionedProvider . id === requestedProvider ;
68
78
}
@@ -73,6 +83,7 @@ export function matchAndGenerateProviders(
73
83
selectedProviders . push ( result ) ;
74
84
}
75
85
console . warn (
86
+ // A provider name is included in config but was not found in allProviders
76
87
`Couldn't find ${ requestedProvider } provider. Please make sure you are passing the correct name.`
77
88
) ;
78
89
} else {
@@ -95,23 +106,13 @@ export function matchAndGenerateProviders(
95
106
return all ;
96
107
}
97
108
98
- // TODO: this is a duplication with what we do in core.
99
- function pickVersionWithFallbackToLegacy (
100
- providers : VersionedProviders [ ] ,
101
- options ?: ProvidersOptions
102
- ) : BothProvidersInterface [ ] {
103
- const { experimentalWallet = 'enabled' } = options || { } ;
104
-
105
- return providers . map ( ( provider ) =>
106
- pickSingleProviderVersionWithFallbackToLegacy ( provider , experimentalWallet )
107
- ) ;
108
- }
109
-
110
- function pickSingleProviderVersionWithFallbackToLegacy (
109
+ function pickProviderVersionWithFallbackToLegacy (
111
110
provider : VersionedProviders ,
112
- experimentalWallet ?: 'enabled' | 'disabled'
111
+ options ?: ProvidersOptions
113
112
) : BothProvidersInterface {
113
+ const { experimentalWallet = 'enabled' } = options || { } ;
114
114
const version = experimentalWallet == 'disabled' ? '0.0.0' : '1.0.0' ;
115
+
115
116
try {
116
117
return pickVersion ( provider , version ) [ 1 ] ;
117
118
} catch {
@@ -124,9 +125,8 @@ export function configWalletsToWalletName(
124
125
config : WidgetConfig [ 'wallets' ] ,
125
126
options ?: ProvidersOptions
126
127
) : string [ ] {
127
- const providers = pickVersionWithFallbackToLegacy (
128
- matchAndGenerateProviders ( config , options ) ,
129
- options
128
+ const providers = matchAndGenerateProviders ( config , options ) . map ( ( provider ) =>
129
+ pickProviderVersionWithFallbackToLegacy ( provider , options )
130
130
) ;
131
131
const names = providers . map ( ( provider ) => {
132
132
if ( provider instanceof Provider ) {
0 commit comments