-
Notifications
You must be signed in to change notification settings - Fork 1
Decouple domain dependencies for modal #54
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
Changes from all commits
Commits
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,12 @@ | |||||
|
|
||||||
| This library was built to make it easier to build cross-domain applications in JS. It unites ecosystem-specific tooling, provides some helpful abstractions but gives you the flexibility to do anything more specific, and offers a configurable modal to manage connections across one or more domains you would like to support in your app. | ||||||
|
|
||||||
| Valence Protocol TS currently has support for these ecosystems: | ||||||
|
|
||||||
| 1. Ethereum | ||||||
| 2. Solana | ||||||
| 3. Cosmos | ||||||
|
|
||||||
| Libraries are in their early stage. APIs subject to change. | ||||||
|
|
||||||
| For developer docs, see `docs` folder. | ||||||
|
|
@@ -15,21 +21,21 @@ pnpm install @valence-protocol/domain-clients-core @valence-protocol/domain-clie | |||||
| ``` | ||||||
|
|
||||||
| 2. Install peer dependencies | ||||||
| Note: for the short term you need to install dependencies for all three supported domains (solana, evm, cosmos). There is a little more work required to allow you to install peer dependencies only for the domains that you wantt. You can still choose which domains show up in the modal in the config. | ||||||
| You will need to install the required libraries for the ecosystem you would like to support. | ||||||
|
|
||||||
| ```bash | ||||||
| # EVM | ||||||
| # for EVM | ||||||
| pnpm install wagmi viem | ||||||
|
|
||||||
| # Solana | ||||||
| # for Solana | ||||||
| pnpm install gill @wallet-ui/react | ||||||
| ## when interacting with frameworks that have not moved to @solana/kit (used by gill under the hood and importable through gill), you may need to install @solana/web3.js @solana/compat | ||||||
| ## note: when interacting with frameworks that have not moved to @solana/kit (used by gill under the hood and importable through gill), you may need to also install @solana/web3.js and @solana/compat | ||||||
|
|
||||||
| # Cosmos | ||||||
| # for Cosmos | ||||||
| pnpm install graz | ||||||
| ``` | ||||||
|
|
||||||
| For graz, you will also need to add a post-install script to install chains locally. They will not be packaged with you app unless you import them. | ||||||
| With graz, you will also need to add a post-install script to generate chain info locally. The generated chain infos will not be packaged with your app unless you import them. | ||||||
|
|
||||||
| ```json | ||||||
| { | ||||||
|
|
@@ -41,10 +47,9 @@ For graz, you will also need to add a post-install script to install chains loca | |||||
| ``` | ||||||
|
|
||||||
| 3. Define config. | ||||||
| Copy [these](https://github.com/timewave-computer/valence-protocol-ts/tree/next/apps/domain-clients-example/src/config/domainClientsConfig) config files as an example. Only include the domains you are interested in working with. | ||||||
|
|
||||||
| - Note:\* for the short term you MUST fill some config for each domain. This will be addressed soon. If you don't want the modal to support this domain, set `hide=true` in the config. You can copy [these](https://github.com/timewave-computer/valence-protocol-ts/tree/next/apps/domain-clients-example/src/config/domainClientsConfig) config files as an example, and have minimal input for the domains you don't want to support. | ||||||
|
|
||||||
| The root config must be | ||||||
| Example of the root config: | ||||||
|
|
||||||
| ```javascript | ||||||
| import { DomainClientsConfig } from '@valence-protocol/domain-clients-react'; | ||||||
|
|
@@ -56,30 +61,29 @@ export const domainClientsConfig: DomainClientsConfig = { | |||||
| }; | ||||||
| ``` | ||||||
|
|
||||||
| 4. Create app providers component with `DomainClientsProvider` and `DomainModalProvider`. They are kept separate in case you want to use a custom modal altogether. | ||||||
| 4. Wrap your app root in a `DomainModalProvider` and import css. For Next.js 14+, you will need to wrap the providers in a client component. | ||||||
|
|
||||||
| ```javascript | ||||||
| 'use client' // for Next.js 14+ | ||||||
| // AppProvider.tsx (for Next.js 14+) | ||||||
|
|
||||||
| 'use client' | ||||||
| import { domainClientsConfig } from '@/config'; | ||||||
| import { ReactQueryProvider } from '@/context'; | ||||||
| import { DomainClientsProvider } from '@valence-protocol/domain-clients-react'; | ||||||
| import { DomainModalProvider } from '@valence-protocol/domain-modal-react'; | ||||||
|
|
||||||
| export const AppProviders = ({ children }: { children: React.ReactNode }) => { | ||||||
| return ( | ||||||
| <ReactQueryProvider> | ||||||
| <DomainClientsProvider config={domainClientsConfig}> | ||||||
| <DomainModalProvider>{children}</DomainModalProvider> | ||||||
| </DomainClientsProvider> | ||||||
| </ReactQueryProvider> | ||||||
| <...OtherProviders> | ||||||
| <DomainModalProvider config={domainClientsConfig}> | ||||||
| {children} | ||||||
| </DomainModalProvider> | ||||||
| <...OtherProviders> | ||||||
| ); | ||||||
| }; | ||||||
| ``` | ||||||
|
|
||||||
| 5. Wrap root project in providers and import css | ||||||
|
|
||||||
| ```javascript | ||||||
| // layout.tsx or similar application root | ||||||
|
|
||||||
| import '@valence-protocol/domain-modal-react/styles.css'; | ||||||
|
|
||||||
| const Root = () => { | ||||||
|
|
@@ -105,21 +109,37 @@ const { showModal } = useDomainModal(); | |||||
|
|
||||||
| ### `domain-clients-core` | ||||||
|
|
||||||
| Pure-JS code that abstract common, implementation-specific methods away. They have a few pre-built operations for you (such as transferring tokens and reading balances). To do anything not pre-built, you can call `getClient` on the respective client and perform anything else with it. More common use patterns will be added over time. | ||||||
| Pure-JS code that abstract common, implementation-specific methods. There are a few pre-built operations (such as transferring tokens and reading balances). To do anything not pre-built, you can call `getClient` on the respective client and perform anything you need. Commonly used patterns will be added as client functions over time. | ||||||
|
|
||||||
| The imports per-domain are tree-shakeable. | ||||||
| Imports per-domain are tree-shakeable. For example: | ||||||
|
|
||||||
| ```javascript | ||||||
| import { EvmClient } from '@valence-protocol/domain-clients-core/evm'; | ||||||
| ``` | ||||||
|
|
||||||
| ### `domain-clients-react` | ||||||
|
|
||||||
| A React provider and hooks to access the config via context within the app, and use domain clients via react hooks. | ||||||
| React hooks and context provider to access the config and use domain clients in a react app. | ||||||
|
|
||||||
| The imports per-domain are tree-shakeable. | ||||||
| The imports per-domain are tree-shakeable. For example: | ||||||
|
|
||||||
| ```javascript | ||||||
| import { | ||||||
| useSigningSolanaClient, | ||||||
| } from '@valence-protocol/domain-clients-react/solana'; | ||||||
|
|
||||||
| // component | ||||||
| const solanaSigningClient = useSolanaSigningClient({clusterId:'solana:devent'}) | ||||||
| solanaSigningClient.getSolBalance({...}) | ||||||
| solanaSigningClient.transfer({...}) | ||||||
|
|
||||||
| ``` | ||||||
|
|
||||||
| ### `domain-modal-react` | ||||||
|
|
||||||
| A React provider and component that allows you to support connecting wallets and accessing the state. It is a loose wrapper around the domain-specific UI hooks. | ||||||
| A React UI component and context provider that allows you to manage wallet connections across multiple domains. It is a loose wrapper around domain-specific UI libraries. Based on the domain clients configuration, it will render the appropriate wallet modal. | ||||||
|
|
||||||
| This is NOT YET tree shakeable. It will be in the future. | ||||||
| The modal will omit dependencies for ecosystems excluded from in the configuration. | ||||||
|
|
||||||
| ## How to use the libraries | ||||||
|
|
||||||
|
|
@@ -151,13 +171,13 @@ If your app is wrapped in the DomainClientsProvider, you can simply call `useXSi | |||||
|
|
||||||
| ```javascript | ||||||
| import { | ||||||
| solanaClient, | ||||||
| useSolanaClient, | ||||||
| useSigningSolanaClient, | ||||||
| useCosmosClient, | ||||||
| useSigningCosmosClient, | ||||||
| useEvmClient, | ||||||
| useSigningEvmClient, | ||||||
| } from '@valence-protocol/domain-clients-react/solana'; | ||||||
| } from '@valence-protocol/domain-clients-react'; | ||||||
|
|
||||||
| const solananClient = useSolanaClient({ clusterId }); | ||||||
|
Contributor
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. |
||||||
| const signingSolanaClient = useSigningSolanaClient({ clusterId }); | ||||||
|
|
@@ -199,12 +219,14 @@ const config = useDomainConfig(); | |||||
|
|
||||||
| ### Domain-specific hooks | ||||||
|
|
||||||
| Use various domain-specific utils as needed. They will work as expected because we render their providers under the hod. The implementation and naming for each varies. You can dig into the tool-specific docs as needed. | ||||||
| Use various domain-specific hooks and utils as needed. They will work as expected because we render their providers under the hod. The implementation and naming for each varies. You can find some examples of how these are used in the example app, but it is suggested to consult the individual docs. | ||||||
|
Contributor
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. There's a typo here. It should be
Suggested change
|
||||||
|
|
||||||
| ```javascript | ||||||
| import { useAccount as useEvmAccount } from 'wagmi'; | ||||||
| import { useAccount as useCosmosAccount } from 'graz'; | ||||||
| import { useWalletUi as useSolanaAccount } from '@wallet-ui/react'; | ||||||
| ``` | ||||||
|
|
||||||
| This is about it! Feel free to raise issues. | ||||||
| ## Contact us | ||||||
|
|
||||||
| Feel free to raise issues, or contact the team on [Telegram](https://t.me/+Sig6DYQn-Ec0NTZh). | ||||||
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
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 |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import { clsx, type ClassValue } from 'clsx'; | ||
| import { twMerge } from 'tailwind-merge'; | ||
|
|
||
| export const cn = (...inputs: ClassValue[]) => { | ||
| return clsx(inputs); | ||
| return twMerge(clsx(inputs)); | ||
| }; |
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 |
|---|---|---|
|
|
@@ -21,5 +21,4 @@ export const cosmosConfig: CosmosConfig = { | |
| }, | ||
| }, | ||
| defaultChainId: neutrontestnet.chainId, | ||
| hide: false, | ||
| }; | ||
10 changes: 10 additions & 0 deletions
10
apps/domain-clients-example/src/config/domainClientsConfig/domainClients.config.ts
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,10 @@ | ||
| import { evmConfig } from './evm.config'; | ||
| import { cosmosConfig } from './cosmos.config'; | ||
| import { solanaConfig } from './solana.config'; | ||
| import { DomainClientsConfig } from '@valence-protocol/domain-clients-react'; | ||
|
|
||
| export const domainClientsConfig: DomainClientsConfig = { | ||
| evm: evmConfig, | ||
| cosmos: cosmosConfig, | ||
| solana: solanaConfig, | ||
| }; |
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
11 changes: 1 addition & 10 deletions
11
apps/domain-clients-example/src/config/domainClientsConfig/index.ts
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 |
|---|---|---|
| @@ -1,10 +1 @@ | ||
| import { evmConfig } from './evm.config'; | ||
| import { cosmosConfig } from './cosmos.config'; | ||
| import { solanaConfig } from './solana.config'; | ||
| import { DomainClientsConfig } from '@valence-protocol/domain-clients-react'; | ||
|
|
||
| export const domainClientsConfig: DomainClientsConfig = { | ||
| evm: evmConfig, | ||
| cosmos: cosmosConfig, | ||
| solana: solanaConfig, | ||
| }; | ||
| export * from './domainClients.config'; |
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 |
|---|---|---|
| @@ -1,15 +1,14 @@ | ||
| 'use client'; | ||
| import { domainClientsConfig } from '@/config'; | ||
| import { ReactQueryProvider } from '@/context'; | ||
| import { DomainClientsProvider } from '@valence-protocol/domain-clients-react'; | ||
| import { DomainModalProvider } from '@valence-protocol/domain-modal-react'; | ||
|
|
||
| export const AppProviders = ({ children }: { children: React.ReactNode }) => { | ||
| return ( | ||
| <ReactQueryProvider> | ||
| <DomainClientsProvider config={domainClientsConfig}> | ||
| <DomainModalProvider>{children}</DomainModalProvider> | ||
| </DomainClientsProvider> | ||
| <DomainModalProvider config={domainClientsConfig}> | ||
| {children} | ||
| </DomainModalProvider> | ||
| </ReactQueryProvider> | ||
| ); | ||
| }; |
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 |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| export type DomainClientConfig = { | ||
| hide: boolean; | ||
| hide?: boolean; | ||
| }; |
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
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
2 changes: 1 addition & 1 deletion
2
...react/src/ui/main/ConnectDomainButton.tsx → ...src/ui/common/ConnectDomainButtonRoot.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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| export const ConnectDomainButton = ({ | ||
| export const ConnectDomainButtonRoot = ({ | ||
| onClick, | ||
| children, | ||
| }: { | ||
|
|
||
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.
There are a couple of typos in this code example that could confuse users:
useSigningSolanaClient, but it's called asuseSolanaSigningClient.clusterIdis'solana:devent', which is likely a typo for'solana:devnet'.Suggesting a fix for consistency and correctness.