diff --git a/packages/base/src/hooks/index.ts b/packages/base/src/hooks/index.ts index 09ab3f90d..2d0757bc8 100644 --- a/packages/base/src/hooks/index.ts +++ b/packages/base/src/hooks/index.ts @@ -29,6 +29,7 @@ export interface IBaseWeb3AuthHookContext { export interface IBaseWalletServicesHookContext { isPluginConnected: boolean; showWalletConnectScanner(showWalletConnectParams?: BaseEmbedControllerState["showWalletConnect"]): Promise; + showSwap(showSwapParams?: BaseEmbedControllerState["showSwap"]): Promise; showCheckout(showCheckoutParams?: BaseEmbedControllerState["showCheckout"]): Promise; showWalletUI(showWalletUiParams?: BaseEmbedControllerState["showWalletUi"]): Promise; } diff --git a/packages/composables/wallet-services-plugin-vue-composables/src/WalletServicesProvider.ts b/packages/composables/wallet-services-plugin-vue-composables/src/WalletServicesProvider.ts index 14b7c9731..e3d479075 100644 --- a/packages/composables/wallet-services-plugin-vue-composables/src/WalletServicesProvider.ts +++ b/packages/composables/wallet-services-plugin-vue-composables/src/WalletServicesProvider.ts @@ -1,3 +1,4 @@ +import { BaseEmbedControllerState } from "@toruslabs/base-controllers"; import { EVM_PLUGINS, IPlugin, PLUGIN_EVENTS, WalletServicesPluginError, Web3AuthContextKey } from "@web3auth/base"; import { WalletServicesPlugin } from "@web3auth/wallet-services-plugin"; import { defineComponent, h, inject, provide, Ref, ref, watch } from "vue"; @@ -57,25 +58,32 @@ export const WalletServicesProvider = defineComponent({ } }); - const showWalletConnectScanner = async () => { + const showWalletConnectScanner = async (showWalletConnectScannerParams?: BaseEmbedControllerState["showWalletConnect"]) => { if (!walletServicesPlugin.value) throw WalletServicesPluginError.notInitialized(); if (!isPluginConnected.value) throw WalletServicesPluginError.walletPluginNotConnected(); - return walletServicesPlugin.value.showWalletConnectScanner(); + return walletServicesPlugin.value.showWalletConnectScanner(showWalletConnectScannerParams); }; - const showWalletUI = async () => { + const showWalletUI = async (showWalletUiParams?: BaseEmbedControllerState["showWalletUi"]) => { if (!walletServicesPlugin.value) throw WalletServicesPluginError.notInitialized(); if (!isPluginConnected.value) throw WalletServicesPluginError.walletPluginNotConnected(); - return walletServicesPlugin.value.showWalletUi(); + return walletServicesPlugin.value.showWalletUi(showWalletUiParams); }; - const showCheckout = async () => { + const showCheckout = async (showCheckoutParams?: BaseEmbedControllerState["showCheckout"]) => { if (!walletServicesPlugin.value) throw WalletServicesPluginError.notInitialized(); if (!isPluginConnected.value) throw WalletServicesPluginError.walletPluginNotConnected(); - return walletServicesPlugin.value.showCheckout(); + return walletServicesPlugin.value.showCheckout(showCheckoutParams); + }; + + const showSwap = async (showSwapParams?: BaseEmbedControllerState["showSwap"]) => { + if (!walletServicesPlugin.value) throw WalletServicesPluginError.notInitialized(); + if (!isPluginConnected.value) throw WalletServicesPluginError.walletPluginNotConnected(); + + return walletServicesPlugin.value.showSwap(showSwapParams); }; provide(WalletServicesContextKey, { @@ -84,6 +92,7 @@ export const WalletServicesProvider = defineComponent({ showWalletConnectScanner, showCheckout, showWalletUI, + showSwap, }); }, render() { diff --git a/packages/composables/wallet-services-plugin-vue-composables/src/interfaces.ts b/packages/composables/wallet-services-plugin-vue-composables/src/interfaces.ts index 45554b0d4..117ad98d9 100644 --- a/packages/composables/wallet-services-plugin-vue-composables/src/interfaces.ts +++ b/packages/composables/wallet-services-plugin-vue-composables/src/interfaces.ts @@ -7,6 +7,7 @@ export interface IBaseWalletServicesComposableContext { showWalletConnectScanner(showWalletConnectParams?: BaseEmbedControllerState["showWalletConnect"]): Promise; showCheckout(showCheckoutParams?: BaseEmbedControllerState["showCheckout"]): Promise; showWalletUI(showWalletUiParams?: BaseEmbedControllerState["showWalletUi"]): Promise; + showSwap(showSwapParams?: BaseEmbedControllerState["showSwap"]): Promise; } export interface IWalletServicesContext extends IBaseWalletServicesComposableContext { diff --git a/packages/hooks/wallet-services-plugin-react-hooks/src/context/WalletServicesContext.ts b/packages/hooks/wallet-services-plugin-react-hooks/src/context/WalletServicesContext.ts index c7e74795a..a24da3c69 100644 --- a/packages/hooks/wallet-services-plugin-react-hooks/src/context/WalletServicesContext.ts +++ b/packages/hooks/wallet-services-plugin-react-hooks/src/context/WalletServicesContext.ts @@ -79,6 +79,16 @@ export function WalletServicesContextProvider { + if (!walletServicesPlugin) throw WalletServicesPluginError.notInitialized(); + if (!isPluginConnected) throw WalletServicesPluginError.walletPluginNotConnected(); + + return walletServicesPlugin.showSwap(showSwapParams); + }, + [walletServicesPlugin, isPluginConnected] + ); + const value = useMemo(() => { return { plugin: walletServicesPlugin, @@ -86,8 +96,9 @@ export function WalletServicesContextProvider { + if (!this.wsEmbedInstance.isLoggedIn) throw WalletServicesPluginError.walletPluginNotConnected(); + return this.wsEmbedInstance.showSwap(showSwapParams); + } + async cleanup(): Promise { return this.wsEmbedInstance.cleanUp(); }