Skip to content

Commit 8075a34

Browse files
committed
Merge branch 'feat/sdk-v10-mipd' into feat/sdk-v10
2 parents 8f184ce + 0ce542c commit 8075a34

File tree

27 files changed

+151
-195
lines changed

27 files changed

+151
-195
lines changed

demo/vite-react-app/src/services/walletServiceHandlers.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
2-
import { log, WalletServicesPlugin } from "@web3auth/modal";
2+
import { log, type WalletServicesPluginType } from "@web3auth/modal";
33
import { verifyMessage as eipVerifyMessage } from "@web3auth/sign-in-with-ethereum";
44
import { BrowserProvider, parseEther } from "ethers";
55

66
import { getV4TypedData } from "../config/config";
77

8-
export const walletSignPersonalMessage = async (provider: WalletServicesPlugin["provider"], uiConsole: any) => {
8+
export const walletSignPersonalMessage = async (provider: WalletServicesPluginType["provider"], uiConsole: any) => {
99
try {
1010
const ethProvider = new BrowserProvider(provider);
1111
const signer = await ethProvider.getSigner();
@@ -31,7 +31,7 @@ export const walletSignPersonalMessage = async (provider: WalletServicesPlugin["
3131
}
3232
};
3333

34-
export const walletSignTypedMessage = async (provider: WalletServicesPlugin["provider"], uiConsole: any) => {
34+
export const walletSignTypedMessage = async (provider: WalletServicesPluginType["provider"], uiConsole: any) => {
3535
try {
3636
const ethProvider = new BrowserProvider(provider);
3737
const signer = await ethProvider.getSigner();
@@ -55,7 +55,7 @@ export const walletSignTypedMessage = async (provider: WalletServicesPlugin["pro
5555
}
5656
};
5757

58-
export const walletSendEth = async (provider: WalletServicesPlugin["provider"], uiConsole: any) => {
58+
export const walletSendEth = async (provider: WalletServicesPluginType["provider"], uiConsole: any) => {
5959
try {
6060
const ethProvider = new BrowserProvider(provider);
6161
const signer = await ethProvider.getSigner();
@@ -73,7 +73,7 @@ export const walletSendEth = async (provider: WalletServicesPlugin["provider"],
7373
}
7474
};
7575

76-
export const walletSignTransaction = async (provider: WalletServicesPlugin["provider"], uiConsole: any) => {
76+
export const walletSignTransaction = async (provider: WalletServicesPluginType["provider"], uiConsole: any) => {
7777
try {
7878
const ethProvider = new BrowserProvider(provider);
7979
const accounts = await provider.request({ method: "eth_accounts" });

demo/vite-react-app/src/services/web3auth.tsx

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CONNECTOR_EVENTS, IProvider, PLUGIN_EVENTS, WalletServicesPlugin, Web3Auth, WEB3AUTH_NETWORK_TYPE, SMART_ACCOUNT } from "@web3auth/modal";
1+
import { CONNECTOR_EVENTS, IProvider, PLUGIN_EVENTS, WalletServicesPluginType, Web3Auth, WEB3AUTH_NETWORK_TYPE, SMART_ACCOUNT, walletServicesPlugin, EVM_PLUGINS } from "@web3auth/modal";
22
import { createContext, FunctionComponent, ReactNode, useContext, useEffect, useState } from "react";
33
import { CHAIN_CONFIG, CHAIN_CONFIG_TYPE } from "../config/chainConfig";
44
import * as ethHandler from "./ethHandler";
@@ -63,7 +63,7 @@ export const Web3AuthProvider: FunctionComponent<IWeb3AuthState> = ({ children,
6363
const [web3Auth, setWeb3Auth] = useState<Web3Auth | null>(null);
6464
const [provider, setProvider] = useState<IProvider | null>(null);
6565
const [waasProvider, setWaasProvider] = useState<IProvider | null>(null);
66-
const [walletServicesPlugin, setWalletServicesPlugin] = useState<WalletServicesPlugin | null>(null);
66+
const [wsPlugin, setWsPlugin] = useState<WalletServicesPluginType | null>(null);
6767
const [user, setUser] = useState<unknown | null>(null);
6868
const [isLoading, setIsLoading] = useState(false);
6969

@@ -90,7 +90,7 @@ export const Web3AuthProvider: FunctionComponent<IWeb3AuthState> = ({ children,
9090
});
9191
};
9292

93-
const subscribePluginEvents = (plugin: WalletServicesPlugin) => {
93+
const subscribePluginEvents = (plugin: WalletServicesPluginType) => {
9494
// Can subscribe to all PLUGIN_EVENTS and LOGIN_MODAL_EVENTS
9595
plugin.on(PLUGIN_EVENTS.CONNECTED, (data: unknown) => {
9696
console.log("Yeah!, you are successfully logged in to plugin");
@@ -147,19 +147,18 @@ export const Web3AuthProvider: FunctionComponent<IWeb3AuthState> = ({ children,
147147
primaryButton: "socialLogin",
148148
},
149149
enableLogging: true,
150+
plugins: [walletServicesPlugin()],
150151
});
151152

152-
// Wallet Services Plugin
153-
154-
const walletServicesPlugin = new WalletServicesPlugin();
155-
156-
subscribePluginEvents(walletServicesPlugin);
157-
setWalletServicesPlugin(walletServicesPlugin);
158-
web3AuthInstance.addPlugin(walletServicesPlugin);
153+
setWsPlugin(wsPlugin);
159154

160155
subscribeAuthEvents(web3AuthInstance);
161156
setWeb3Auth(web3AuthInstance);
162-
await web3AuthInstance.initModal();
157+
await web3AuthInstance.init();
158+
159+
const plugin = web3AuthInstance.getPlugin(EVM_PLUGINS.WALLET_SERVICES) as WalletServicesPluginType;
160+
setWsPlugin(plugin);
161+
subscribePluginEvents(plugin);
163162
} catch (error) {
164163
console.error(error);
165164
} finally {
@@ -265,7 +264,7 @@ export const Web3AuthProvider: FunctionComponent<IWeb3AuthState> = ({ children,
265264
};
266265

267266
const showWalletConnectScanner = async () => {
268-
if (!walletServicesPlugin) {
267+
if (!wsPlugin) {
269268
console.log("walletServicesPlugin not initialized yet");
270269
uiConsole("walletServicesPlugin not initialized yet");
271270
return;
@@ -275,11 +274,11 @@ export const Web3AuthProvider: FunctionComponent<IWeb3AuthState> = ({ children,
275274
uiConsole("web3Auth not initialized yet");
276275
return;
277276
}
278-
await walletServicesPlugin.showWalletConnectScanner();
277+
await wsPlugin.showWalletConnectScanner();
279278
};
280279

281280
const showWalletUi = async () => {
282-
if (!walletServicesPlugin) {
281+
if (!wsPlugin) {
283282
console.log("walletServicesPlugin not initialized yet");
284283
uiConsole("walletServicesPlugin not initialized yet");
285284
return;
@@ -289,7 +288,7 @@ export const Web3AuthProvider: FunctionComponent<IWeb3AuthState> = ({ children,
289288
uiConsole("web3Auth not initialized yet");
290289
return;
291290
}
292-
await walletServicesPlugin.showWalletUi();
291+
await wsPlugin.showWalletUi();
293292
};
294293

295294
const uiConsole = (...args: unknown[]): void => {

demo/vue-app-new/src/MainView.vue

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
3-
import { CHAIN_NAMESPACES, ChainNamespaceType, coinbaseConnector, ConnectorFn, NFTCheckoutPlugin, storageAvailable, WALLET_CONNECTORS, walletConnectV2Connector, WalletServicesPlugin, type Web3AuthOptions } from "@web3auth/modal";
3+
import { CHAIN_NAMESPACES, ChainNamespaceType, coinbaseConnector, ConnectorFn, nftCheckoutPlugin, PluginFn, storageAvailable, WALLET_CONNECTORS, walletConnectV2Connector, walletServicesPlugin, type Web3AuthOptions } from "@web3auth/modal";
44
import { Web3AuthContextConfig, Web3AuthProvider } from "@web3auth/modal/vue";
55
import { WalletServicesProvider } from "@web3auth/no-modal/vue";
66
import { computed, onBeforeMount, ref, watch } from "vue";
@@ -63,6 +63,18 @@ const options = computed((): Web3AuthOptions => {
6363
}
6464
6565
const chains = formData.chains.map((chainId) => allChains.find((x) => x.chainId === chainId)!);
66+
// Plugins
67+
const plugins: PluginFn[] = [];
68+
if (formData.chainNamespaces.includes(CHAIN_NAMESPACES.EIP155) || formData.chainNamespaces.includes(CHAIN_NAMESPACES.SOLANA)) {
69+
if (formData.nftCheckoutPlugin.enable && formData.chainNamespaces.includes(CHAIN_NAMESPACES.EIP155)) {
70+
plugins.push(nftCheckoutPlugin({ clientId: NFT_CHECKOUT_CLIENT_ID }));
71+
}
72+
if (formData.walletPlugin.enable) {
73+
plugins.push(walletServicesPlugin());
74+
}
75+
}
76+
77+
6678
return {
6779
clientId: clientIds[formData.network],
6880
web3AuthNetwork: formData.network,
@@ -79,6 +91,7 @@ const options = computed((): Web3AuthOptions => {
7991
chains,
8092
enableLogging: true,
8193
connectors: externalConnectors.value,
94+
plugins,
8295
multiInjectedProviderDiscovery: formData.multiInjectedProviderDiscovery,
8396
walletServicesConfig,
8497
};
@@ -160,23 +173,8 @@ watch(
160173
);
161174
162175
const configs = computed<Web3AuthContextConfig>(() => {
163-
const plugins = [];
164-
if (formData.chainNamespaces.includes(CHAIN_NAMESPACES.EIP155) || formData.chainNamespaces.includes(CHAIN_NAMESPACES.SOLANA)) {
165-
if (formData.nftCheckoutPlugin.enable && formData.chainNamespaces.includes(CHAIN_NAMESPACES.EIP155)) {
166-
const nftCheckoutPlugin = new NFTCheckoutPlugin({
167-
clientId: NFT_CHECKOUT_CLIENT_ID,
168-
});
169-
plugins.push(nftCheckoutPlugin);
170-
}
171-
if (formData.walletPlugin.enable) {
172-
const walletServicesPlugin = new WalletServicesPlugin();
173-
plugins.push(walletServicesPlugin);
174-
}
175-
}
176-
177176
return {
178177
web3AuthOptions: options.value,
179-
plugins,
180178
modalConfig: modalParams.value,
181179
hideWalletDiscovery: !formData.showWalletDiscovery,
182180
};

package-lock.json

Lines changed: 4 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/modal/src/modalManager.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,11 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
9191
}
9292

9393
// initialize connectors
94-
this.connectorStore.subscribe(() => this.initConnectors(projectConfig, params));
94+
this.on(CONNECTOR_EVENTS.CONNECTORS_UPDATED, () => this.initConnectors(projectConfig, params));
9595
await this.loadConnectors({ projectConfig });
96+
97+
// initialize plugins
98+
await this.initPlugins();
9699
}
97100

98101
public async connect(): Promise<IProvider | null> {

packages/modal/src/react/context/Web3AuthInnerContext.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
CONNECTOR_EVENTS,
44
CONNECTOR_STATUS,
55
type CONNECTOR_STATUS_TYPE,
6-
type IPlugin,
76
type IProvider,
87
type LoginParams,
98
WalletInitializationError,
@@ -31,14 +30,6 @@ export function Web3AuthInnerProvider(params: PropsWithChildren<Web3AuthProvider
3130
const [isInitialized, setIsInitialized] = useState<boolean>(false);
3231
const [status, setStatus] = useState<CONNECTOR_STATUS_TYPE | null>(null);
3332

34-
const addPlugin = useCallback(
35-
(plugin: IPlugin) => {
36-
if (!web3Auth) throw WalletInitializationError.notReady();
37-
return web3Auth.addPlugin(plugin);
38-
},
39-
[web3Auth]
40-
);
41-
4233
const getPlugin = useCallback(
4334
(name: string) => {
4435
if (!web3Auth) throw WalletInitializationError.notReady();
@@ -116,13 +107,8 @@ export function Web3AuthInnerProvider(params: PropsWithChildren<Web3AuthProvider
116107
};
117108

118109
resetHookState();
119-
const { web3AuthOptions, plugins = [] } = config;
110+
const { web3AuthOptions } = config;
120111
const web3AuthInstance = new Web3Auth(web3AuthOptions);
121-
if (plugins.length) {
122-
plugins.forEach((plugin) => {
123-
web3AuthInstance.addPlugin(plugin);
124-
});
125-
}
126112
setWeb3Auth(web3AuthInstance);
127113
}, [config]);
128114

@@ -227,7 +213,6 @@ export function Web3AuthInnerProvider(params: PropsWithChildren<Web3AuthProvider
227213
enableMFA,
228214
manageMFA,
229215
logout,
230-
addPlugin,
231216
authenticateUser,
232217
switchChain,
233218
getPlugin,
@@ -249,7 +234,6 @@ export function Web3AuthInnerProvider(params: PropsWithChildren<Web3AuthProvider
249234
enableMFA,
250235
manageMFA,
251236
logout,
252-
addPlugin,
253237
authenticateUser,
254238
switchChain,
255239
isInitializing,

packages/modal/src/react/interfaces.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ConnectorFn, IBaseWeb3AuthHookContext, IPlugin, IProvider, WALLET_CONNECTOR_TYPE } from "@web3auth/no-modal";
1+
import type { ConnectorFn, IBaseWeb3AuthHookContext, IProvider, PluginFn, WALLET_CONNECTOR_TYPE } from "@web3auth/no-modal";
22

33
import { type ModalConfig } from "../interface";
44
import type { Web3Auth, Web3AuthOptions } from "../modalManager";
@@ -8,7 +8,7 @@ export type Web3AuthContextConfig = {
88
modalConfig?: Record<WALLET_CONNECTOR_TYPE, ModalConfig>;
99
hideWalletDiscovery?: boolean;
1010
connectors?: ConnectorFn[];
11-
plugins?: IPlugin[];
11+
plugins?: PluginFn[];
1212
};
1313

1414
export interface Web3AuthProviderProps {

packages/modal/src/vue/Web3AuthProvider.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
CONNECTOR_EVENTS,
44
CONNECTOR_STATUS,
55
type CONNECTOR_STATUS_TYPE,
6-
type IPlugin,
76
type IProvider,
87
LoginParams,
98
WalletInitializationError,
@@ -33,11 +32,6 @@ export const Web3AuthProvider = defineComponent({
3332
const connectError = ref<Error | null>(null);
3433
const isConnected = ref(false);
3534

36-
const addPlugin = (plugin: IPlugin) => {
37-
if (!web3Auth.value) throw WalletInitializationError.notReady();
38-
return web3Auth.value.addPlugin(plugin);
39-
};
40-
4135
const getPlugin = (name: string) => {
4236
if (!web3Auth.value) throw WalletInitializationError.notReady();
4337
return web3Auth.value.getPlugin(name);
@@ -101,14 +95,8 @@ export const Web3AuthProvider = defineComponent({
10195
};
10296

10397
resetHookState();
104-
const { web3AuthOptions, plugins = [] } = newConfig;
98+
const { web3AuthOptions } = newConfig;
10599
const web3AuthInstance = new Web3Auth(web3AuthOptions);
106-
if (plugins.length) {
107-
plugins.forEach((plugin) => {
108-
web3AuthInstance.addPlugin(plugin);
109-
});
110-
}
111-
112100
web3Auth.value = web3AuthInstance;
113101
},
114102
{ immediate: true }
@@ -223,7 +211,6 @@ export const Web3AuthProvider = defineComponent({
223211
enableMFA,
224212
manageMFA,
225213
logout,
226-
addPlugin,
227214
authenticateUser,
228215
switchChain,
229216
isInitializing,

0 commit comments

Comments
 (0)