UNPKG

@quirks/store

Version:
2 lines (1 loc) 973 B
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u={name:"quirks-shared",excluded:["wallet","wallets"],enabled:!1},h=(r,c=u)=>(o,n,d)=>{if(globalThis.BroadcastChannel||console.debug("BroadcastChannel is not supported in this context!"),!globalThis.BroadcastChannel||!c.enabled)return r(o,n,d);const l=new BroadcastChannel(c.name),f=(...e)=>{const a=n();o(...e);const s=n(),i={};Object.keys(s).forEach(t=>{if(!c.excluded.includes(t)&&s[t]!==a[t]){if(typeof s[t]=="function"||c.excluded.includes(t))return;i[t]=s[t]}}),Object.keys(i).length&&(l==null||l.postMessage(i))};return l&&(l.onmessage=e=>{o(e.data)}),d.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(f,n,d)};exports.defaultSharedOptions=u;exports.shared=h;