Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support notification when ibc transfer from cosmos #725

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown>, integration: Keplr) => async () => {
const accounts = await integration.accounts();
Expand All @@ -13,3 +15,17 @@ export const KeplrAccountChangedHandler =
dispatch(fetchBalances());
}
};

export const KeplrBridgeTransferCompletedHandler =
(dispatch: Dispatch<unknown>) => 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: "",
})
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Events, KeplrEvents, MetamaskEvents } from "@namada/types";
import { useAppDispatch } from "store";
import {
KeplrAccountChangedHandler,
KeplrBridgeTransferCompletedHandler,
MetamaskAccountChangedHandler,
MetamaskBridgeTransferCompletedHandler,
NamadaAccountChangedHandler,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -115,6 +119,10 @@ export const ExtensionEventsProvider: React.FC = (props): JSX.Element => {
metamaskBridgeTransferCompletedHandler
);

useEventListenerOnce(
KeplrEvents.BridgeTransferCompleted,
keplrBridgeTransferCompletedHandler
);
return (
<ExtensionEventsContext.Provider value={{}}>
{props.children}
Expand Down
3 changes: 2 additions & 1 deletion packages/integrations/src/Keplr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
CosmosTokens,
TokenBalances,
tokenByMinDenom,
KeplrEvents
} from "@namada/types";
import { BridgeProps, Integration } from "./types/Integration";

Expand Down Expand Up @@ -210,7 +211,7 @@ class Keplr implements Integration<Account, OfflineSigner, CosmosTokenType> {
`Transaction failed with code ${response.code}! Message: ${response.rawLog}`
);
}

window.dispatchEvent(new Event(KeplrEvents.BridgeTransferCompleted));
return;
}

Expand Down
1 change: 1 addition & 0 deletions packages/types/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export enum Events {
// Keplr extension events
export enum KeplrEvents {
AccountChanged = "keplr_keystorechange",
BridgeTransferCompleted = "readystatechange",
}

// Metamask extension window.ethereum events
Expand Down