connect icon indicating copy to clipboard operation
connect copied to clipboard

feat: expose WalletConnect.initializeProvider for independent inialization

Open jfstn opened this issue 3 months ago • 0 comments

Description

As a Stacks Connect developer, I would like to initialize WalletConnect independently from the request flow so that I can provide a better user experience in my application. This is needed because the current implementation forces WalletConnect initialization to happen during the request() call, which ties initialization to user actions and limits UX control.

Motivation for change

Previously, WalletConnect could only be initialized by passing walletConnect or walletConnectProjectId options to the request() function. This meant consumers using the library as an abstraction layer had no way to pre-initialize WalletConnect, resulting in initialization delays during critical user interactions.

What was changed

  1. Exported the initializeProvider function from the WalletConnect namespace
  2. Re-exported config constants (Networks, Chains, Default) from walletconnect/index.ts
  3. Updated main index.ts to export the full WalletConnect module instead of just config
  4. Added JSDoc documentation with usage examples

How does this impact application developers

Application developers can now:

  • Initialize WalletConnect at application startup or any time before making requests
  • Provide a smoother UX by separating initialization from user actions
  • Continue using the existing pattern (backward compatible)

Examples of use cases

Initializing at app startup:

import { WalletConnect } from '@stacks/connect';

// In your app initialization
await WalletConnect.initializeProvider('your-project-id');

With full configuration:

import { WalletConnect } from '@stacks/connect';

await WalletConnect.initializeProvider({
  projectId: 'your-project-id',
  metadata: {
    name: 'My Stacks App',
    description: 'A decentralized application',
    url: 'https://myapp.com',
    icons: ['https://myapp.com/icon.png']
  },
  networks: [WalletConnect.Networks.Stacks]
});

Making requests after initialization:

import { request } from '@stacks/connect';

// WalletConnect is already initialized, just make the request
const result = await request('getAddresses');

Acceptance criteria

  • WalletConnect.initializeProvider() is accessible from @stacks/connect
  • ✅ Function accepts both string (projectId) and full config object
  • ✅ Existing walletConnect option in request() continues to work
  • ✅ Config constants (Networks, Chains, Default) remain accessible

Link to relevant documentation

JSDoc examples added in the code provide inline documentation for developers.

Type of Change

  • [x] New feature

Does this introduce a breaking change?

No breaking changes. This PR is fully backward compatible:

  • Existing code using walletConnect options in request() continues to work unchanged
  • Only adds new functionality, doesn't modify or remove existing APIs

Checklist

  • [x] Code is commented where needed
  • [ ] Unit test coverage for new or modified code paths
  • [x] Changelog is updated
  • [x] Tag @janniks for review

@janniks

jfstn avatar Nov 05 '25 14:11 jfstn