diff --git a/apps/namada-interface/src/services/extensionEvents/handlers/keplr.ts b/apps/namada-interface/src/services/extensionEvents/handlers/keplr.ts index da1cd3d9f..e2367703b 100644 --- a/apps/namada-interface/src/services/extensionEvents/handlers/keplr.ts +++ b/apps/namada-interface/src/services/extensionEvents/handlers/keplr.ts @@ -4,6 +4,8 @@ import { Keplr } from "@namada/integrations"; import { addAccounts, fetchBalances } from "slices/accounts"; +import { actions as notificationsActions } from "slices/notifications"; + export const KeplrAccountChangedHandler = (dispatch: Dispatch, integration: Keplr) => async () => { const accounts = await integration.accounts(); @@ -13,3 +15,17 @@ export const KeplrAccountChangedHandler = dispatch(fetchBalances()); } }; + +export const KeplrBridgeTransferCompletedHandler = + (dispatch: Dispatch) => async (event: CustomEventInit) => { + const msgId = (Math.random() + 1).toString(36).substring(7); + const success = true; + dispatch( + notificationsActions.txCompletedToast({ + id: msgId, + txTypeLabel: "IBC Transfer", + success, + error: "", + }) + ); + }; diff --git a/apps/namada-interface/src/services/extensionEvents/provider.tsx b/apps/namada-interface/src/services/extensionEvents/provider.tsx index 37111546f..aa610e9f6 100644 --- a/apps/namada-interface/src/services/extensionEvents/provider.tsx +++ b/apps/namada-interface/src/services/extensionEvents/provider.tsx @@ -7,6 +7,7 @@ import { Events, KeplrEvents, MetamaskEvents } from "@namada/types"; import { useAppDispatch } from "store"; import { KeplrAccountChangedHandler, + KeplrBridgeTransferCompletedHandler, MetamaskAccountChangedHandler, MetamaskBridgeTransferCompletedHandler, NamadaAccountChangedHandler, @@ -72,6 +73,9 @@ export const ExtensionEventsProvider: React.FC = (props): JSX.Element => { keplrIntegration as Keplr ); + const keplrBridgeTransferCompletedHandler = + KeplrBridgeTransferCompletedHandler(dispatch); + // Metamask handlers const metamaskAccountChangedHandler = MetamaskAccountChangedHandler( dispatch, @@ -115,6 +119,10 @@ export const ExtensionEventsProvider: React.FC = (props): JSX.Element => { metamaskBridgeTransferCompletedHandler ); + useEventListenerOnce( + KeplrEvents.BridgeTransferCompleted, + keplrBridgeTransferCompletedHandler + ); return ( {props.children} diff --git a/packages/integrations/src/Keplr.ts b/packages/integrations/src/Keplr.ts index b390c6062..a1e7ee31a 100644 --- a/packages/integrations/src/Keplr.ts +++ b/packages/integrations/src/Keplr.ts @@ -24,6 +24,7 @@ import { CosmosTokens, TokenBalances, tokenByMinDenom, + KeplrEvents } from "@namada/types"; import { BridgeProps, Integration } from "./types/Integration"; @@ -210,7 +211,7 @@ class Keplr implements Integration { `Transaction failed with code ${response.code}! Message: ${response.rawLog}` ); } - + window.dispatchEvent(new Event(KeplrEvents.BridgeTransferCompleted)); return; } diff --git a/packages/types/src/events.ts b/packages/types/src/events.ts index fe97f2283..f9b275c12 100644 --- a/packages/types/src/events.ts +++ b/packages/types/src/events.ts @@ -16,6 +16,7 @@ export enum Events { // Keplr extension events export enum KeplrEvents { AccountChanged = "keplr_keystorechange", + BridgeTransferCompleted = "readystatechange", } // Metamask extension window.ethereum events