Skip to content

Commit

Permalink
fix: preserve order of providers as passed into useInitializeProviders
Browse files Browse the repository at this point in the history
Closes #104
  • Loading branch information
No-Cash-7970 committed Sep 18, 2023
1 parent b8bf195 commit acff1c0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/utils/initializeProviders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe('initializeProviders', () => {
const result = await initializeProviders(providers)

// Check if the returned object has the correct keys
expect(Object.keys(result)).toEqual(expect.arrayContaining(providers))
expect(Object.keys(result)).toEqual(providers)

// Check if the returned clients are instances of BaseClient
for (const clientInstance of Object.values(result)) {
Expand Down
6 changes: 5 additions & 1 deletion src/utils/initializeProviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ export const initializeProviders = async <T extends keyof ProviderConfigMapping>

debugLog('Initializing providers:', getProviderList(providers))

const initPromises = providers.map((provider) => initClient(provider))
const initPromises = providers.map((provider) => {
const providerId = typeof provider === 'string'? provider : provider.id
initializedProviders[providerId] = null // Set to null to preserve order of providers
initClient(provider)
})
await Promise.all(initPromises)

return initializedProviders
Expand Down

0 comments on commit acff1c0

Please sign in to comment.