Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions demo/vite-react-app-solana/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 17 additions & 5 deletions demo/vue-app-new/src/components/AppDashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ import { CONNECTOR_INITIAL_AUTHENTICATION_MODE } from "@web3auth/no-modal";
import { useI18n } from "petite-vue-i18n";

import { useSignMessage as useSolanaSignMessage, useSolanaWallet, useSolanaClient } from "@web3auth/modal/vue/solana";
import { useConnection, useBalance, useSignMessage, useSignTypedData, useSwitchChain as useWagmiSwitchChain, useConfig } from "@wagmi/vue";
import {
useConnection,
useBalance,
useSignMessage,
useSignTypedData,
useSwitchChain as useWagmiSwitchChain,
useConfig,
useChainId,
} from "@wagmi/vue";
import { getCapabilities, getCallsStatus, sendCalls, showCallsStatus } from "@wagmi/core";
import { parseEther } from "viem";
import { createWalletTransactionSigner, toAddress } from "@solana/client";
Expand All @@ -28,6 +36,7 @@ import AccountLinkingSection from "./AccountLinkingSection.vue";
import X402Tester from "./X402Tester.vue";
import { getPrivateKey, sendEth, sendEthWithSmartAccount, signTransaction as signEthTransaction } from "../services/ethHandlers";
import { formDataStore } from "../store/form";
import { numberToHex } from "viem/utils";

const { t } = useI18n({ useScope: "global" });

Expand All @@ -38,7 +47,7 @@ const { loading: userInfoLoading, getUserInfo } = useWeb3AuthUser();
const { enableMFA } = useEnableMFA();
const { manageMFA } = useManageMFA();
const { mutateAsync: switchChainAsync } = useWagmiSwitchChain();

const wagmiConnectedChainId = useChainId();
const { showWalletUI, loading: showWalletUILoading } = useWalletUI();
const { showWalletConnectScanner, loading: showWalletConnectScannerLoading } = useWalletConnectScanner();
const { showCheckout, loading: showCheckoutLoading } = useCheckout();
Expand Down Expand Up @@ -174,7 +183,10 @@ const onGetPrivateKey = async () => {
};

const getConnectedChainId = async () => {
printToConsole("chainId", web3Auth.value?.currentChain?.chainId);
printToConsole("chainId", {
web3AuthChainId: web3Auth.value?.currentChain?.chainId,
wagmiChainId: numberToHex(wagmiConnectedChainId.value),
});
};

const onGetBalance = async () => {
Expand Down Expand Up @@ -375,14 +387,14 @@ const canSwitchChainNamespace = computed(() => {
});

const onSwitchChain = async () => {
log.info("switching chain");
try {
const chainId = connection.value?.ethereumProvider?.chainId;
if (!chainId) throw new Error("No ethereum provider chainId");
if (chainId !== currentChainId.value) throw new Error("chainId does not match current chainId");

const newChain = eip155Chains.value.find((c) => c.chainId !== chainId);
if (!newChain) throw new Error("Please configure at least 2 EVM chains in the config");
log.info("switching chain", newChain.chainId);
const data = await switchChainAsync({ chainId: Number(newChain.chainId) });
printToConsole("switchedChain", { chainId: data.id });
} catch (error) {
Expand Down Expand Up @@ -429,7 +441,7 @@ const onSwitchChainNamespace = async () => {
{{ $t("app.buttons.btnClearConsole") }}
</Button>
</div>
<div class="mb-2">
<div v-if="web3Auth?.primaryConnectorName === WALLET_CONNECTORS.AUTH" class="mb-2">
<Button :loading="userInfoLoading" block size="xs" pill @click="onGetUserInfo">
{{ $t("app.buttons.btnGetUserInfo") }}
</Button>
Expand Down
2 changes: 1 addition & 1 deletion demo/vue-app-new/src/components/X402Tester.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { computed, ref, watch } from "vue";
const BASE_SEPOLIA_CHAIN_ID = "0x14a34"; // 84532
const SOLANA_DEVNET_CHAIN_ID = "0x67"; // 103
const SOLANA_DEVNET_CAIP_CHAIN_ID = `solana:${Number(SOLANA_DEVNET_CHAIN_ID)}`;
const DEFAULT_X402_URL = "https://web3auth-dev-demo-x420.sapphire-dev-2-1.authnetwork.dev";
const DEFAULT_X402_URL = "https://web3auth-dev-demo-x402.node-1.dev-node.web3auth.io/weather-plain";

const { isConnected, connection, web3Auth } = useWeb3Auth();
const { chainId, chainNamespace } = useChain();
Expand Down
52 changes: 26 additions & 26 deletions demo/wagmi-react-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion demo/wagmi-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"dependencies": {
"@tanstack/react-query": "^5.95.2",
"@web3auth/auth": "^11.6.0",
"@web3auth/auth": "^11.8.1",
"@web3auth/modal": "file:../../packages/modal",
"react": "^19.2.4",
"react-dom": "^19.2.4",
Expand Down
2 changes: 1 addition & 1 deletion demo/wagmi-react-app/src/components/X402.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useWalletClient } from "wagmi";

import styles from "../styles/Home.module.css";

const X402_URL = import.meta.env.VITE_APP_X402_TEST_CONTENT_URL || "https://x402.org/protected";
const X402_URL = "https://web3auth-dev-demo-x402.node-1.dev-node.web3auth.io/weather-plain";
const FETCH_OPTIONS: RequestInit = { method: "GET", headers: { "Content-Type": "application/json" } };

// ─── Shared response renderer ────────────────────────────────────────────────
Expand Down
33 changes: 23 additions & 10 deletions packages/modal/src/modalManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {

private removeAccountLinkingResetOnCloseListener: (() => void) | null = null;

private accountLinkingPickerResolver: ((connectorName: WALLET_CONNECTOR_TYPE | string) => void) | null = null;
private accountLinkingPickerResolver:
| ((selection: { connectorName: WALLET_CONNECTOR_TYPE | string; chainNamespace?: ChainNamespaceType }) => void)
| null = null;

private removeAccountLinkingPickerCloseListener: (() => void) | null = null;

Expand Down Expand Up @@ -365,14 +367,23 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
// Pre-flight: ensure user is connected via AUTH so we fail fast before opening the modal.
this.getMainAuthConnector();

const chainId = this.resolveLinkAccountChainId(params?.chainId);
const resolvedChainConfig = this.resolveLinkAccountChainConfig(params?.chainId);
let resolvedChainId = resolvedChainConfig.chainId;

if (!params?.connectorName) {
const pickedConnector = await this.pickWalletForAccountLinking(chainId);
return this.linkAccountWithChosenConnector(pickedConnector, chainId);
const pickedSelection = await this.pickWalletForAccountLinking(resolvedChainId);
// if user picked a different chain namespace from the wallet picker, then we will used the picked chain
if (pickedSelection.chainNamespace) {
if (resolvedChainConfig.chainNamespace !== pickedSelection.chainNamespace) {
resolvedChainId =
this.coreOptions.chains?.find((chain) => chain.chainNamespace === pickedSelection.chainNamespace)?.chainId || resolvedChainId;
return this.linkAccountWithChosenConnector(pickedSelection.connectorName, resolvedChainId);
Comment thread
cursor[bot] marked this conversation as resolved.
}
}
return this.linkAccountWithChosenConnector(pickedSelection.connectorName, resolvedChainId);
}

return this.linkAccountWithChosenConnector(params.connectorName, chainId);
return this.linkAccountWithChosenConnector(params.connectorName, resolvedChainId);
}

protected startAccountLinkingModalSession(params: {
Expand Down Expand Up @@ -868,7 +879,7 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
// to the linking flow instead of running the regular login `connectTo`.
if (this.accountLinkingPickerResolver) {
const resolver = this.accountLinkingPickerResolver;
resolver(params.connector);
resolver({ connectorName: params.connector, chainNamespace: params.loginParams?.chainNamespace });
return;
}
try {
Expand Down Expand Up @@ -1099,15 +1110,17 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
});
}

private pickWalletForAccountLinking(chainId: string): Promise<WALLET_CONNECTOR_TYPE | string> {
private pickWalletForAccountLinking(
chainId: string
): Promise<{ connectorName: WALLET_CONNECTOR_TYPE | string; chainNamespace?: ChainNamespaceType }> {
if (!this.loginModal) throw WalletInitializationError.notReady("Login modal is not initialized");
if (this.accountLinkingPickerResolver) {
throw AccountLinkingError.requestFailed("Another account linking picker is already in progress.");
}

this.loginModal.startAccountLinkingPicker({ chainId });

return new Promise<WALLET_CONNECTOR_TYPE | string>((resolve, reject) => {
return new Promise<{ connectorName: WALLET_CONNECTOR_TYPE | string; chainNamespace?: ChainNamespaceType }>((resolve, reject) => {
const cleanup = () => {
this.accountLinkingPickerResolver = null;
if (this.removeAccountLinkingPickerCloseListener) {
Expand All @@ -1123,9 +1136,9 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
reject(WalletLoginError.popupClosed("User closed the modal"));
};

this.accountLinkingPickerResolver = (connector) => {
this.accountLinkingPickerResolver = (selection) => {
cleanup();
resolve(connector);
resolve(selection);
};
this.on(LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, handleVisibility);
this.removeAccountLinkingPickerCloseListener = () => {
Expand Down
Loading