-
Notifications
You must be signed in to change notification settings - Fork 117
feat(playground): add bitcoin support to reown provider #658
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
+185
−191
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
58 changes: 58 additions & 0 deletions
58
packages/widget-playground/src/providers/ExternalWalletProvider/BitcoinProvider.tsx
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,58 @@ | ||
| import type { Config } from '@bigmi/client' | ||
| import { createConfig, reown } from '@bigmi/client' | ||
| import { bitcoin, ChainId, createClient, http } from '@bigmi/core' | ||
| import { BigmiProvider } from '@bigmi/react' | ||
| import { | ||
| useAppKitAccount, | ||
| useAppKitProvider, | ||
| useWalletInfo, | ||
| } from '@reown/appkit/react' | ||
| import type { BitcoinConnector } from '@reown/appkit-adapter-bitcoin' | ||
| import { type FC, type PropsWithChildren, useEffect } from 'react' | ||
|
|
||
| const bigmiConfig = createConfig({ | ||
| chains: [bitcoin], | ||
| client: ({ chain }) => createClient({ chain, transport: http() }), | ||
| multiInjectedProviderDiscovery: false, | ||
| ssr: true, | ||
| }) as Config | ||
|
|
||
| const BitcoinReownHandler: FC<PropsWithChildren> = ({ children }) => { | ||
| const { isConnected, address } = useAppKitAccount({ namespace: 'bip122' }) | ||
| const { walletProvider } = useAppKitProvider<BitcoinConnector>('bip122') | ||
| const { walletInfo } = useWalletInfo('bip122') | ||
|
|
||
| useEffect(() => { | ||
| if (!isConnected || !walletProvider || !address) { | ||
| bigmiConfig._internal.connectors.setState([]) | ||
| bigmiConfig.setState((state) => ({ ...state, connections: new Map() })) | ||
| return | ||
| } | ||
|
|
||
| const connector = bigmiConfig._internal.connectors.setup( | ||
| reown({ | ||
| connector: walletProvider, | ||
| walletInfo, | ||
| address, | ||
| }) | ||
| ) | ||
|
|
||
| bigmiConfig._internal.connectors.setState([connector]) | ||
|
|
||
| connector.getAccounts().then((accounts) => { | ||
| bigmiConfig._internal.events.connect({ | ||
| accounts, | ||
| chainId: ChainId.BITCOIN_MAINNET, | ||
| uid: connector.uid, | ||
| }) | ||
| }) | ||
| }, [isConnected, walletProvider, address, walletInfo]) | ||
|
|
||
| return <>{children}</> | ||
| } | ||
|
|
||
| export const BitcoinProvider: FC<PropsWithChildren> = ({ children }) => ( | ||
| <BigmiProvider config={bigmiConfig} reconnectOnMount={true}> | ||
| <BitcoinReownHandler>{children}</BitcoinReownHandler> | ||
| </BigmiProvider> | ||
| ) | ||
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Module-level bigmiConfig stores mutable connector/state at import time; in SSR/Node environments this can persist across requests and leak per-request connection data.
Details
✨ AI Reasoning
A module-scoped configuration object is created once at import time and persists for the lifetime of the process. In server/SSR contexts, that object can retain request-specific connectors, accounts, or connection state across different requests/users, leading to data leakage or race conditions. The code initializes a Config (bigmiConfig) at the top-level and later mutates its internal connectors and events based on per-request/provider state. This pattern introduces shared mutable state that is not request-scoped.
🔧 How do I fix it?
Avoid storing request-specific data in module-level variables. Use request-scoped variables or explicitly mark shared caches as intentional.
Reply
@AikidoSec feedback: [FEEDBACK]to get better review comments in the future.Reply
@AikidoSec ignore: [REASON]to ignore this issue.More info