-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat: <AppKitProvider>
#4696
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
Merged
Merged
feat: <AppKitProvider>
#4696
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
856d73e
feat: appkit react provider
0xmkh 9f18f35
chore: tweak
0xmkh 886b82c
chore: add changeset
0xmkh a6ebc15
chore: cleanup
0xmkh 25a6c7b
chore: tweak
0xmkh d1d6380
chore: rename jsx to tsx
0xmkh 3183ba5
chore: export packages
0xmkh a813c7a
chore: export packages
0xmkh e426f59
Merge branch 'main' into feat/react-providers
0xmkh 7da43f4
chore: use strict version
0xmkh 2af98f7
Merge branch 'main' into feat/react-providers
0xmkh f81bab3
Merge branch 'main' into feat/react-providers
0xmkh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| --- | ||
| '@reown/appkit': patch | ||
| '@reown/appkit-adapter-bitcoin': patch | ||
| '@reown/appkit-adapter-ethers': patch | ||
| '@reown/appkit-adapter-ethers5': patch | ||
| '@reown/appkit-adapter-solana': patch | ||
| '@reown/appkit-adapter-wagmi': patch | ||
| '@reown/appkit-utils': patch | ||
| '@reown/appkit-cdn': patch | ||
| '@reown/appkit-cli': patch | ||
| '@reown/appkit-codemod': patch | ||
| '@reown/appkit-common': patch | ||
| '@reown/appkit-controllers': patch | ||
| '@reown/appkit-core': patch | ||
| '@reown/appkit-experimental': patch | ||
| '@reown/appkit-pay': patch | ||
| '@reown/appkit-polyfills': patch | ||
| '@reown/appkit-scaffold-ui': patch | ||
| '@reown/appkit-siwe': patch | ||
| '@reown/appkit-siwx': patch | ||
| '@reown/appkit-testing': patch | ||
| '@reown/appkit-ui': patch | ||
| '@reown/appkit-wallet': patch | ||
| '@reown/appkit-wallet-button': patch | ||
| --- | ||
|
|
||
| Introduced `AppKitProvider` React component for easy AppKit integration in React apps | ||
|
|
||
| **Example usage** | ||
|
|
||
| ```tsx | ||
| import { AppKitProvider } from '@reown/appkit/react'; | ||
|
|
||
| function App() { | ||
| return ( | ||
| <AppKitProvider projectId="YOUR_PROJECT_ID" networks={[/* Your Networks */]}> | ||
| {/* Your App */} | ||
| </AppKitProvider> | ||
| ); | ||
| } | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { type ReactNode } from 'react' | ||
|
|
||
| import { type CreateAppKit, createAppKit } from '../../../exports/react.js' | ||
|
|
||
| // -- Types -------------------------------------------------------------------------------- | ||
| export type AppKitProviderProps = CreateAppKit & { | ||
| children: ReactNode | ||
| } | ||
|
|
||
| // -- State -------------------------------------------------------------------------------- | ||
| let appkit: ReturnType<typeof createAppKit> | null = null | ||
|
|
||
| // -- Utils & Others ----------------------------------------------------------------------- | ||
| export function memoizeCreateAppKit(config: CreateAppKit) { | ||
| if (!appkit) { | ||
| appkit = createAppKit(config) | ||
| } | ||
|
|
||
| return appkit | ||
| } | ||
|
|
||
| // -- Providers ---------------------------------------------------------------------------- | ||
| export function AppKitProvider({ children, ...props }: AppKitProviderProps) { | ||
| memoizeCreateAppKit(props) | ||
|
|
||
| return children | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { createElement } from 'react' | ||
|
|
||
| import { render } from '@testing-library/react' | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| import { AppKitProvider, type AppKitProviderProps } from '../../src/library/react/providers' | ||
|
|
||
| let mod: typeof import('../../exports/react') | ||
|
|
||
| describe('AppKitProvider', () => { | ||
| beforeEach(async () => { | ||
| vi.clearAllMocks() | ||
| mod = await import('../../exports/react') | ||
| vi.spyOn(mod, 'createAppKit') | ||
| }) | ||
|
|
||
| it('should call createAppKit with the correct parameters', () => { | ||
| const props = { | ||
| projectId: 'test', | ||
| networks: [], | ||
| children: 'child' | ||
| } as unknown as AppKitProviderProps | ||
|
|
||
| const { rerender } = render( | ||
| createElement(AppKitProvider, props, createElement('div', null, 'child')) | ||
| ) | ||
|
|
||
| delete props.children | ||
|
|
||
| expect(mod.createAppKit).toHaveBeenCalledTimes(1) | ||
| expect(mod.createAppKit).toHaveBeenCalledWith(props) | ||
|
|
||
| rerender(createElement('div', null, 'child')) | ||
|
|
||
| expect(mod.createAppKit).toHaveBeenCalledTimes(1) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.