Skip to content

Commit

Permalink
refactor provider discovery (#219)
Browse files Browse the repository at this point in the history
* refactor provider discovery

* Fix promise call

---------

Co-authored-by: BenRey <[email protected]>
  • Loading branch information
Thykof and Ben-Rey authored Apr 23, 2024
1 parent 8a536ed commit 8f35c4c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/massaStation/MassaStationDiscovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ export async function isMassaStationAvailable(): Promise<boolean> {
export async function isMassaWalletEnabled(): Promise<boolean> {
const response = await fetchPluginData();

if (response.isError) return false;
if (response.isError) {
console.warn('Error fetching plugin data:', response.error);

Check warning on line 29 in src/massaStation/MassaStationDiscovery.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

Check warning on line 29 in src/massaStation/MassaStationDiscovery.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
return false;
}

const walletPlugin = findWalletPlugin(response.result);
return walletPlugin && walletPlugin.status === 'Up';
Expand Down
22 changes: 14 additions & 8 deletions src/providersManager/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,23 @@ export async function providers(): Promise<IProvider[]> {

export async function getProvidersInstances(): Promise<IProvider[]> {
const providerInstances: IProvider[] = [];

const promises = [];
for (const provider of providerList) {
try {
if (await provider.checkInstalled()) {
providerInstances.push(provider.createInstance());
}
} catch (error) {
console.error(`Error initializing provider ${provider.name}:`, error);
}
promises.push(
(async () => {
try {
if (await provider.checkInstalled()) {
providerInstances.push(provider.createInstance());
}
} catch (error) {
console.error(`Error initializing provider ${provider.name}:`, error);
}
})(),
);
}

await Promise.all(promises);

providerInstances.push(...addCustomProvider(connector));

return providerInstances;
Expand Down

0 comments on commit 8f35c4c

Please sign in to comment.