Skip to content
Merged
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
59 changes: 38 additions & 21 deletions plugins/hodei/src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,41 +37,58 @@ export type HodeiPluginConfig = {
initialize: typeof defaultInitialize;
};

const hodeiWalletKey = "hodei";

export function hodeiPlugin(config?: Partial<HodeiPluginConfig>): WeldPlugin {
return {
key: "hodei",
key: hodeiWalletKey,
connector: getDefaultWalletConnector(HodeiHandler),
initialize: runOnce((weld) => {
const shouldHandleCallback = (): boolean => {
if (weld.wallet.key === hodeiWalletKey || weld.wallet.isConnectingTo === hodeiWalletKey) {
return true;
}
if (weld.config.debug) {
console.warn(
"[WELD] Ignoring Hodei socket error. Weld isn't connected nor connecting to Hodei",
);
}
return false;
};

const initFn = config?.initialize ?? defaultInitialize;
const walletApi = initFn({
debug: weld.config.debug,
...config,
onError: (data) => {
if (weld.wallet.key === "hodei") {
if (weld.config.debug) {
console.error("[WELD] Hodei socket error, disconnecting.", data);
}
config?.onError?.(data, weld);
weld.wallet.disconnect();
onError: (state) => {
if (!shouldHandleCallback()) {
return;
}
if (weld.config.debug) {
console.error("[WELD] Hodei socket error, disconnecting.", state);
}
config?.onError?.(state, weld);
weld.wallet.disconnect();
},
onClose: (data) => {
if (weld.wallet.key === "hodei") {
if (weld.config.debug) {
console.error("[WELD] Hodei socket closed, disconnecting.", data);
}
config?.onClose?.(data, weld);
weld.wallet.disconnect();
if (!shouldHandleCallback()) {
return;
}
if (weld.config.debug) {
console.error("[WELD] Hodei socket closed, disconnecting.", data);
}
config?.onClose?.(data, weld);
weld.wallet.disconnect();
},
onWalletUpdate: (wallet) => {
if (weld.wallet.key === "hodei") {
if (weld.config.debug) {
console.log("[WELD] Hodei wallet updated, updating state.", wallet);
}
config?.onWalletUpdate?.(wallet, weld);
weld.wallet.updateState();
if (!shouldHandleCallback()) {
return;
}
if (weld.config.debug) {
console.log("[WELD] Hodei wallet updated, updating state.", wallet);
}
config?.onWalletUpdate?.(wallet, weld);
weld.wallet.updateState();
},
});

Expand All @@ -82,7 +99,7 @@ export function hodeiPlugin(config?: Partial<HodeiPluginConfig>): WeldPlugin {
weld.extensions.registerWallets([
{
supported: true,
key: "hodei",
key: hodeiWalletKey,
displayName: "Hodei",
icon: "https://raw.githubusercontent.com/cardano-forge/weld/main/images/wallets/hodei.png",
website: "https://github.com/cardano-forge/hodei-client",
Expand Down
Loading