Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: preserve order of providers as passed into useInitializeProviders #111

Merged
merged 2 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 8 additions & 2 deletions src/utils/initializeProviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ export const initializeProviders = async <T extends keyof ProviderConfigMapping>
nodeConfig?: NodeConfig,
algosdkStatic?: typeof algosdk
): Promise<SupportedProviders> => {
const initializedProviders: SupportedProviders = {}

if (typeof window === 'undefined') {
debugLog('Window object is not available, skipping initialization')
return initializedProviders
return {} as SupportedProviders
}

// Set all providers to null to preserve order
const initializedProviders = providers.reduce((acc, provider) => {
const providerId = typeof provider === 'string'? provider : provider.id
acc[providerId] = null
return acc
}, {} as SupportedProviders)

const {
network = DEFAULT_NETWORK,
nodeServer = DEFAULT_NODE_BASEURL,
Expand Down