UNPKG

@quirks/store

Version:
107 lines (106 loc) 2.82 kB
import { subscribeWithSelector as D, persist as H } from "zustand/middleware"; import { createStore as T } from "zustand/vanilla"; import { connectInitialState as h, createConnectSlice as W } from "./index12.js"; import { walletConnectInitialState as O, createWalletConnectSlice as k } from "./index13.js"; import { shared as x, defaultSharedOptions as C } from "./index11.js"; import { createConfigSlice as F, configInitialState as L } from "./index14.js"; import { createAccountSlice as P, accountInitialState as _ } from "./index15.js"; import { createSignSlice as $, signInitialState as I } from "./index16.js"; import { defaultPersistOptions as j } from "./index9.js"; const U = (N) => { var f, u; const { wallets: c, chains: a, assetsLists: r, autoConnect: m = !0, autoSuggestions: v = !0, autoAccountChange: w = !0, persistOptions: n = j, sharedOptions: E = C, walletConnectOptions: e, signOptions: l, signerOptions: b } = N, y = l || I.signOptions, S = { ...I, signOptions: y, signerOptions: b }, p = { ...h, options: { ...h.options, autoSuggestions: v, autoAccountChange: w } }, s = O.namespaces, g = a.map((t) => `cosmos:${t.chain_id}`); e != null && e.namespaces ? s.cosmos = { ...e.namespaces.cosmos, chains: g, events: [ ...s.cosmos.events, ...e.namespaces.cosmos.events ], methods: [ ...s.cosmos.methods, ...e.namespaces.cosmos.methods ] } : s.cosmos = { ...s.cosmos, chains: g }; const d = { ...O, ...e, namespaces: s }, A = (f = n.getInitialState) == null ? void 0 : f.call(n), o = T( D( H( x( (...t) => ({ ...F(...t), wallets: c, chains: a, assetsLists: r, ...W(...t), ...P(...t), ...p, ...$(...t), ...S, ...k(...t), ...d, reset: () => { t[0]({ ...L, ...p, ..._, ...S, ...d, wallets: c, chains: a, assetsLists: r }); }, ...A }), { ...C, ...E } ), n ) ) ); if (o.persist.getOptions().skipHydration) { const t = (u = o.persist) == null ? void 0 : u.onFinishHydration((i) => { i.walletName && i.status === "CONNECTED" && !i.wallet && m && (o.getState().reconnect(i.walletName), t()); }); } else { const t = o.getState(); t.walletName && t.status === "CONNECTED" && !t.wallet && m && o.getState().reconnect(t.walletName); } return o; }; export { U as createConfig };