@rango-dev/wallets-react 0.27.1-next.13 → 0.27.1-next.2
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/hub/autoConnect.d.ts.map +1 -1
- package/dist/hub/helpers.d.ts +1 -2
- package/dist/hub/helpers.d.ts.map +1 -1
- package/dist/hub/mod.d.ts +1 -1
- package/dist/hub/mod.d.ts.map +1 -1
- package/dist/hub/useHubAdapter.d.ts.map +1 -1
- package/dist/hub/utils.d.ts +5 -5
- package/dist/hub/utils.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +3 -3
- package/dist/legacy/autoConnect.d.ts.map +1 -1
- package/dist/legacy/types.d.ts +24 -17
- package/dist/legacy/types.d.ts.map +1 -1
- package/dist/useProviders.d.ts.map +1 -1
- package/dist/wallets-react.build.json +1 -1
- package/package.json +8 -14
- package/src/hub/autoConnect.ts +35 -62
- package/src/hub/helpers.ts +9 -14
- package/src/hub/mod.ts +1 -5
- package/src/hub/useHubAdapter.ts +46 -79
- package/src/hub/utils.ts +158 -155
- package/src/index.ts +1 -0
- package/src/legacy/autoConnect.ts +24 -12
- package/src/legacy/types.ts +25 -25
- package/src/useProviders.ts +6 -2
- package/dist/helpers/index.d.ts +0 -2
- package/dist/helpers/index.d.ts.map +0 -1
- package/dist/helpers/index.js +0 -2
- package/dist/helpers/index.js.map +0 -7
- package/helpers/package.json +0 -8
- package/src/helpers/index.ts +0 -1
package/src/hub/utils.ts
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import type { AllProxiedNamespaces } from './types.js';
|
|
2
|
-
import type { Hub, Provider } from '@rango-dev/wallets-core';
|
|
2
|
+
import type { Hub, Provider, State } from '@rango-dev/wallets-core';
|
|
3
3
|
import type {
|
|
4
4
|
LegacyNamespaceInputForConnect,
|
|
5
5
|
LegacyProviderInterface,
|
|
6
6
|
LegacyEventHandler as WalletEventHandler,
|
|
7
7
|
} from '@rango-dev/wallets-core/legacy';
|
|
8
|
-
import type { Event } from '@rango-dev/wallets-core/store';
|
|
9
8
|
|
|
9
|
+
import {
|
|
10
|
+
guessProviderStateSelector,
|
|
11
|
+
namespaceStateSelector,
|
|
12
|
+
} from '@rango-dev/wallets-core';
|
|
10
13
|
import { LegacyEvents as Events } from '@rango-dev/wallets-core/legacy';
|
|
11
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
generateStoreId,
|
|
16
|
+
type VersionedProviders,
|
|
17
|
+
} from '@rango-dev/wallets-core/utils';
|
|
12
18
|
import { pickVersion } from '@rango-dev/wallets-core/utils';
|
|
13
19
|
import {
|
|
14
20
|
type AddEthereumChainParameter,
|
|
@@ -31,25 +37,34 @@ import { LastConnectedWalletsFromStorage } from './lastConnectedWallets.js';
|
|
|
31
37
|
|
|
32
38
|
/* Gets a list of hub and legacy providers and returns a tuple which separates them. */
|
|
33
39
|
export function separateLegacyAndHubProviders(
|
|
34
|
-
providers: VersionedProviders[]
|
|
40
|
+
providers: VersionedProviders[],
|
|
41
|
+
options?: { isExperimentalEnabled?: boolean }
|
|
35
42
|
): [LegacyProviderInterface[], Provider[]] {
|
|
36
43
|
const LEGACY_VERSION = '0.0.0';
|
|
37
44
|
const HUB_VERSION = '1.0.0';
|
|
45
|
+
const { isExperimentalEnabled = false } = options || {};
|
|
46
|
+
|
|
47
|
+
if (isExperimentalEnabled) {
|
|
48
|
+
const legacyProviders: LegacyProviderInterface[] = [];
|
|
49
|
+
const hubProviders: Provider[] = [];
|
|
50
|
+
|
|
51
|
+
providers.forEach((provider) => {
|
|
52
|
+
try {
|
|
53
|
+
const target = pickVersion(provider, HUB_VERSION);
|
|
54
|
+
hubProviders.push(target[1]);
|
|
55
|
+
} catch {
|
|
56
|
+
const target = pickVersion(provider, LEGACY_VERSION);
|
|
57
|
+
legacyProviders.push(target[1]);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
38
60
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
providers.forEach((provider) => {
|
|
43
|
-
try {
|
|
44
|
-
const target = pickVersion(provider, HUB_VERSION);
|
|
45
|
-
hubProviders.push(target[1]);
|
|
46
|
-
} catch {
|
|
47
|
-
const target = pickVersion(provider, LEGACY_VERSION);
|
|
48
|
-
legacyProviders.push(target[1]);
|
|
49
|
-
}
|
|
50
|
-
});
|
|
61
|
+
return [legacyProviders, hubProviders];
|
|
62
|
+
}
|
|
51
63
|
|
|
52
|
-
|
|
64
|
+
const legacyProviders = providers.map(
|
|
65
|
+
(provider) => pickVersion(provider, LEGACY_VERSION)[1]
|
|
66
|
+
);
|
|
67
|
+
return [legacyProviders, []];
|
|
53
68
|
}
|
|
54
69
|
|
|
55
70
|
export function findProviderByType(
|
|
@@ -68,188 +83,176 @@ const lastConnectedWalletsFromStorage = new LastConnectedWalletsFromStorage(
|
|
|
68
83
|
HUB_LAST_CONNECTED_WALLETS
|
|
69
84
|
);
|
|
70
85
|
|
|
71
|
-
export function
|
|
86
|
+
export function checkHubStateAndTriggerEvents(
|
|
72
87
|
hub: Hub,
|
|
73
|
-
|
|
88
|
+
currentState: State,
|
|
89
|
+
previousState: State,
|
|
74
90
|
onUpdateState: WalletEventHandler,
|
|
75
91
|
allProviders: VersionedProviders[],
|
|
76
92
|
allBlockChains: ProviderProps['allBlockChains']
|
|
77
93
|
): void {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
94
|
+
hub.getAll().forEach((provider, providerId) => {
|
|
95
|
+
const currentProviderState = guessProviderStateSelector(
|
|
96
|
+
currentState,
|
|
97
|
+
providerId
|
|
98
|
+
);
|
|
99
|
+
const previousProviderState = guessProviderStateSelector(
|
|
100
|
+
previousState,
|
|
101
|
+
providerId
|
|
85
102
|
);
|
|
86
|
-
}
|
|
87
103
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
104
|
+
let accounts: string[] | null = [];
|
|
105
|
+
/*
|
|
106
|
+
* We don't rely `accounts` to make sure we will trigger proper event on this case:
|
|
107
|
+
* previous value: [0x...]
|
|
108
|
+
* current value: []
|
|
109
|
+
*/
|
|
110
|
+
let hasAccountChanged = false;
|
|
111
|
+
let hasNetworkChanged = false;
|
|
112
|
+
let hasProviderDisconnected = false;
|
|
113
|
+
// It will pick the last network from namespaces.
|
|
114
|
+
let maybeNetwork = null;
|
|
115
|
+
const disconnectedNamespacesIds: string[] = [];
|
|
116
|
+
|
|
117
|
+
provider.getAll().forEach((namespace) => {
|
|
118
|
+
const storeId = generateStoreId(providerId, namespace.namespaceId);
|
|
119
|
+
const currentNamespaceState = namespaceStateSelector(
|
|
120
|
+
currentState,
|
|
121
|
+
storeId
|
|
122
|
+
);
|
|
123
|
+
const previousNamespaceState = namespaceStateSelector(
|
|
124
|
+
previousState,
|
|
125
|
+
storeId
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
if (currentNamespaceState.network !== null) {
|
|
129
|
+
maybeNetwork = currentNamespaceState.network;
|
|
94
130
|
}
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
131
|
|
|
98
|
-
|
|
99
|
-
|
|
132
|
+
// Check for network
|
|
133
|
+
if (currentNamespaceState.network !== previousNamespaceState.network) {
|
|
134
|
+
hasNetworkChanged = true;
|
|
135
|
+
}
|
|
100
136
|
|
|
101
|
-
|
|
102
|
-
? provider.findByNamespace(namespaceId)
|
|
103
|
-
: undefined;
|
|
104
|
-
let accounts: string[] | null = null;
|
|
105
|
-
let network: string | null = null;
|
|
137
|
+
// TODO: `accounts` has been frozen, we should check and find where object.freeze() is calling.
|
|
106
138
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
139
|
+
// Check for accounts
|
|
140
|
+
if (
|
|
141
|
+
previousNamespaceState.accounts?.slice().sort().toString() !==
|
|
142
|
+
currentNamespaceState.accounts?.slice().sort().toString()
|
|
143
|
+
) {
|
|
144
|
+
if (currentNamespaceState.accounts) {
|
|
145
|
+
const formattedAddresses = currentNamespaceState.accounts.map(
|
|
146
|
+
fromAccountIdToLegacyAddressFormat
|
|
147
|
+
);
|
|
112
148
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
accounts,
|
|
119
|
-
network,
|
|
120
|
-
reachable: true,
|
|
121
|
-
};
|
|
149
|
+
if (accounts) {
|
|
150
|
+
accounts = [...accounts, ...formattedAddresses];
|
|
151
|
+
} else {
|
|
152
|
+
accounts = [...formattedAddresses];
|
|
153
|
+
}
|
|
122
154
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
155
|
+
hasAccountChanged = true;
|
|
156
|
+
} else {
|
|
157
|
+
// Namespace has been disconnected
|
|
158
|
+
disconnectedNamespacesIds.push(namespace.namespaceId);
|
|
159
|
+
accounts = null;
|
|
160
|
+
hasProviderDisconnected = true;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
if (disconnectedNamespacesIds.length > 0) {
|
|
166
|
+
lastConnectedWalletsFromStorage.removeNamespacesFromWallet(
|
|
167
|
+
providerId,
|
|
168
|
+
disconnectedNamespacesIds
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
let legacyProvider;
|
|
173
|
+
try {
|
|
174
|
+
legacyProvider = getLegacyProvider(allProviders, providerId);
|
|
175
|
+
} catch (e) {
|
|
176
|
+
console.warn(
|
|
177
|
+
'Having legacy provider is required for including some information like supported chain. ',
|
|
178
|
+
e
|
|
179
|
+
);
|
|
180
|
+
}
|
|
130
181
|
|
|
131
|
-
|
|
132
|
-
|
|
182
|
+
const coreState = {
|
|
183
|
+
connected: currentProviderState.connected,
|
|
184
|
+
connecting: currentProviderState.connecting,
|
|
185
|
+
installed: currentProviderState.installed,
|
|
186
|
+
accounts: accounts,
|
|
187
|
+
network: maybeNetwork,
|
|
188
|
+
reachable: true,
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const eventInfo = {
|
|
192
|
+
supportedBlockchains:
|
|
193
|
+
legacyProvider?.getWalletInfo(allBlockChains || []).supportedChains ||
|
|
194
|
+
[],
|
|
195
|
+
isContractWallet: false,
|
|
196
|
+
isHub: true,
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
if (previousProviderState.installed !== currentProviderState.installed) {
|
|
133
200
|
onUpdateState(
|
|
134
|
-
|
|
201
|
+
providerId,
|
|
135
202
|
Events.INSTALLED,
|
|
136
|
-
|
|
203
|
+
currentProviderState.installed,
|
|
137
204
|
coreState,
|
|
138
205
|
eventInfo
|
|
139
206
|
);
|
|
140
|
-
|
|
141
|
-
|
|
207
|
+
}
|
|
208
|
+
if (previousProviderState.connecting !== currentProviderState.connecting) {
|
|
142
209
|
onUpdateState(
|
|
143
|
-
|
|
210
|
+
providerId,
|
|
144
211
|
Events.CONNECTING,
|
|
145
|
-
|
|
212
|
+
currentProviderState.connecting,
|
|
146
213
|
coreState,
|
|
147
214
|
eventInfo
|
|
148
215
|
);
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
onUpdateState(
|
|
152
|
-
event.provider,
|
|
153
|
-
Events.CONNECTED,
|
|
154
|
-
true,
|
|
155
|
-
coreState,
|
|
156
|
-
eventInfo
|
|
157
|
-
);
|
|
158
|
-
break;
|
|
159
|
-
case 'provider_disconnected':
|
|
216
|
+
}
|
|
217
|
+
if (previousProviderState.connected !== currentProviderState.connected) {
|
|
160
218
|
onUpdateState(
|
|
161
|
-
|
|
219
|
+
providerId,
|
|
162
220
|
Events.CONNECTED,
|
|
163
|
-
|
|
221
|
+
currentProviderState.connected,
|
|
164
222
|
coreState,
|
|
165
223
|
eventInfo
|
|
166
224
|
);
|
|
225
|
+
}
|
|
226
|
+
if (hasAccountChanged) {
|
|
167
227
|
onUpdateState(
|
|
168
|
-
|
|
228
|
+
providerId,
|
|
169
229
|
Events.ACCOUNTS,
|
|
170
|
-
|
|
230
|
+
accounts,
|
|
171
231
|
coreState,
|
|
172
232
|
eventInfo
|
|
173
233
|
);
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
);
|
|
180
|
-
|
|
234
|
+
}
|
|
235
|
+
if (hasProviderDisconnected) {
|
|
236
|
+
onUpdateState(providerId, Events.ACCOUNTS, null, coreState, eventInfo);
|
|
237
|
+
}
|
|
238
|
+
if (hasNetworkChanged) {
|
|
181
239
|
onUpdateState(
|
|
182
|
-
|
|
183
|
-
Events.
|
|
184
|
-
|
|
240
|
+
providerId,
|
|
241
|
+
Events.NETWORK,
|
|
242
|
+
maybeNetwork,
|
|
185
243
|
coreState,
|
|
186
|
-
|
|
187
|
-
...eventInfo,
|
|
188
|
-
namespace: event.namespace,
|
|
189
|
-
}
|
|
244
|
+
eventInfo
|
|
190
245
|
);
|
|
191
|
-
|
|
192
|
-
break;
|
|
193
|
-
case 'namespace_connected':
|
|
194
|
-
case 'namespace_account_switched':
|
|
195
|
-
{
|
|
196
|
-
if (event.type === 'namespace_account_switched') {
|
|
197
|
-
onUpdateState(
|
|
198
|
-
event.provider,
|
|
199
|
-
Events.NAMESPACE_DISCONNECTED,
|
|
200
|
-
event.namespace,
|
|
201
|
-
coreState,
|
|
202
|
-
eventInfo
|
|
203
|
-
);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const formattedAddresses = event.accounts.map(
|
|
207
|
-
fromAccountIdToLegacyAddressFormat
|
|
208
|
-
);
|
|
209
|
-
onUpdateState(
|
|
210
|
-
event.provider,
|
|
211
|
-
Events.ACCOUNTS,
|
|
212
|
-
formattedAddresses,
|
|
213
|
-
coreState,
|
|
214
|
-
{
|
|
215
|
-
...eventInfo,
|
|
216
|
-
namespace: event.namespace,
|
|
217
|
-
}
|
|
218
|
-
);
|
|
219
|
-
}
|
|
220
|
-
break;
|
|
221
|
-
case 'namespace_network_switched':
|
|
222
|
-
onUpdateState(event.provider, Events.NETWORK, event.network, coreState, {
|
|
223
|
-
...eventInfo,
|
|
224
|
-
namespace: event.namespace,
|
|
225
|
-
});
|
|
226
|
-
break;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
export function getAllLegacyProviders(
|
|
231
|
-
allProviders: VersionedProviders[]
|
|
232
|
-
): LegacyProviderInterface[] {
|
|
233
|
-
const LEGACY_VERSION = '0.0.0';
|
|
234
|
-
|
|
235
|
-
const legacyProviders: LegacyProviderInterface[] = [];
|
|
236
|
-
|
|
237
|
-
allProviders.forEach((provider) => {
|
|
238
|
-
const target = pickVersion(provider, LEGACY_VERSION);
|
|
239
|
-
legacyProviders.push(target[1]);
|
|
246
|
+
}
|
|
240
247
|
});
|
|
241
|
-
|
|
242
|
-
return legacyProviders;
|
|
243
248
|
}
|
|
244
249
|
|
|
245
250
|
export function getLegacyProvider(
|
|
246
251
|
allProviders: VersionedProviders[],
|
|
247
252
|
type: string
|
|
248
253
|
): LegacyProviderInterface {
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
const provider = legacyProviders.find((legacyProvider) => {
|
|
254
|
+
const [legacy] = separateLegacyAndHubProviders(allProviders);
|
|
255
|
+
const provider = legacy.find((legacyProvider) => {
|
|
253
256
|
return legacyProvider.config.type === type;
|
|
254
257
|
});
|
|
255
258
|
|
package/src/index.ts
CHANGED
|
@@ -46,21 +46,33 @@ export async function autoConnect(
|
|
|
46
46
|
eagerConnectQueue.map(async ({ eagerConnect }) => eagerConnect())
|
|
47
47
|
);
|
|
48
48
|
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
const canRestoreAnyConnection = !!result.find(
|
|
50
|
+
({ status }) => status === 'fulfilled'
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
/*
|
|
54
|
+
*After successfully connecting to at least one wallet,
|
|
55
|
+
*we will removing the other wallets from persistence.
|
|
56
|
+
*If we are unable to connect to any wallet,
|
|
57
|
+
*the persistence will not be removed and the eager connection will be retried with another page load.
|
|
58
|
+
*/
|
|
59
|
+
if (canRestoreAnyConnection) {
|
|
60
|
+
const walletsToRemoveFromPersistance: WalletType[] = [];
|
|
61
|
+
result.forEach((settleResult, index) => {
|
|
62
|
+
const { status } = settleResult;
|
|
63
|
+
|
|
64
|
+
if (status === 'rejected') {
|
|
65
|
+
walletsToRemoveFromPersistance.push(
|
|
66
|
+
eagerConnectQueue[index].walletType
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
52
70
|
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
|
|
71
|
+
if (walletsToRemoveFromPersistance.length) {
|
|
72
|
+
lastConnectedWalletsFromStorage.removeWallets(
|
|
73
|
+
walletsToRemoveFromPersistance
|
|
56
74
|
);
|
|
57
75
|
}
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
if (walletsToRemoveFromPersistance.length) {
|
|
61
|
-
lastConnectedWalletsFromStorage.removeWallets(
|
|
62
|
-
walletsToRemoveFromPersistance
|
|
63
|
-
);
|
|
64
76
|
}
|
|
65
77
|
}
|
|
66
78
|
}
|
package/src/legacy/types.ts
CHANGED
|
@@ -11,11 +11,6 @@ import type {
|
|
|
11
11
|
import type { BlockchainMeta, SignerFactory } from 'rango-types';
|
|
12
12
|
import type { PropsWithChildren } from 'react';
|
|
13
13
|
|
|
14
|
-
import { LegacyEvents as Events } from '@rango-dev/wallets-core/legacy';
|
|
15
|
-
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
-
type InstanceType = any;
|
|
18
|
-
|
|
19
14
|
export type State = {
|
|
20
15
|
[key: string]: WalletState | undefined;
|
|
21
16
|
};
|
|
@@ -23,10 +18,10 @@ export type State = {
|
|
|
23
18
|
export type ConnectResult = {
|
|
24
19
|
accounts: string[] | null;
|
|
25
20
|
network: Network | null;
|
|
26
|
-
provider:
|
|
21
|
+
provider: any;
|
|
27
22
|
};
|
|
28
23
|
|
|
29
|
-
export type Providers = { [type in WalletType]?:
|
|
24
|
+
export type Providers = { [type in WalletType]?: any };
|
|
30
25
|
|
|
31
26
|
export type ExtendedWalletInfo = WalletInfo & {
|
|
32
27
|
properties?: ProviderInfo['properties'];
|
|
@@ -39,7 +34,6 @@ export type ProviderContext = {
|
|
|
39
34
|
namespaces?: LegacyNamespaceInputForConnect[]
|
|
40
35
|
): Promise<ConnectResult[]>;
|
|
41
36
|
disconnect(type: WalletType): Promise<void>;
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
37
|
disconnectAll(): Promise<PromiseSettledResult<any>[]>;
|
|
44
38
|
state(type: WalletType): WalletState;
|
|
45
39
|
canSwitchNetworkTo(type: WalletType, network: Network): boolean;
|
|
@@ -62,11 +56,19 @@ export type ProviderProps = PropsWithChildren<{
|
|
|
62
56
|
autoConnect?: boolean;
|
|
63
57
|
providers: VersionedProviders[];
|
|
64
58
|
configs?: {
|
|
59
|
+
isExperimentalEnabled?: boolean;
|
|
65
60
|
wallets?: (WalletType | LegacyProviderInterface)[];
|
|
66
61
|
};
|
|
67
62
|
}>;
|
|
68
63
|
|
|
69
|
-
export
|
|
64
|
+
export enum Events {
|
|
65
|
+
CONNECTED = 'connected',
|
|
66
|
+
CONNECTING = 'connecting',
|
|
67
|
+
REACHABLE = 'reachable',
|
|
68
|
+
INSTALLED = 'installed',
|
|
69
|
+
ACCOUNTS = 'accounts',
|
|
70
|
+
NETWORK = 'network',
|
|
71
|
+
}
|
|
70
72
|
|
|
71
73
|
export type ProviderConnectResult = {
|
|
72
74
|
accounts: string[];
|
|
@@ -75,7 +77,7 @@ export type ProviderConnectResult = {
|
|
|
75
77
|
|
|
76
78
|
export type GetInstanceOptions = {
|
|
77
79
|
network?: Network;
|
|
78
|
-
currentProvider:
|
|
80
|
+
currentProvider: any;
|
|
79
81
|
meta: BlockchainMeta[];
|
|
80
82
|
getState: () => WalletState;
|
|
81
83
|
/**
|
|
@@ -89,28 +91,26 @@ export type GetInstanceOptions = {
|
|
|
89
91
|
};
|
|
90
92
|
|
|
91
93
|
export type GetInstance =
|
|
92
|
-
| (() =>
|
|
93
|
-
| ((options: GetInstanceOptions) => Promise<
|
|
94
|
+
| (() => any)
|
|
95
|
+
| ((options: GetInstanceOptions) => Promise<any>);
|
|
94
96
|
export type TryGetInstance =
|
|
95
|
-
| (() =>
|
|
96
|
-
| ((
|
|
97
|
-
options: Pick<GetInstanceOptions, 'force' | 'network'>
|
|
98
|
-
) => Promise<InstanceType>);
|
|
97
|
+
| (() => any)
|
|
98
|
+
| ((options: Pick<GetInstanceOptions, 'force' | 'network'>) => Promise<any>);
|
|
99
99
|
export type Connect = (options: {
|
|
100
|
-
instance:
|
|
100
|
+
instance: any;
|
|
101
101
|
network?: Network;
|
|
102
102
|
meta: BlockchainMeta[];
|
|
103
103
|
}) => Promise<ProviderConnectResult | ProviderConnectResult[]>;
|
|
104
104
|
|
|
105
105
|
export type Disconnect = (options: {
|
|
106
|
-
instance:
|
|
106
|
+
instance: any;
|
|
107
107
|
destroyInstance: () => void;
|
|
108
108
|
}) => Promise<void>;
|
|
109
109
|
|
|
110
110
|
type CleanupSubscribe = () => void;
|
|
111
111
|
|
|
112
112
|
export type Subscribe = (options: {
|
|
113
|
-
instance:
|
|
113
|
+
instance: any;
|
|
114
114
|
state: WalletState;
|
|
115
115
|
meta: BlockchainMeta[];
|
|
116
116
|
updateChainId: (chainId: string) => void;
|
|
@@ -120,7 +120,7 @@ export type Subscribe = (options: {
|
|
|
120
120
|
}) => CleanupSubscribe | void;
|
|
121
121
|
|
|
122
122
|
export type SwitchNetwork = (options: {
|
|
123
|
-
instance:
|
|
123
|
+
instance: any;
|
|
124
124
|
network: Network;
|
|
125
125
|
meta: BlockchainMeta[];
|
|
126
126
|
newInstance?: TryGetInstance;
|
|
@@ -129,7 +129,7 @@ export type SwitchNetwork = (options: {
|
|
|
129
129
|
}) => Promise<void>;
|
|
130
130
|
|
|
131
131
|
export type Suggest = (options: {
|
|
132
|
-
instance:
|
|
132
|
+
instance: any;
|
|
133
133
|
network: Network;
|
|
134
134
|
meta: BlockchainMeta[];
|
|
135
135
|
}) => Promise<void>;
|
|
@@ -137,17 +137,17 @@ export type Suggest = (options: {
|
|
|
137
137
|
export type CanSwitchNetwork = (options: {
|
|
138
138
|
network: Network;
|
|
139
139
|
meta: BlockchainMeta[];
|
|
140
|
-
provider:
|
|
140
|
+
provider: any;
|
|
141
141
|
}) => boolean;
|
|
142
142
|
|
|
143
143
|
export type CanEagerConnect = (options: {
|
|
144
|
-
instance:
|
|
144
|
+
instance: any;
|
|
145
145
|
meta: BlockchainMeta[];
|
|
146
146
|
}) => Promise<boolean>;
|
|
147
147
|
|
|
148
148
|
export interface WalletActions {
|
|
149
149
|
connect: Connect;
|
|
150
|
-
getInstance:
|
|
150
|
+
getInstance: any;
|
|
151
151
|
disconnect?: Disconnect;
|
|
152
152
|
subscribe?: Subscribe;
|
|
153
153
|
// unsubscribe, // coupled to subscribe.
|
|
@@ -155,7 +155,7 @@ export interface WalletActions {
|
|
|
155
155
|
// Optional, but should be provided at the same time.
|
|
156
156
|
suggest?: Suggest;
|
|
157
157
|
switchNetwork?: SwitchNetwork;
|
|
158
|
-
getSigners: (provider:
|
|
158
|
+
getSigners: (provider: any) => Promise<SignerFactory>;
|
|
159
159
|
canSwitchNetworkTo?: CanSwitchNetwork;
|
|
160
160
|
canEagerConnect?: CanEagerConnect;
|
|
161
161
|
getWalletInfo(allBlockChains: BlockchainMeta[]): WalletInfo;
|
package/src/useProviders.ts
CHANGED
|
@@ -22,8 +22,12 @@ import { useLegacyProviders } from './legacy/mod.js';
|
|
|
22
22
|
*/
|
|
23
23
|
function useProviders(props: ProviderProps) {
|
|
24
24
|
const { providers, ...restProps } = props;
|
|
25
|
-
const [legacyProviders, hubProviders] =
|
|
26
|
-
|
|
25
|
+
const [legacyProviders, hubProviders] = separateLegacyAndHubProviders(
|
|
26
|
+
providers,
|
|
27
|
+
{
|
|
28
|
+
isExperimentalEnabled: restProps.configs?.isExperimentalEnabled,
|
|
29
|
+
}
|
|
30
|
+
);
|
|
27
31
|
|
|
28
32
|
const legacyApi = useLegacyProviders({
|
|
29
33
|
...restProps,
|
package/dist/helpers/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/helpers/index.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var g=Object.defineProperty;var o=(d,e)=>g(d,"name",{value:e,configurable:!0});import{LegacyEvents as je}from"@rango-dev/wallets-core/legacy";import"@rango-dev/wallets-core/utils";import{pickVersion as C}from"@rango-dev/wallets-core/utils";import{convertEvmBlockchainMetaToEvmChainInfo as qe}from"@rango-dev/wallets-shared";import{isEvmBlockchain as Me}from"rango-types";var s="last-connected-wallets",n="hub-v1-last-connected-wallets";import{createContext as w}from"react";var c="Context hasn't been initialized yet.",h={async connect(){throw new Error(c)},async disconnect(){throw new Error(c)},async disconnectAll(){throw new Error(c)},async suggestAndConnect(){throw new Error(c)},state(){throw new Error(c)},canSwitchNetworkTo(){throw new Error(c)},providers(){throw new Error(c)},getWalletInfo(){throw new Error(c)},getSigners(){throw new Error(c)}},u=w(h);import{useEffect as we,useReducer as he}from"react";import{Persistor as i}from"@rango-dev/wallets-core/legacy";var l=class{static{o(this,"LastConnectedWalletsFromStorage")}#e;constructor(e){this.#e=e}addWallet(e,t){if(this.#e===n)return this.#t(e,t);if(this.#e===s)return this.#a(e);throw new Error("Not implemented")}removeWallets(e){if(this.#e===n)return this.#r(e);if(this.#e===s)return this.#c(e);throw new Error("Not implemented")}list(){if(this.#e===n)return this.#n();if(this.#e===s)return this.#o();throw new Error("Not implemented")}removeNamespacesFromWallet(e,t){if(this.#e===n)return this.#s(e,t);throw new Error("Not implemented")}#o(){let t=new i().getItem(s)||[],r={};return t.forEach(a=>{r[a]=[]}),r}#n(){return new i().getItem(n)||{}}#t(e,t){let r=new i,a=r.getItem(this.#e)||{};r.setItem(this.#e,{...a,[e]:t})}#a(e){let t=new i,r=t.getItem(this.#e)||[];t.setItem(s,r.concat(e))}#r(e){let t=new i,r=t.getItem(this.#e)||{};if(!e){t.setItem(this.#e,{});return}e.forEach(a=>{r[a]&&delete r[a]}),t.setItem(this.#e,r)}#s(e,t){let m=(new i().getItem(this.#e)||{})[e].filter(f=>!t.includes(f.namespace));this.#r([e]),this.#t(e,m)}#c(e){let t=new i,r=t.getItem(this.#e)||[];if(!e){t.setItem(this.#e,[]);return}t.setItem(s,r.filter(a=>!e.includes(a)))}};import{Persistor as B}from"@rango-dev/wallets-core/legacy";import{LegacyWallet as Y}from"@rango-dev/wallets-core/legacy";import{useContext as $,useRef as q}from"react";import{useEffect as Z,useRef as ee}from"react";import{legacyFormatAddressWithNetwork as Te}from"@rango-dev/wallets-core/legacy";import{CAIP as be}from"@rango-dev/wallets-core/utils";import{Err as _e,Ok as Re}from"ts-results";var Je=new l(n);function p(d){let e="0.0.0",t=[];return d.forEach(r=>{let a=C(r,e);t.push(a[1])}),t}o(p,"getAllLegacyProviders");import"@rango-dev/wallets-shared";import{useEffect as Tt,useRef as xt,useState as bt}from"react";import{Ok as _t,Result as Rt}from"ts-results";import{legacyEagerConnectHandler as rt,legacyIsEvmNamespace as ot}from"@rango-dev/wallets-core/legacy";import{Result as at}from"ts-results";var dt=new l(n);import{createStore as gt,Hub as wt}from"@rango-dev/wallets-core";import{useRef as yt}from"react";export{p as getAllLegacyProviders};
|
|
2
|
-
//# sourceMappingURL=index.js.map
|