@rango-dev/wallets-core 0.39.1-next.0 → 0.40.1-next.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 (55) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/hub/hub.d.ts.map +1 -1
  3. package/dist/hub/mod.d.ts +1 -0
  4. package/dist/hub/mod.d.ts.map +1 -1
  5. package/dist/hub/namespaces/namespace.d.ts.map +1 -1
  6. package/dist/hub/provider/mod.d.ts +1 -1
  7. package/dist/hub/provider/mod.d.ts.map +1 -1
  8. package/dist/hub/provider/types.d.ts +5 -2
  9. package/dist/hub/provider/types.d.ts.map +1 -1
  10. package/dist/hub/store/providers.d.ts +3 -3
  11. package/dist/hub/store/providers.d.ts.map +1 -1
  12. package/dist/legacy/mod.d.ts +3 -2
  13. package/dist/legacy/mod.d.ts.map +1 -1
  14. package/dist/legacy/mod.js +1 -1
  15. package/dist/legacy/mod.js.map +4 -4
  16. package/dist/legacy/types.d.ts +28 -0
  17. package/dist/legacy/types.d.ts.map +1 -1
  18. package/dist/legacy/utils.d.ts +10 -0
  19. package/dist/legacy/utils.d.ts.map +1 -0
  20. package/dist/legacy/wallet.d.ts +6 -6
  21. package/dist/legacy/wallet.d.ts.map +1 -1
  22. package/dist/mod.d.ts +3 -3
  23. package/dist/mod.d.ts.map +1 -1
  24. package/dist/mod.js +1 -1
  25. package/dist/mod.js.map +3 -3
  26. package/dist/namespaces/common/mod.d.ts +1 -0
  27. package/dist/namespaces/common/mod.d.ts.map +1 -1
  28. package/dist/namespaces/common/mod.js +1 -1
  29. package/dist/namespaces/common/mod.js.map +2 -2
  30. package/dist/namespaces/cosmos/types.d.ts +1 -0
  31. package/dist/namespaces/cosmos/types.d.ts.map +1 -1
  32. package/dist/namespaces/evm/mod.js +1 -1
  33. package/dist/namespaces/evm/mod.js.map +2 -2
  34. package/dist/namespaces/solana/mod.js +1 -1
  35. package/dist/namespaces/solana/mod.js.map +2 -2
  36. package/dist/utils/mod.js +1 -1
  37. package/dist/utils/mod.js.map +2 -2
  38. package/dist/utils/versions.d.ts +10 -10
  39. package/dist/utils/versions.d.ts.map +1 -1
  40. package/dist/wallets-core.build.json +1 -1
  41. package/package.json +1 -1
  42. package/src/hub/hub.ts +0 -7
  43. package/src/hub/mod.ts +3 -0
  44. package/src/hub/namespaces/namespace.ts +4 -1
  45. package/src/hub/provider/mod.ts +1 -0
  46. package/src/hub/provider/types.ts +6 -2
  47. package/src/hub/store/providers.ts +3 -9
  48. package/src/legacy/mod.ts +9 -0
  49. package/src/legacy/types.ts +42 -0
  50. package/src/legacy/utils.ts +31 -0
  51. package/src/legacy/wallet.ts +29 -16
  52. package/src/mod.ts +10 -6
  53. package/src/namespaces/common/mod.ts +6 -0
  54. package/src/namespaces/cosmos/types.ts +1 -0
  55. package/src/utils/versions.ts +13 -14
package/src/legacy/mod.ts CHANGED
@@ -23,6 +23,8 @@ export type {
23
23
  InstallObjects as LegacyInstallObjects,
24
24
  WalletInfo as LegacyWalletInfo,
25
25
  ConnectResult as LegacyConnectResult,
26
+ NamespaceInputForConnect as LegacyNamespaceInputForConnect,
27
+ NamespaceInputWithDiscoverMode as LegacyNamespaceInputWithDiscoverMode,
26
28
  } from './types.js';
27
29
 
28
30
  export {
@@ -35,5 +37,12 @@ export { Persistor } from './persistor.js';
35
37
  export {
36
38
  readAccountAddress as legacyReadAccountAddress,
37
39
  getBlockChainNameFromId as legacyGetBlockChainNameFromId,
40
+ formatAddressWithNetwork as legacyFormatAddressWithNetwork,
38
41
  } from './helpers.js';
39
42
  export { default as LegacyWallet } from './wallet.js';
43
+
44
+ export {
45
+ eagerConnectHandler as legacyEagerConnectHandler,
46
+ isNamespaceDiscoverMode as legacyIsNamespaceDiscoverMode,
47
+ isEvmNamespace as legacyIsEvmNamespace,
48
+ } from './utils.js';
@@ -93,6 +93,9 @@ export type WalletInfo = {
93
93
  name: string;
94
94
  img: string;
95
95
  installLink: InstallObjects | string;
96
+ /**
97
+ * @deprecated we don't use this value anymore.
98
+ */
96
99
  color: string;
97
100
  supportedChains: BlockchainMeta[];
98
101
  showOnMobile?: boolean;
@@ -202,6 +205,12 @@ export type CanEagerConnect = (options: {
202
205
  meta: BlockchainMeta[];
203
206
  }) => Promise<boolean>;
204
207
 
208
+ export type EagerConnectResult<I = unknown> = {
209
+ accounts: string[] | null;
210
+ network: string | null;
211
+ provider: I | null;
212
+ };
213
+
205
214
  export interface WalletActions {
206
215
  connect: Connect;
207
216
  getInstance: any;
@@ -235,3 +244,36 @@ export type WalletProviders = Map<
235
244
  >;
236
245
 
237
246
  export type ProviderInterface = { config: WalletConfig } & WalletActions;
247
+
248
+ // it comes from wallets.ts and `connect`
249
+ type NetworkTypeFromLegacyConnect = Network | undefined;
250
+
251
+ export type NetworkTypeForNamespace<T extends NamespacesWithDiscoverMode> =
252
+ T extends 'DISCOVER_MODE'
253
+ ? string
254
+ : T extends Namespace
255
+ ? NetworkTypeFromLegacyConnect
256
+ : never;
257
+
258
+ export type NamespacesWithDiscoverMode = Namespace | 'DISCOVER_MODE';
259
+
260
+ export type NamespaceInputWithDiscoverMode = {
261
+ namespace: 'DISCOVER_MODE';
262
+ network: string;
263
+ derivationPath?: string;
264
+ };
265
+
266
+ export type NamespaceInputForConnect<T extends Namespace = Namespace> =
267
+ | {
268
+ /**
269
+ * By default, you should specify namespace (e.g. evm).
270
+ * For backward compatibility with legacy implementation, DISCOVER_MODE will try to map a list of known (and hardcoded) networks to a namespace.
271
+ */
272
+ namespace: T;
273
+ /**
274
+ * In some cases, we need to connect a specific network on a namespace. e.g. Polygon on EVM.
275
+ */
276
+ network: NetworkTypeForNamespace<T>;
277
+ derivationPath?: string;
278
+ }
279
+ | NamespaceInputWithDiscoverMode;
@@ -0,0 +1,31 @@
1
+ import type {
2
+ NamespaceInputForConnect,
3
+ NamespaceInputWithDiscoverMode,
4
+ } from './types.js';
5
+
6
+ import { Namespace } from './types.js';
7
+
8
+ export async function eagerConnectHandler<R = unknown>(params: {
9
+ canEagerConnect: () => Promise<boolean>;
10
+ connectHandler: () => Promise<R>;
11
+ providerName: string;
12
+ }) {
13
+ // Check if we can eagerly connect to the wallet
14
+ if (await params.canEagerConnect()) {
15
+ // Connect to wallet as usual
16
+ return await params.connectHandler();
17
+ }
18
+ throw new Error(`can't restore connection for ${params.providerName}.`);
19
+ }
20
+
21
+ export function isNamespaceDiscoverMode(
22
+ namespace: NamespaceInputForConnect
23
+ ): namespace is NamespaceInputWithDiscoverMode {
24
+ return namespace.namespace === 'DISCOVER_MODE';
25
+ }
26
+
27
+ export function isEvmNamespace(
28
+ namespace: NamespaceInputForConnect
29
+ ): namespace is NamespaceInputForConnect<Namespace.Evm> {
30
+ return namespace.namespace === Namespace.Evm;
31
+ }
@@ -1,4 +1,5 @@
1
1
  import type {
2
+ EagerConnectResult,
2
3
  GetInstanceOptions,
3
4
  NamespaceData,
4
5
  Network,
@@ -14,6 +15,7 @@ import {
14
15
  needsCheckInstallation,
15
16
  } from './helpers.js';
16
17
  import { Events, Networks } from './types.js';
18
+ import { eagerConnectHandler } from './utils.js';
17
19
 
18
20
  export type EventHandler = (
19
21
  type: WalletType,
@@ -26,11 +28,16 @@ export type EventHandler = (
26
28
  export type EventInfo = {
27
29
  supportedBlockchains: BlockchainMeta[];
28
30
  isContractWallet: boolean;
31
+ // This is for Hub and be able to make it compatible with legacy behavior.
32
+ isHub: boolean;
29
33
  };
30
34
 
31
35
  export interface State {
32
36
  connected: boolean;
33
37
  connecting: boolean;
38
+ /**
39
+ * @depreacted it always returns `false`. don't use it.
40
+ */
34
41
  reachable: boolean;
35
42
  installed: boolean;
36
43
  accounts: string[] | null;
@@ -57,6 +64,7 @@ class Wallet<InstanceType = any> {
57
64
  this.info = {
58
65
  supportedBlockchains: [],
59
66
  isContractWallet: false,
67
+ isHub: false,
60
68
  };
61
69
  this.state = {
62
70
  connected: false,
@@ -264,26 +272,30 @@ class Wallet<InstanceType = any> {
264
272
  }
265
273
 
266
274
  // This method is only used for auto connection
267
- async eagerConnect() {
275
+ async eagerConnect(): Promise<EagerConnectResult<InstanceType>> {
268
276
  const instance = await this.tryGetInstance({ network: undefined });
269
277
  const { canEagerConnect } = this.actions;
270
- const error_message = `can't restore connection for ${this.options.config.type} .`;
278
+ const providerName = this.options.config.type;
271
279
 
272
- if (canEagerConnect) {
273
- // Check if we can eagerly connect to the wallet
274
- const eagerConnection = await canEagerConnect({
275
- instance: instance,
276
- meta: this.info.supportedBlockchains,
277
- });
280
+ return await eagerConnectHandler({
281
+ canEagerConnect: async () => {
282
+ if (!canEagerConnect) {
283
+ throw new Error(
284
+ `${providerName} provider hasn't implemented canEagerConnect.`
285
+ );
286
+ }
278
287
 
279
- if (eagerConnection) {
280
- // Connect to wallet as usual
281
- return this.connect();
282
- }
283
- throw new Error(error_message);
284
- } else {
285
- throw new Error(error_message);
286
- }
288
+ return await canEagerConnect({
289
+ instance: instance,
290
+ meta: this.info.supportedBlockchains,
291
+ });
292
+ },
293
+ connectHandler: async () => {
294
+ const result = await this.connect();
295
+ return result;
296
+ },
297
+ providerName,
298
+ });
287
299
  }
288
300
 
289
301
  async getSigners(provider: any) {
@@ -408,6 +420,7 @@ class Wallet<InstanceType = any> {
408
420
  const eventInfo: EventInfo = {
409
421
  supportedBlockchains: this.info.supportedBlockchains,
410
422
  isContractWallet: this.info.isContractWallet,
423
+ isHub: false,
411
424
  };
412
425
  this.options.handler(
413
426
  this.options.config.type,
package/src/mod.ts CHANGED
@@ -1,4 +1,10 @@
1
- export type { Store, State, ProviderInfo } from './hub/mod.js';
1
+ export type {
2
+ Store,
3
+ State,
4
+ ProviderInfo,
5
+ CommonNamespaces,
6
+ CommonNamespaceKeys,
7
+ } from './hub/mod.js';
2
8
  export {
3
9
  Hub,
4
10
  Provider,
@@ -7,10 +13,8 @@ export {
7
13
  guessProviderStateSelector,
8
14
  namespaceStateSelector,
9
15
  } from './hub/mod.js';
10
- export type {
11
- ProxiedNamespace,
12
- FindProxiedNamespace as NamespaceInterface,
13
- } from './builders/mod.js';
16
+
17
+ export type { ProxiedNamespace, FindProxiedNamespace } from './builders/mod.js';
14
18
  export {
15
19
  NamespaceBuilder,
16
20
  ProviderBuilder,
@@ -31,5 +35,5 @@ export {
31
35
  * To make it work for Parcel, we should go with second mentioned option.
32
36
  *
33
37
  */
34
- export type { Versions } from './utils/mod.js';
38
+ export type { VersionedProviders } from './utils/mod.js';
35
39
  export { defineVersions, pickVersion } from './utils/mod.js';
@@ -10,3 +10,9 @@ export {
10
10
  recommended as andRecommended,
11
11
  } from './and.js';
12
12
  export { intoConnecting, recommended as beforeRecommended } from './before.js';
13
+
14
+ export type {
15
+ CaipAccount,
16
+ Accounts,
17
+ AccountsWithActiveChain,
18
+ } from '../../types/accounts.js';
@@ -7,4 +7,5 @@ export interface CosmosActions
7
7
  extends AutoImplementedActionsByRecommended,
8
8
  CommonActions {
9
9
  // TODO
10
+ connect: () => Promise<string>;
10
11
  }
@@ -1,22 +1,21 @@
1
1
  import type { Provider } from '../hub/mod.js';
2
2
  import type { LegacyProviderInterface } from '../legacy/mod.js';
3
3
 
4
- type VersionedVLegacy = ['0.0.0', LegacyProviderInterface];
5
- type VersionedV1 = ['1.0.0', Provider];
6
- type AvailableVersions = VersionedVLegacy | VersionedV1;
7
- export type Versions = AvailableVersions[];
8
- // eslint-disable-next-line @typescript-eslint/no-magic-numbers
9
- export type VersionInterface<T extends AvailableVersions[]> = T[1];
4
+ type LegacyVersioned = ['0.0.0', LegacyProviderInterface];
5
+ type HubVersioned = ['1.0.0', Provider];
6
+ type AvailableVersionedProviders = LegacyVersioned | HubVersioned;
7
+ export type VersionedProviders = AvailableVersionedProviders[];
8
+ export type VersionInterface<T extends AvailableVersionedProviders[]> = T[1];
10
9
 
11
10
  type SemVer<T extends [string, any]> = T extends [infer U, any] ? U : never;
12
- type MatchVersion<T extends Versions, Version> = Extract<
11
+ type MatchVersion<T extends VersionedProviders, Version> = Extract<
13
12
  T[number],
14
13
  [Version, any]
15
14
  >;
16
15
 
17
16
  export function pickVersion<
18
- L extends Versions,
19
- V extends SemVer<Versions[number]>
17
+ L extends VersionedProviders,
18
+ V extends SemVer<VersionedProviders[number]>
20
19
  >(list: L, targetVersion: V): MatchVersion<L, V> {
21
20
  if (!targetVersion) {
22
21
  throw new Error(`You should provide a valid semver, e.g 1.0.0.`);
@@ -35,15 +34,15 @@ export function pickVersion<
35
34
  }
36
35
 
37
36
  interface DefineVersionsApi {
38
- version: <T extends SemVer<Versions[number]>>(
37
+ version: <T extends SemVer<VersionedProviders[number]>>(
39
38
  semver: T,
40
- value: VersionInterface<MatchVersion<Versions, T>>
39
+ value: VersionInterface<MatchVersion<VersionedProviders, T>>
41
40
  ) => DefineVersionsApi;
42
- build: () => Versions;
41
+ build: () => VersionedProviders;
43
42
  }
44
43
 
45
44
  export function defineVersions(): DefineVersionsApi {
46
- const versions: Versions = [];
45
+ const versions: VersionedProviders = [];
47
46
  const api: DefineVersionsApi = {
48
47
  version: (semver, value) => {
49
48
  versions.push([semver, value]);
@@ -58,6 +57,6 @@ export function defineVersions(): DefineVersionsApi {
58
57
 
59
58
  export function legacyProviderImportsToVersionsInterface(
60
59
  provider: LegacyProviderInterface
61
- ): Versions {
60
+ ): VersionedProviders {
62
61
  return defineVersions().version('0.0.0', provider).build();
63
62
  }