Skip to content

Commit 6146705

Browse files
committed
fix: fix review comments
1 parent 66b5ad8 commit 6146705

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

wallets/react/src/hub/autoConnect.ts

+4
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ export async function autoConnect(deps: {
108108
// Run `.connect` if `.canEagerConnect` returns `true`.
109109
walletIds.forEach((providerName) => {
110110
if (wallets && !wallets.includes(providerName)) {
111+
console.warn(
112+
'Trying to run auto connect for a wallet which is not included in config. Desired wallet:',
113+
providerName
114+
);
111115
walletsToRemoveFromPersistance.push(providerName);
112116
return;
113117
}

widget/embedded/src/utils/providers.ts

+22-22
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ export function matchAndGenerateProviders(
4848
const all = allProviders(envs);
4949

5050
if (providers) {
51+
/*
52+
* If `wallets` is included in widget config,
53+
* allProviders should be filtered based on wallets list
54+
*/
5155
const selectedProviders: VersionedProviders[] = [];
5256

5357
providers.forEach((requestedProvider) => {
@@ -58,11 +62,17 @@ export function matchAndGenerateProviders(
5862
*/
5963
if (typeof requestedProvider === 'string') {
6064
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+
);
6676
if (versionedProvider instanceof Provider) {
6777
return versionedProvider.id === requestedProvider;
6878
}
@@ -73,6 +83,7 @@ export function matchAndGenerateProviders(
7383
selectedProviders.push(result);
7484
}
7585
console.warn(
86+
// A provider name is included in config but was not found in allProviders
7687
`Couldn't find ${requestedProvider} provider. Please make sure you are passing the correct name.`
7788
);
7889
} else {
@@ -95,23 +106,13 @@ export function matchAndGenerateProviders(
95106
return all;
96107
}
97108

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(
111110
provider: VersionedProviders,
112-
experimentalWallet?: 'enabled' | 'disabled'
111+
options?: ProvidersOptions
113112
): BothProvidersInterface {
113+
const { experimentalWallet = 'enabled' } = options || {};
114114
const version = experimentalWallet == 'disabled' ? '0.0.0' : '1.0.0';
115+
115116
try {
116117
return pickVersion(provider, version)[1];
117118
} catch {
@@ -124,9 +125,8 @@ export function configWalletsToWalletName(
124125
config: WidgetConfig['wallets'],
125126
options?: ProvidersOptions
126127
): string[] {
127-
const providers = pickVersionWithFallbackToLegacy(
128-
matchAndGenerateProviders(config, options),
129-
options
128+
const providers = matchAndGenerateProviders(config, options).map((provider) =>
129+
pickProviderVersionWithFallbackToLegacy(provider, options)
130130
);
131131
const names = providers.map((provider) => {
132132
if (provider instanceof Provider) {

0 commit comments

Comments
 (0)