Skip to content

Commit

Permalink
use wallet service plugin provider by default
Browse files Browse the repository at this point in the history
  • Loading branch information
lionellbriones committed Dec 17, 2024
1 parent d8dc214 commit 1377564
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 23 deletions.
55 changes: 33 additions & 22 deletions demo/vue-app-new/src/MainView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import { CommonPrivateKeyProvider } from "@web3auth/base-provider";
import { CoinbaseAdapter } from "@web3auth/coinbase-adapter";
import { getInjectedAdapters as getInjectedEvmAdapters } from "@web3auth/default-evm-adapter";
import { getInjectedAdapters as getInjectedSolanaAdapters } from "@web3auth/default-solana-adapter";
import { EthereumPrivateKeyProvider } from "@web3auth/ethereum-provider";
// import { EthereumPrivateKeyProvider } from "@web3auth/ethereum-provider";
import { type Web3AuthOptions } from "@web3auth/modal";
import { Web3AuthProvider } from "@web3auth/modal-vue-composables";
import { NFTCheckoutPlugin } from "@web3auth/nft-checkout-plugin";
import { SolanaPrivateKeyProvider } from "@web3auth/solana-provider";
// import { SolanaPrivateKeyProvider } from "@web3auth/solana-provider";
import { TorusWalletAdapter } from "@web3auth/torus-evm-adapter";
import { SolanaWalletAdapter } from "@web3auth/torus-solana-adapter";
import { WalletConnectV2Adapter } from "@web3auth/wallet-connect-v2-adapter";
Expand Down Expand Up @@ -50,6 +50,12 @@ const walletPlugins = computed(() => {
walletInitOptions: {
whiteLabel: { showWidgetButton: true, logoDark: logoDark || "logo", logoLight: logoLight || "logo" },
confirmationStrategy,
// walletUrls: {
// production: {
// url: "http://localhost:4050",
// logLevel: "debug",
// },
// },
},
});
plugins.push(walletServicesPlugin);
Expand All @@ -68,26 +74,31 @@ const chainOptions = computed(() =>
const privateKeyProvider = computed((): IBaseProvider<string> => {
const chainConfig = chainConfigs[formData.chainNamespace as ChainNamespaceType].find((x) => x.chainId === formData.chain)!;
switch (formData.chainNamespace) {
case CHAIN_NAMESPACES.EIP155:
return new EthereumPrivateKeyProvider({
config: {
chainConfig,
},
});
case CHAIN_NAMESPACES.SOLANA:
return new SolanaPrivateKeyProvider({
config: {
chainConfig,
},
});
default:
return new CommonPrivateKeyProvider({
config: {
chainConfig,
},
});
}
return new CommonPrivateKeyProvider({
config: {
chainConfig,
},
});
// switch (formData.chainNamespace) {
// case CHAIN_NAMESPACES.EIP155:
// return new EthereumPrivateKeyProvider({
// config: {
// chainConfig,
// },
// });
// case CHAIN_NAMESPACES.SOLANA:
// return new SolanaPrivateKeyProvider({
// config: {
// chainConfig,
// },
// });
// default:
// return new CommonPrivateKeyProvider({
// config: {
// chainConfig,
// },
// });
// }
});
const showAAProviderSettings = computed(() => formData.chainNamespace === CHAIN_NAMESPACES.EIP155);
Expand Down
1 change: 1 addition & 0 deletions packages/no-modal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@web3auth/auth": "^9.6.2",
"@web3auth/base": "^9.5.0",
"@web3auth/base-provider": "^9.5.0",
"@web3auth/wallet-services-plugin": "^9.5.0",
"deepmerge": "^4.3.1"
},
"devDependencies": {
Expand Down
12 changes: 11 additions & 1 deletion packages/no-modal/src/noModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
IWeb3Auth,
IWeb3AuthCoreOptions,
log,
PLUGIN_EVENTS,
PLUGIN_NAMESPACES,
PLUGIN_STATUS,
PROJECT_CONFIG_RESPONSE,
Expand All @@ -27,13 +28,15 @@ import {
UserInfo,
WALLET_ADAPTER_TYPE,
WALLET_ADAPTERS,
WALLET_PLUGINS,
WalletInitializationError,
WalletLoginError,
Web3AuthError,
Web3AuthNoModalEvents,
} from "@web3auth/base";
import { CommonJRPCProvider } from "@web3auth/base-provider";
import { CommonJRPCProvider, CommonPrivateKeyProvider } from "@web3auth/base-provider";
import { WalletConnectV2Adapter } from "@web3auth/wallet-connect-v2-adapter";
import { type WalletServicesPlugin } from "@web3auth/wallet-services-plugin";
import deepmerge from "deepmerge";

const ADAPTER_CACHE_KEY = "Web3Auth-cachedAdapter";
Expand Down Expand Up @@ -342,6 +345,13 @@ export class Web3AuthNoModal extends SafeEventEmitter<Web3AuthNoModalEvents> imp
this.cacheWallet(data.adapter);
log.debug("connected", this.status, this.connectedAdapterName);
this.connectToPlugins(data);
if (this.plugins[WALLET_PLUGINS.WALLET_SERVICES]) {
this.plugins[WALLET_PLUGINS.WALLET_SERVICES].on(PLUGIN_EVENTS.CONNECTED, () => {
(provider as CommonPrivateKeyProvider).updateProviderEngineProxy(
(this.plugins[WALLET_PLUGINS.WALLET_SERVICES] as WalletServicesPlugin).wsEmbedInstance.provider
);
});
}
this.emit(ADAPTER_EVENTS.CONNECTED, { ...data });
});

Expand Down

0 comments on commit 1377564

Please sign in to comment.