@rango-dev/wallets-core 0.40.0 → 0.40.1-next.1
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/CHANGELOG.md +4 -0
- package/dist/hub/hub.d.ts.map +1 -1
- package/dist/hub/mod.d.ts +1 -0
- package/dist/hub/mod.d.ts.map +1 -1
- package/dist/hub/namespaces/namespace.d.ts.map +1 -1
- package/dist/hub/provider/mod.d.ts +1 -1
- package/dist/hub/provider/mod.d.ts.map +1 -1
- package/dist/hub/provider/types.d.ts +5 -2
- package/dist/hub/provider/types.d.ts.map +1 -1
- package/dist/hub/store/providers.d.ts +3 -3
- package/dist/hub/store/providers.d.ts.map +1 -1
- package/dist/legacy/mod.d.ts +3 -2
- package/dist/legacy/mod.d.ts.map +1 -1
- package/dist/legacy/mod.js +1 -1
- package/dist/legacy/mod.js.map +4 -4
- package/dist/legacy/types.d.ts +28 -0
- package/dist/legacy/types.d.ts.map +1 -1
- package/dist/legacy/utils.d.ts +10 -0
- package/dist/legacy/utils.d.ts.map +1 -0
- package/dist/legacy/wallet.d.ts +6 -6
- package/dist/legacy/wallet.d.ts.map +1 -1
- package/dist/mod.d.ts +3 -3
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +1 -1
- package/dist/mod.js.map +3 -3
- package/dist/namespaces/common/mod.d.ts +1 -0
- package/dist/namespaces/common/mod.d.ts.map +1 -1
- package/dist/namespaces/common/mod.js +1 -1
- package/dist/namespaces/common/mod.js.map +2 -2
- package/dist/namespaces/cosmos/types.d.ts +1 -0
- package/dist/namespaces/cosmos/types.d.ts.map +1 -1
- package/dist/namespaces/evm/actions.d.ts +1 -0
- package/dist/namespaces/evm/actions.d.ts.map +1 -1
- package/dist/namespaces/evm/mod.js +1 -1
- package/dist/namespaces/evm/mod.js.map +3 -3
- package/dist/namespaces/solana/mod.js +1 -1
- package/dist/namespaces/solana/mod.js.map +2 -2
- package/dist/utils/mod.js +1 -1
- package/dist/utils/mod.js.map +2 -2
- package/dist/utils/versions.d.ts +10 -10
- package/dist/utils/versions.d.ts.map +1 -1
- package/dist/wallets-core.build.json +1 -1
- package/package.json +1 -1
- package/src/hub/hub.ts +0 -7
- package/src/hub/mod.ts +3 -0
- package/src/hub/namespaces/namespace.ts +4 -1
- package/src/hub/provider/mod.ts +1 -0
- package/src/hub/provider/types.ts +6 -2
- package/src/hub/store/providers.ts +3 -9
- package/src/legacy/mod.ts +9 -0
- package/src/legacy/types.ts +42 -0
- package/src/legacy/utils.ts +31 -0
- package/src/legacy/wallet.ts +29 -16
- package/src/mod.ts +10 -6
- package/src/namespaces/common/mod.ts +6 -0
- package/src/namespaces/cosmos/types.ts +1 -0
- package/src/namespaces/evm/actions.ts +32 -0
- package/src/utils/versions.ts +13 -14
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
State as InternalProviderState,
|
|
4
|
-
} from '../provider/mod.js';
|
|
1
|
+
import type { State as InternalProviderState } from '../provider/mod.js';
|
|
2
|
+
import type { CommonNamespaceKeys } from '../provider/types.js';
|
|
5
3
|
import type { StateCreator } from 'zustand';
|
|
6
4
|
|
|
7
5
|
import { produce } from 'immer';
|
|
8
6
|
|
|
9
7
|
import { guessProviderStateSelector, type State } from './mod.js';
|
|
10
8
|
|
|
11
|
-
type NamespaceName =
|
|
12
|
-
| keyof CommonNamespaces
|
|
13
|
-
| Omit<string, keyof CommonNamespaces>;
|
|
14
|
-
|
|
15
9
|
type Browsers = 'firefox' | 'chrome' | 'edge' | 'brave' | 'homepage';
|
|
16
10
|
type Property<N extends string, V> = { name: N; value: V };
|
|
17
|
-
type DetachedInstances = Property<'detached',
|
|
11
|
+
type DetachedInstances = Property<'detached', CommonNamespaceKeys[]>;
|
|
18
12
|
|
|
19
13
|
export type ProviderInfo = {
|
|
20
14
|
name: string;
|
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';
|
package/src/legacy/types.ts
CHANGED
|
@@ -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
|
+
}
|
package/src/legacy/wallet.ts
CHANGED
|
@@ -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
|
|
278
|
+
const providerName = this.options.config.type;
|
|
271
279
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
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
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
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 {
|
|
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
|
-
|
|
11
|
-
|
|
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 {
|
|
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';
|
|
@@ -95,3 +95,35 @@ export function changeAccountSubscriber(
|
|
|
95
95
|
},
|
|
96
96
|
];
|
|
97
97
|
}
|
|
98
|
+
|
|
99
|
+
export function changeChainSubscriber(
|
|
100
|
+
instance: () => ProviderAPI
|
|
101
|
+
): [Subscriber<EvmActions>, SubscriberCleanUp<EvmActions>] {
|
|
102
|
+
let eventCallback: EIP1193EventMap['chainChanged'];
|
|
103
|
+
|
|
104
|
+
return [
|
|
105
|
+
(context) => {
|
|
106
|
+
const evmInstance = instance();
|
|
107
|
+
|
|
108
|
+
if (!evmInstance) {
|
|
109
|
+
throw new Error(
|
|
110
|
+
'Trying to subscribe to your EVM wallet, but seems its instance is not available.'
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const [, setState] = context.state();
|
|
115
|
+
|
|
116
|
+
eventCallback = async (chainId: string) => {
|
|
117
|
+
setState('network', chainId);
|
|
118
|
+
};
|
|
119
|
+
evmInstance.on('chainChanged', eventCallback);
|
|
120
|
+
},
|
|
121
|
+
() => {
|
|
122
|
+
const evmInstance = instance();
|
|
123
|
+
|
|
124
|
+
if (eventCallback && evmInstance) {
|
|
125
|
+
evmInstance.removeListener('chainChanged', eventCallback);
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
];
|
|
129
|
+
}
|
package/src/utils/versions.ts
CHANGED
|
@@ -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
|
|
5
|
-
type
|
|
6
|
-
type
|
|
7
|
-
export type
|
|
8
|
-
|
|
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
|
|
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
|
|
19
|
-
V extends SemVer<
|
|
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<
|
|
37
|
+
version: <T extends SemVer<VersionedProviders[number]>>(
|
|
39
38
|
semver: T,
|
|
40
|
-
value: VersionInterface<MatchVersion<
|
|
39
|
+
value: VersionInterface<MatchVersion<VersionedProviders, T>>
|
|
41
40
|
) => DefineVersionsApi;
|
|
42
|
-
build: () =>
|
|
41
|
+
build: () => VersionedProviders;
|
|
43
42
|
}
|
|
44
43
|
|
|
45
44
|
export function defineVersions(): DefineVersionsApi {
|
|
46
|
-
const 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
|
-
):
|
|
60
|
+
): VersionedProviders {
|
|
62
61
|
return defineVersions().version('0.0.0', provider).build();
|
|
63
62
|
}
|