-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat: Injected Universal Provider #3177
base: main
Are you sure you want to change the base?
Changes from all commits
a28acbd
99e674c
638dedd
b695b6b
c9a4c22
98fab2a
c220c83
da0b35b
b3d2ce8
e63dd7c
73ae536
c93c998
2da6057
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
'@reown/appkit-scaffold-ui': patch | ||
'@reown/appkit': patch | ||
'@reown/appkit-core': 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-common': patch | ||
'@reown/appkit-experimental': patch | ||
'@reown/appkit-polyfills': patch | ||
'@reown/appkit-siwe': patch | ||
'@reown/appkit-siwx': patch | ||
'@reown/appkit-ui': patch | ||
'@reown/appkit-wallet': patch | ||
'@reown/appkit-wallet-button': patch | ||
--- | ||
|
||
Adds walletConnectProvider and enableUniversalProviderManualControl flags to inject a UniversalProvider instance to be used by AppKit' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { AppKit, createAppKit } from '@reown/appkit/react' | ||
import { ThemeStore } from '../../utils/StoreUtil' | ||
import { ConstantsUtil } from '../../utils/ConstantsUtil' | ||
import { AppKitButtons } from '../../components/AppKitButtons' | ||
import { mainnet } from '@reown/appkit/networks' | ||
import { MultiChainInfo } from '../../components/MultiChainInfo' | ||
import { UpaTests } from '../../components/UPA/UpaTests' | ||
import Provider, { UniversalProvider } from '@walletconnect/universal-provider' | ||
import { useEffect, useState } from 'react' | ||
|
||
const networks = ConstantsUtil.EvmNetworks | ||
|
||
export default function MultiChainWagmiAdapterOnly() { | ||
const [uprovider, setUprovider] = useState<Provider | null>(null) | ||
const [appkit, setAppKit] = useState<AppKit | null>(null) | ||
|
||
async function initializeUniversalProvider() { | ||
const provider = await UniversalProvider.init({ | ||
projectId: ConstantsUtil.ProjectId | ||
}) | ||
|
||
const modal = createAppKit({ | ||
networks, | ||
defaultNetwork: mainnet, | ||
projectId: ConstantsUtil.ProjectId, | ||
metadata: ConstantsUtil.Metadata, | ||
enableUniversalProviderManualControl: true, | ||
walletConnectProvider: provider | ||
}) | ||
|
||
ThemeStore.setModal(modal) | ||
setAppKit(modal) | ||
|
||
provider.on('display_uri', (connection: string) => { | ||
modal.open({ view: 'ConnectingWalletConnectBasic', uri: connection }) | ||
}) | ||
|
||
setUprovider(provider) | ||
} | ||
|
||
useEffect(() => { | ||
initializeUniversalProvider() | ||
}, []) | ||
|
||
return ( | ||
<> | ||
{uprovider && appkit ? ( | ||
<> | ||
<AppKitButtons /> | ||
<MultiChainInfo /> | ||
<UpaTests /> | ||
</> | ||
) : ( | ||
'' | ||
)} | ||
</> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import type { AppKitNetwork, CaipNetwork, ThemeVariables } from '@reown/appkit-common' | ||
import type { ChainAdapter, Metadata, OptionsControllerState, ThemeMode } from '@reown/appkit-core' | ||
import type { AppKitSIWEClient } from '@reown/appkit-siwe' | ||
import type { IUniversalProvider } from '@walletconnect/universal-provider' | ||
|
||
export type AppKitOptions = { | ||
/** | ||
|
@@ -72,9 +73,10 @@ export type AppKitOptions = { | |
* @see https://cloud.walletconnect.com/ | ||
*/ | ||
metadata?: Metadata | ||
/** | ||
* UniversalProvider instance to be used by AppKit. | ||
* AppKit will generate its own instance by default in none provided | ||
* @default undefined | ||
*/ | ||
walletConnectProvider?: IUniversalProvider | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we call it |
||
} & OptionsControllerState | ||
|
||
export type AppKitOptionsWithCaipNetworks = Omit<AppKitOptions, 'defaultNetwork' | 'networks'> & { | ||
defaultNetwork?: CaipNetwork | ||
networks: [CaipNetwork, ...CaipNetwork[]] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export const PACKAGE_VERSION = '1.5.3' | ||
export const PACKAGE_VERSION = '1.6.0' |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,7 +93,14 @@ export { AccountController } | |
|
||
// -- Types -------------------------------------------------------------------- | ||
export interface OpenOptions { | ||
view: 'Account' | 'Connect' | 'Networks' | 'ApproveTransaction' | 'OnRampProviders' | ||
view: | ||
| 'Account' | ||
| 'Connect' | ||
| 'Networks' | ||
| 'ApproveTransaction' | ||
| 'OnRampProviders' | ||
| 'ConnectingWalletConnectBasic' | ||
uri?: string | ||
} | ||
|
||
type Adapters = Record<ChainNamespace, AdapterBlueprint> | ||
|
@@ -237,6 +244,10 @@ export class AppKit { | |
// -- Public ------------------------------------------------------------------- | ||
public async open(options?: OpenOptions) { | ||
await this.initOrContinue() | ||
if (options?.uri && this.universalAdapter) { | ||
console.log('options.uri', options.uri) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Log |
||
ConnectionController.setUri(options.uri) | ||
} | ||
ModalController.open(options) | ||
} | ||
|
||
|
@@ -1778,7 +1789,8 @@ export class AppKit { | |
logger | ||
} | ||
|
||
this.universalProvider = await UniversalProvider.init(universalProviderOptions) | ||
this.universalProvider = | ||
this.options.walletConnectProvider ?? (await UniversalProvider.init(universalProviderOptions)) | ||
} | ||
|
||
public async getUniversalProvider() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,7 @@ export interface ConnectionControllerState { | |
recentWallet?: WcWallet | ||
buffering: boolean | ||
status?: 'connecting' | 'connected' | 'disconnected' | ||
enableUniversalProviderManualControl?: boolean | ||
connectionControllerClient?: ConnectionControllerClient | ||
} | ||
|
||
|
@@ -133,10 +134,7 @@ export const ConnectionController = { | |
state.wcPairingExpiry = undefined | ||
this.state.status = 'connected' | ||
} else { | ||
await this._getClient()?.connectWalletConnect?.(uri => { | ||
state.wcUri = uri | ||
state.wcPairingExpiry = CoreHelperUtil.getPairingExpiry() | ||
}) | ||
await this._getClient()?.connectWalletConnect?.(uri => this.setUri(uri)) | ||
} | ||
}, | ||
|
||
|
@@ -225,6 +223,10 @@ export const ConnectionController = { | |
TransactionsController.resetTransactions() | ||
StorageUtil.deleteWalletConnectDeepLink() | ||
}, | ||
setUri(uri: string) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very important - an empty line between functions xd |
||
state.wcUri = uri | ||
state.wcPairingExpiry = CoreHelperUtil.getPairingExpiry() | ||
}, | ||
|
||
setWcLinking(wcLinking: ConnectionControllerState['wcLinking']) { | ||
state.wcLinking = wcLinking | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,6 +130,11 @@ export interface OptionsControllerStatePublic { | |
* @default false | ||
*/ | ||
enableEmbedded?: boolean | ||
/** | ||
* Enable manual control of WalletConnect connections. | ||
* @default false | ||
*/ | ||
enableUniversalProviderManualControl?: boolean | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this flag to expose to the users? If I'm not missing another detail, we could keep it as an internal state depending on the given There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree with Enes here. I think this can confuse user's. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can, the flag was to provide an option for delegating control of the provider entirely |
||
} | ||
|
||
export interface OptionsControllerStateInternal { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { ApiController, CoreHelperUtil, OptionsController, StorageUtil } from '@reown/appkit-core' | ||
import { customElement } from '@reown/appkit-ui' | ||
import { LitElement, html } from 'lit' | ||
import { state } from 'lit/decorators.js' | ||
|
||
@customElement('w3m-connecting-wc-basic-view') | ||
export class W3mConnectingWcBasicView extends LitElement { | ||
@state() private isMobile = CoreHelperUtil.isMobile() | ||
|
||
// -- Render -------------------------------------------- // | ||
public override render() { | ||
// eslint-disable-next-line no-console | ||
console.log('W3mConnectingWcBasicView.constructor()', this.isMobile) | ||
|
||
if (this.isMobile) { | ||
const { featured, recommended } = ApiController.state | ||
const { customWallets } = OptionsController.state | ||
const recent = StorageUtil.getRecentWallets() | ||
|
||
const showConnectors = | ||
featured.length || recommended.length || customWallets?.length || recent.length | ||
// eslint-disable-next-line no-console | ||
console.log('W3mConnectingWcBasicView.constructor()', recommended) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. log |
||
|
||
return html`<wui-flex | ||
flexDirection="column" | ||
gap="xs" | ||
.margin=${['3xs', 's', 's', 's'] as const} | ||
> | ||
${showConnectors ? html`<w3m-connector-list></w3m-connector-list>` : null} | ||
<w3m-all-wallets-widget></w3m-all-wallets-widget> | ||
</wui-flex>` | ||
} | ||
|
||
return html`<wui-flex flexDirection="column" .padding=${['0', '0', 'l', '0'] as const}> | ||
<w3m-connecting-wc-view></w3m-connecting-wc-view> | ||
<wui-flex flexDirection="column" .padding=${['0', 'm', '0', 'm'] as const}> | ||
<w3m-all-wallets-widget></w3m-all-wallets-widget> </wui-flex | ||
></wui-flex>` | ||
} | ||
} | ||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'w3m-connecting-wc-basic-view': W3mConnectingWcBasicView | ||
} | ||
} |
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.
I think we could avoid making changes to
*-new
packages until we start working on Reskin to keep the PRs smaller