@rango-dev/wallets-core 0.0.0-experimental-936229e8-20251208
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 +334 -0
- package/dist/builders/action.d.ts +22 -0
- package/dist/builders/action.d.ts.map +1 -0
- package/dist/builders/mod.d.ts +5 -0
- package/dist/builders/mod.d.ts.map +1 -0
- package/dist/builders/namespace.d.ts +47 -0
- package/dist/builders/namespace.d.ts.map +1 -0
- package/dist/builders/provider.d.ts +13 -0
- package/dist/builders/provider.d.ts.map +1 -0
- package/dist/builders/types.d.ts +21 -0
- package/dist/builders/types.d.ts.map +1 -0
- package/dist/hub/helpers.d.ts +6 -0
- package/dist/hub/helpers.d.ts.map +1 -0
- package/dist/hub/hub.d.ts +29 -0
- package/dist/hub/hub.d.ts.map +1 -0
- package/dist/hub/mod.d.ts +9 -0
- package/dist/hub/mod.d.ts.map +1 -0
- package/dist/hub/namespaces/errors.d.ts +5 -0
- package/dist/hub/namespaces/errors.d.ts.map +1 -0
- package/dist/hub/namespaces/mod.d.ts +3 -0
- package/dist/hub/namespaces/mod.d.ts.map +1 -0
- package/dist/hub/namespaces/namespace.d.ts +148 -0
- package/dist/hub/namespaces/namespace.d.ts.map +1 -0
- package/dist/hub/namespaces/namespace.test.d.ts +11 -0
- package/dist/hub/namespaces/namespace.test.d.ts.map +1 -0
- package/dist/hub/namespaces/types.d.ts +36 -0
- package/dist/hub/namespaces/types.d.ts.map +1 -0
- package/dist/hub/provider/mod.d.ts +3 -0
- package/dist/hub/provider/mod.d.ts.map +1 -0
- package/dist/hub/provider/provider.d.ts +136 -0
- package/dist/hub/provider/provider.d.ts.map +1 -0
- package/dist/hub/provider/provider.test.d.ts +2 -0
- package/dist/hub/provider/provider.test.d.ts.map +1 -0
- package/dist/hub/provider/types.d.ts +37 -0
- package/dist/hub/provider/types.d.ts.map +1 -0
- package/dist/hub/store/events.d.ts +54 -0
- package/dist/hub/store/events.d.ts.map +1 -0
- package/dist/hub/store/extend.d.ts +14 -0
- package/dist/hub/store/extend.d.ts.map +1 -0
- package/dist/hub/store/hub.d.ts +11 -0
- package/dist/hub/store/hub.d.ts.map +1 -0
- package/dist/hub/store/mod.d.ts +8 -0
- package/dist/hub/store/mod.d.ts.map +1 -0
- package/dist/hub/store/mod.js +2 -0
- package/dist/hub/store/mod.js.map +7 -0
- package/dist/hub/store/namespaces.d.ts +38 -0
- package/dist/hub/store/namespaces.d.ts.map +1 -0
- package/dist/hub/store/providers.d.ts +77 -0
- package/dist/hub/store/providers.d.ts.map +1 -0
- package/dist/hub/store/selectors.d.ts +18 -0
- package/dist/hub/store/selectors.d.ts.map +1 -0
- package/dist/hub/store/store.d.ts +14 -0
- package/dist/hub/store/store.d.ts.map +1 -0
- package/dist/hub/store/store.test.d.ts +2 -0
- package/dist/hub/store/store.test.d.ts.map +1 -0
- package/dist/legacy/helpers.d.ts +12 -0
- package/dist/legacy/helpers.d.ts.map +1 -0
- package/dist/legacy/mod.d.ts +8 -0
- package/dist/legacy/mod.d.ts.map +1 -0
- package/dist/legacy/mod.js +2 -0
- package/dist/legacy/mod.js.map +7 -0
- package/dist/legacy/persistor.d.ts +11 -0
- package/dist/legacy/persistor.d.ts.map +1 -0
- package/dist/legacy/types.d.ts +247 -0
- package/dist/legacy/types.d.ts.map +1 -0
- package/dist/legacy/utils.d.ts +8 -0
- package/dist/legacy/utils.d.ts.map +1 -0
- package/dist/legacy/wallet.d.ts +65 -0
- package/dist/legacy/wallet.d.ts.map +1 -0
- package/dist/mod.d.ts +9 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +2 -0
- package/dist/mod.js.map +7 -0
- package/dist/namespaces/common/actions.d.ts +4 -0
- package/dist/namespaces/common/actions.d.ts.map +1 -0
- package/dist/namespaces/common/after.d.ts +4 -0
- package/dist/namespaces/common/after.d.ts.map +1 -0
- package/dist/namespaces/common/and.d.ts +6 -0
- package/dist/namespaces/common/and.d.ts.map +1 -0
- package/dist/namespaces/common/before.d.ts +4 -0
- package/dist/namespaces/common/before.d.ts.map +1 -0
- package/dist/namespaces/common/builders.d.ts +5 -0
- package/dist/namespaces/common/builders.d.ts.map +1 -0
- package/dist/namespaces/common/helpers.d.ts +2 -0
- package/dist/namespaces/common/helpers.d.ts.map +1 -0
- package/dist/namespaces/common/hooks/changeAccountSubscriber.d.ts +90 -0
- package/dist/namespaces/common/hooks/changeAccountSubscriber.d.ts.map +1 -0
- package/dist/namespaces/common/hooks/changeAccountSubscriber.test.d.ts +2 -0
- package/dist/namespaces/common/hooks/changeAccountSubscriber.test.d.ts.map +1 -0
- package/dist/namespaces/common/mod.d.ts +11 -0
- package/dist/namespaces/common/mod.d.ts.map +1 -0
- package/dist/namespaces/common/mod.js +2 -0
- package/dist/namespaces/common/mod.js.map +7 -0
- package/dist/namespaces/common/or.d.ts +13 -0
- package/dist/namespaces/common/or.d.ts.map +1 -0
- package/dist/namespaces/common/types.d.ts +11 -0
- package/dist/namespaces/common/types.d.ts.map +1 -0
- package/dist/namespaces/common/utils.d.ts +10 -0
- package/dist/namespaces/common/utils.d.ts.map +1 -0
- package/dist/namespaces/cosmos/actions.d.ts +2 -0
- package/dist/namespaces/cosmos/actions.d.ts.map +1 -0
- package/dist/namespaces/cosmos/after.d.ts +2 -0
- package/dist/namespaces/cosmos/after.d.ts.map +1 -0
- package/dist/namespaces/cosmos/and.d.ts +3 -0
- package/dist/namespaces/cosmos/and.d.ts.map +1 -0
- package/dist/namespaces/cosmos/before.d.ts +2 -0
- package/dist/namespaces/cosmos/before.d.ts.map +1 -0
- package/dist/namespaces/cosmos/builders.d.ts +4 -0
- package/dist/namespaces/cosmos/builders.d.ts.map +1 -0
- package/dist/namespaces/cosmos/constants.d.ts +2 -0
- package/dist/namespaces/cosmos/constants.d.ts.map +1 -0
- package/dist/namespaces/cosmos/mod.d.ts +9 -0
- package/dist/namespaces/cosmos/mod.d.ts.map +1 -0
- package/dist/namespaces/cosmos/mod.js +2 -0
- package/dist/namespaces/cosmos/mod.js.map +7 -0
- package/dist/namespaces/cosmos/types.d.ts +19 -0
- package/dist/namespaces/cosmos/types.d.ts.map +1 -0
- package/dist/namespaces/cosmos/utils.d.ts +3 -0
- package/dist/namespaces/cosmos/utils.d.ts.map +1 -0
- package/dist/namespaces/evm/actions.d.ts +10 -0
- package/dist/namespaces/evm/actions.d.ts.map +1 -0
- package/dist/namespaces/evm/after.d.ts +2 -0
- package/dist/namespaces/evm/after.d.ts.map +1 -0
- package/dist/namespaces/evm/and.d.ts +3 -0
- package/dist/namespaces/evm/and.d.ts.map +1 -0
- package/dist/namespaces/evm/before.d.ts +2 -0
- package/dist/namespaces/evm/before.d.ts.map +1 -0
- package/dist/namespaces/evm/builders.d.ts +9 -0
- package/dist/namespaces/evm/builders.d.ts.map +1 -0
- package/dist/namespaces/evm/constants.d.ts +3 -0
- package/dist/namespaces/evm/constants.d.ts.map +1 -0
- package/dist/namespaces/evm/eip1193.d.ts +1229 -0
- package/dist/namespaces/evm/eip1193.d.ts.map +1 -0
- package/dist/namespaces/evm/hooks.d.ts +5 -0
- package/dist/namespaces/evm/hooks.d.ts.map +1 -0
- package/dist/namespaces/evm/mod.d.ts +10 -0
- package/dist/namespaces/evm/mod.d.ts.map +1 -0
- package/dist/namespaces/evm/mod.js +2 -0
- package/dist/namespaces/evm/mod.js.map +7 -0
- package/dist/namespaces/evm/types.d.ts +23 -0
- package/dist/namespaces/evm/types.d.ts.map +1 -0
- package/dist/namespaces/evm/utils.d.ts +13 -0
- package/dist/namespaces/evm/utils.d.ts.map +1 -0
- package/dist/namespaces/solana/actions.d.ts +7 -0
- package/dist/namespaces/solana/actions.d.ts.map +1 -0
- package/dist/namespaces/solana/after.d.ts +2 -0
- package/dist/namespaces/solana/after.d.ts.map +1 -0
- package/dist/namespaces/solana/and.d.ts +3 -0
- package/dist/namespaces/solana/and.d.ts.map +1 -0
- package/dist/namespaces/solana/before.d.ts +2 -0
- package/dist/namespaces/solana/before.d.ts.map +1 -0
- package/dist/namespaces/solana/builders.d.ts +6 -0
- package/dist/namespaces/solana/builders.d.ts.map +1 -0
- package/dist/namespaces/solana/constants.d.ts +3 -0
- package/dist/namespaces/solana/constants.d.ts.map +1 -0
- package/dist/namespaces/solana/hooks.d.ts +4 -0
- package/dist/namespaces/solana/hooks.d.ts.map +1 -0
- package/dist/namespaces/solana/mod.d.ts +10 -0
- package/dist/namespaces/solana/mod.d.ts.map +1 -0
- package/dist/namespaces/solana/mod.js +2 -0
- package/dist/namespaces/solana/mod.js.map +7 -0
- package/dist/namespaces/solana/types.d.ts +11 -0
- package/dist/namespaces/solana/types.d.ts.map +1 -0
- package/dist/namespaces/solana/utils.d.ts +8 -0
- package/dist/namespaces/solana/utils.d.ts.map +1 -0
- package/dist/namespaces/sui/actions.d.ts +8 -0
- package/dist/namespaces/sui/actions.d.ts.map +1 -0
- package/dist/namespaces/sui/builders.d.ts +14 -0
- package/dist/namespaces/sui/builders.d.ts.map +1 -0
- package/dist/namespaces/sui/constants.d.ts +3 -0
- package/dist/namespaces/sui/constants.d.ts.map +1 -0
- package/dist/namespaces/sui/hooks.d.ts +4 -0
- package/dist/namespaces/sui/hooks.d.ts.map +1 -0
- package/dist/namespaces/sui/mod.d.ts +7 -0
- package/dist/namespaces/sui/mod.d.ts.map +1 -0
- package/dist/namespaces/sui/mod.js +2 -0
- package/dist/namespaces/sui/mod.js.map +7 -0
- package/dist/namespaces/sui/types.d.ts +12 -0
- package/dist/namespaces/sui/types.d.ts.map +1 -0
- package/dist/namespaces/sui/utils.d.ts +15 -0
- package/dist/namespaces/sui/utils.d.ts.map +1 -0
- package/dist/namespaces/tron/actions.d.ts +2 -0
- package/dist/namespaces/tron/actions.d.ts.map +1 -0
- package/dist/namespaces/tron/after.d.ts +2 -0
- package/dist/namespaces/tron/after.d.ts.map +1 -0
- package/dist/namespaces/tron/and.d.ts +3 -0
- package/dist/namespaces/tron/and.d.ts.map +1 -0
- package/dist/namespaces/tron/before.d.ts +2 -0
- package/dist/namespaces/tron/before.d.ts.map +1 -0
- package/dist/namespaces/tron/builders.d.ts +5 -0
- package/dist/namespaces/tron/builders.d.ts.map +1 -0
- package/dist/namespaces/tron/constants.d.ts +3 -0
- package/dist/namespaces/tron/constants.d.ts.map +1 -0
- package/dist/namespaces/tron/mod.d.ts +9 -0
- package/dist/namespaces/tron/mod.d.ts.map +1 -0
- package/dist/namespaces/tron/mod.js +2 -0
- package/dist/namespaces/tron/mod.js.map +7 -0
- package/dist/namespaces/tron/types.d.ts +8 -0
- package/dist/namespaces/tron/types.d.ts.map +1 -0
- package/dist/namespaces/tron/utils.d.ts +2 -0
- package/dist/namespaces/tron/utils.d.ts.map +1 -0
- package/dist/namespaces/utxo/actions.d.ts +2 -0
- package/dist/namespaces/utxo/actions.d.ts.map +1 -0
- package/dist/namespaces/utxo/after.d.ts +2 -0
- package/dist/namespaces/utxo/after.d.ts.map +1 -0
- package/dist/namespaces/utxo/and.d.ts +3 -0
- package/dist/namespaces/utxo/and.d.ts.map +1 -0
- package/dist/namespaces/utxo/before.d.ts +2 -0
- package/dist/namespaces/utxo/before.d.ts.map +1 -0
- package/dist/namespaces/utxo/builders.d.ts +4 -0
- package/dist/namespaces/utxo/builders.d.ts.map +1 -0
- package/dist/namespaces/utxo/constants.d.ts +3 -0
- package/dist/namespaces/utxo/constants.d.ts.map +1 -0
- package/dist/namespaces/utxo/mod.d.ts +9 -0
- package/dist/namespaces/utxo/mod.d.ts.map +1 -0
- package/dist/namespaces/utxo/mod.js +2 -0
- package/dist/namespaces/utxo/mod.js.map +7 -0
- package/dist/namespaces/utxo/types.d.ts +8 -0
- package/dist/namespaces/utxo/types.d.ts.map +1 -0
- package/dist/namespaces/utxo/utils.d.ts +2 -0
- package/dist/namespaces/utxo/utils.d.ts.map +1 -0
- package/dist/test-utils/fixtures.d.ts +4 -0
- package/dist/test-utils/fixtures.d.ts.map +1 -0
- package/dist/types/accounts.d.ts +11 -0
- package/dist/types/accounts.d.ts.map +1 -0
- package/dist/types/actions.d.ts +5 -0
- package/dist/types/actions.d.ts.map +1 -0
- package/dist/types/mod.d.ts +2 -0
- package/dist/types/mod.d.ts.map +1 -0
- package/dist/types/utils.d.ts +7 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/dist/utils/mod.d.ts +4 -0
- package/dist/utils/mod.d.ts.map +1 -0
- package/dist/utils/mod.js +2 -0
- package/dist/utils/mod.js.map +7 -0
- package/dist/utils/versions.d.ts +21 -0
- package/dist/utils/versions.d.ts.map +1 -0
- package/dist/utils/versions.test.d.ts +2 -0
- package/dist/utils/versions.test.d.ts.map +1 -0
- package/dist/wallets-core.build.json +1 -0
- package/legacy/package.json +8 -0
- package/package.json +84 -0
- package/readme.md +4 -0
- package/src/builders/action.ts +86 -0
- package/src/builders/mod.ts +5 -0
- package/src/builders/namespace.ts +258 -0
- package/src/builders/provider.ts +61 -0
- package/src/builders/types.ts +29 -0
- package/src/hub/helpers.ts +11 -0
- package/src/hub/hub.ts +128 -0
- package/src/hub/mod.ts +18 -0
- package/src/hub/namespaces/errors.ts +11 -0
- package/src/hub/namespaces/mod.ts +10 -0
- package/src/hub/namespaces/namespace.test.ts +443 -0
- package/src/hub/namespaces/namespace.ts +470 -0
- package/src/hub/namespaces/types.ts +58 -0
- package/src/hub/provider/mod.ts +10 -0
- package/src/hub/provider/provider.test.ts +232 -0
- package/src/hub/provider/provider.ts +335 -0
- package/src/hub/provider/types.ts +50 -0
- package/src/hub/store/events.ts +89 -0
- package/src/hub/store/extend.ts +125 -0
- package/src/hub/store/hub.ts +18 -0
- package/src/hub/store/mod.ts +25 -0
- package/src/hub/store/namespaces.ts +177 -0
- package/src/hub/store/providers.ts +169 -0
- package/src/hub/store/selectors.ts +59 -0
- package/src/hub/store/store.test.ts +50 -0
- package/src/hub/store/store.ts +30 -0
- package/src/legacy/helpers.ts +75 -0
- package/src/legacy/mod.ts +44 -0
- package/src/legacy/persistor.ts +19 -0
- package/src/legacy/types.ts +291 -0
- package/src/legacy/utils.ts +20 -0
- package/src/legacy/wallet.ts +552 -0
- package/src/mod.ts +44 -0
- package/src/namespaces/common/actions.ts +12 -0
- package/src/namespaces/common/after.ts +8 -0
- package/src/namespaces/common/and.ts +42 -0
- package/src/namespaces/common/before.ts +9 -0
- package/src/namespaces/common/builders.ts +14 -0
- package/src/namespaces/common/helpers.ts +10 -0
- package/src/namespaces/common/hooks/changeAccountSubscriber.test.ts +173 -0
- package/src/namespaces/common/hooks/changeAccountSubscriber.ts +236 -0
- package/src/namespaces/common/mod.ts +23 -0
- package/src/namespaces/common/or.ts +17 -0
- package/src/namespaces/common/types.ts +25 -0
- package/src/namespaces/common/utils.ts +43 -0
- package/src/namespaces/cosmos/actions.ts +3 -0
- package/src/namespaces/cosmos/after.ts +3 -0
- package/src/namespaces/cosmos/and.ts +5 -0
- package/src/namespaces/cosmos/before.ts +3 -0
- package/src/namespaces/cosmos/builders.ts +15 -0
- package/src/namespaces/cosmos/constants.ts +1 -0
- package/src/namespaces/cosmos/mod.ts +9 -0
- package/src/namespaces/cosmos/types.ts +26 -0
- package/src/namespaces/cosmos/utils.ts +21 -0
- package/src/namespaces/evm/actions.ts +119 -0
- package/src/namespaces/evm/after.ts +3 -0
- package/src/namespaces/evm/and.ts +5 -0
- package/src/namespaces/evm/before.ts +3 -0
- package/src/namespaces/evm/builders.ts +52 -0
- package/src/namespaces/evm/constants.ts +2 -0
- package/src/namespaces/evm/eip1193.ts +1415 -0
- package/src/namespaces/evm/hooks.ts +43 -0
- package/src/namespaces/evm/mod.ts +10 -0
- package/src/namespaces/evm/types.ts +33 -0
- package/src/namespaces/evm/utils.ts +106 -0
- package/src/namespaces/solana/actions.ts +44 -0
- package/src/namespaces/solana/after.ts +3 -0
- package/src/namespaces/solana/and.ts +5 -0
- package/src/namespaces/solana/before.ts +3 -0
- package/src/namespaces/solana/builders.ts +40 -0
- package/src/namespaces/solana/constants.ts +2 -0
- package/src/namespaces/solana/hooks.ts +10 -0
- package/src/namespaces/solana/mod.ts +10 -0
- package/src/namespaces/solana/types.ts +26 -0
- package/src/namespaces/solana/utils.ts +36 -0
- package/src/namespaces/sui/actions.ts +27 -0
- package/src/namespaces/sui/builders.ts +77 -0
- package/src/namespaces/sui/constants.ts +8 -0
- package/src/namespaces/sui/hooks.ts +10 -0
- package/src/namespaces/sui/mod.ts +8 -0
- package/src/namespaces/sui/types.ts +26 -0
- package/src/namespaces/sui/utils.ts +56 -0
- package/src/namespaces/tron/actions.ts +3 -0
- package/src/namespaces/tron/after.ts +3 -0
- package/src/namespaces/tron/and.ts +5 -0
- package/src/namespaces/tron/before.ts +3 -0
- package/src/namespaces/tron/builders.ts +15 -0
- package/src/namespaces/tron/constants.ts +8 -0
- package/src/namespaces/tron/mod.ts +8 -0
- package/src/namespaces/tron/types.ts +15 -0
- package/src/namespaces/tron/utils.ts +18 -0
- package/src/namespaces/utxo/actions.ts +3 -0
- package/src/namespaces/utxo/after.ts +3 -0
- package/src/namespaces/utxo/and.ts +5 -0
- package/src/namespaces/utxo/before.ts +3 -0
- package/src/namespaces/utxo/builders.ts +12 -0
- package/src/namespaces/utxo/constants.ts +2 -0
- package/src/namespaces/utxo/mod.ts +8 -0
- package/src/namespaces/utxo/types.ts +15 -0
- package/src/namespaces/utxo/utils.ts +18 -0
- package/src/test-utils/fixtures.ts +13 -0
- package/src/types/accounts.ts +12 -0
- package/src/types/actions.ts +11 -0
- package/src/types/mod.ts +1 -0
- package/src/types/utils.ts +7 -0
- package/src/utils/mod.ts +8 -0
- package/src/utils/versions.test.ts +22 -0
- package/src/utils/versions.ts +62 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { ConnectOptions, EvmActions, ProviderAPI } from './types.js';
|
|
2
|
+
import type { Context } from '../../hub/namespaces/mod.js';
|
|
3
|
+
import type { CanEagerConnect } from '../../hub/namespaces/types.js';
|
|
4
|
+
import type { FunctionWithContext } from '../../types/actions.js';
|
|
5
|
+
|
|
6
|
+
import { recommended as commonRecommended } from '../common/actions.js';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
filterAndGetEvmBlockchainNames,
|
|
10
|
+
formatAccountsToCAIP,
|
|
11
|
+
getAccounts,
|
|
12
|
+
switchOrAddNetwork,
|
|
13
|
+
} from './utils.js';
|
|
14
|
+
|
|
15
|
+
export const recommended = [...commonRecommended];
|
|
16
|
+
export function connect(
|
|
17
|
+
instance: () => ProviderAPI,
|
|
18
|
+
options?: ConnectOptions
|
|
19
|
+
): FunctionWithContext<EvmActions['connect'], Context> {
|
|
20
|
+
return async (context, chain) => {
|
|
21
|
+
// Setting connect args to be used on other actions
|
|
22
|
+
const [, setState] = context.state();
|
|
23
|
+
setState('connectArgs', { chain });
|
|
24
|
+
const evmInstance = instance();
|
|
25
|
+
|
|
26
|
+
if (!evmInstance) {
|
|
27
|
+
throw new Error(
|
|
28
|
+
'Do your wallet injected correctly and is evm compatible?'
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (chain) {
|
|
33
|
+
/*
|
|
34
|
+
* The `switchOrAddNetwork` function can be optionally provided through `options`
|
|
35
|
+
* to handle network switching or addition in a way that is compatible with the specific wallet provider.
|
|
36
|
+
* This approach is necessary because not all providers follow the same conventions—
|
|
37
|
+
* for example, Rabby uses a different error code for "chain not found".
|
|
38
|
+
*/
|
|
39
|
+
if (options?.switchOrAddNetwork) {
|
|
40
|
+
await options.switchOrAddNetwork(evmInstance, chain);
|
|
41
|
+
} else {
|
|
42
|
+
await switchOrAddNetwork(evmInstance, chain);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const providerAccounts = await getAccounts(evmInstance);
|
|
47
|
+
|
|
48
|
+
/*
|
|
49
|
+
* Ensure that the provider returns at least one valid account before proceeding.
|
|
50
|
+
* This prevents cases (e.g., MetaMask bug) where a user connects with an account
|
|
51
|
+
* that has no associated EVM address, leaving the dApp without any usable accounts.
|
|
52
|
+
*/
|
|
53
|
+
if (!providerAccounts.accounts || !providerAccounts.accounts.length) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
'No accounts were returned by the provider. Please make sure your wallet has an active EVM-compatible account selected.'
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
const formattedAccounts = formatAccountsToCAIP(
|
|
59
|
+
providerAccounts.accounts,
|
|
60
|
+
providerAccounts.chainId
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
accounts: formattedAccounts,
|
|
65
|
+
network: providerAccounts.chainId,
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function canEagerConnect(
|
|
71
|
+
instance: () => ProviderAPI | undefined
|
|
72
|
+
): CanEagerConnect<EvmActions> {
|
|
73
|
+
return async () => {
|
|
74
|
+
const evmInstance = instance();
|
|
75
|
+
|
|
76
|
+
if (!evmInstance) {
|
|
77
|
+
throw new Error(
|
|
78
|
+
'Trying to eagerly connect to your EVM wallet, but seems its instance is not available.'
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
const accounts: string[] = await evmInstance.request({
|
|
84
|
+
method: 'eth_accounts',
|
|
85
|
+
});
|
|
86
|
+
if (accounts.length) {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
90
|
+
} catch {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
export function canSwitchNetwork(): FunctionWithContext<
|
|
96
|
+
EvmActions['canSwitchNetwork'],
|
|
97
|
+
Context
|
|
98
|
+
> {
|
|
99
|
+
return (context, params) => {
|
|
100
|
+
const { network, supportedChains } = params;
|
|
101
|
+
return filterAndGetEvmBlockchainNames(supportedChains).includes(network);
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function getChainId(
|
|
106
|
+
instance: () => ProviderAPI | undefined
|
|
107
|
+
): FunctionWithContext<EvmActions['getChainId'], Context> {
|
|
108
|
+
return async () => {
|
|
109
|
+
const evmInstance = instance();
|
|
110
|
+
|
|
111
|
+
if (!evmInstance) {
|
|
112
|
+
throw new Error(
|
|
113
|
+
'Trying to get chain id from your EVM wallet, but instance is not available.'
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return evmInstance.request({ method: 'eth_chainId' });
|
|
118
|
+
};
|
|
119
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { EvmActions, ProviderAPI } from './types.js';
|
|
2
|
+
|
|
3
|
+
import { ActionBuilder } from '../../mod.js';
|
|
4
|
+
import { ChangeAccountSubscriberBuilder } from '../common/hooks/changeAccountSubscriber.js';
|
|
5
|
+
import {
|
|
6
|
+
connectAndUpdateStateForMultiNetworks,
|
|
7
|
+
intoConnecting,
|
|
8
|
+
intoConnectionFinished,
|
|
9
|
+
} from '../common/mod.js';
|
|
10
|
+
|
|
11
|
+
import { formatAccountsToCAIP } from './utils.js';
|
|
12
|
+
|
|
13
|
+
// Actions
|
|
14
|
+
export const connect = () =>
|
|
15
|
+
new ActionBuilder<EvmActions, 'connect'>('connect')
|
|
16
|
+
.and(connectAndUpdateStateForMultiNetworks)
|
|
17
|
+
.before(intoConnecting)
|
|
18
|
+
.after(intoConnectionFinished);
|
|
19
|
+
|
|
20
|
+
export const canEagerConnect = () =>
|
|
21
|
+
new ActionBuilder<EvmActions, 'canEagerConnect'>('canEagerConnect');
|
|
22
|
+
export const canSwitchNetwork = () =>
|
|
23
|
+
new ActionBuilder<EvmActions, 'canSwitchNetwork'>('canSwitchNetwork');
|
|
24
|
+
|
|
25
|
+
// Hooks
|
|
26
|
+
export const changeAccountSubscriber = (getInstance: () => ProviderAPI) =>
|
|
27
|
+
new ChangeAccountSubscriberBuilder<string[], ProviderAPI, EvmActions>()
|
|
28
|
+
.getInstance(getInstance)
|
|
29
|
+
/*
|
|
30
|
+
* In some wallets, when a user switches to an account not yet connected to the dApp, it returns null.
|
|
31
|
+
* A null value indicates no access to the account, requiring a disconnect and user reconnection.
|
|
32
|
+
* This behavior may vary across different wallets, and if so, a different approach may be needed.
|
|
33
|
+
*/
|
|
34
|
+
.onSwitchAccount((event, context) => {
|
|
35
|
+
if (!event.payload || !event.payload.length) {
|
|
36
|
+
context.action('disconnect');
|
|
37
|
+
event.preventDefault();
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
.format(async (instance, accounts) => {
|
|
41
|
+
const chainId = await instance.request({ method: 'eth_chainId' });
|
|
42
|
+
return formatAccountsToCAIP(accounts, chainId);
|
|
43
|
+
})
|
|
44
|
+
.addEventListener((instance, callback) => {
|
|
45
|
+
instance.on('accountsChanged', callback);
|
|
46
|
+
})
|
|
47
|
+
.removeEventListener((instance, callback) => {
|
|
48
|
+
instance.removeListener?.('accountsChanged', callback);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
export const getChainId = () =>
|
|
52
|
+
new ActionBuilder<EvmActions, 'getChainId'>('getChainId');
|