@rango-dev/wallets-react 0.21.2-next.4 → 0.21.2-next.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var b=Object.defineProperty;var s=(e,t)=>b(e,"name",{value:t,configurable:!0});import{Persistor as g}from"@rango-dev/wallets-core";var u="last-connected-wallets";function K(e,t){return e.find(c=>c.type===t)||null}s(K,"choose");var W={connected:!1,connecting:!1,reachable:!1,installed:!1,accounts:null,network:null};function k(e,t){if(t.type==="new_state"){let c=e[t.wallet];return c?{...e,[t.wallet]:{...c,[t.name]:t.value}}:{...e,[t.wallet]:{...W,[t.name]:t.value}}}return e}s(k,"state_reducer");function I(e){return Object.entries(e).filter(([,t])=>t?.connected).map(([t])=>t)}s(I,"connectedWallets");function P(e){return Object.entries(e).map(([t])=>t)}s(P,"availableWallets");function x(e){let t=new Map;return e.forEach(c=>{let{config:l,...o}=c;t.set(l.type,{actions:o,config:l})}),t}s(x,"checkWalletProviders");function q(e){return e?.constructor?.name==="AsyncFunction"}s(q,"isAsync");function J(e){let{checkInstallation:t=!0}=e.config;return t}s(J,"needsCheckInstallation");async function S({type:e,walletActions:t,getState:c}){if(t.canEagerConnect){let l=new g,o=l.getItem(u);o?.find(d=>!c(d).connected)&&v();let p=!!o?.find(d=>d===e);o&&!p?l.setItem(u,o.concat(e)):l.setItem(u,[e])}}s(S,"tryPersistWallet");function E({type:e,walletActions:t}){if(t.canEagerConnect){let c=new g,l=c.getItem(u);l&&c.setItem(u,l.filter(o=>o!==e))}}s(E,"tryRemoveWalletFromPersistance");function v(){let e=new g;e.getItem(u)&&e.removeItem(u)}s(v,"clearPersistance");async function T(e,t){let c=new g,l=c.getItem(u);if(l&&l.length){let o=[];l.forEach(d=>{let n=e.get(d);if(n){let r=t(n);o.push({walletType:d,eagerConnect:r.eagerConnect.bind(r)})}});let w=await Promise.allSettled(o.map(async({eagerConnect:d})=>d()));if(!!w.find(({status:d})=>d==="fulfilled")){let d=[];w.forEach((n,r)=>{let{status:a}=n;a==="rejected"&&d.push(o[r].walletType)}),d.length&&c.setItem(u,l.filter(n=>!d.includes(n)))}}}s(T,"autoConnect");function C(e,t){return s((l,o,w,p,d)=>{e({type:"new_state",wallet:l,name:o,value:w}),t&&t(l,o,w,p,d)},"handler")}s(C,"makeEventHandler");import _,{useEffect as h,useReducer as D,useRef as F}from"react";import{createContext as B}from"react";var f="Context hasn't been initialized yet.",R={async connect(){throw new Error(f)},async disconnect(){throw new Error(f)},async disconnectAll(){throw new Error(f)},async suggestAndConnect(){throw new Error(f)},state(){throw new Error(f)},canSwitchNetworkTo(){throw new Error(f)},providers(){throw new Error(f)},getWalletInfo(){throw new Error(f)},getSigners(){throw new Error(f)}},m=B(R);import H from"@rango-dev/wallets-core";import{useContext as O,useRef as M}from"react";function A(e){let t=M({});function c(l){let o=l.config.type;return typeof t.current[o]>"u"&&(t.current[o]=new H({config:l.config,handler:e},l.actions)),t.current[o]}return s(c,"updater"),c}s(A,"useInitializers");function L(){let e=O(m);if(!e)throw Error("useWallet can only be used within the Provider component");return e}s(L,"useWallets");function j(e){let[t,c]=D(k,{}),l=F(!1),o=A(C(c,e.onUpdateState)),w=e.providers,p=x(w),d={async connect(n,r,a){let i=p.get(n);if(!i)throw new Error(`You should add ${n} to provider first.`);let N=await o(i).connect(r,a);return e.autoConnect&&S({type:n,walletActions:i.actions,getState:d.state}),N},async disconnect(n){let r=p.get(n);if(!r)throw new Error(`You should add ${n} to provider first.`);await o(r).disconnect(),e.autoConnect&&E({type:n,walletActions:r.actions})},async disconnectAll(){let n=[];return I(t).forEach(r=>{let a=p.get(r);if(a){let i=o(a);n.push(i.disconnect())}}),e.autoConnect&&v(),await Promise.allSettled(n)},async suggestAndConnect(n,r){let a=p.get(n);if(!a)throw new Error(`You should add ${n} to provider first.`);return await o(a).suggestAndConnect(r)},state(n){return t[n]||W},canSwitchNetworkTo(n,r){let a=p.get(n);if(!a)return!1;let i=o(a);return i.canSwitchNetworkTo?i.canSwitchNetworkTo(r,i.provider):!1},providers(){let n={};return P(t).forEach(r=>{let a=p.get(r);if(a){let i=o(a);n[r]=i.provider}}),n},getWalletInfo(n){let r=p.get(n);if(!r)throw new Error(`You should add ${n} to provider first.`);return r.actions.getWalletInfo(e.allBlockChains||[])},getSigners(n){let r=p.get(n);if(!r)throw new Error(`You should add ${n} to provider first.`);let a=o(r),i=a.provider;return a.getSigners(i)}};return h(()=>{p.forEach(n=>{let r=o(n),a=s(()=>{r.onInit&&r.onInit()},"runOnInit"),i=s(y=>{y.target&&y.target.readyState==="complete"&&(a(),document.removeEventListener("readystatechange",i))},"initWhenPageIsReady");a(),document.addEventListener("readystatechange",i)})},[]),h(()=>{e.allBlockChains&&p.forEach(r=>{let a=o(r),i=a.getWalletInfo(e.allBlockChains||[]);a.setInfo({supportedBlockchains:i.supportedChains,isContractWallet:!!i.isContractWallet})})},[e.allBlockChains]),h(()=>{p.forEach(n=>{o(n).setHandler(C(c,e.onUpdateState))})},[e.onUpdateState]),h(()=>{e.allBlockChains&&e.allBlockChains.length&&e.autoConnect&&!l.current&&(l.current=!0,(async()=>await T(p,o))())},[e.autoConnect,e.allBlockChains]),_.createElement(m.Provider,{value:d},e.children)}s(j,"Provider");var G=j;import{Events as he,readAccountAddress as We}from"@rango-dev/wallets-core";export{he as Events,G as Provider,T as autoConnect,P as availableWallets,x as checkWalletProviders,K as choose,v as clearPersistance,I as connectedWallets,W as defaultWalletState,q as isAsync,C as makeEventHandler,J as needsCheckInstallation,We as readAccountAddress,k as state_reducer,S as tryPersistWallet,E as tryRemoveWalletFromPersistance,L as useWallets};
1
+ var B=Object.defineProperty;var l=(e,n)=>B(e,"name",{value:n,configurable:!0});import{Persistor as y}from"@rango-dev/wallets-core";var p="last-connected-wallets";function J(e,n){return e.find(c=>c.type===n)||null}l(J,"choose");var g={connected:!1,connecting:!1,reachable:!1,installed:!1,accounts:null,network:null};function v(e,n){if(n.type==="new_state"){let c=e[n.wallet];return c?{...e,[n.wallet]:{...c,[n.name]:n.value}}:{...e,[n.wallet]:{...g,[n.name]:n.value}}}return e}l(v,"stateReducer");function P(e){return Object.entries(e).filter(([,n])=>n?.connected).map(([n])=>n)}l(P,"connectedWallets");function I(e){return Object.entries(e).map(([n])=>n)}l(I,"availableWallets");function k(e){let n=new Map;return e.forEach(c=>{let{config:r,...i}=c;n.set(r.type,{actions:i,config:r})}),n}l(k,"checkWalletProviders");function Q(e){return e?.constructor?.name==="AsyncFunction"}l(Q,"isAsync");function V(e){let{checkInstallation:n=!0}=e.config;return n}l(V,"needsCheckInstallation");async function x({type:e,walletActions:n,getState:c}){if(n.canEagerConnect){let r=new y,i=r.getItem(p);i?.find(t=>!c(t).connected)&&W();let f=!!i?.find(t=>t===e);i&&!f?r.setItem(p,i.concat(e)):r.setItem(p,[e])}}l(x,"tryPersistWallet");function S({type:e,walletActions:n}){if(n.canEagerConnect){let c=new y,r=c.getItem(p);r&&c.setItem(p,r.filter(i=>i!==e))}}l(S,"tryRemoveWalletFromPersistance");function W(){let e=new y;e.getItem(p)&&e.removeItem(p)}l(W,"clearPersistance");async function E(e,n){let c=new y,r=c.getItem(p);if(r&&r.length){let i=[];r.forEach(t=>{let o=e.get(t);if(o){let a=n(o);i.push({walletType:t,eagerConnect:a.eagerConnect.bind(a)})}});let d=await Promise.allSettled(i.map(async({eagerConnect:t})=>t()));if(!!d.find(({status:t})=>t==="fulfilled")){let t=[];d.forEach((o,a)=>{let{status:s}=o;s==="rejected"&&t.push(i[a].walletType)}),t.length&&c.setItem(p,r.filter(o=>!t.includes(o)))}}}l(E,"autoConnect");function h(e,n){return l((r,i,d,f,t)=>{e({type:"new_state",wallet:r,name:i,value:d}),n&&n(r,i,d,f,t)},"handler")}l(h,"makeEventHandler");import _ from"react";import{createContext as R}from"react";var u="Context hasn't been initialized yet.",L={async connect(){throw new Error(u)},async disconnect(){throw new Error(u)},async disconnectAll(){throw new Error(u)},async suggestAndConnect(){throw new Error(u)},state(){throw new Error(u)},canSwitchNetworkTo(){throw new Error(u)},providers(){throw new Error(u)},getWalletInfo(){throw new Error(u)},getSigners(){throw new Error(u)}},m=R(L);import{useEffect as C,useReducer as D}from"react";import H from"@rango-dev/wallets-core";import{useContext as O,useRef as M}from"react";function T(e){let n=M({});function c(r){let i=r.config.type;return typeof n.current[i]>"u"&&(n.current[i]=new H({config:r.config,handler:e},r.actions)),n.current[i]}return l(c,"updater"),c}l(T,"useInitializers");function F(){let e=O(m);if(!e)throw Error("useWallet can only be used within the Provider component");return e}l(F,"useWallets");import{useEffect as G,useRef as j}from"react";function A(e){let n=j(!1);G(()=>{e.allBlockChains&&e.allBlockChains.length&&e.autoConnect&&!n.current&&(n.current=!0,(async()=>await E(e.wallets,e.getWalletInstanceFromLegacy))())},[e.autoConnect,e.allBlockChains])}l(A,"useAutoConnect");function N(e){let[n,c]=D(v,{}),r=T(h(c,e.onUpdateState)),i=e.providers,d=k(i);A({wallets:d,allBlockChains:e.allBlockChains,autoConnect:e.autoConnect,getWalletInstanceFromLegacy:r});let f={async connect(t,o,a){let s=d.get(t);if(!s)throw new Error(`You should add ${t} to provider first.`);let b=await r(s).connect(o,a);return e.autoConnect&&x({type:t,walletActions:s.actions,getState:f.state}),b},async disconnect(t){let o=d.get(t);if(!o)throw new Error(`You should add ${t} to provider first.`);await r(o).disconnect(),e.autoConnect&&S({type:t,walletActions:o.actions})},async disconnectAll(){let t=[];return P(n).forEach(o=>{let a=d.get(o);if(a){let s=r(a);t.push(s.disconnect())}}),e.autoConnect&&W(),await Promise.allSettled(t)},async suggestAndConnect(t,o){let a=d.get(t);if(!a)throw new Error(`You should add ${t} to provider first.`);return await r(a).suggestAndConnect(o)},state(t){return n[t]||g},canSwitchNetworkTo(t,o){let a=d.get(t);if(!a)return!1;let s=r(a);return s.canSwitchNetworkTo?s.canSwitchNetworkTo(o,s.provider):!1},providers(){let t={};return I(n).forEach(o=>{let a=d.get(o);if(a){let s=r(a);t[o]=s.provider}}),t},getWalletInfo(t){let o=d.get(t);if(!o)throw new Error(`You should add ${t} to provider first.`);return o.actions.getWalletInfo(e.allBlockChains||[])},getSigners(t){let o=d.get(t);if(!o)throw new Error(`You should add ${t} to provider first.`);let a=r(o),s=a.provider;return a.getSigners(s)}};return C(()=>{d.forEach(t=>{let o=r(t),a=l(()=>{o.onInit&&o.onInit()},"runOnInit"),s=l(w=>{w.target&&w.target.readyState==="complete"&&(a(),document.removeEventListener("readystatechange",s))},"initWhenPageIsReady");a(),document.addEventListener("readystatechange",s)})},[]),C(()=>{e.allBlockChains&&d.forEach(o=>{let a=r(o),s=a.getWalletInfo(e.allBlockChains||[]);a.setInfo({supportedBlockchains:s.supportedChains,isContractWallet:!!s.isContractWallet})})},[e.allBlockChains]),C(()=>{d.forEach(t=>{r(t).setHandler(h(c,e.onUpdateState))})},[e.onUpdateState]),f}l(N,"useLegacyProviders");function Y(e){let n=N(e);return _.createElement(m.Provider,{value:n},e.children)}l(Y,"Provider");var $=Y;import{Events as Ae,readAccountAddress as Ne}from"@rango-dev/wallets-core";export{Ae as Events,$ as Provider,E as autoConnect,I as availableWallets,k as checkWalletProviders,J as choose,W as clearPersistance,P as connectedWallets,g as defaultWalletState,Q as isAsync,h as makeEventHandler,V as needsCheckInstallation,Ne as readAccountAddress,v as stateReducer,x as tryPersistWallet,S as tryRemoveWalletFromPersistance,F as useWallets};
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/legacy/helpers.ts", "../src/legacy/constants.ts", "../src/provider.tsx", "../src/legacy/context.ts", "../src/legacy/hooks.ts", "../src/index.ts"],
4
- "sourcesContent": ["import type {\n ProviderInterface,\n State,\n WalletActions,\n WalletProviders,\n} from './types.js';\nimport type Wallet from '@rango-dev/wallets-core';\nimport type {\n Options,\n EventHandler as WalletEventHandler,\n State as WalletState,\n} from '@rango-dev/wallets-core';\nimport type { WalletConfig, WalletType } from '@rango-dev/wallets-shared';\n\nimport { Persistor } from '@rango-dev/wallets-core';\n\nimport { LAST_CONNECTED_WALLETS } from './constants.js';\n\nexport function choose(wallets: any[], type: WalletType): any | null {\n return wallets.find((wallet) => wallet.type === type) || null;\n}\n\nexport const defaultWalletState: WalletState = {\n connected: false,\n connecting: false,\n reachable: false,\n installed: false,\n accounts: null,\n network: null,\n};\n\nexport function state_reducer(state: State, action: any) {\n if (action.type === 'new_state') {\n // TODO fix problem and remove ts-ignore\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const target_wallet = state[action.wallet];\n if (!target_wallet) {\n return {\n ...state,\n [action.wallet]: {\n ...defaultWalletState,\n [action.name]: action.value,\n },\n };\n }\n\n return {\n ...state,\n [action.wallet]: {\n ...target_wallet,\n [action.name]: action.value,\n },\n };\n }\n\n return state;\n}\n\nexport function connectedWallets(providersState: State): WalletType[] {\n return Object.entries(providersState)\n .filter(([, wallet_state]) => {\n return wallet_state?.connected;\n })\n .map(([type]) => {\n return type;\n });\n}\n\nexport function availableWallets(providersState: State): WalletType[] {\n return Object.entries(providersState).map(([type]) => {\n return type;\n });\n}\n\nexport function checkWalletProviders(\n list: ProviderInterface[]\n): WalletProviders {\n const wallets: WalletProviders = new Map();\n\n list.forEach((provider) => {\n const { config, ...actions } = provider;\n wallets.set(config.type, {\n actions,\n config,\n });\n });\n\n return wallets;\n}\n\n/* eslint-disable @typescript-eslint/ban-types */\nexport function isAsync(fn: Function) {\n return fn?.constructor?.name === 'AsyncFunction';\n}\n\nexport function needsCheckInstallation(options: Options) {\n const { checkInstallation = true } = options.config;\n return checkInstallation;\n}\n\nexport async function tryPersistWallet({\n type,\n walletActions,\n getState,\n}: {\n type: WalletType;\n walletActions: WalletActions;\n getState: (walletType: WalletType) => WalletState;\n}) {\n if (walletActions.canEagerConnect) {\n const persistor = new Persistor<string[]>();\n const wallets = persistor.getItem(LAST_CONNECTED_WALLETS);\n\n /*\n *If on the last attempt we are unable to eagerly connect to any wallet and the user connects any wallet manualy,\n *persistance will be outdated and will need to be removed.\n */\n const shouldClearPersistance = wallets?.find(\n (walletType) => !getState(walletType).connected\n );\n\n if (shouldClearPersistance) {\n clearPersistance();\n }\n\n const walletAlreadyPersisted = !!wallets?.find((wallet) => wallet === type);\n if (wallets && !walletAlreadyPersisted) {\n persistor.setItem(LAST_CONNECTED_WALLETS, wallets.concat(type));\n } else {\n persistor.setItem(LAST_CONNECTED_WALLETS, [type]);\n }\n }\n}\n\nexport function tryRemoveWalletFromPersistance({\n type,\n walletActions,\n}: {\n type: WalletType;\n walletActions: WalletActions;\n}) {\n if (walletActions.canEagerConnect) {\n const persistor = new Persistor<string[]>();\n const wallets = persistor.getItem(LAST_CONNECTED_WALLETS);\n if (wallets) {\n persistor.setItem(\n LAST_CONNECTED_WALLETS,\n wallets.filter((wallet) => wallet !== type)\n );\n }\n }\n}\n\nexport function clearPersistance() {\n const persistor = new Persistor<string[]>();\n const wallets = persistor.getItem(LAST_CONNECTED_WALLETS);\n if (wallets) {\n persistor.removeItem(LAST_CONNECTED_WALLETS);\n }\n}\n\n/*\n *If a wallet has multiple providers and one of them can be eagerly connected,\n *then the whole wallet will support it at that point and we try to connect to that wallet as usual in eagerConnect method.\n */\nexport async function autoConnect(\n wallets: WalletProviders,\n getWalletInstance: (wallet: {\n actions: WalletActions;\n config: WalletConfig;\n }) => Wallet<any>\n) {\n const persistor = new Persistor<string[]>();\n const lastConnectedWallets = persistor.getItem(LAST_CONNECTED_WALLETS);\n if (lastConnectedWallets && lastConnectedWallets.length) {\n const connect_promises: {\n walletType: WalletType;\n eagerConnect: () => Promise<any>;\n }[] = [];\n lastConnectedWallets.forEach((walletType) => {\n const wallet = wallets.get(walletType);\n\n if (!!wallet) {\n const walletInstance = getWalletInstance(wallet);\n connect_promises.push({\n walletType,\n eagerConnect: walletInstance.eagerConnect.bind(walletInstance),\n });\n }\n });\n\n const result = await Promise.allSettled(\n connect_promises.map(async ({ eagerConnect }) => eagerConnect())\n );\n\n const canRestoreAnyConnection = !!result.find(\n ({ status }) => status === 'fulfilled'\n );\n\n /*\n *After successfully connecting to at least one wallet,\n *we will removing the other wallets from persistence.\n *If we are unable to connect to any wallet,\n *the persistence will not be removed and the eager connection will be retried with another page load.\n */\n if (canRestoreAnyConnection) {\n const walletsToRemoveFromPersistance: WalletType[] = [];\n result.forEach((settleResult, index) => {\n const { status } = settleResult;\n\n if (status === 'rejected') {\n walletsToRemoveFromPersistance.push(\n connect_promises[index].walletType\n );\n }\n });\n\n if (walletsToRemoveFromPersistance.length) {\n persistor.setItem(\n LAST_CONNECTED_WALLETS,\n lastConnectedWallets.filter(\n (walletType) => !walletsToRemoveFromPersistance.includes(walletType)\n )\n );\n }\n }\n }\n}\n/*\n *Our event handler includes an internal state updater, and a notifier\n *for the outside listener.\n *On creating first wallet refrence, and on chaning `props.onUpdateState`\n *we are using this function.\n */\nexport function makeEventHandler(\n dispatcher: any,\n onUpdateState?: WalletEventHandler\n) {\n const handler: WalletEventHandler = (\n type,\n name,\n value,\n coreState,\n supportedChains\n ) => {\n const action = { type: 'new_state', wallet: type, name, value };\n // Update state\n dispatcher(action);\n\n // Giving the event to the outside listener\n if (onUpdateState) {\n onUpdateState(type, name, value, coreState, supportedChains);\n }\n };\n\n return handler;\n}\n", "export const LAST_CONNECTED_WALLETS = 'last-connected-wallets';\n", "import type { ProviderContext, ProviderProps } from './legacy/types.js';\nimport type { WalletType } from '@rango-dev/wallets-shared';\n\nimport React, { useEffect, useReducer, useRef } from 'react';\n\nimport { WalletContext } from './legacy/context.js';\nimport {\n autoConnect,\n availableWallets,\n checkWalletProviders,\n clearPersistance,\n connectedWallets,\n defaultWalletState,\n makeEventHandler,\n state_reducer,\n tryPersistWallet,\n tryRemoveWalletFromPersistance,\n} from './legacy/helpers.js';\nimport { useInitializers } from './legacy/hooks.js';\n\nfunction Provider(props: ProviderProps) {\n const [providersState, dispatch] = useReducer(state_reducer, {});\n const autoConnectInitiated = useRef(false);\n\n // Get (or add) wallet instance (`provider`s will be wraped in a `Wallet`)\n const getWalletInstance = useInitializers(\n makeEventHandler(dispatch, props.onUpdateState)\n );\n\n // Getting providers from props and put all of them in a `Map` with an appropriate interface.\n const listOfProviders = props.providers;\n const wallets = checkWalletProviders(listOfProviders);\n\n // Final API we put in context and it will be available to use for users.\n // eslint-disable-next-line react/jsx-no-constructed-context-values\n const api: ProviderContext = {\n async connect(type, network, namespaces) {\n const wallet = wallets.get(type);\n if (!wallet) {\n throw new Error(`You should add ${type} to provider first.`);\n }\n const walletInstance = getWalletInstance(wallet);\n const result = await walletInstance.connect(network, namespaces);\n if (props.autoConnect) {\n void tryPersistWallet({\n type,\n walletActions: wallet.actions,\n getState: api.state,\n });\n }\n\n return result;\n },\n async disconnect(type) {\n const wallet = wallets.get(type);\n if (!wallet) {\n throw new Error(`You should add ${type} to provider first.`);\n }\n\n const walletInstance = getWalletInstance(wallet);\n await walletInstance.disconnect();\n if (props.autoConnect) {\n tryRemoveWalletFromPersistance({ type, walletActions: wallet.actions });\n }\n },\n async disconnectAll() {\n const disconnect_promises: Promise<any>[] = [];\n\n /*\n * When a wallet is initializing, a record will be added to `providersState`\n * So we use them to know what wallet has been initialized then we need to\n * filter connected wallets only.\n */\n connectedWallets(providersState).forEach((type) => {\n const wallet = wallets.get(type);\n\n if (wallet) {\n const walletInstance = getWalletInstance(wallet);\n disconnect_promises.push(walletInstance.disconnect());\n }\n });\n\n if (props.autoConnect) {\n clearPersistance();\n }\n return await Promise.allSettled(disconnect_promises);\n },\n\n async suggestAndConnect(type, network) {\n const wallet = wallets.get(type);\n if (!wallet) {\n throw new Error(`You should add ${type} to provider first.`);\n }\n const walletInstance = getWalletInstance(wallet);\n const result = await walletInstance.suggestAndConnect(network);\n\n return result;\n },\n\n state(type) {\n return providersState[type] || defaultWalletState;\n },\n canSwitchNetworkTo(type, network) {\n const wallet = wallets.get(type);\n if (!wallet) {\n return false;\n }\n\n const walletInstance = getWalletInstance(wallet);\n return walletInstance.canSwitchNetworkTo\n ? walletInstance.canSwitchNetworkTo(network, walletInstance.provider)\n : false;\n },\n providers() {\n const providers: { [type in WalletType]?: any } = {};\n availableWallets(providersState).forEach((type) => {\n const wallet = wallets.get(type);\n if (wallet) {\n const walletInstance = getWalletInstance(wallet);\n providers[type] = walletInstance.provider;\n }\n });\n\n return providers;\n },\n getWalletInfo(type) {\n const wallet = wallets.get(type);\n if (!wallet) {\n throw new Error(`You should add ${type} to provider first.`);\n }\n\n /*\n * Get wallet info could be used in render methods to show wallets data\n * So, addWalletRef method shouldn't be called in this method\n */\n\n return wallet.actions.getWalletInfo(props.allBlockChains || []);\n },\n getSigners(type) {\n const wallet = wallets.get(type);\n\n if (!wallet) {\n throw new Error(`You should add ${type} to provider first.`);\n }\n const walletInstance = getWalletInstance(wallet);\n const provider = walletInstance.provider;\n const result = walletInstance.getSigners(provider);\n\n return result;\n },\n };\n\n useEffect(() => {\n wallets.forEach((wallet) => {\n const walletInstance = getWalletInstance(wallet);\n const runOnInit = () => {\n if (walletInstance.onInit) {\n walletInstance.onInit();\n }\n };\n\n const initWhenPageIsReady = (event: Event) => {\n if (\n event.target &&\n (event.target as Document).readyState === 'complete'\n ) {\n runOnInit();\n\n document.removeEventListener('readystatechange', initWhenPageIsReady);\n }\n };\n\n // Try to run, maybe it's ready.\n runOnInit();\n\n /*\n * Try again when the page has been completely loaded.\n * Some of wallets, take some time to be fully injected and loaded.\n */\n document.addEventListener('readystatechange', initWhenPageIsReady);\n });\n }, []);\n\n useEffect(() => {\n const allBlockChains = props.allBlockChains;\n if (allBlockChains) {\n wallets.forEach((wallet) => {\n const walletInstance = getWalletInstance(wallet);\n const walletInfo = walletInstance.getWalletInfo(\n props.allBlockChains || []\n );\n walletInstance.setInfo({\n supportedBlockchains: walletInfo.supportedChains,\n isContractWallet: !!walletInfo.isContractWallet,\n });\n });\n }\n }, [props.allBlockChains]);\n\n useEffect(() => {\n wallets.forEach((wallet) => {\n const walletInstance = getWalletInstance(wallet);\n walletInstance.setHandler(\n makeEventHandler(dispatch, props.onUpdateState)\n );\n });\n }, [props.onUpdateState]);\n\n useEffect(() => {\n const shouldTryAutoConnect =\n props.allBlockChains &&\n props.allBlockChains.length &&\n props.autoConnect &&\n !autoConnectInitiated.current;\n\n if (shouldTryAutoConnect) {\n autoConnectInitiated.current = true;\n void (async () => {\n await autoConnect(wallets, getWalletInstance);\n })();\n }\n }, [props.autoConnect, props.allBlockChains]);\n\n return (\n <WalletContext.Provider value={api}>\n {props.children}\n </WalletContext.Provider>\n );\n}\n\nexport default Provider;\n", "import type { ProviderContext } from './types.js';\n\nimport { createContext } from 'react';\n\nconst defaultErrorMesssage = \"Context hasn't been initialized yet.\";\nconst defaultContext: ProviderContext = {\n async connect() {\n throw new Error(defaultErrorMesssage);\n },\n async disconnect() {\n throw new Error(defaultErrorMesssage);\n },\n async disconnectAll() {\n throw new Error(defaultErrorMesssage);\n },\n async suggestAndConnect() {\n throw new Error(defaultErrorMesssage);\n },\n state() {\n throw new Error(defaultErrorMesssage);\n },\n canSwitchNetworkTo() {\n throw new Error(defaultErrorMesssage);\n },\n providers() {\n throw new Error(defaultErrorMesssage);\n },\n getWalletInfo() {\n throw new Error(defaultErrorMesssage);\n },\n getSigners() {\n throw new Error(defaultErrorMesssage);\n },\n};\n\nexport const WalletContext = createContext<ProviderContext>(defaultContext);\n", "import type { ProviderContext, WalletActions, WalletConfig } from './types.js';\nimport type { EventHandler as WalletEventHandler } from '@rango-dev/wallets-core';\n\nimport Wallet from '@rango-dev/wallets-core';\nimport { useContext, useRef } from 'react';\n\nimport { WalletContext } from './context.js';\n\n/**\n *\n *\n */\nexport function useInitializers(onChangeState: WalletEventHandler) {\n const availableWallets = useRef<{\n [key: string]: Wallet | undefined;\n }>({});\n\n /*\n * If `wallet` hasn't been added to `availableWallets`,\n * Get a instance of `Wallet` and save the refrence in `availableWallets`.\n * Otherwise, return the already created instance.\n */\n function updater(wallet: {\n actions: WalletActions;\n config: WalletConfig;\n }): Wallet {\n const type = wallet.config.type;\n // We only update, if there is no instance available.\n if (typeof availableWallets.current[type] === 'undefined') {\n availableWallets.current[type] = new Wallet(\n {\n config: wallet.config,\n handler: onChangeState,\n },\n wallet.actions\n );\n }\n\n return availableWallets.current[type]!;\n }\n\n return updater;\n}\n\nexport function useWallets(): ProviderContext {\n const context = useContext(WalletContext);\n if (!context) {\n throw Error('useWallet can only be used within the Provider component');\n }\n return context;\n}\n", "export * from './legacy/helpers.js';\nexport { default as Provider } from './provider.js';\nexport { useWallets } from './legacy/hooks.js';\nexport * from './legacy/types.js';\n\nexport type { EventHandler } from '@rango-dev/wallets-core';\nexport { Events, readAccountAddress } from '@rango-dev/wallets-core';\n"],
5
- "mappings": "+EAcA,OAAS,aAAAA,MAAiB,0BCdnB,IAAMC,EAAyB,yBDkB/B,SAASC,EAAOC,EAAgBC,EAA8B,CACnE,OAAOD,EAAQ,KAAME,GAAWA,EAAO,OAASD,CAAI,GAAK,IAC3D,CAFgBE,EAAAJ,EAAA,UAIT,IAAMK,EAAkC,CAC7C,UAAW,GACX,WAAY,GACZ,UAAW,GACX,UAAW,GACX,SAAU,KACV,QAAS,IACX,EAEO,SAASC,EAAcC,EAAcC,EAAa,CACvD,GAAIA,EAAO,OAAS,YAAa,CAI/B,IAAMC,EAAgBF,EAAMC,EAAO,MAAM,EACzC,OAAKC,EAUE,CACL,GAAGF,EACH,CAACC,EAAO,MAAM,EAAG,CACf,GAAGC,EACH,CAACD,EAAO,IAAI,EAAGA,EAAO,KACxB,CACF,EAfS,CACL,GAAGD,EACH,CAACC,EAAO,MAAM,EAAG,CACf,GAAGH,EACH,CAACG,EAAO,IAAI,EAAGA,EAAO,KACxB,CACF,CAUJ,CAEA,OAAOD,CACT,CA1BgBH,EAAAE,EAAA,iBA4BT,SAASI,EAAiBC,EAAqC,CACpE,OAAO,OAAO,QAAQA,CAAc,EACjC,OAAO,CAAC,CAAC,CAAEC,CAAY,IACfA,GAAc,SACtB,EACA,IAAI,CAAC,CAAC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
6
- "names": ["Persistor", "LAST_CONNECTED_WALLETS", "choose", "wallets", "type", "wallet", "__name", "defaultWalletState", "state_reducer", "state", "action", "target_wallet", "connectedWallets", "providersState", "wallet_state", "availableWallets", "checkWalletProviders", "list", "provider", "config", "actions", "isAsync", "fn", "needsCheckInstallation", "options", "checkInstallation", "tryPersistWallet", "walletActions", "getState", "persistor", "Persistor", "LAST_CONNECTED_WALLETS", "walletType", "clearPersistance", "walletAlreadyPersisted", "tryRemoveWalletFromPersistance", "autoConnect", "getWalletInstance", "lastConnectedWallets", "connect_promises", "walletInstance", "result", "eagerConnect", "status", "walletsToRemoveFromPersistance", "settleResult", "index", "makeEventHandler", "dispatcher", "onUpdateState", "name", "value", "coreState", "supportedChains", "React", "useEffect", "useReducer", "useRef", "createContext", "defaultErrorMesssage", "defaultContext", "WalletContext", "Wallet", "useContext", "useRef", "useInitializers", "onChangeState", "availableWallets", "useRef", "updater", "wallet", "type", "Wallet", "__name", "useWallets", "context", "useContext", "WalletContext", "Provider", "props", "providersState", "dispatch", "useReducer", "state_reducer", "autoConnectInitiated", "useRef", "getWalletInstance", "useInitializers", "makeEventHandler", "listOfProviders", "wallets", "checkWalletProviders", "api", "type", "network", "namespaces", "wallet", "result", "tryPersistWallet", "tryRemoveWalletFromPersistance", "disconnect_promises", "connectedWallets", "walletInstance", "clearPersistance", "defaultWalletState", "providers", "availableWallets", "provider", "useEffect", "runOnInit", "__name", "initWhenPageIsReady", "event", "walletInfo", "autoConnect", "React", "WalletContext", "provider_default", "Events", "readAccountAddress"]
3
+ "sources": ["../src/legacy/helpers.ts", "../src/legacy/constants.ts", "../src/provider.tsx", "../src/legacy/context.ts", "../src/legacy/useLegacyProviders.ts", "../src/legacy/hooks.ts", "../src/legacy/useAutoConnect.ts", "../src/index.ts"],
4
+ "sourcesContent": ["import type {\n ProviderInterface,\n State,\n WalletActions,\n WalletProviders,\n} from './types.js';\nimport type Wallet from '@rango-dev/wallets-core';\nimport type {\n Options,\n EventHandler as WalletEventHandler,\n State as WalletState,\n} from '@rango-dev/wallets-core';\nimport type { WalletConfig, WalletType } from '@rango-dev/wallets-shared';\n\nimport { Persistor } from '@rango-dev/wallets-core';\n\nimport { LAST_CONNECTED_WALLETS } from './constants.js';\n\nexport function choose(wallets: any[], type: WalletType): any | null {\n return wallets.find((wallet) => wallet.type === type) || null;\n}\n\nexport const defaultWalletState: WalletState = {\n connected: false,\n connecting: false,\n reachable: false,\n installed: false,\n accounts: null,\n network: null,\n};\n\nexport function stateReducer(state: State, action: any) {\n if (action.type === 'new_state') {\n // TODO fix problem and remove ts-ignore\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const target_wallet = state[action.wallet];\n if (!target_wallet) {\n return {\n ...state,\n [action.wallet]: {\n ...defaultWalletState,\n [action.name]: action.value,\n },\n };\n }\n\n return {\n ...state,\n [action.wallet]: {\n ...target_wallet,\n [action.name]: action.value,\n },\n };\n }\n\n return state;\n}\n\nexport function connectedWallets(providersState: State): WalletType[] {\n return Object.entries(providersState)\n .filter(([, wallet_state]) => {\n return wallet_state?.connected;\n })\n .map(([type]) => {\n return type;\n });\n}\n\nexport function availableWallets(providersState: State): WalletType[] {\n return Object.entries(providersState).map(([type]) => {\n return type;\n });\n}\n\nexport function checkWalletProviders(\n list: ProviderInterface[]\n): WalletProviders {\n const wallets: WalletProviders = new Map();\n\n list.forEach((provider) => {\n const { config, ...actions } = provider;\n wallets.set(config.type, {\n actions,\n config,\n });\n });\n\n return wallets;\n}\n\n/* eslint-disable @typescript-eslint/ban-types */\nexport function isAsync(fn: Function) {\n return fn?.constructor?.name === 'AsyncFunction';\n}\n\nexport function needsCheckInstallation(options: Options) {\n const { checkInstallation = true } = options.config;\n return checkInstallation;\n}\n\nexport async function tryPersistWallet({\n type,\n walletActions,\n getState,\n}: {\n type: WalletType;\n walletActions: WalletActions;\n getState: (walletType: WalletType) => WalletState;\n}) {\n if (walletActions.canEagerConnect) {\n const persistor = new Persistor<string[]>();\n const wallets = persistor.getItem(LAST_CONNECTED_WALLETS);\n\n /*\n *If on the last attempt we are unable to eagerly connect to any wallet and the user connects any wallet manualy,\n *persistance will be outdated and will need to be removed.\n */\n const shouldClearPersistance = wallets?.find(\n (walletType) => !getState(walletType).connected\n );\n\n if (shouldClearPersistance) {\n clearPersistance();\n }\n\n const walletAlreadyPersisted = !!wallets?.find((wallet) => wallet === type);\n if (wallets && !walletAlreadyPersisted) {\n persistor.setItem(LAST_CONNECTED_WALLETS, wallets.concat(type));\n } else {\n persistor.setItem(LAST_CONNECTED_WALLETS, [type]);\n }\n }\n}\n\nexport function tryRemoveWalletFromPersistance({\n type,\n walletActions,\n}: {\n type: WalletType;\n walletActions: WalletActions;\n}) {\n if (walletActions.canEagerConnect) {\n const persistor = new Persistor<string[]>();\n const wallets = persistor.getItem(LAST_CONNECTED_WALLETS);\n if (wallets) {\n persistor.setItem(\n LAST_CONNECTED_WALLETS,\n wallets.filter((wallet) => wallet !== type)\n );\n }\n }\n}\n\nexport function clearPersistance() {\n const persistor = new Persistor<string[]>();\n const wallets = persistor.getItem(LAST_CONNECTED_WALLETS);\n if (wallets) {\n persistor.removeItem(LAST_CONNECTED_WALLETS);\n }\n}\n\n/*\n *If a wallet has multiple providers and one of them can be eagerly connected,\n *then the whole wallet will support it at that point and we try to connect to that wallet as usual in eagerConnect method.\n */\nexport async function autoConnect(\n wallets: WalletProviders,\n getWalletInstance: (wallet: {\n actions: WalletActions;\n config: WalletConfig;\n }) => Wallet<any>\n) {\n const persistor = new Persistor<string[]>();\n const lastConnectedWallets = persistor.getItem(LAST_CONNECTED_WALLETS);\n if (lastConnectedWallets && lastConnectedWallets.length) {\n const connect_promises: {\n walletType: WalletType;\n eagerConnect: () => Promise<any>;\n }[] = [];\n lastConnectedWallets.forEach((walletType) => {\n const wallet = wallets.get(walletType);\n\n if (!!wallet) {\n const walletInstance = getWalletInstance(wallet);\n connect_promises.push({\n walletType,\n eagerConnect: walletInstance.eagerConnect.bind(walletInstance),\n });\n }\n });\n\n const result = await Promise.allSettled(\n connect_promises.map(async ({ eagerConnect }) => eagerConnect())\n );\n\n const canRestoreAnyConnection = !!result.find(\n ({ status }) => status === 'fulfilled'\n );\n\n /*\n *After successfully connecting to at least one wallet,\n *we will removing the other wallets from persistence.\n *If we are unable to connect to any wallet,\n *the persistence will not be removed and the eager connection will be retried with another page load.\n */\n if (canRestoreAnyConnection) {\n const walletsToRemoveFromPersistance: WalletType[] = [];\n result.forEach((settleResult, index) => {\n const { status } = settleResult;\n\n if (status === 'rejected') {\n walletsToRemoveFromPersistance.push(\n connect_promises[index].walletType\n );\n }\n });\n\n if (walletsToRemoveFromPersistance.length) {\n persistor.setItem(\n LAST_CONNECTED_WALLETS,\n lastConnectedWallets.filter(\n (walletType) => !walletsToRemoveFromPersistance.includes(walletType)\n )\n );\n }\n }\n }\n}\n/*\n *Our event handler includes an internal state updater, and a notifier\n *for the outside listener.\n *On creating first wallet refrence, and on chaning `props.onUpdateState`\n *we are using this function.\n */\nexport function makeEventHandler(\n dispatcher: any,\n onUpdateState?: WalletEventHandler\n) {\n const handler: WalletEventHandler = (\n type,\n name,\n value,\n coreState,\n supportedChains\n ) => {\n const action = { type: 'new_state', wallet: type, name, value };\n // Update state\n dispatcher(action);\n\n // Giving the event to the outside listener\n if (onUpdateState) {\n onUpdateState(type, name, value, coreState, supportedChains);\n }\n };\n\n return handler;\n}\n", "export const LAST_CONNECTED_WALLETS = 'last-connected-wallets';\n", "import type { ProviderProps } from './legacy/types.js';\n\nimport React from 'react';\n\nimport { WalletContext } from './legacy/context.js';\nimport { useLegacyProviders } from './legacy/useLegacyProviders.js';\n\nfunction Provider(props: ProviderProps) {\n const legacyApi = useLegacyProviders(props);\n\n return (\n <WalletContext.Provider value={legacyApi}>\n {props.children}\n </WalletContext.Provider>\n );\n}\n\nexport default Provider;\n", "import type { ProviderContext } from './types.js';\n\nimport { createContext } from 'react';\n\nconst defaultErrorMesssage = \"Context hasn't been initialized yet.\";\nconst defaultContext: ProviderContext = {\n async connect() {\n throw new Error(defaultErrorMesssage);\n },\n async disconnect() {\n throw new Error(defaultErrorMesssage);\n },\n async disconnectAll() {\n throw new Error(defaultErrorMesssage);\n },\n async suggestAndConnect() {\n throw new Error(defaultErrorMesssage);\n },\n state() {\n throw new Error(defaultErrorMesssage);\n },\n canSwitchNetworkTo() {\n throw new Error(defaultErrorMesssage);\n },\n providers() {\n throw new Error(defaultErrorMesssage);\n },\n getWalletInfo() {\n throw new Error(defaultErrorMesssage);\n },\n getSigners() {\n throw new Error(defaultErrorMesssage);\n },\n};\n\nexport const WalletContext = createContext<ProviderContext>(defaultContext);\n", "import type { ProviderContext, ProviderProps } from './types.js';\nimport type { WalletType } from '@rango-dev/wallets-shared';\n\nimport { useEffect, useReducer } from 'react';\n\nimport {\n availableWallets,\n checkWalletProviders,\n clearPersistance,\n connectedWallets,\n defaultWalletState,\n makeEventHandler,\n stateReducer,\n tryPersistWallet,\n tryRemoveWalletFromPersistance,\n} from './helpers.js';\nimport { useInitializers } from './hooks.js';\nimport { useAutoConnect } from './useAutoConnect.js';\n\nexport function useLegacyProviders(props: ProviderProps): ProviderContext {\n const [providersState, dispatch] = useReducer(stateReducer, {});\n\n // Get (or add) wallet instance (`provider`s will be wrapped in a `Wallet`)\n const getWalletInstance = useInitializers(\n makeEventHandler(dispatch, props.onUpdateState)\n );\n\n // Getting providers from props and put all of them in a `Map` with an appropriate interface.\n const listOfProviders = props.providers;\n const wallets = checkWalletProviders(listOfProviders);\n\n useAutoConnect({\n wallets,\n allBlockChains: props.allBlockChains,\n autoConnect: props.autoConnect,\n getWalletInstanceFromLegacy: getWalletInstance,\n });\n\n // Final API we put in context and it will be available to use for users.\n // eslint-disable-next-line react/jsx-no-constructed-context-values\n const api: ProviderContext = {\n async connect(type, network, namespaces) {\n const wallet = wallets.get(type);\n if (!wallet) {\n throw new Error(`You should add ${type} to provider first.`);\n }\n const walletInstance = getWalletInstance(wallet);\n const result = await walletInstance.connect(network, namespaces);\n if (props.autoConnect) {\n void tryPersistWallet({\n type,\n walletActions: wallet.actions,\n getState: api.state,\n });\n }\n\n return result;\n },\n async disconnect(type) {\n const wallet = wallets.get(type);\n if (!wallet) {\n throw new Error(`You should add ${type} to provider first.`);\n }\n\n const walletInstance = getWalletInstance(wallet);\n await walletInstance.disconnect();\n if (props.autoConnect) {\n tryRemoveWalletFromPersistance({ type, walletActions: wallet.actions });\n }\n },\n async disconnectAll() {\n const disconnect_promises: Promise<any>[] = [];\n\n /*\n * When a wallet is initializing, a record will be added to `providersState`\n * So we use them to know what wallet has been initialized then we need to\n * filter connected wallets only.\n */\n connectedWallets(providersState).forEach((type) => {\n const wallet = wallets.get(type);\n\n if (wallet) {\n const walletInstance = getWalletInstance(wallet);\n disconnect_promises.push(walletInstance.disconnect());\n }\n });\n\n if (props.autoConnect) {\n clearPersistance();\n }\n return await Promise.allSettled(disconnect_promises);\n },\n\n async suggestAndConnect(type, network) {\n const wallet = wallets.get(type);\n if (!wallet) {\n throw new Error(`You should add ${type} to provider first.`);\n }\n const walletInstance = getWalletInstance(wallet);\n const result = await walletInstance.suggestAndConnect(network);\n\n return result;\n },\n\n state(type) {\n return providersState[type] || defaultWalletState;\n },\n canSwitchNetworkTo(type, network) {\n const wallet = wallets.get(type);\n if (!wallet) {\n return false;\n }\n\n const walletInstance = getWalletInstance(wallet);\n return walletInstance.canSwitchNetworkTo\n ? walletInstance.canSwitchNetworkTo(network, walletInstance.provider)\n : false;\n },\n providers() {\n const providers: { [type in WalletType]?: any } = {};\n availableWallets(providersState).forEach((type) => {\n const wallet = wallets.get(type);\n if (wallet) {\n const walletInstance = getWalletInstance(wallet);\n providers[type] = walletInstance.provider;\n }\n });\n\n return providers;\n },\n getWalletInfo(type) {\n const wallet = wallets.get(type);\n if (!wallet) {\n throw new Error(`You should add ${type} to provider first.`);\n }\n\n /*\n * Get wallet info could be used in render methods to show wallets data\n * So, addWalletRef method shouldn't be called in this method\n */\n\n return wallet.actions.getWalletInfo(props.allBlockChains || []);\n },\n getSigners(type) {\n const wallet = wallets.get(type);\n\n if (!wallet) {\n throw new Error(`You should add ${type} to provider first.`);\n }\n const walletInstance = getWalletInstance(wallet);\n const provider = walletInstance.provider;\n const result = walletInstance.getSigners(provider);\n\n return result;\n },\n };\n\n // Initialize instances\n useEffect(() => {\n wallets.forEach((wallet) => {\n const walletInstance = getWalletInstance(wallet);\n const runOnInit = () => {\n if (walletInstance.onInit) {\n walletInstance.onInit();\n }\n };\n\n const initWhenPageIsReady = (event: Event) => {\n if (\n event.target &&\n (event.target as Document).readyState === 'complete'\n ) {\n runOnInit();\n\n document.removeEventListener('readystatechange', initWhenPageIsReady);\n }\n };\n\n // Try to run, maybe it's ready.\n runOnInit();\n\n /*\n * Try again when the page has been completely loaded.\n * Some of wallets, take some time to be fully injected and loaded.\n */\n document.addEventListener('readystatechange', initWhenPageIsReady);\n });\n }, []);\n\n // Setting supported blockchains on instances\n useEffect(() => {\n const allBlockChains = props.allBlockChains;\n if (allBlockChains) {\n wallets.forEach((wallet) => {\n const walletInstance = getWalletInstance(wallet);\n const walletInfo = walletInstance.getWalletInfo(\n props.allBlockChains || []\n );\n walletInstance.setInfo({\n supportedBlockchains: walletInfo.supportedChains,\n isContractWallet: !!walletInfo.isContractWallet,\n });\n });\n }\n }, [props.allBlockChains]);\n\n // Setting event handler on instances\n useEffect(() => {\n wallets.forEach((wallet) => {\n const walletInstance = getWalletInstance(wallet);\n walletInstance.setHandler(\n makeEventHandler(dispatch, props.onUpdateState)\n );\n });\n }, [props.onUpdateState]);\n\n return api;\n}\n", "import type { ProviderContext, WalletActions, WalletConfig } from './types.js';\nimport type { EventHandler as WalletEventHandler } from '@rango-dev/wallets-core';\n\nimport Wallet from '@rango-dev/wallets-core';\nimport { useContext, useRef } from 'react';\n\nimport { WalletContext } from './context.js';\n\nexport type GetWalletInstance = (wallet: {\n actions: WalletActions;\n config: WalletConfig;\n}) => Wallet;\n\nexport function useInitializers(\n onChangeState: WalletEventHandler\n): GetWalletInstance {\n const availableWallets = useRef<{\n [key: string]: Wallet | undefined;\n }>({});\n\n /*\n * If `wallet` hasn't been added to `availableWallets`,\n * Get a instance of `Wallet` and save the refrence in `availableWallets`.\n * Otherwise, return the already created instance.\n */\n function updater(wallet: {\n actions: WalletActions;\n config: WalletConfig;\n }): Wallet {\n const type = wallet.config.type;\n // We only update, if there is no instance available.\n if (typeof availableWallets.current[type] === 'undefined') {\n availableWallets.current[type] = new Wallet(\n {\n config: wallet.config,\n handler: onChangeState,\n },\n wallet.actions\n );\n }\n\n return availableWallets.current[type]!;\n }\n\n return updater;\n}\n\nexport function useWallets(): ProviderContext {\n const context = useContext(WalletContext);\n if (!context) {\n throw Error('useWallet can only be used within the Provider component');\n }\n return context;\n}\n", "import type { GetWalletInstance } from './hooks.js';\nimport type { ProviderProps, WalletProviders } from './types.js';\n\nimport { useEffect, useRef } from 'react';\n\nimport { autoConnect } from './helpers.js';\n\nexport function useAutoConnect(\n props: Pick<ProviderProps, 'allBlockChains' | 'autoConnect'> & {\n wallets: WalletProviders;\n getWalletInstanceFromLegacy: GetWalletInstance;\n }\n) {\n const autoConnectInitiated = useRef(false);\n\n // Running auto connect on instances\n useEffect(() => {\n const shouldTryAutoConnect =\n props.allBlockChains &&\n props.allBlockChains.length &&\n props.autoConnect &&\n !autoConnectInitiated.current;\n\n if (shouldTryAutoConnect) {\n autoConnectInitiated.current = true;\n void (async () => {\n await autoConnect(props.wallets, props.getWalletInstanceFromLegacy);\n })();\n }\n }, [props.autoConnect, props.allBlockChains]);\n}\n", "export * from './legacy/helpers.js';\nexport { default as Provider } from './provider.js';\nexport { useWallets } from './legacy/hooks.js';\nexport * from './legacy/types.js';\n\nexport type { EventHandler } from '@rango-dev/wallets-core';\nexport { Events, readAccountAddress } from '@rango-dev/wallets-core';\n"],
5
+ "mappings": "+EAcA,OAAS,aAAAA,MAAiB,0BCdnB,IAAMC,EAAyB,yBDkB/B,SAASC,EAAOC,EAAgBC,EAA8B,CACnE,OAAOD,EAAQ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QACjBA,EAAe,OAAO,CAE1B,EAJkB,aAMZS,EAAsBD,EAACE,GAAiB,CAE1CA,EAAM,QACLA,EAAM,OAAoB,aAAe,aAE1CH,EAAU,EAEV,SAAS,oBAAoB,mBAAoBE,CAAmB,EAExE,EAT4B,uBAY5BF,EAAU,EAMV,SAAS,iBAAiB,mBAAoBE,CAAmB,CACnE,CAAC,CACH,EAAG,CAAC,CAAC,EAGLH,EAAU,IAAM,CACS5B,EAAM,gBAE3BS,EAAQ,QAASO,GAAW,CAC1B,IAAMM,EAAiBjB,EAAkBW,CAAM,EACzCiB,EAAaX,EAAe,cAChCtB,EAAM,gBAAkB,CAAC,CAC3B,EACAsB,EAAe,QAAQ,CACrB,qBAAsBW,EAAW,gBACjC,iBAAkB,CAAC,CAACA,EAAW,gBACjC,CAAC,CACH,CAAC,CAEL,EAAG,CAACjC,EAAM,cAAc,CAAC,EAGzB4B,EAAU,IAAM,CACdnB,EAAQ,QAASO,GAAW,CACHX,EAAkBW,CAAM,EAChC,WACbT,EAAiBL,EAAUF,EAAM,aAAa,CAChD,CACF,CAAC,CACH,EAAG,CAACA,EAAM,aAAa,CAAC,EAEjBY,CACT,CAtMgBkB,EAAA/B,EAAA,sBFZhB,SAASmC,EAASC,EAAsB,CACtC,IAAMC,EAAYC,EAAmBF,CAAK,EAE1C,OACEG,EAAA,cAACC,EAAc,SAAd,CAAuB,MAAOH,GAC5BD,EAAM,QACT,CAEJ,CARSK,EAAAN,EAAA,YAUT,IAAOO,EAAQP,EKXf,OAAS,UAAAQ,GAAQ,sBAAAC,OAA0B",
6
+ "names": ["Persistor", "LAST_CONNECTED_WALLETS", "choose", "wallets", "type", "wallet", "__name", "defaultWalletState", "stateReducer", "state", "action", "target_wallet", "connectedWallets", "providersState", "wallet_state", "availableWallets", "checkWalletProviders", "list", "provider", "config", "actions", "isAsync", "fn", "needsCheckInstallation", "options", "checkInstallation", "tryPersistWallet", "walletActions", "getState", "persistor", "Persistor", "LAST_CONNECTED_WALLETS", "walletType", "clearPersistance", "walletAlreadyPersisted", "tryRemoveWalletFromPersistance", "autoConnect", "getWalletInstance", "lastConnectedWallets", "connect_promises", "walletInstance", "result", "eagerConnect", "status", "walletsToRemoveFromPersistance", "settleResult", "index", "makeEventHandler", "dispatcher", "onUpdateState", "name", "value", "coreState", "supportedChains", "React", "createContext", "defaultErrorMesssage", "defaultContext", "WalletContext", "useEffect", "useReducer", "Wallet", "useContext", "useRef", "useInitializers", "onChangeState", "availableWallets", "useRef", "updater", "wallet", "type", "Wallet", "__name", "useWallets", "context", "useContext", "WalletContext", "useEffect", "useRef", "useAutoConnect", "props", "autoConnectInitiated", "useRef", "useEffect", "autoConnect", "__name", "useLegacyProviders", "props", "providersState", "dispatch", "useReducer", "stateReducer", "getWalletInstance", "useInitializers", "makeEventHandler", "listOfProviders", "wallets", "checkWalletProviders", "useAutoConnect", "api", "type", "network", "namespaces", "wallet", "result", "tryPersistWallet", "tryRemoveWalletFromPersistance", "disconnect_promises", "connectedWallets", "walletInstance", "clearPersistance", "defaultWalletState", "providers", "availableWallets", "provider", "useEffect", "runOnInit", "__name", "initWhenPageIsReady", "event", "walletInfo", "Provider", "props", "legacyApi", "useLegacyProviders", "React", "WalletContext", "__name", "provider_default", "Events", "readAccountAddress"]
7
7
  }
@@ -4,7 +4,7 @@ import type { Options, EventHandler as WalletEventHandler, State as WalletState
4
4
  import type { WalletConfig, WalletType } from '@rango-dev/wallets-shared';
5
5
  export declare function choose(wallets: any[], type: WalletType): any | null;
6
6
  export declare const defaultWalletState: WalletState;
7
- export declare function state_reducer(state: State, action: any): State;
7
+ export declare function stateReducer(state: State, action: any): State;
8
8
  export declare function connectedWallets(providersState: State): WalletType[];
9
9
  export declare function availableWallets(providersState: State): WalletType[];
10
10
  export declare function checkWalletProviders(list: ProviderInterface[]): WalletProviders;
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/legacy/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAA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,IAAI,EACJ,aAAa,EACb,QAAQ,GACT,EAAE;IACD,IAAI,EAAE,UAAU,CAAC;IACjB,aAAa,EAAE,aAAa,CAAC;IAC7B,QAAQ,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,WAAW,CAAC;CACnD,iBAwBA;AAED,wBAAgB,8BAA8B,CAAC,EAC7C,IAAI,EACJ,aAAa,GACd,EAAE;IACD,IAAI,EAAE,UAAU,CAAC;IACjB,aAAa,EAAE,aAAa,CAAC;CAC9B,QAWA;AAED,wBAAgB,gBAAgB,SAM/B;AAMD,wBAAsB,WAAW,CAC/B,OAAO,EAAE,eAAe,EACxB,iBAAiB,EAAE,CAAC,MAAM,EAAE;IAC1B,OAAO,EAAE,aAAa,CAAC;IACvB,MAAM,EAAE,YAAY,CAAC;CACtB,KAAK,MAAM,CAAC,GAAG,CAAC,iBAyDlB;AAOD,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,GAAG,EACf,aAAa,CAAC,EAAE,kBAAkB,sBAoBnC"}
@@ -1,13 +1,10 @@
1
1
  import type { ProviderContext, WalletActions, WalletConfig } from './types.js';
2
2
  import type { EventHandler as WalletEventHandler } from '@rango-dev/wallets-core';
3
3
  import Wallet from '@rango-dev/wallets-core';
4
- /**
5
- *
6
- *
7
- */
8
- export declare function useInitializers(onChangeState: WalletEventHandler): (wallet: {
4
+ export type GetWalletInstance = (wallet: {
9
5
  actions: WalletActions;
10
6
  config: WalletConfig;
11
7
  }) => Wallet;
8
+ export declare function useInitializers(onChangeState: WalletEventHandler): GetWalletInstance;
12
9
  export declare function useWallets(): ProviderContext;
13
10
  //# sourceMappingURL=hooks.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/legacy/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/E,OAAO,KAAK,EAAE,YAAY,IAAI,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElF,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAK7C;;;GAGG;AACH,wBAAgB,eAAe,CAAC,aAAa,EAAE,kBAAkB,YAUtC;IACvB,OAAO,EAAE,aAAa,CAAC;IACvB,MAAM,EAAE,YAAY,CAAC;CACtB,KAAG,MAAM,CAiBX;AAED,wBAAgB,UAAU,IAAI,eAAe,CAM5C"}
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/legacy/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/E,OAAO,KAAK,EAAE,YAAY,IAAI,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElF,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAK7C,MAAM,MAAM,iBAAiB,GAAG,CAAC,MAAM,EAAE;IACvC,OAAO,EAAE,aAAa,CAAC;IACvB,MAAM,EAAE,YAAY,CAAC;CACtB,KAAK,MAAM,CAAC;AAEb,wBAAgB,eAAe,CAC7B,aAAa,EAAE,kBAAkB,GAChC,iBAAiB,CA8BnB;AAED,wBAAgB,UAAU,IAAI,eAAe,CAM5C"}
@@ -19,6 +19,13 @@ export type ProviderContext = {
19
19
  disconnectAll(): Promise<PromiseSettledResult<any>[]>;
20
20
  state(type: WalletType): WalletState;
21
21
  canSwitchNetworkTo(type: WalletType, network: Network): boolean;
22
+ /**
23
+ * `Provider` in legacy terms means injected instances by wallets into window (e.g. window.ethereum)
24
+ * that can be retrieved by `getInstance`.
25
+ *
26
+ * Note 1: Providers are lazy evaluated, which means you need to call `connect` (or `state`) first, then the value will be shown in object.
27
+ * before doing that, it's a key (wallet name or we call it `type` to be more specific) with null value. (e.g. {metamask: null})
28
+ */
22
29
  providers(): Providers;
23
30
  getSigners(type: WalletType): SignerFactory;
24
31
  getWalletInfo(type: WalletType): WalletInfo;
@@ -1 +1 @@
1
- {"version":3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cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED,MAAM,MAAM,eAAe,GAAG,GAAG,CAC/B,UAAU,EACV;IACE,OAAO,EAAE,aAAa,CAAC;IACvB,MAAM,EAAE,YAAY,CAAC;CACtB,CACF,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAAE,MAAM,EAAE,YAAY,CAAA;CAAE,GAAG,aAAa,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { GetWalletInstance } from './hooks.js';
2
+ import type { ProviderProps, WalletProviders } from './types.js';
3
+ export declare function useAutoConnect(props: Pick<ProviderProps, 'allBlockChains' | 'autoConnect'> & {
4
+ wallets: WalletProviders;
5
+ getWalletInstanceFromLegacy: GetWalletInstance;
6
+ }): void;
7
+ //# sourceMappingURL=useAutoConnect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAutoConnect.d.ts","sourceRoot":"","sources":["../../src/legacy/useAutoConnect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAMjE,wBAAgB,cAAc,CAC5B,KAAK,EAAE,IAAI,CAAC,aAAa,EAAE,gBAAgB,GAAG,aAAa,CAAC,GAAG;IAC7D,OAAO,EAAE,eAAe,CAAC;IACzB,2BAA2B,EAAE,iBAAiB,CAAC;CAChD,QAmBF"}
@@ -0,0 +1,3 @@
1
+ import type { ProviderContext, ProviderProps } from './types.js';
2
+ export declare function useLegacyProviders(props: ProviderProps): ProviderContext;
3
+ //# sourceMappingURL=useLegacyProviders.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLegacyProviders.d.ts","sourceRoot":"","sources":["../../src/legacy/useLegacyProviders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAmBjE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,aAAa,GAAG,eAAe,CAsMxE"}
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGxE,OAAO,KAAwC,MAAM,OAAO,CAAC;AAiB7D,iBAAS,QAAQ,CAAC,KAAK,EAAE,aAAa,qBAgNrC;AAED,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,iBAAS,QAAQ,CAAC,KAAK,EAAE,aAAa,qBAQrC;AAED,eAAe,QAAQ,CAAC"}
@@ -1 +1 @@
1
- {"inputs":{"src/legacy/constants.ts":{"bytes":64,"imports":[],"format":"esm"},"src/legacy/helpers.ts":{"bytes":6906,"imports":[{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"src/legacy/constants.ts","kind":"import-statement","original":"./constants.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/legacy/context.ts":{"bytes":905,"imports":[{"path":"react","kind":"import-statement","external":true}],"format":"esm"},"src/legacy/hooks.ts":{"bytes":1388,"imports":[{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"src/legacy/context.ts","kind":"import-statement","original":"./context.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/provider.tsx":{"bytes":6913,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"src/legacy/context.ts","kind":"import-statement","original":"./legacy/context.js"},{"path":"src/legacy/helpers.ts","kind":"import-statement","original":"./legacy/helpers.js"},{"path":"src/legacy/hooks.ts","kind":"import-statement","original":"./legacy/hooks.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/legacy/types.ts":{"bytes":4338,"imports":[],"format":"esm"},"src/index.ts":{"bytes":305,"imports":[{"path":"src/legacy/helpers.ts","kind":"import-statement","original":"./legacy/helpers.js"},{"path":"src/provider.tsx","kind":"import-statement","original":"./provider.js"},{"path":"src/legacy/hooks.ts","kind":"import-statement","original":"./legacy/hooks.js"},{"path":"src/legacy/types.ts","kind":"import-statement","original":"./legacy/types.js"},{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"dist/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":26244},"dist/index.js":{"imports":[{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true}],"exports":["Events","Provider","autoConnect","availableWallets","checkWalletProviders","choose","clearPersistance","connectedWallets","defaultWalletState","isAsync","makeEventHandler","needsCheckInstallation","readAccountAddress","state_reducer","tryPersistWallet","tryRemoveWalletFromPersistance","useWallets"],"entryPoint":"src/index.ts","inputs":{"src/legacy/helpers.ts":{"bytesInOutput":1934},"src/legacy/constants.ts":{"bytesInOutput":31},"src/index.ts":{"bytesInOutput":75},"src/provider.tsx":{"bytesInOutput":2179},"src/legacy/context.ts":{"bytesInOutput":427},"src/legacy/hooks.ts":{"bytesInOutput":427}},"bytes":5548}}}
1
+ {"inputs":{"src/legacy/constants.ts":{"bytes":64,"imports":[],"format":"esm"},"src/legacy/helpers.ts":{"bytes":6905,"imports":[{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"src/legacy/constants.ts","kind":"import-statement","original":"./constants.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/legacy/context.ts":{"bytes":905,"imports":[{"path":"react","kind":"import-statement","external":true}],"format":"esm"},"src/legacy/hooks.ts":{"bytes":1505,"imports":[{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"src/legacy/context.ts","kind":"import-statement","original":"./context.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/legacy/useAutoConnect.ts":{"bytes":916,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"src/legacy/helpers.ts","kind":"import-statement","original":"./helpers.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/legacy/useLegacyProviders.ts":{"bytes":6602,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"src/legacy/helpers.ts","kind":"import-statement","original":"./helpers.js"},{"path":"src/legacy/hooks.ts","kind":"import-statement","original":"./hooks.js"},{"path":"src/legacy/useAutoConnect.ts","kind":"import-statement","original":"./useAutoConnect.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/provider.tsx":{"bytes":442,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"src/legacy/context.ts","kind":"import-statement","original":"./legacy/context.js"},{"path":"src/legacy/useLegacyProviders.ts","kind":"import-statement","original":"./legacy/useLegacyProviders.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/legacy/types.ts":{"bytes":4784,"imports":[],"format":"esm"},"src/index.ts":{"bytes":305,"imports":[{"path":"src/legacy/helpers.ts","kind":"import-statement","original":"./legacy/helpers.js"},{"path":"src/provider.tsx","kind":"import-statement","original":"./provider.js"},{"path":"src/legacy/hooks.ts","kind":"import-statement","original":"./legacy/hooks.js"},{"path":"src/legacy/types.ts","kind":"import-statement","original":"./legacy/types.js"},{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"dist/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":27945},"dist/index.js":{"imports":[{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true}],"exports":["Events","Provider","autoConnect","availableWallets","checkWalletProviders","choose","clearPersistance","connectedWallets","defaultWalletState","isAsync","makeEventHandler","needsCheckInstallation","readAccountAddress","stateReducer","tryPersistWallet","tryRemoveWalletFromPersistance","useWallets"],"entryPoint":"src/index.ts","inputs":{"src/legacy/helpers.ts":{"bytesInOutput":1933},"src/legacy/constants.ts":{"bytesInOutput":31},"src/index.ts":{"bytesInOutput":75},"src/provider.tsx":{"bytesInOutput":126},"src/legacy/context.ts":{"bytesInOutput":427},"src/legacy/useLegacyProviders.ts":{"bytesInOutput":2065},"src/legacy/hooks.ts":{"bytesInOutput":427},"src/legacy/useAutoConnect.ts":{"bytesInOutput":283}},"bytes":5841}}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/wallets-react",
3
- "version": "0.21.2-next.4",
3
+ "version": "0.21.2-next.5",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "source": "./src/index.ts",
@@ -33,4 +33,4 @@
33
33
  "publishConfig": {
34
34
  "access": "public"
35
35
  }
36
- }
36
+ }
@@ -29,7 +29,7 @@ export const defaultWalletState: WalletState = {
29
29
  network: null,
30
30
  };
31
31
 
32
- export function state_reducer(state: State, action: any) {
32
+ export function stateReducer(state: State, action: any) {
33
33
  if (action.type === 'new_state') {
34
34
  // TODO fix problem and remove ts-ignore
35
35
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -6,11 +6,14 @@ import { useContext, useRef } from 'react';
6
6
 
7
7
  import { WalletContext } from './context.js';
8
8
 
9
- /**
10
- *
11
- *
12
- */
13
- export function useInitializers(onChangeState: WalletEventHandler) {
9
+ export type GetWalletInstance = (wallet: {
10
+ actions: WalletActions;
11
+ config: WalletConfig;
12
+ }) => Wallet;
13
+
14
+ export function useInitializers(
15
+ onChangeState: WalletEventHandler
16
+ ): GetWalletInstance {
14
17
  const availableWallets = useRef<{
15
18
  [key: string]: Wallet | undefined;
16
19
  }>({});
@@ -33,6 +33,13 @@ export type ProviderContext = {
33
33
  disconnectAll(): Promise<PromiseSettledResult<any>[]>;
34
34
  state(type: WalletType): WalletState;
35
35
  canSwitchNetworkTo(type: WalletType, network: Network): boolean;
36
+ /**
37
+ * `Provider` in legacy terms means injected instances by wallets into window (e.g. window.ethereum)
38
+ * that can be retrieved by `getInstance`.
39
+ *
40
+ * Note 1: Providers are lazy evaluated, which means you need to call `connect` (or `state`) first, then the value will be shown in object.
41
+ * before doing that, it's a key (wallet name or we call it `type` to be more specific) with null value. (e.g. {metamask: null})
42
+ */
36
43
  providers(): Providers;
37
44
  getSigners(type: WalletType): SignerFactory;
38
45
  getWalletInfo(type: WalletType): WalletInfo;
@@ -0,0 +1,31 @@
1
+ import type { GetWalletInstance } from './hooks.js';
2
+ import type { ProviderProps, WalletProviders } from './types.js';
3
+
4
+ import { useEffect, useRef } from 'react';
5
+
6
+ import { autoConnect } from './helpers.js';
7
+
8
+ export function useAutoConnect(
9
+ props: Pick<ProviderProps, 'allBlockChains' | 'autoConnect'> & {
10
+ wallets: WalletProviders;
11
+ getWalletInstanceFromLegacy: GetWalletInstance;
12
+ }
13
+ ) {
14
+ const autoConnectInitiated = useRef(false);
15
+
16
+ // Running auto connect on instances
17
+ useEffect(() => {
18
+ const shouldTryAutoConnect =
19
+ props.allBlockChains &&
20
+ props.allBlockChains.length &&
21
+ props.autoConnect &&
22
+ !autoConnectInitiated.current;
23
+
24
+ if (shouldTryAutoConnect) {
25
+ autoConnectInitiated.current = true;
26
+ void (async () => {
27
+ await autoConnect(props.wallets, props.getWalletInstanceFromLegacy);
28
+ })();
29
+ }
30
+ }, [props.autoConnect, props.allBlockChains]);
31
+ }
@@ -0,0 +1,218 @@
1
+ import type { ProviderContext, ProviderProps } from './types.js';
2
+ import type { WalletType } from '@rango-dev/wallets-shared';
3
+
4
+ import { useEffect, useReducer } from 'react';
5
+
6
+ import {
7
+ availableWallets,
8
+ checkWalletProviders,
9
+ clearPersistance,
10
+ connectedWallets,
11
+ defaultWalletState,
12
+ makeEventHandler,
13
+ stateReducer,
14
+ tryPersistWallet,
15
+ tryRemoveWalletFromPersistance,
16
+ } from './helpers.js';
17
+ import { useInitializers } from './hooks.js';
18
+ import { useAutoConnect } from './useAutoConnect.js';
19
+
20
+ export function useLegacyProviders(props: ProviderProps): ProviderContext {
21
+ const [providersState, dispatch] = useReducer(stateReducer, {});
22
+
23
+ // Get (or add) wallet instance (`provider`s will be wrapped in a `Wallet`)
24
+ const getWalletInstance = useInitializers(
25
+ makeEventHandler(dispatch, props.onUpdateState)
26
+ );
27
+
28
+ // Getting providers from props and put all of them in a `Map` with an appropriate interface.
29
+ const listOfProviders = props.providers;
30
+ const wallets = checkWalletProviders(listOfProviders);
31
+
32
+ useAutoConnect({
33
+ wallets,
34
+ allBlockChains: props.allBlockChains,
35
+ autoConnect: props.autoConnect,
36
+ getWalletInstanceFromLegacy: getWalletInstance,
37
+ });
38
+
39
+ // Final API we put in context and it will be available to use for users.
40
+ // eslint-disable-next-line react/jsx-no-constructed-context-values
41
+ const api: ProviderContext = {
42
+ async connect(type, network, namespaces) {
43
+ const wallet = wallets.get(type);
44
+ if (!wallet) {
45
+ throw new Error(`You should add ${type} to provider first.`);
46
+ }
47
+ const walletInstance = getWalletInstance(wallet);
48
+ const result = await walletInstance.connect(network, namespaces);
49
+ if (props.autoConnect) {
50
+ void tryPersistWallet({
51
+ type,
52
+ walletActions: wallet.actions,
53
+ getState: api.state,
54
+ });
55
+ }
56
+
57
+ return result;
58
+ },
59
+ async disconnect(type) {
60
+ const wallet = wallets.get(type);
61
+ if (!wallet) {
62
+ throw new Error(`You should add ${type} to provider first.`);
63
+ }
64
+
65
+ const walletInstance = getWalletInstance(wallet);
66
+ await walletInstance.disconnect();
67
+ if (props.autoConnect) {
68
+ tryRemoveWalletFromPersistance({ type, walletActions: wallet.actions });
69
+ }
70
+ },
71
+ async disconnectAll() {
72
+ const disconnect_promises: Promise<any>[] = [];
73
+
74
+ /*
75
+ * When a wallet is initializing, a record will be added to `providersState`
76
+ * So we use them to know what wallet has been initialized then we need to
77
+ * filter connected wallets only.
78
+ */
79
+ connectedWallets(providersState).forEach((type) => {
80
+ const wallet = wallets.get(type);
81
+
82
+ if (wallet) {
83
+ const walletInstance = getWalletInstance(wallet);
84
+ disconnect_promises.push(walletInstance.disconnect());
85
+ }
86
+ });
87
+
88
+ if (props.autoConnect) {
89
+ clearPersistance();
90
+ }
91
+ return await Promise.allSettled(disconnect_promises);
92
+ },
93
+
94
+ async suggestAndConnect(type, network) {
95
+ const wallet = wallets.get(type);
96
+ if (!wallet) {
97
+ throw new Error(`You should add ${type} to provider first.`);
98
+ }
99
+ const walletInstance = getWalletInstance(wallet);
100
+ const result = await walletInstance.suggestAndConnect(network);
101
+
102
+ return result;
103
+ },
104
+
105
+ state(type) {
106
+ return providersState[type] || defaultWalletState;
107
+ },
108
+ canSwitchNetworkTo(type, network) {
109
+ const wallet = wallets.get(type);
110
+ if (!wallet) {
111
+ return false;
112
+ }
113
+
114
+ const walletInstance = getWalletInstance(wallet);
115
+ return walletInstance.canSwitchNetworkTo
116
+ ? walletInstance.canSwitchNetworkTo(network, walletInstance.provider)
117
+ : false;
118
+ },
119
+ providers() {
120
+ const providers: { [type in WalletType]?: any } = {};
121
+ availableWallets(providersState).forEach((type) => {
122
+ const wallet = wallets.get(type);
123
+ if (wallet) {
124
+ const walletInstance = getWalletInstance(wallet);
125
+ providers[type] = walletInstance.provider;
126
+ }
127
+ });
128
+
129
+ return providers;
130
+ },
131
+ getWalletInfo(type) {
132
+ const wallet = wallets.get(type);
133
+ if (!wallet) {
134
+ throw new Error(`You should add ${type} to provider first.`);
135
+ }
136
+
137
+ /*
138
+ * Get wallet info could be used in render methods to show wallets data
139
+ * So, addWalletRef method shouldn't be called in this method
140
+ */
141
+
142
+ return wallet.actions.getWalletInfo(props.allBlockChains || []);
143
+ },
144
+ getSigners(type) {
145
+ const wallet = wallets.get(type);
146
+
147
+ if (!wallet) {
148
+ throw new Error(`You should add ${type} to provider first.`);
149
+ }
150
+ const walletInstance = getWalletInstance(wallet);
151
+ const provider = walletInstance.provider;
152
+ const result = walletInstance.getSigners(provider);
153
+
154
+ return result;
155
+ },
156
+ };
157
+
158
+ // Initialize instances
159
+ useEffect(() => {
160
+ wallets.forEach((wallet) => {
161
+ const walletInstance = getWalletInstance(wallet);
162
+ const runOnInit = () => {
163
+ if (walletInstance.onInit) {
164
+ walletInstance.onInit();
165
+ }
166
+ };
167
+
168
+ const initWhenPageIsReady = (event: Event) => {
169
+ if (
170
+ event.target &&
171
+ (event.target as Document).readyState === 'complete'
172
+ ) {
173
+ runOnInit();
174
+
175
+ document.removeEventListener('readystatechange', initWhenPageIsReady);
176
+ }
177
+ };
178
+
179
+ // Try to run, maybe it's ready.
180
+ runOnInit();
181
+
182
+ /*
183
+ * Try again when the page has been completely loaded.
184
+ * Some of wallets, take some time to be fully injected and loaded.
185
+ */
186
+ document.addEventListener('readystatechange', initWhenPageIsReady);
187
+ });
188
+ }, []);
189
+
190
+ // Setting supported blockchains on instances
191
+ useEffect(() => {
192
+ const allBlockChains = props.allBlockChains;
193
+ if (allBlockChains) {
194
+ wallets.forEach((wallet) => {
195
+ const walletInstance = getWalletInstance(wallet);
196
+ const walletInfo = walletInstance.getWalletInfo(
197
+ props.allBlockChains || []
198
+ );
199
+ walletInstance.setInfo({
200
+ supportedBlockchains: walletInfo.supportedChains,
201
+ isContractWallet: !!walletInfo.isContractWallet,
202
+ });
203
+ });
204
+ }
205
+ }, [props.allBlockChains]);
206
+
207
+ // Setting event handler on instances
208
+ useEffect(() => {
209
+ wallets.forEach((wallet) => {
210
+ const walletInstance = getWalletInstance(wallet);
211
+ walletInstance.setHandler(
212
+ makeEventHandler(dispatch, props.onUpdateState)
213
+ );
214
+ });
215
+ }, [props.onUpdateState]);
216
+
217
+ return api;
218
+ }
package/src/provider.tsx CHANGED
@@ -1,228 +1,15 @@
1
- import type { ProviderContext, ProviderProps } from './legacy/types.js';
2
- import type { WalletType } from '@rango-dev/wallets-shared';
1
+ import type { ProviderProps } from './legacy/types.js';
3
2
 
4
- import React, { useEffect, useReducer, useRef } from 'react';
3
+ import React from 'react';
5
4
 
6
5
  import { WalletContext } from './legacy/context.js';
7
- import {
8
- autoConnect,
9
- availableWallets,
10
- checkWalletProviders,
11
- clearPersistance,
12
- connectedWallets,
13
- defaultWalletState,
14
- makeEventHandler,
15
- state_reducer,
16
- tryPersistWallet,
17
- tryRemoveWalletFromPersistance,
18
- } from './legacy/helpers.js';
19
- import { useInitializers } from './legacy/hooks.js';
6
+ import { useLegacyProviders } from './legacy/useLegacyProviders.js';
20
7
 
21
8
  function Provider(props: ProviderProps) {
22
- const [providersState, dispatch] = useReducer(state_reducer, {});
23
- const autoConnectInitiated = useRef(false);
24
-
25
- // Get (or add) wallet instance (`provider`s will be wraped in a `Wallet`)
26
- const getWalletInstance = useInitializers(
27
- makeEventHandler(dispatch, props.onUpdateState)
28
- );
29
-
30
- // Getting providers from props and put all of them in a `Map` with an appropriate interface.
31
- const listOfProviders = props.providers;
32
- const wallets = checkWalletProviders(listOfProviders);
33
-
34
- // Final API we put in context and it will be available to use for users.
35
- // eslint-disable-next-line react/jsx-no-constructed-context-values
36
- const api: ProviderContext = {
37
- async connect(type, network, namespaces) {
38
- const wallet = wallets.get(type);
39
- if (!wallet) {
40
- throw new Error(`You should add ${type} to provider first.`);
41
- }
42
- const walletInstance = getWalletInstance(wallet);
43
- const result = await walletInstance.connect(network, namespaces);
44
- if (props.autoConnect) {
45
- void tryPersistWallet({
46
- type,
47
- walletActions: wallet.actions,
48
- getState: api.state,
49
- });
50
- }
51
-
52
- return result;
53
- },
54
- async disconnect(type) {
55
- const wallet = wallets.get(type);
56
- if (!wallet) {
57
- throw new Error(`You should add ${type} to provider first.`);
58
- }
59
-
60
- const walletInstance = getWalletInstance(wallet);
61
- await walletInstance.disconnect();
62
- if (props.autoConnect) {
63
- tryRemoveWalletFromPersistance({ type, walletActions: wallet.actions });
64
- }
65
- },
66
- async disconnectAll() {
67
- const disconnect_promises: Promise<any>[] = [];
68
-
69
- /*
70
- * When a wallet is initializing, a record will be added to `providersState`
71
- * So we use them to know what wallet has been initialized then we need to
72
- * filter connected wallets only.
73
- */
74
- connectedWallets(providersState).forEach((type) => {
75
- const wallet = wallets.get(type);
76
-
77
- if (wallet) {
78
- const walletInstance = getWalletInstance(wallet);
79
- disconnect_promises.push(walletInstance.disconnect());
80
- }
81
- });
82
-
83
- if (props.autoConnect) {
84
- clearPersistance();
85
- }
86
- return await Promise.allSettled(disconnect_promises);
87
- },
88
-
89
- async suggestAndConnect(type, network) {
90
- const wallet = wallets.get(type);
91
- if (!wallet) {
92
- throw new Error(`You should add ${type} to provider first.`);
93
- }
94
- const walletInstance = getWalletInstance(wallet);
95
- const result = await walletInstance.suggestAndConnect(network);
96
-
97
- return result;
98
- },
99
-
100
- state(type) {
101
- return providersState[type] || defaultWalletState;
102
- },
103
- canSwitchNetworkTo(type, network) {
104
- const wallet = wallets.get(type);
105
- if (!wallet) {
106
- return false;
107
- }
108
-
109
- const walletInstance = getWalletInstance(wallet);
110
- return walletInstance.canSwitchNetworkTo
111
- ? walletInstance.canSwitchNetworkTo(network, walletInstance.provider)
112
- : false;
113
- },
114
- providers() {
115
- const providers: { [type in WalletType]?: any } = {};
116
- availableWallets(providersState).forEach((type) => {
117
- const wallet = wallets.get(type);
118
- if (wallet) {
119
- const walletInstance = getWalletInstance(wallet);
120
- providers[type] = walletInstance.provider;
121
- }
122
- });
123
-
124
- return providers;
125
- },
126
- getWalletInfo(type) {
127
- const wallet = wallets.get(type);
128
- if (!wallet) {
129
- throw new Error(`You should add ${type} to provider first.`);
130
- }
131
-
132
- /*
133
- * Get wallet info could be used in render methods to show wallets data
134
- * So, addWalletRef method shouldn't be called in this method
135
- */
136
-
137
- return wallet.actions.getWalletInfo(props.allBlockChains || []);
138
- },
139
- getSigners(type) {
140
- const wallet = wallets.get(type);
141
-
142
- if (!wallet) {
143
- throw new Error(`You should add ${type} to provider first.`);
144
- }
145
- const walletInstance = getWalletInstance(wallet);
146
- const provider = walletInstance.provider;
147
- const result = walletInstance.getSigners(provider);
148
-
149
- return result;
150
- },
151
- };
152
-
153
- useEffect(() => {
154
- wallets.forEach((wallet) => {
155
- const walletInstance = getWalletInstance(wallet);
156
- const runOnInit = () => {
157
- if (walletInstance.onInit) {
158
- walletInstance.onInit();
159
- }
160
- };
161
-
162
- const initWhenPageIsReady = (event: Event) => {
163
- if (
164
- event.target &&
165
- (event.target as Document).readyState === 'complete'
166
- ) {
167
- runOnInit();
168
-
169
- document.removeEventListener('readystatechange', initWhenPageIsReady);
170
- }
171
- };
172
-
173
- // Try to run, maybe it's ready.
174
- runOnInit();
175
-
176
- /*
177
- * Try again when the page has been completely loaded.
178
- * Some of wallets, take some time to be fully injected and loaded.
179
- */
180
- document.addEventListener('readystatechange', initWhenPageIsReady);
181
- });
182
- }, []);
183
-
184
- useEffect(() => {
185
- const allBlockChains = props.allBlockChains;
186
- if (allBlockChains) {
187
- wallets.forEach((wallet) => {
188
- const walletInstance = getWalletInstance(wallet);
189
- const walletInfo = walletInstance.getWalletInfo(
190
- props.allBlockChains || []
191
- );
192
- walletInstance.setInfo({
193
- supportedBlockchains: walletInfo.supportedChains,
194
- isContractWallet: !!walletInfo.isContractWallet,
195
- });
196
- });
197
- }
198
- }, [props.allBlockChains]);
199
-
200
- useEffect(() => {
201
- wallets.forEach((wallet) => {
202
- const walletInstance = getWalletInstance(wallet);
203
- walletInstance.setHandler(
204
- makeEventHandler(dispatch, props.onUpdateState)
205
- );
206
- });
207
- }, [props.onUpdateState]);
208
-
209
- useEffect(() => {
210
- const shouldTryAutoConnect =
211
- props.allBlockChains &&
212
- props.allBlockChains.length &&
213
- props.autoConnect &&
214
- !autoConnectInitiated.current;
215
-
216
- if (shouldTryAutoConnect) {
217
- autoConnectInitiated.current = true;
218
- void (async () => {
219
- await autoConnect(wallets, getWalletInstance);
220
- })();
221
- }
222
- }, [props.autoConnect, props.allBlockChains]);
9
+ const legacyApi = useLegacyProviders(props);
223
10
 
224
11
  return (
225
- <WalletContext.Provider value={api}>
12
+ <WalletContext.Provider value={legacyApi}>
226
13
  {props.children}
227
14
  </WalletContext.Provider>
228
15
  );