-
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
fix/missing action functions exports from clients #2778
fix/missing action functions exports from clients #2778
Conversation
…e definitions accordingly
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
♻️ Vite-Size ♻️Size Difference
Current Size
Base Size
|
@@ -303,7 +344,11 @@ export class AppKit { | |||
AssetUtil.getConnectorImage(connector) | |||
|
|||
// -- Private ------------------------------------------------------------------ | |||
private async initControllers(options: AppKitOptions) { | |||
private async initControllers( | |||
options: AppKitOptions & { |
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.
Why remove adapters from type and add it manually here?
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.
- In v5, we have only backwards compatible versions and they are working with single adapter on background. Every client is creating adapter instance and pass it to the adapters array like this:
export function createWeb3Modal(options: EthersAppKitOptions) {
const ethersAdapter = new EVMEthersClient({
ethersConfig: options.ethersConfig,
siweConfig: options.siweConfig,
chains: options.chains,
defaultChain: options.defaultChain
})
return new AppKit<EthersStoreUtilState, number>({
...options,
defaultChain: ethersAdapter.defaultChain,
adapters: [ethersAdapter],
sdkType: 'w3m',
sdkVersion: `html-ethers-${ConstantsUtil.VERSION}`
})
}
But each adapter have type differences for the exposed functions, for example, getWalletProvider
returns different typed value for each adapter:
public getWalletProvider() {
return this.adapter?.getWalletProvider?.()
}
To resolve this problem, we are now using generics and passing the type values for some unknown types by base, with the generics, base package know what are the types of these function returns.
So for the question:
Why remove adapters from type and add it manually here?
base
should get the types of the adapter (yes it's array but it's actually using single adapter) instead of justChainAdapter
type. I went with this solution to resolve this problem for having fully type safed exposed functions.
|
Description
While migrating to the multi-chain architecture, there are few getter, action and listeners methods that the new modal instances don't expose but was available for the previous clients. This PR introduces changes with the required type definition tricks to have type safe method expose.
The reason we needed to use generics for AppKit and
ChainAdapter
types is that each client's following methods have different type of parameters and returns. When users use@web3modal/ethers
or@web3modal/solana
, the TS should know which type it'll take an return for these methods. For that to resolve, we need to use generics while exporting the backwards compatibility support.This PR also introduces:
Type of change
Associated Issues
For Linear issues: Closes APKT-xxx
For GH issues: closes #...
Showcase (Optional)
If there is a UI change include the screenshots with before and after state.
If new feature is being introduced, include the link to demo recording.
Checklist