Skip to content
This repository was archived by the owner on Sep 3, 2026. It is now read-only.

feat(custom-provider): add custom providers support - #472

Merged
TrueCarry merged 2 commits into
mainfrom
feat/custom-provider
Jun 17, 2026
Merged

TrueCarry merged 2 commits into
mainfrom
feat/custom-provider

Conversation

@vkarchava

@vkarchava vkarchava commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features
    • Added custom provider support across the SDK, including a custom provider registry and access via customProviders.
    • Added getCustomProvider and watchCustomProviders for retrieving and reacting to custom provider registrations.
    • Added useCustomProvider React hook for accessing registered custom providers by id.
  • Documentation
    • Updated action and hook docs with getCustomProvider/useCustomProvider usage guidance.
    • Added runnable examples for custom provider actions and the React hook.
  • Tests
    • Added integration tests for the custom provider action and React hook examples.

@vercel

vercel Bot commented Jun 17, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
appkit-minter Ready Ready Preview, Comment Jun 17, 2026 1:59pm
kit-demo-wallet Ready Ready Preview, Comment Jun 17, 2026 1:59pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 17, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a CustomProvider interface and CustomProvidersManager registry to @ton/walletkit, wires it into TonWalletKit and AppKit as a new provider type 'custom', exposes getCustomProvider and watchCustomProviders action helpers, adds a useCustomProvider React hook to @ton/appkit-react, and ships demo examples, tests, and documentation.

Changes

Custom Provider Feature

Layer / File(s) Summary
CustomProvider interface and CustomProvidersManager registry
packages/walletkit/src/providers/CustomProvider.ts, packages/walletkit/src/providers/CustomProvidersManager.ts, packages/walletkit/src/providers/CustomProvidersManager.spec.ts, packages/walletkit/src/providers/index.ts, packages/walletkit/src/index.ts
Defines CustomProvider as a BaseProvider extension with type: 'custom' and CustomProvidersManager with registerProvider, getProvider, hasProvider, and getRegisteredProviders methods backed by a Map and an injected EventEmitter. Spec covers registration, lookup, replacement, enumeration, factory resolution, and event emission.
TonWalletKit and AppKit integration
packages/walletkit/src/core/TonWalletKit.ts, packages/appkit/src/core/app-kit/services/app-kit.ts, packages/appkit/src/types/provider.ts, packages/appkit/src/providers/index.ts, packages/appkit/src/index.ts
Adds customProvidersManager field to both TonWalletKit and AppKit, initializes it via the factory-context callback pattern, adds a 'custom' case to registerProvider, exposes a customProviders getter on TonWalletKit, and extends AppKitProvider union with CustomProvider.
getCustomProvider and watchCustomProviders action helpers
packages/appkit/src/actions/providers/get-custom-provider.ts, packages/appkit/src/actions/providers/watch-custom-providers.ts, packages/appkit/src/actions/index.ts
getCustomProvider delegates to customProvidersManager.getProvider(id) with typed options/return types. watchCustomProviders subscribes to emitter 'provider:registered' and calls onChange only for type === 'custom' events. Both are re-exported from the actions index.
useCustomProvider React hook
packages/appkit-react/src/features/providers/hooks/use-custom-provider.ts, packages/appkit-react/src/features/providers/index.ts, packages/appkit-react/src/index.ts
Implements useCustomProvider using useSyncExternalStore with memoized subscribe (via watchCustomProviders) and getSnapshot (via getCustomProvider) callbacks, returning T | undefined. Wired through the feature barrel into the package root.
Demo examples and integration tests
demo/examples/src/appkit/actions/providers/get-custom-provider.ts, demo/examples/src/appkit/actions/providers/providers.test.ts, demo/examples/src/appkit/hooks/providers/use-custom-provider.tsx, demo/examples/src/appkit/hooks/providers/providers.test.tsx
Action example calls getCustomProvider with a custom interface and logs availability. Hook example component UseCustomProviderExample renders registered/unregistered states. Both have tests: the action test registers a provider and checks console.log; the hook test mocks customProvidersManager.getProvider and checks rendered text.
Documentation
packages/appkit/docs/actions.md, packages/appkit-react/docs/hooks.md, template/packages/appkit/docs/actions.md, template/packages/appkit-react/docs/hooks.md, .changeset/custom-providers.md
Documents getCustomProvider (id usage) in appkit actions docs and template. Documents useCustomProvider hook with conditional rendering example in appkit-react hooks docs and template. Fixes getGaslessQuote example to use asBase64(). Includes changeset describing all custom provider features across the three packages.

Sequence Diagram(s)

sequenceDiagram
  participant App
  participant AppKit
  participant CustomProvidersManager
  participant EventEmitter
  participant useCustomProvider

  App->>AppKit: registerProvider({ type: 'custom', ... })
  AppKit->>CustomProvidersManager: registerProvider(input)
  CustomProvidersManager->>EventEmitter: emit provider:registered { type: 'custom' }

  rect rgba(100, 149, 237, 0.5)
    note over useCustomProvider: React subscription via useSyncExternalStore
    useCustomProvider->>AppKit: watchCustomProviders(appKit, { onChange })
    EventEmitter-->>useCustomProvider: provider:registered (type='custom') → onChange()
    useCustomProvider->>AppKit: getCustomProvider(appKit, { id })
    AppKit->>CustomProvidersManager: getProvider(id)
    CustomProvidersManager-->>useCustomProvider: T | undefined
  end

  useCustomProvider-->>App: renders provider-ready or not-registered UI
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 Hoppity-hop, a new provider in town,
With generic types, it won't let you down!
registerProvider stores it away,
getCustomProvider finds it each day.
The hook subscribes and the React tree glows,
Where custom providers go, a rabbit knows! 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'feat(custom-provider): add custom providers support' directly and clearly summarizes the main objective of the changeset: introducing comprehensive custom providers support across walletkit, appkit, and appkit-react packages.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/custom-provider

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@demo/examples/src/appkit/hooks/providers/providers.test.tsx`:
- Around line 9-18: The mockAppKit variable is declared with a broad any type
annotation, which violates coding guidelines for non-invalid-input test
scenarios. Replace the any type on the mockAppKit variable declaration with an
explicit type that matches the actual mock structure being set up in the
beforeEach hook. Define a proper interface or type that captures the shape of
the AppKit mock object to maintain type safety throughout the test.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9a44f57d-b67f-4233-9747-307e467a6db6

📥 Commits

Reviewing files that changed from the base of the PR and between 8596599 and e2fded2.

📒 Files selected for processing (24)
  • demo/examples/src/appkit/actions/providers/get-custom-provider.ts
  • demo/examples/src/appkit/actions/providers/providers.test.ts
  • demo/examples/src/appkit/hooks/providers/providers.test.tsx
  • demo/examples/src/appkit/hooks/providers/use-custom-provider.tsx
  • packages/appkit-react/docs/hooks.md
  • packages/appkit-react/src/features/providers/hooks/use-custom-provider.ts
  • packages/appkit-react/src/features/providers/index.ts
  • packages/appkit-react/src/index.ts
  • packages/appkit/docs/actions.md
  • packages/appkit/src/actions/index.ts
  • packages/appkit/src/actions/providers/get-custom-provider.ts
  • packages/appkit/src/actions/providers/watch-custom-providers.ts
  • packages/appkit/src/core/app-kit/services/app-kit.ts
  • packages/appkit/src/index.ts
  • packages/appkit/src/providers/index.ts
  • packages/appkit/src/types/provider.ts
  • packages/walletkit/src/core/TonWalletKit.ts
  • packages/walletkit/src/index.ts
  • packages/walletkit/src/providers/CustomProvider.ts
  • packages/walletkit/src/providers/CustomProvidersManager.spec.ts
  • packages/walletkit/src/providers/CustomProvidersManager.ts
  • packages/walletkit/src/providers/index.ts
  • template/packages/appkit-react/docs/hooks.md
  • template/packages/appkit/docs/actions.md

Comment on lines +9 to +18
/* eslint-disable @typescript-eslint/no-explicit-any */

import { render, screen, cleanup } from '@testing-library/react';
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';

import { createWrapper } from '../../../__tests__/test-utils';
import { UseCustomProviderExample } from './use-custom-provider';

describe('Provider Hooks Examples', () => {
let mockAppKit: any;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify this test no longer uses explicit any or disables no-explicit-any
rg -n 'no-explicit-any|:\s*any\b' demo/examples/src/appkit/hooks/providers/providers.test.tsx

Repository: ton-org/kit

Length of output: 141


🏁 Script executed:

cat -n demo/examples/src/appkit/hooks/providers/providers.test.tsx

Repository: ton-org/kit

Length of output: 2137


Remove broad any from the test mock type

This test file uses any at line 18 without deliberately testing invalid input. The coding guidelines require replacing any with proper types in non-invalid-input test scenarios.

Replace the any type with an explicit mock shape based on the actual mockAppKit structure defined in beforeEach:

Suggested fix
-/* eslint-disable `@typescript-eslint/no-explicit-any` */
-
 import { render, screen, cleanup } from '`@testing-library/react`';
-import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
+import { describe, it, expect, vi, beforeEach, afterEach, type Mock } from 'vitest';
 
 import { createWrapper } from '../../../__tests__/test-utils';
 import { UseCustomProviderExample } from './use-custom-provider';
 
 describe('Provider Hooks Examples', () => {
+    type MockAppKit = {
+        emitter: { on: Mock; off: Mock };
+        connectors: never[];
+        customProvidersManager: { getProvider: Mock };
+    };
-    let mockAppKit: any;
+    let mockAppKit: MockAppKit;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/* eslint-disable @typescript-eslint/no-explicit-any */
import { render, screen, cleanup } from '@testing-library/react';
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { createWrapper } from '../../../__tests__/test-utils';
import { UseCustomProviderExample } from './use-custom-provider';
describe('Provider Hooks Examples', () => {
let mockAppKit: any;
import { render, screen, cleanup } from '`@testing-library/react`';
import { describe, it, expect, vi, beforeEach, afterEach, type Mock } from 'vitest';
import { createWrapper } from '../../../__tests__/test-utils';
import { UseCustomProviderExample } from './use-custom-provider';
describe('Provider Hooks Examples', () => {
type MockAppKit = {
emitter: { on: Mock; off: Mock };
connectors: never[];
customProvidersManager: { getProvider: Mock };
};
let mockAppKit: MockAppKit;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@demo/examples/src/appkit/hooks/providers/providers.test.tsx` around lines 9 -
18, The mockAppKit variable is declared with a broad any type annotation, which
violates coding guidelines for non-invalid-input test scenarios. Replace the any
type on the mockAppKit variable declaration with an explicit type that matches
the actual mock structure being set up in the beforeEach hook. Define a proper
interface or type that captures the shape of the AppKit mock object to maintain
type safety throughout the test.

Source: Coding guidelines

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/walletkit/src/providers/CustomProvidersManager.spec.ts (1)

36-87: ⚡ Quick win

Consider adding a test case documenting type-mismatch behavior.

The test suite doesn't demonstrate what happens when a provider is retrieved with a mismatched generic type parameter (e.g., registering TestProvider but retrieving as DifferentProvider). While TypeScript won't prevent this at compile time, a test case would document the current behavior and serve as a reference for the limitation noted in the manager implementation.

Example test:

it('returns a provider even when retrieved with a mismatched type parameter', () => {
    interface OtherProvider extends CustomProvider {
        otherMethod: () => void;
    }
    
    manager.registerProvider(makeProvider('test'));
    // This compiles but returns TestProvider, not OtherProvider
    const provider = manager.getProvider<OtherProvider>('test');
    expect(provider).toBeDefined();
    expect(provider?.providerId).toBe('test');
    // provider.otherMethod() would fail at runtime
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/walletkit/src/providers/CustomProvidersManager.spec.ts` around lines
36 - 87, Add a test case to the CustomProvidersManager describe block that
documents the type-mismatch behavior when a provider is retrieved with a
mismatched generic type parameter. Create a new test that registers a provider
as TestProvider, retrieves it using a different generic type parameter (like
OtherProvider extending CustomProvider), and verify that the provider is still
returned with the correct providerId despite the type mismatch. This test should
document that while the retrieval succeeds at runtime, the type parameter
mismatch represents a potential type safety issue that TypeScript cannot
prevent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/walletkit/src/providers/CustomProvidersManager.ts`:
- Around line 54-55: The getProvider method in CustomProvidersManager uses an
unchecked cast to return a provider with the requested generic type T, which
allows runtime type mismatches. To fix this, either implement runtime validation
by storing type metadata alongside each provider in the providers map during
registerProvider and checking that metadata in getProvider before casting, or
add prominent documentation warning users that the method does not validate type
safety and that retrieving a provider with an incorrect generic type parameter
will cause runtime errors.

---

Nitpick comments:
In `@packages/walletkit/src/providers/CustomProvidersManager.spec.ts`:
- Around line 36-87: Add a test case to the CustomProvidersManager describe
block that documents the type-mismatch behavior when a provider is retrieved
with a mismatched generic type parameter. Create a new test that registers a
provider as TestProvider, retrieves it using a different generic type parameter
(like OtherProvider extending CustomProvider), and verify that the provider is
still returned with the correct providerId despite the type mismatch. This test
should document that while the retrieval succeeds at runtime, the type parameter
mismatch represents a potential type safety issue that TypeScript cannot
prevent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b16a141f-9b2e-40b2-988d-c6a84b91521d

📥 Commits

Reviewing files that changed from the base of the PR and between e2fded2 and 438588e.

📒 Files selected for processing (9)
  • .changeset/custom-providers.md
  • demo/examples/src/appkit/actions/providers/get-custom-provider.ts
  • demo/examples/src/appkit/hooks/providers/use-custom-provider.tsx
  • packages/appkit-react/docs/hooks.md
  • packages/appkit-react/src/features/providers/hooks/use-custom-provider.ts
  • packages/appkit/docs/actions.md
  • packages/appkit/src/actions/providers/get-custom-provider.ts
  • packages/walletkit/src/providers/CustomProvidersManager.spec.ts
  • packages/walletkit/src/providers/CustomProvidersManager.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/appkit/docs/actions.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • demo/examples/src/appkit/hooks/providers/use-custom-provider.tsx

Comment on lines +54 to +55
getProvider<T extends CustomProvider>(providerId: string): T | undefined {
return this.providers.get(providerId) as T | undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | 🏗️ Heavy lift

Runtime type safety is not enforced.

The unchecked cast as T | undefined allows callers to retrieve a provider using an incorrect generic type parameter, leading to runtime errors when methods are called. TypeScript will not catch this mismatch.

Example failure:

interface ProviderA extends CustomProvider { 
    methodA(): void; 
}
interface ProviderB extends CustomProvider { 
    methodB(): void; 
}

// Register ProviderA
manager.registerProvider<ProviderA>({ 
    providerId: 'my-id', 
    type: 'custom', 
    methodA: () => {} 
});

// Retrieve with wrong type - TypeScript allows this
const provider = manager.getProvider<ProviderB>('my-id');
provider?.methodB(); // Runtime error: methodB is not a function

Consider adding runtime validation (e.g., storing type metadata with each provider and checking it at retrieval) or prominently documenting this limitation.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/walletkit/src/providers/CustomProvidersManager.ts` around lines 54 -
55, The getProvider method in CustomProvidersManager uses an unchecked cast to
return a provider with the requested generic type T, which allows runtime type
mismatches. To fix this, either implement runtime validation by storing type
metadata alongside each provider in the providers map during registerProvider
and checking that metadata in getProvider before casting, or add prominent
documentation warning users that the method does not validate type safety and
that retrieving a provider with an incorrect generic type parameter will cause
runtime errors.

@TrueCarry
TrueCarry merged commit 58825b9 into main Jun 17, 2026
10 checks passed

This branch was successfully deployed

2 active deployments
Preview – kit-demo-wallet — 438588e8 Deployed Jun 17, 2026 by vercel[bot]
Preview – appkit-minter — 438588e8 Deployed Jun 17, 2026 by vercel[bot]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants