@rango-dev/wallets-react 0.27.0 → 0.27.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.
- package/CHANGELOG.md +4 -0
- package/dist/hub/autoConnect.d.ts +11 -0
- package/dist/hub/autoConnect.d.ts.map +1 -0
- package/dist/hub/constants.d.ts +3 -0
- package/dist/hub/constants.d.ts.map +1 -0
- package/dist/hub/helpers.d.ts +19 -0
- package/dist/hub/helpers.d.ts.map +1 -0
- package/dist/hub/lastConnectedWallets.d.ts +21 -0
- package/dist/hub/lastConnectedWallets.d.ts.map +1 -0
- package/dist/hub/mod.d.ts +3 -0
- package/dist/hub/mod.d.ts.map +1 -0
- package/dist/hub/types.d.ts +4 -0
- package/dist/hub/types.d.ts.map +1 -0
- package/dist/hub/useHubAdapter.d.ts +10 -0
- package/dist/hub/useHubAdapter.d.ts.map +1 -0
- package/dist/hub/useHubRefs.d.ts +7 -0
- package/dist/hub/useHubRefs.d.ts.map +1 -0
- package/dist/hub/utils.d.ts +32 -0
- package/dist/hub/utils.d.ts.map +1 -0
- 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 +4 -4
- package/dist/legacy/autoConnect.d.ts +8 -0
- package/dist/legacy/autoConnect.d.ts.map +1 -0
- package/dist/legacy/helpers.d.ts +2 -6
- package/dist/legacy/helpers.d.ts.map +1 -1
- package/dist/legacy/mod.d.ts +5 -0
- package/dist/legacy/mod.d.ts.map +1 -0
- package/dist/legacy/types.d.ts +13 -4
- package/dist/legacy/types.d.ts.map +1 -1
- package/dist/legacy/useAutoConnect.d.ts +5 -4
- package/dist/legacy/useAutoConnect.d.ts.map +1 -1
- package/dist/legacy/useLegacyProviders.d.ts +5 -1
- package/dist/legacy/useLegacyProviders.d.ts.map +1 -1
- package/dist/legacy/utils.d.ts +3 -0
- package/dist/legacy/utils.d.ts.map +1 -0
- package/dist/test-utils/env.d.ts +7 -0
- package/dist/test-utils/env.d.ts.map +1 -0
- package/dist/test-utils/fixtures.d.ts +14 -0
- package/dist/test-utils/fixtures.d.ts.map +1 -0
- package/dist/useProviders.d.ts +4 -0
- package/dist/useProviders.d.ts.map +1 -0
- package/dist/wallets-react.build.json +1 -1
- package/package.json +14 -6
- package/src/hub/autoConnect.ts +186 -0
- package/src/hub/constants.ts +2 -0
- package/src/hub/helpers.ts +67 -0
- package/src/hub/lastConnectedWallets.ts +124 -0
- package/src/hub/mod.ts +2 -0
- package/src/hub/types.ts +12 -0
- package/src/hub/useHubAdapter.ts +353 -0
- package/src/hub/useHubRefs.ts +53 -0
- package/src/hub/utils.ts +322 -0
- package/src/index.ts +1 -0
- package/src/legacy/autoConnect.ts +78 -0
- package/src/legacy/helpers.ts +17 -92
- package/src/legacy/mod.ts +13 -0
- package/src/legacy/types.ts +16 -6
- package/src/legacy/useAutoConnect.ts +8 -16
- package/src/legacy/useLegacyProviders.ts +23 -6
- package/src/legacy/utils.ts +7 -0
- package/src/provider.tsx +3 -3
- package/src/test-utils/env.ts +10 -0
- package/src/test-utils/fixtures.ts +238 -0
- package/src/useProviders.ts +120 -0
- package/dist/legacy/constants.d.ts +0 -2
- package/dist/legacy/constants.d.ts.map +0 -1
- package/src/legacy/constants.ts +0 -1
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { ProviderContext, ProviderProps } from './types.js';
|
|
2
|
+
import type { LegacyProviderInterface } from '@rango-dev/wallets-core/legacy';
|
|
2
3
|
import type { WalletType } from '@rango-dev/wallets-shared';
|
|
3
4
|
|
|
4
5
|
import { useEffect, useReducer } from 'react';
|
|
5
6
|
|
|
7
|
+
import { autoConnect } from './autoConnect.js';
|
|
6
8
|
import {
|
|
7
9
|
availableWallets,
|
|
8
10
|
checkWalletProviders,
|
|
@@ -17,7 +19,13 @@ import {
|
|
|
17
19
|
import { useInitializers } from './hooks.js';
|
|
18
20
|
import { useAutoConnect } from './useAutoConnect.js';
|
|
19
21
|
|
|
20
|
-
export
|
|
22
|
+
export type LegacyProviderProps = Omit<ProviderProps, 'providers'> & {
|
|
23
|
+
providers: LegacyProviderInterface[];
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export function useLegacyProviders(
|
|
27
|
+
props: LegacyProviderProps
|
|
28
|
+
): ProviderContext {
|
|
21
29
|
const [providersState, dispatch] = useReducer(stateReducer, {});
|
|
22
30
|
|
|
23
31
|
// Get (or add) wallet instance (`provider`s will be wrapped in a `Wallet`)
|
|
@@ -30,20 +38,29 @@ export function useLegacyProviders(props: ProviderProps): ProviderContext {
|
|
|
30
38
|
const wallets = checkWalletProviders(listOfProviders);
|
|
31
39
|
|
|
32
40
|
useAutoConnect({
|
|
33
|
-
wallets,
|
|
34
41
|
allBlockChains: props.allBlockChains,
|
|
35
42
|
autoConnect: props.autoConnect,
|
|
36
|
-
|
|
43
|
+
autoConnectHandler: async () => autoConnect(wallets, getWalletInstance),
|
|
37
44
|
});
|
|
38
45
|
|
|
39
46
|
// 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
47
|
const api: ProviderContext = {
|
|
42
|
-
async connect(type,
|
|
48
|
+
async connect(type, namespaces) {
|
|
43
49
|
const wallet = wallets.get(type);
|
|
44
50
|
if (!wallet) {
|
|
45
51
|
throw new Error(`You should add ${type} to provider first.`);
|
|
46
52
|
}
|
|
53
|
+
|
|
54
|
+
// Legacy providers doesn't implemented multiple namespaces, so it will always be one value.
|
|
55
|
+
let network = undefined;
|
|
56
|
+
if (namespaces && namespaces.length > 0) {
|
|
57
|
+
/*
|
|
58
|
+
* This may not be safe in cases there are two `network` for namespaces, the first one will be picked always.
|
|
59
|
+
* But since legacy provider only accepts one value, it shouldn't be happened when we are using legacy mode.
|
|
60
|
+
*/
|
|
61
|
+
network = namespaces.find((ns) => !!ns.network)?.network;
|
|
62
|
+
}
|
|
63
|
+
|
|
47
64
|
const walletInstance = getWalletInstance(wallet);
|
|
48
65
|
const result = await walletInstance.connect(network, namespaces);
|
|
49
66
|
if (props.autoConnect) {
|
|
@@ -54,7 +71,7 @@ export function useLegacyProviders(props: ProviderProps): ProviderContext {
|
|
|
54
71
|
});
|
|
55
72
|
}
|
|
56
73
|
|
|
57
|
-
return result;
|
|
74
|
+
return [result];
|
|
58
75
|
},
|
|
59
76
|
async disconnect(type) {
|
|
60
77
|
const wallet = wallets.get(type);
|
package/src/provider.tsx
CHANGED
|
@@ -3,13 +3,13 @@ import type { ProviderProps } from './legacy/types.js';
|
|
|
3
3
|
import React from 'react';
|
|
4
4
|
|
|
5
5
|
import { WalletContext } from './legacy/context.js';
|
|
6
|
-
import {
|
|
6
|
+
import { useProviders } from './useProviders.js';
|
|
7
7
|
|
|
8
8
|
function Provider(props: ProviderProps) {
|
|
9
|
-
const
|
|
9
|
+
const api = useProviders(props);
|
|
10
10
|
|
|
11
11
|
return (
|
|
12
|
-
<WalletContext.Provider value={
|
|
12
|
+
<WalletContext.Provider value={api}>
|
|
13
13
|
{props.children}
|
|
14
14
|
</WalletContext.Provider>
|
|
15
15
|
);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const TEST_ENVIRONMENT_AGENT = 'HappyDOM/0.0.0';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Detecting wether our code is running in a test environment or not.
|
|
5
|
+
*
|
|
6
|
+
* Note: This is only useful when HappyDOM or jsdom has been added to test runner.
|
|
7
|
+
*/
|
|
8
|
+
export function isRunningInTestEnvironmentWithDom(): boolean {
|
|
9
|
+
return navigator.userAgent.includes(TEST_ENVIRONMENT_AGENT);
|
|
10
|
+
}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import type { LegacyProviderInterface } from '@rango-dev/wallets-core/legacy';
|
|
2
|
+
import type { BlockchainMeta, GenericSigner } from 'rango-types';
|
|
3
|
+
import type { EvmTransaction } from 'rango-types/mainApi';
|
|
4
|
+
|
|
5
|
+
import { DefaultSignerFactory, TransactionType } from 'rango-types';
|
|
6
|
+
|
|
7
|
+
export const legacyAddress = '0x000000000000000000000000000000000000dead';
|
|
8
|
+
|
|
9
|
+
export class MockEvmSigner implements GenericSigner<EvmTransaction> {
|
|
10
|
+
async signMessage(
|
|
11
|
+
_msg: string,
|
|
12
|
+
_address: string,
|
|
13
|
+
_chainId: string | null
|
|
14
|
+
): Promise<string> {
|
|
15
|
+
return '0x';
|
|
16
|
+
}
|
|
17
|
+
async signAndSendTx(
|
|
18
|
+
_tx: EvmTransaction,
|
|
19
|
+
_address: string,
|
|
20
|
+
_chainId: string | null
|
|
21
|
+
): Promise<{ hash: string; response?: any }> {
|
|
22
|
+
return {
|
|
23
|
+
hash: '0x',
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const legacyProvider: LegacyProviderInterface = {
|
|
29
|
+
config: {
|
|
30
|
+
type: 'legacy-garbage',
|
|
31
|
+
},
|
|
32
|
+
async connect({ network }) {
|
|
33
|
+
// we added a timeout to simulate requesting to extension for connection.
|
|
34
|
+
return await new Promise((resolve, reject) => {
|
|
35
|
+
setTimeout(() => {
|
|
36
|
+
// This is useful for simulating error scenarios.
|
|
37
|
+
if (network === 'When Airdrop?') {
|
|
38
|
+
reject(
|
|
39
|
+
'please stay tuned we shall announce the detailed information soon.'
|
|
40
|
+
);
|
|
41
|
+
} else {
|
|
42
|
+
resolve([
|
|
43
|
+
{
|
|
44
|
+
accounts: [legacyAddress],
|
|
45
|
+
chainId: network || '',
|
|
46
|
+
},
|
|
47
|
+
]);
|
|
48
|
+
}
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
|
50
|
+
}, 10);
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
getInstance() {
|
|
54
|
+
return {};
|
|
55
|
+
},
|
|
56
|
+
async getSigners() {
|
|
57
|
+
const signers = new DefaultSignerFactory();
|
|
58
|
+
signers.registerSigner(TransactionType.EVM, new MockEvmSigner());
|
|
59
|
+
return signers;
|
|
60
|
+
},
|
|
61
|
+
getWalletInfo() {
|
|
62
|
+
return {
|
|
63
|
+
name: 'legacy garbage wallet',
|
|
64
|
+
color: '#000',
|
|
65
|
+
img: 'https://...',
|
|
66
|
+
installLink: 'https://...',
|
|
67
|
+
supportedChains: [],
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const blockchainsMeta: BlockchainMeta[] = [
|
|
73
|
+
{
|
|
74
|
+
name: 'BTC',
|
|
75
|
+
defaultDecimals: 8,
|
|
76
|
+
addressPatterns: [
|
|
77
|
+
'^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$|^(bc1)[0-9A-Za-z]{39,59}$',
|
|
78
|
+
],
|
|
79
|
+
feeAssets: [
|
|
80
|
+
{
|
|
81
|
+
blockchain: 'BTC',
|
|
82
|
+
symbol: 'BTC',
|
|
83
|
+
address: null,
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
logo: 'https://raw.githubusercontent.com/rango-exchange/assets/main/blockchains/BTC/icon.svg',
|
|
87
|
+
displayName: 'Bitcoin',
|
|
88
|
+
shortName: 'BTC',
|
|
89
|
+
sort: 12,
|
|
90
|
+
color: '#F7931A',
|
|
91
|
+
enabled: true,
|
|
92
|
+
type: TransactionType.TRANSFER,
|
|
93
|
+
chainId: null,
|
|
94
|
+
info: {
|
|
95
|
+
infoType: 'TransferMetaInfo',
|
|
96
|
+
blockExplorerUrls: ['https://www.blockchain.com/btc/'],
|
|
97
|
+
addressUrl: 'https://www.blockchain.com/btc/address/{wallet}',
|
|
98
|
+
transactionUrl: 'https://www.blockchain.com/btc/tx/{txHash}',
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: 'ETH',
|
|
103
|
+
defaultDecimals: 18,
|
|
104
|
+
addressPatterns: ['^(0x)[0-9A-Fa-f]{40}$'],
|
|
105
|
+
feeAssets: [
|
|
106
|
+
{
|
|
107
|
+
blockchain: 'ETH',
|
|
108
|
+
symbol: 'ETH',
|
|
109
|
+
address: null,
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
logo: 'https://raw.githubusercontent.com/rango-exchange/assets/main/blockchains/ETH/icon.svg',
|
|
113
|
+
displayName: 'Ethereum',
|
|
114
|
+
shortName: 'ETH',
|
|
115
|
+
sort: 0,
|
|
116
|
+
color: '#ecf0f1',
|
|
117
|
+
enabled: true,
|
|
118
|
+
type: TransactionType.EVM,
|
|
119
|
+
chainId: '0x1',
|
|
120
|
+
info: {
|
|
121
|
+
infoType: 'EvmMetaInfo',
|
|
122
|
+
chainName: 'Ethereum Mainnet',
|
|
123
|
+
nativeCurrency: {
|
|
124
|
+
name: 'ETH',
|
|
125
|
+
symbol: 'ETH',
|
|
126
|
+
decimals: 18,
|
|
127
|
+
},
|
|
128
|
+
rpcUrls: ['https://rpc.ankr.com/eth'],
|
|
129
|
+
blockExplorerUrls: ['https://etherscan.io'],
|
|
130
|
+
addressUrl: 'https://etherscan.io/address/{wallet}',
|
|
131
|
+
transactionUrl: 'https://etherscan.io/tx/{txHash}',
|
|
132
|
+
enableGasV2: true,
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
name: 'SOLANA',
|
|
137
|
+
defaultDecimals: 9,
|
|
138
|
+
addressPatterns: ['^[1-9A-HJ-NP-Za-km-z]{32,44}$'],
|
|
139
|
+
feeAssets: [
|
|
140
|
+
{
|
|
141
|
+
blockchain: 'SOLANA',
|
|
142
|
+
symbol: 'SOL',
|
|
143
|
+
address: null,
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
logo: 'https://raw.githubusercontent.com/rango-exchange/assets/main/blockchains/SOLANA/icon.svg',
|
|
147
|
+
displayName: 'Solana',
|
|
148
|
+
shortName: 'Solana',
|
|
149
|
+
sort: 20,
|
|
150
|
+
color: '#708DD2',
|
|
151
|
+
enabled: true,
|
|
152
|
+
type: TransactionType.SOLANA,
|
|
153
|
+
chainId: 'mainnet-beta',
|
|
154
|
+
info: {
|
|
155
|
+
infoType: 'SolanaMetaInfo',
|
|
156
|
+
blockExplorerUrls: ['https://solscan.io/'],
|
|
157
|
+
addressUrl: 'https://solscan.io/account/{wallet}',
|
|
158
|
+
transactionUrl: 'https://solscan.io/tx/{txHash}',
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
name: 'COSMOS',
|
|
163
|
+
defaultDecimals: 6,
|
|
164
|
+
addressPatterns: ['^(cosmos1)[0-9a-z]{38}$'],
|
|
165
|
+
feeAssets: [
|
|
166
|
+
{
|
|
167
|
+
blockchain: 'COSMOS',
|
|
168
|
+
symbol: 'ATOM',
|
|
169
|
+
address: null,
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
logo: 'https://raw.githubusercontent.com/rango-exchange/assets/main/blockchains/COSMOS/icon.svg',
|
|
173
|
+
displayName: 'Cosmos',
|
|
174
|
+
shortName: 'Cosmos',
|
|
175
|
+
sort: 15,
|
|
176
|
+
color: '#2E3148',
|
|
177
|
+
enabled: true,
|
|
178
|
+
type: TransactionType.COSMOS,
|
|
179
|
+
chainId: 'cosmoshub-4',
|
|
180
|
+
info: {
|
|
181
|
+
infoType: 'CosmosMetaInfo',
|
|
182
|
+
experimental: false,
|
|
183
|
+
rpc: 'https://cosmos-rpc.polkachu.com',
|
|
184
|
+
rest: 'https://lcd-cosmoshub.blockapsis.com',
|
|
185
|
+
cosmostationLcdUrl: 'https://lcd-cosmoshub.blockapsis.com',
|
|
186
|
+
cosmostationApiUrl: 'https://cosmos-rpc.polkachu.com',
|
|
187
|
+
cosmostationDenomTracePath: '/ibc/apps/transfer/v1/denom_traces/',
|
|
188
|
+
mintScanName: 'cosmos',
|
|
189
|
+
chainName: 'Cosmos',
|
|
190
|
+
stakeCurrency: {
|
|
191
|
+
coinDenom: 'ATOM',
|
|
192
|
+
coinMinimalDenom: 'uatom',
|
|
193
|
+
coinDecimals: 6,
|
|
194
|
+
coinGeckoId: 'cosmos',
|
|
195
|
+
coinImageUrl: '/tokens/blockchain/cosmos.svg',
|
|
196
|
+
},
|
|
197
|
+
bip44: {
|
|
198
|
+
coinType: 118,
|
|
199
|
+
},
|
|
200
|
+
bech32Config: {
|
|
201
|
+
bech32PrefixAccAddr: 'cosmos',
|
|
202
|
+
bech32PrefixAccPub: 'cosmospub',
|
|
203
|
+
bech32PrefixValAddr: 'cosmosvaloper',
|
|
204
|
+
bech32PrefixValPub: 'cosmosvaloperpub',
|
|
205
|
+
bech32PrefixConsAddr: 'cosmosvalcons',
|
|
206
|
+
bech32PrefixConsPub: 'cosmosvalconspub',
|
|
207
|
+
},
|
|
208
|
+
currencies: [
|
|
209
|
+
{
|
|
210
|
+
coinDenom: 'ATOM',
|
|
211
|
+
coinMinimalDenom: 'uatom',
|
|
212
|
+
coinDecimals: 6,
|
|
213
|
+
coinGeckoId: 'cosmos',
|
|
214
|
+
coinImageUrl: '/tokens/blockchain/cosmos.svg',
|
|
215
|
+
},
|
|
216
|
+
],
|
|
217
|
+
feeCurrencies: [
|
|
218
|
+
{
|
|
219
|
+
coinDenom: 'ATOM',
|
|
220
|
+
coinMinimalDenom: 'uatom',
|
|
221
|
+
coinDecimals: 6,
|
|
222
|
+
coinGeckoId: 'cosmos',
|
|
223
|
+
coinImageUrl: '/tokens/blockchain/cosmos.svg',
|
|
224
|
+
},
|
|
225
|
+
],
|
|
226
|
+
features: ['stargate', 'ibc-transfer'],
|
|
227
|
+
explorerUrlToTx: 'https://www.mintscan.io/cosmos/txs/{txHash}',
|
|
228
|
+
gasPriceStep: {
|
|
229
|
+
low: 0.01,
|
|
230
|
+
average: 0.025,
|
|
231
|
+
high: 0.04,
|
|
232
|
+
},
|
|
233
|
+
blockExplorerUrls: ['https://www.mintscan.io/cosmos/'],
|
|
234
|
+
addressUrl: 'https://www.mintscan.io/cosmos/account/{wallet}',
|
|
235
|
+
transactionUrl: 'https://www.mintscan.io/cosmos/txs/{txHash}',
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
];
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ExtendedWalletInfo,
|
|
3
|
+
ProviderContext,
|
|
4
|
+
ProviderProps,
|
|
5
|
+
Providers,
|
|
6
|
+
} from './index.js';
|
|
7
|
+
import type { ConnectResult } from './legacy/mod.js';
|
|
8
|
+
import type { LegacyState } from '@rango-dev/wallets-core/legacy';
|
|
9
|
+
import type { SignerFactory } from 'rango-types';
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
findProviderByType,
|
|
13
|
+
separateLegacyAndHubProviders,
|
|
14
|
+
useHubAdapter,
|
|
15
|
+
} from './hub/mod.js';
|
|
16
|
+
import { useLegacyProviders } from './legacy/mod.js';
|
|
17
|
+
|
|
18
|
+
/*
|
|
19
|
+
* We have two separate interface for our providers: legacy and hub.
|
|
20
|
+
* This hook sits between this two interface by keeping old interface as main API and try to add Hub providers by using an adapter.
|
|
21
|
+
* For gradual migrating and backward compatibility, we are supporting hub by an adapter besides of the old one.
|
|
22
|
+
*/
|
|
23
|
+
function useProviders(props: ProviderProps) {
|
|
24
|
+
const { providers, ...restProps } = props;
|
|
25
|
+
const [legacyProviders, hubProviders] = separateLegacyAndHubProviders(
|
|
26
|
+
providers,
|
|
27
|
+
{
|
|
28
|
+
isExperimentalEnabled: restProps.configs?.isExperimentalEnabled,
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const legacyApi = useLegacyProviders({
|
|
33
|
+
...restProps,
|
|
34
|
+
providers: legacyProviders,
|
|
35
|
+
});
|
|
36
|
+
const hubApi = useHubAdapter({
|
|
37
|
+
...restProps,
|
|
38
|
+
providers: hubProviders,
|
|
39
|
+
allVersionedProviders: providers,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const api: ProviderContext = {
|
|
43
|
+
canSwitchNetworkTo(type, network): boolean {
|
|
44
|
+
if (findProviderByType(hubProviders, type)) {
|
|
45
|
+
return hubApi.canSwitchNetworkTo(type, network);
|
|
46
|
+
}
|
|
47
|
+
return legacyApi.canSwitchNetworkTo(type, network);
|
|
48
|
+
},
|
|
49
|
+
async connect(type, network): Promise<ConnectResult[]> {
|
|
50
|
+
const hubProvider = findProviderByType(hubProviders, type);
|
|
51
|
+
if (hubProvider) {
|
|
52
|
+
return await hubApi.connect(type, network);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return await legacyApi.connect(type, network);
|
|
56
|
+
},
|
|
57
|
+
async disconnect(type): Promise<void> {
|
|
58
|
+
const hubProvider = findProviderByType(hubProviders, type);
|
|
59
|
+
if (hubProvider) {
|
|
60
|
+
return await hubApi.disconnect(type);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return await legacyApi.disconnect(type);
|
|
64
|
+
},
|
|
65
|
+
async disconnectAll() {
|
|
66
|
+
return await Promise.allSettled([
|
|
67
|
+
hubApi.disconnectAll(),
|
|
68
|
+
legacyApi.disconnectAll(),
|
|
69
|
+
]);
|
|
70
|
+
},
|
|
71
|
+
async getSigners(type): Promise<SignerFactory> {
|
|
72
|
+
const hubProvider = findProviderByType(hubProviders, type);
|
|
73
|
+
if (hubProvider) {
|
|
74
|
+
return hubApi.getSigners(type);
|
|
75
|
+
}
|
|
76
|
+
return legacyApi.getSigners(type);
|
|
77
|
+
},
|
|
78
|
+
getWalletInfo(type): ExtendedWalletInfo {
|
|
79
|
+
const hubProvider = findProviderByType(hubProviders, type);
|
|
80
|
+
if (hubProvider) {
|
|
81
|
+
return hubApi.getWalletInfo(type);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return legacyApi.getWalletInfo(type);
|
|
85
|
+
},
|
|
86
|
+
providers(): Providers {
|
|
87
|
+
let output: Providers = {};
|
|
88
|
+
if (hubProviders.length > 0) {
|
|
89
|
+
output = { ...output, ...hubApi.providers() };
|
|
90
|
+
}
|
|
91
|
+
if (legacyProviders.length > 0) {
|
|
92
|
+
output = { ...output, ...legacyApi.providers() };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return output;
|
|
96
|
+
},
|
|
97
|
+
state(type): LegacyState {
|
|
98
|
+
const hubProvider = findProviderByType(hubProviders, type);
|
|
99
|
+
|
|
100
|
+
if (hubProvider) {
|
|
101
|
+
return hubApi.state(type);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return legacyApi.state(type);
|
|
105
|
+
},
|
|
106
|
+
async suggestAndConnect(type, network): Promise<ConnectResult> {
|
|
107
|
+
const hubProvider = findProviderByType(hubProviders, type);
|
|
108
|
+
|
|
109
|
+
if (hubProvider) {
|
|
110
|
+
return hubApi.suggestAndConnect(type, network);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return await legacyApi.suggestAndConnect(type, network);
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
return api;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export { useProviders };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/legacy/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB,2BAA2B,CAAC"}
|
package/src/legacy/constants.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const LAST_CONNECTED_WALLETS = 'last-connected-wallets';
|