@quirks/store
Version:
35 lines (34 loc) • 1.16 kB
JavaScript
const f = {
name: "quirks-shared",
excluded: ["wallet", "wallets"],
enabled: !1
}, h = (r, c = f) => (o, n, i) => {
if (globalThis.BroadcastChannel || console.debug("BroadcastChannel is not supported in this context!"), !globalThis.BroadcastChannel || !c.enabled)
return r(o, n, i);
const l = new BroadcastChannel(c.name), u = (...e) => {
const a = n();
o(...e);
const s = n(), d = {};
Object.keys(s).forEach((t) => {
if (!c.excluded.includes(t) && s[t] !== a[t]) {
if (typeof s[t] == "function" || c.excluded.includes(t))
return;
d[t] = s[t];
}
}), Object.keys(d).length && (l == null || l.postMessage(d));
};
return l && (l.onmessage = (e) => {
o(e.data);
}), i.subscribe(async (e) => {
if (e.walletName && !e.wallet && e.status === "CONNECTED" && !e.connecting) {
const a = n().wallets.find(
(s) => s.options.wallet_name === e.walletName
);
(a == null ? void 0 : a.options.connection_type) === "wallet_connect" && await a.init(n().providerOpts), n().setWallet(a);
}
}), r(u, n, i);
};
export {
f as defaultSharedOptions,
h as shared
};