-
Notifications
You must be signed in to change notification settings - Fork 741
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: replace wcm with appkit, create options mapping function #5564
Draft
tomiir
wants to merge
28
commits into
v2.0
Choose a base branch
from
feat/replace-wcm-with-appkit
base: v2.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
e8decc1
feat: replace wcm with appkit, create options mapping function
tomiir 326e1f5
chore: remove viem
tomiir 6539f9c
chore: debugging
tomiir 58360af
chore: update rollup and appkit deps
tomiir 24ecd20
Update with v2.0
tomiir 38d9720
chore: update lock
tomiir 1366d17
chore: update to appkit basic canary 2
tomiir 88acc25
chore: use basic setuop
tomiir 55fecf9
chore: include optionalChains with chains
magiziz 3a45293
chore: update to appkit canary 3
tomiir 04c7da3
chore: update appkit, remove viem
tomiir 2bac726
chore: update lock
tomiir ba1e8b9
Merge branch 'v2.0' of github.com:WalletConnect/walletconnect-monorep…
tomiir aed4f5d
chore: update lock
tomiir 8ed165a
chore: type issue
tomiir 44cae9c
chore: update to appkit basic canary 5
tomiir d3bdbfc
chore: update ak to preview 6
tomiir 55f7da1
chore: set color mix strength to 0
magiziz d0673d1
chore: open appkit modal before connecting
magiziz f547225
chore: show error message when error is thrown
magiziz b01a3b6
chore: remove close call
magiziz 68347c6
Merge pull request #5632 from WalletConnect/chore/optimize-appkit
magiziz bb839cd
chore: update ak basic canary
tomiir b893705
chore: add manual control
tomiir 1b0c275
chore: update to appkit core canary 1
tomiir 222ad50
chore: update to ak preview core 2
tomiir 7b443aa
chore: update to 1.7.0 alpha0
tomiir 9559806
Merge branch 'v2.0' of github.com:WalletConnect/walletconnect-monorep…
tomiir 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 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 |
---|---|---|
|
@@ -5,6 +5,9 @@ npm-debug.log* | |
lerna-debug.log | ||
*.lerna_backup | ||
|
||
# Bundle | ||
**/bundle-stats.html | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
|
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 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,135 @@ | ||
import type { AppKitOptions, CaipNetwork, CaipNetworkId } from "@reown/appkit"; | ||
import type { WalletConnectModalConfig } from "./types"; | ||
import { defineChain } from "@reown/appkit/networks"; | ||
import type { AppKitNetwork } from "@reown/appkit/networks"; | ||
import type { EthereumProviderOptions } from "./EthereumProvider"; | ||
|
||
function convertThemeVariables( | ||
wcmTheme?: WalletConnectModalConfig["themeVariables"], | ||
): AppKitOptions["themeVariables"] | undefined { | ||
if (!wcmTheme) return undefined; | ||
|
||
return { | ||
"--w3m-font-family": wcmTheme["--wcm-font-family"], | ||
"--w3m-accent": wcmTheme["--wcm-accent-color"], | ||
"--w3m-color-mix": wcmTheme["--wcm-background-color"], | ||
"--w3m-z-index": wcmTheme["--wcm-z-index"] ? Number(wcmTheme["--wcm-z-index"]) : undefined, | ||
|
||
"--w3m-qr-color": wcmTheme["--wcm-accent-color"], | ||
|
||
"--w3m-font-size-master": wcmTheme["--wcm-text-medium-regular-size"], | ||
"--w3m-border-radius-master": wcmTheme["--wcm-container-border-radius"], | ||
"--w3m-color-mix-strength": 0, | ||
}; | ||
} | ||
|
||
const mapCaipIdToAppKitCaipNetwork = (caipId: CaipNetworkId): CaipNetwork => { | ||
const [namespace, chainId] = caipId.split(":"); | ||
const chain = defineChain({ | ||
id: chainId, | ||
caipNetworkId: caipId, | ||
chainNamespace: namespace as CaipNetwork["chainNamespace"], | ||
name: "", | ||
nativeCurrency: { | ||
name: "", | ||
symbol: "", | ||
decimals: 8, | ||
}, | ||
rpcUrls: { | ||
default: { http: ["https://rpc.walletconnect.org/v1"] }, | ||
}, | ||
}); | ||
|
||
return chain as CaipNetwork; | ||
}; | ||
|
||
export function convertWCMToAppKitOptions( | ||
wcmConfig: WalletConnectModalConfig & { metadata?: EthereumProviderOptions["metadata"] }, | ||
): AppKitOptions { | ||
// Convert chains toCaipNetwork format | ||
const networks: CaipNetwork[] = (wcmConfig.chains as CaipNetworkId[]) | ||
?.map(mapCaipIdToAppKitCaipNetwork) | ||
.filter(Boolean); | ||
|
||
console.log(">> Networks", networks); | ||
// Ensure at least one network is present | ||
if (networks.length === 0) { | ||
throw new Error("At least one chain must be specified"); | ||
} | ||
|
||
const defaultNetwork = networks.find((network) => network.id === wcmConfig.defaultChain?.id); | ||
const appKitOptions: AppKitOptions = { | ||
projectId: wcmConfig.projectId, | ||
networks: networks as [AppKitNetwork, ...AppKitNetwork[]], | ||
themeMode: wcmConfig.themeMode, | ||
themeVariables: convertThemeVariables(wcmConfig.themeVariables), | ||
chainImages: wcmConfig.chainImages, | ||
connectorImages: wcmConfig.walletImages, | ||
defaultNetwork, | ||
metadata: { | ||
...wcmConfig.metadata, | ||
name: wcmConfig.metadata?.name || "WalletConnect", | ||
description: wcmConfig.metadata?.description || "Connect to WalletConnect-compatible wallets", | ||
url: wcmConfig.metadata?.url || "https://walletconnect.org", | ||
icons: wcmConfig.metadata?.icons || ["https://walletconnect.org/walletconnect-logo.png"], | ||
}, | ||
showWallets: true, | ||
// Explorer options mapping | ||
featuredWalletIds: | ||
wcmConfig.explorerRecommendedWalletIds === "NONE" | ||
? [] | ||
: Array.isArray(wcmConfig.explorerRecommendedWalletIds) | ||
? wcmConfig.explorerRecommendedWalletIds | ||
: [], | ||
|
||
excludeWalletIds: | ||
wcmConfig.explorerExcludedWalletIds === "ALL" | ||
? [] | ||
: Array.isArray(wcmConfig.explorerExcludedWalletIds) | ||
? wcmConfig.explorerExcludedWalletIds | ||
: [], | ||
|
||
// Additional AppKit-specific options that don't have direct WCM equivalents | ||
enableEIP6963: false, // Disable 6963 by default | ||
enableInjected: false, // Disable injected by default | ||
enableCoinbase: true, // Default to true | ||
enableWalletConnect: true, // Default to true, | ||
features: { | ||
email: false, | ||
socials: false, | ||
}, | ||
}; | ||
|
||
// Add mobile and desktop wallets as custom wallets if provided | ||
if (wcmConfig.mobileWallets?.length || wcmConfig.desktopWallets?.length) { | ||
const customWallets = [ | ||
...(wcmConfig.mobileWallets || []).map((wallet) => ({ | ||
id: wallet.id, | ||
name: wallet.name, | ||
links: wallet.links, | ||
})), | ||
...(wcmConfig.desktopWallets || []).map((wallet) => ({ | ||
id: wallet.id, | ||
name: wallet.name, | ||
links: { | ||
native: wallet.links.native, | ||
universal: wallet.links.universal, | ||
}, | ||
})), | ||
]; | ||
|
||
const allWallets = [ | ||
...(appKitOptions.featuredWalletIds || []), | ||
...(appKitOptions.excludeWalletIds || []), | ||
]; | ||
|
||
// Only add a custom wallet if it's not on the other lists | ||
const uniqueCustomWallets = customWallets.filter((wallet) => !allWallets.includes(wallet.id)); | ||
|
||
if (uniqueCustomWallets.length) { | ||
appKitOptions.customWallets = uniqueCustomWallets; | ||
} | ||
} | ||
|
||
return appKitOptions; | ||
} |
This file contains 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.
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.
this is not correct, change