@rango-dev/wallets-react 0.48.1-next.5 → 0.49.0

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.
Files changed (83) hide show
  1. package/dist/context.d.ts.map +1 -0
  2. package/dist/helpers.d.ts +1 -1
  3. package/dist/hooks.d.ts +3 -0
  4. package/dist/hooks.d.ts.map +1 -0
  5. package/dist/hub/autoConnect.d.ts +2 -4
  6. package/dist/hub/autoConnect.d.ts.map +1 -1
  7. package/dist/hub/constants.d.ts +0 -1
  8. package/dist/hub/constants.d.ts.map +1 -1
  9. package/dist/hub/helpers.d.ts +2 -0
  10. package/dist/hub/helpers.d.ts.map +1 -1
  11. package/dist/hub/lastConnectedWallets.d.ts +1 -2
  12. package/dist/hub/lastConnectedWallets.d.ts.map +1 -1
  13. package/dist/hub/mod.d.ts +1 -1
  14. package/dist/hub/mod.d.ts.map +1 -1
  15. package/dist/hub/persistor.d.ts +11 -0
  16. package/dist/hub/persistor.d.ts.map +1 -0
  17. package/dist/{legacy → hub}/useAutoConnect.d.ts +1 -1
  18. package/dist/hub/useAutoConnect.d.ts.map +1 -0
  19. package/dist/hub/useHubAdapter.d.ts +1 -5
  20. package/dist/hub/useHubAdapter.d.ts.map +1 -1
  21. package/dist/hub/utils.d.ts +7 -8
  22. package/dist/hub/utils.d.ts.map +1 -1
  23. package/dist/index.d.ts +2 -2
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +1 -1
  26. package/dist/index.js.map +4 -4
  27. package/dist/legacy/mod.d.ts +2 -4
  28. package/dist/legacy/mod.d.ts.map +1 -1
  29. package/dist/legacy/types.d.ts +89 -69
  30. package/dist/legacy/types.d.ts.map +1 -1
  31. package/dist/provider.d.ts +1 -1
  32. package/dist/provider.d.ts.map +1 -1
  33. package/dist/types.d.ts +39 -0
  34. package/dist/types.d.ts.map +1 -0
  35. package/package.json +6 -11
  36. package/src/{legacy/context.ts → context.ts} +0 -3
  37. package/src/helpers.ts +1 -1
  38. package/src/hooks.ts +13 -0
  39. package/src/hub/autoConnect.ts +26 -35
  40. package/src/hub/constants.ts +0 -1
  41. package/src/hub/helpers.ts +8 -1
  42. package/src/hub/lastConnectedWallets.ts +3 -51
  43. package/src/hub/mod.ts +1 -5
  44. package/src/hub/persistor.ts +19 -0
  45. package/src/{legacy → hub}/useAutoConnect.ts +2 -2
  46. package/src/hub/useHubAdapter.ts +37 -35
  47. package/src/hub/utils.ts +20 -55
  48. package/src/index.ts +2 -2
  49. package/src/legacy/mod.ts +6 -9
  50. package/src/legacy/types.ts +112 -97
  51. package/src/provider.tsx +8 -4
  52. package/src/types.ts +58 -0
  53. package/CHANGELOG.md +0 -343
  54. package/dist/helpers/index.d.ts +0 -2
  55. package/dist/helpers/index.d.ts.map +0 -1
  56. package/dist/helpers/index.js +0 -2
  57. package/dist/helpers/index.js.map +0 -7
  58. package/dist/legacy/autoConnect.d.ts +0 -7
  59. package/dist/legacy/autoConnect.d.ts.map +0 -1
  60. package/dist/legacy/context.d.ts.map +0 -1
  61. package/dist/legacy/helpers.d.ts +0 -31
  62. package/dist/legacy/helpers.d.ts.map +0 -1
  63. package/dist/legacy/hooks.d.ts +0 -10
  64. package/dist/legacy/hooks.d.ts.map +0 -1
  65. package/dist/legacy/useAutoConnect.d.ts.map +0 -1
  66. package/dist/legacy/useLegacyProviders.d.ts +0 -7
  67. package/dist/legacy/useLegacyProviders.d.ts.map +0 -1
  68. package/dist/legacy/utils.d.ts +0 -3
  69. package/dist/legacy/utils.d.ts.map +0 -1
  70. package/dist/test-utils/fixtures.d.ts +0 -14
  71. package/dist/test-utils/fixtures.d.ts.map +0 -1
  72. package/dist/useProviders.d.ts +0 -4
  73. package/dist/useProviders.d.ts.map +0 -1
  74. package/helpers/package.json +0 -8
  75. package/src/helpers/index.ts +0 -1
  76. package/src/legacy/autoConnect.ts +0 -69
  77. package/src/legacy/helpers.ts +0 -193
  78. package/src/legacy/hooks.ts +0 -54
  79. package/src/legacy/useLegacyProviders.ts +0 -246
  80. package/src/legacy/utils.ts +0 -7
  81. package/src/test-utils/fixtures.ts +0 -164
  82. package/src/useProviders.ts +0 -121
  83. /package/dist/{legacy/context.d.ts → context.d.ts} +0 -0
@@ -1,102 +1,123 @@
1
- import type { Provider, ProviderMetadata } from '@hub3js/core';
2
- import type { NamespaceData } from '@hub3js/core/store';
3
- import type { VersionedProviders } from '@hub3js/core/utils';
4
- import type { Namespace } from '@hub3js/namespaces';
5
1
  import type {
6
- LegacyNamespaceInputForConnect,
7
- LegacyProviderInterface,
8
- LegacyNetwork as Network,
9
- LegacyEventHandler as WalletEventHandler,
10
- LegacyWalletInfo as WalletInfo,
11
- LegacyState as WalletState,
12
- LegacyWalletType as WalletType,
13
- } from '@rango-dev/wallets-core/legacy';
2
+ DerivationPathProperty,
3
+ NamespacesProperty,
4
+ ProviderMetadata,
5
+ WalletType,
6
+ } from '@hub3js/core';
7
+ import type { Namespace } from '@hub3js/namespaces';
8
+ import type { Network } from '@rango-dev/internal-blockchains';
14
9
  import type { BlockchainMeta, SignerFactory } from 'rango-types';
15
- import type { PropsWithChildren } from 'react';
16
10
 
17
- import { LegacyEvents as Events } from '@rango-dev/wallets-core/legacy';
11
+ export type NamespaceMeta = NamespacesProperty['value']['data'][number];
12
+ export type NeedsNamespace = NamespacesProperty['value'];
13
+ export type NeedsDerivationPath = DerivationPathProperty['value'];
18
14
 
19
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
- type InstanceType = any;
15
+ export type InstallObjects = {
16
+ CHROME?: string;
17
+ FIREFOX?: string;
18
+ EDGE?: string;
19
+ BRAVE?: string;
20
+ DEFAULT: string;
21
+ };
21
22
 
22
- export type State = {
23
- [key: string]: WalletState | undefined;
23
+ export type WalletInfo = {
24
+ name: string;
25
+ img: string;
26
+ installLink: InstallObjects | string;
27
+ /**
28
+ * @deprecated we don't use this value anymore.
29
+ */
30
+ color: string;
31
+ supportedChains: BlockchainMeta[];
32
+ showOnMobile?: boolean;
33
+ isContractWallet?: boolean;
34
+ mobileWallet?: boolean;
35
+
36
+ needsDerivationPath?: NeedsDerivationPath;
37
+ needsNamespace?: NeedsNamespace;
24
38
  };
25
39
 
26
- export type ConnectResult = {
40
+ export type WalletState = {
41
+ connected: boolean;
42
+ connecting: boolean;
43
+ /**
44
+ * @deprecated it always returns `false`. don't use it.
45
+ */
46
+ reachable: boolean;
47
+ installed: boolean;
27
48
  accounts: string[] | null;
28
49
  network: Network | null;
29
- provider: InstanceType;
50
+ derivationPath?: string;
30
51
  };
31
52
 
32
- export type Providers = { [type in WalletType]?: InstanceType };
53
+ type NamespaceData = {
54
+ namespace: Namespace;
55
+ derivationPath?: string;
56
+ };
57
+
58
+ export type NamespaceInputForConnect<T extends Namespace = Namespace> = {
59
+ /**
60
+ * By default, you should specify namespace (e.g. evm).
61
+ */
62
+ namespace: T;
63
+ /**
64
+ * In some cases, we need to connect a specific network on a namespace. e.g. Polygon on EVM.
65
+ */
66
+ network: Network | undefined;
67
+ derivationPath?: string;
68
+ };
69
+
70
+ export enum Events {
71
+ CONNECTED = 'connected',
72
+ CONNECTING = 'connecting',
73
+ REACHABLE = 'reachable',
74
+ INSTALLED = 'installed',
75
+ ACCOUNTS = 'accounts',
76
+ NETWORK = 'network',
77
+ // Hub only events
78
+ NAMESPACE_DISCONNECTED = 'namespace_disconnected',
79
+
80
+ PROVIDER_DISCONNECTED = 'provider_disconnected',
81
+ }
82
+
83
+ export type EventInfo = {
84
+ supportedBlockchains: BlockchainMeta[];
85
+ isContractWallet: boolean;
86
+ isHub: boolean;
87
+ // will be set alongside ACCOUNT event
88
+ namespace?: Namespace;
89
+ derivationPath?: string;
90
+ };
91
+
92
+ export type EventHandler = (
93
+ type: WalletType,
94
+ event: Events,
95
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
96
+ value: any,
97
+ coreState: WalletState,
98
+ info: EventInfo
99
+ ) => void;
100
+
101
+ export type ConnectResult = {
102
+ accounts: string[] | null;
103
+ network: Network | null;
104
+ };
33
105
 
34
106
  export type ExtendedWalletInfo = WalletInfo & {
35
107
  properties?: ProviderMetadata['properties'];
36
108
  isHub?: boolean;
37
109
  };
38
110
 
39
- export type ProviderContext = {
40
- connect(
41
- type: WalletType,
42
- namespaces?: LegacyNamespaceInputForConnect[]
43
- ): Promise<ConnectResult[]>;
44
- disconnect(type: WalletType, namespaces?: Namespace[]): Promise<void>;
45
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
46
- disconnectAll(): Promise<PromiseSettledResult<any>[]>;
47
-
48
- state(
49
- type: WalletType
50
- ): WalletState & { namespaces?: Map<Namespace, NamespaceData> };
51
- canSwitchNetworkTo(
52
- type: WalletType,
53
- network: Network,
54
- namespace?: LegacyNamespaceInputForConnect
55
- ): boolean;
56
- /**
57
- * `Provider` in legacy terms means injected instances by wallets into window (e.g. window.ethereum)
58
- * that can be retrieved by `getInstance`.
59
- *
60
- * Note 1: Providers are lazy evaluated, which means you need to call `connect` (or `state`) first, then the value will be shown in object.
61
- * 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})
62
- */
63
- providers(): Providers;
64
- getSigners(type: WalletType): Promise<SignerFactory>;
65
- getWalletInfo(type: WalletType): ExtendedWalletInfo;
66
- suggestAndConnect(
67
- type: WalletType,
68
- namespace: LegacyNamespaceInputForConnect
69
- ): Promise<ConnectResult>;
70
- hubProvider(type: WalletType): Provider;
71
- };
111
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
112
+ type InstanceType = any;
72
113
 
73
- export type ProviderProps = PropsWithChildren<{
74
- onUpdateState?: WalletEventHandler;
75
- allBlockChains?: BlockchainMeta[];
76
- autoConnect?: boolean;
77
- providers: VersionedProviders[];
78
- configs?: {
79
- wallets?: (WalletType | LegacyProviderInterface | Provider)[];
80
- walletOptions?: {
81
- [key: WalletType]: {
82
- provider?: unknown;
83
- namespaces?: {
84
- [namespaceId: string]: unknown;
85
- };
86
- };
87
- };
88
- };
89
- }>;
90
-
91
- export { Events };
92
-
93
- export type ProviderConnectResult = {
114
+ type ProviderConnectResult = {
94
115
  accounts: string[];
95
116
  chainId: string;
96
117
  derivationPath?: string;
97
118
  };
98
119
 
99
- export type GetInstanceOptions = {
120
+ type GetInstanceOptions = {
100
121
  network?: Network;
101
122
  currentProvider: InstanceType;
102
123
  meta: BlockchainMeta[];
@@ -111,28 +132,27 @@ export type GetInstanceOptions = {
111
132
  updateChainId: (chainId: number | string) => void;
112
133
  };
113
134
 
114
- export type GetInstance =
115
- | (() => InstanceType)
116
- | ((options: GetInstanceOptions) => Promise<InstanceType>);
117
- export type TryGetInstance =
135
+ type TryGetInstance =
118
136
  | (() => InstanceType)
119
137
  | ((
120
138
  options: Pick<GetInstanceOptions, 'force' | 'network'>
121
139
  ) => Promise<InstanceType>);
122
- export type Connect = (options: {
140
+
141
+ type Connect = (options: {
123
142
  instance: InstanceType;
124
143
  network?: Network;
125
144
  meta: BlockchainMeta[];
145
+ namespaces?: NamespaceData[];
126
146
  }) => Promise<ProviderConnectResult | ProviderConnectResult[]>;
127
147
 
128
- export type Disconnect = (options: {
148
+ type Disconnect = (options: {
129
149
  instance: InstanceType;
130
150
  destroyInstance: () => void;
131
151
  }) => Promise<void>;
132
152
 
133
153
  type CleanupSubscribe = () => void;
134
154
 
135
- export type Subscribe = (options: {
155
+ type Subscribe = (options: {
136
156
  instance: InstanceType;
137
157
  state: WalletState;
138
158
  meta: BlockchainMeta[];
@@ -142,7 +162,7 @@ export type Subscribe = (options: {
142
162
  disconnect: () => void;
143
163
  }) => CleanupSubscribe | void;
144
164
 
145
- export type SwitchNetwork = (options: {
165
+ type SwitchNetwork = (options: {
146
166
  instance: InstanceType;
147
167
  network: Network;
148
168
  meta: BlockchainMeta[];
@@ -151,24 +171,24 @@ export type SwitchNetwork = (options: {
151
171
  updateChainId: (chainId: string) => void;
152
172
  }) => Promise<void>;
153
173
 
154
- export type Suggest = (options: {
174
+ type Suggest = (options: {
155
175
  instance: InstanceType;
156
176
  network: Network;
157
177
  meta: BlockchainMeta[];
158
178
  }) => Promise<void>;
159
179
 
160
- export type CanSwitchNetwork = (options: {
180
+ type CanSwitchNetwork = (options: {
161
181
  network: Network;
162
182
  meta: BlockchainMeta[];
163
183
  provider: InstanceType;
164
184
  }) => boolean;
165
185
 
166
- export type CanEagerConnect = (options: {
186
+ type CanEagerConnect = (options: {
167
187
  instance: InstanceType;
168
188
  meta: BlockchainMeta[];
169
189
  }) => Promise<boolean>;
170
190
 
171
- export interface WalletActions {
191
+ interface WalletActions {
172
192
  connect: Connect;
173
193
  getInstance: InstanceType;
174
194
  disconnect?: Disconnect;
@@ -184,7 +204,7 @@ export interface WalletActions {
184
204
  getWalletInfo(allBlockChains: BlockchainMeta[]): WalletInfo;
185
205
  }
186
206
 
187
- export interface WalletConfig {
207
+ interface WalletConfig {
188
208
  type: WalletType;
189
209
  defaultNetwork?: Network;
190
210
  checkInstallation?: boolean;
@@ -192,12 +212,7 @@ export interface WalletConfig {
192
212
  isAsyncSwitchNetwork?: boolean;
193
213
  }
194
214
 
195
- export type WalletProviders = Map<
196
- WalletType,
197
- {
198
- actions: WalletActions;
199
- config: WalletConfig;
200
- }
201
- >;
202
-
215
+ /**
216
+ * @deprecated Pass a hub `Provider` instead. This type will be removed in future versions.
217
+ */
203
218
  export type ProviderInterface = { config: WalletConfig } & WalletActions;
package/src/provider.tsx CHANGED
@@ -1,12 +1,16 @@
1
- import type { ProviderProps } from './legacy/types.js';
1
+ import type { ProviderProps } from './types.js';
2
2
 
3
3
  import React from 'react';
4
4
 
5
- import { WalletContext } from './legacy/context.js';
6
- import { useProviders } from './useProviders.js';
5
+ import { WalletContext } from './context.js';
6
+ import { useHubAdapter } from './hub/mod.js';
7
+ import { getHubProviders } from './hub/utils.js';
7
8
 
8
9
  function Provider(props: ProviderProps) {
9
- const api = useProviders(props);
10
+ const api = useHubAdapter({
11
+ ...props,
12
+ providers: getHubProviders(props.providers),
13
+ });
10
14
 
11
15
  return (
12
16
  <WalletContext.Provider value={api}>
package/src/types.ts ADDED
@@ -0,0 +1,58 @@
1
+ import type {
2
+ ConnectResult,
3
+ EventHandler,
4
+ ExtendedWalletInfo,
5
+ NamespaceInputForConnect,
6
+ WalletState,
7
+ } from './legacy/types.js';
8
+ import type { Provider, WalletType } from '@hub3js/core';
9
+ import type { NamespaceData as HubNamespaceData } from '@hub3js/core/store';
10
+ import type { VersionedProviders } from '@hub3js/core/utils';
11
+ import type { Namespace } from '@hub3js/namespaces';
12
+ import type { Network } from '@rango-dev/internal-blockchains';
13
+ import type { BlockchainMeta, SignerFactory } from 'rango-types';
14
+ import type { PropsWithChildren } from 'react';
15
+
16
+ export type ProviderContext = {
17
+ connect(
18
+ type: WalletType,
19
+ namespaces?: NamespaceInputForConnect[]
20
+ ): Promise<ConnectResult[]>;
21
+ disconnect(type: WalletType, namespaces?: Namespace[]): Promise<void>;
22
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
+ disconnectAll(): Promise<PromiseSettledResult<any>[]>;
24
+
25
+ state(
26
+ type: WalletType
27
+ ): WalletState & { namespaces?: Map<Namespace, HubNamespaceData> };
28
+ canSwitchNetworkTo(
29
+ type: WalletType,
30
+ network: Network,
31
+ namespace?: NamespaceInputForConnect
32
+ ): boolean;
33
+ getSigners(type: WalletType): Promise<SignerFactory>;
34
+ getWalletInfo(type: WalletType): ExtendedWalletInfo;
35
+ suggestAndConnect(
36
+ type: WalletType,
37
+ namespace: NamespaceInputForConnect
38
+ ): Promise<ConnectResult>;
39
+ hubProvider(type: WalletType): Provider;
40
+ };
41
+
42
+ export type ProviderProps = PropsWithChildren<{
43
+ onUpdateState?: EventHandler;
44
+ allBlockChains?: BlockchainMeta[];
45
+ autoConnect?: boolean;
46
+ providers: VersionedProviders[];
47
+ configs?: {
48
+ wallets?: (WalletType | Provider)[];
49
+ walletOptions?: {
50
+ [key: WalletType]: {
51
+ provider?: unknown;
52
+ namespaces?: {
53
+ [namespaceId: string]: unknown;
54
+ };
55
+ };
56
+ };
57
+ };
58
+ }>;