@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,61 @@
|
|
|
1
|
+
import type { FindProxiedNamespace } from './types.js';
|
|
2
|
+
import type {
|
|
3
|
+
CommonNamespaces,
|
|
4
|
+
ExtendableInternalActions,
|
|
5
|
+
ProviderBuilderOptions,
|
|
6
|
+
} from '../hub/provider/mod.js';
|
|
7
|
+
import type { ProviderConfig } from '../hub/store/mod.js';
|
|
8
|
+
|
|
9
|
+
import { Provider } from '../hub/provider/mod.js';
|
|
10
|
+
|
|
11
|
+
export class ProviderBuilder {
|
|
12
|
+
#id: string;
|
|
13
|
+
#namespaces = new Map();
|
|
14
|
+
#methods: ExtendableInternalActions = {};
|
|
15
|
+
#configs: Partial<ProviderConfig> = {};
|
|
16
|
+
#options: Partial<ProviderBuilderOptions>;
|
|
17
|
+
|
|
18
|
+
constructor(id: string, options?: ProviderBuilderOptions) {
|
|
19
|
+
this.#id = id;
|
|
20
|
+
this.#options = options || {};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public add<K extends keyof CommonNamespaces>(
|
|
24
|
+
id: K,
|
|
25
|
+
namespace: FindProxiedNamespace<K, CommonNamespaces>
|
|
26
|
+
) {
|
|
27
|
+
if (this.#options.store) {
|
|
28
|
+
namespace.store(this.#options.store);
|
|
29
|
+
}
|
|
30
|
+
this.#namespaces.set(id, namespace);
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public config<K extends keyof ProviderConfig>(
|
|
35
|
+
name: K,
|
|
36
|
+
value: ProviderConfig[K]
|
|
37
|
+
) {
|
|
38
|
+
this.#configs[name] = value;
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public init(cb: Exclude<ExtendableInternalActions['init'], undefined>) {
|
|
43
|
+
this.#methods.init = cb;
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public build(): Provider {
|
|
48
|
+
if (this.#isConfigsValid(this.#configs)) {
|
|
49
|
+
return new Provider(this.#id, this.#namespaces, this.#configs, {
|
|
50
|
+
extendInternalActions: this.#methods,
|
|
51
|
+
store: this.#options.store,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
throw new Error('You need to set all required configs.');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
#isConfigsValid(config: Partial<ProviderConfig>): config is ProviderConfig {
|
|
59
|
+
return !!config.metadata;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { allowedMethods } from './namespace.js';
|
|
2
|
+
import type { Actions, Namespace } from '../hub/namespaces/mod.js';
|
|
3
|
+
|
|
4
|
+
// These should be matched with `/hub/namespace.ts` public values.
|
|
5
|
+
type NamespacePublicValues = {
|
|
6
|
+
namespaceId: string;
|
|
7
|
+
providerId: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* NamespaceBuilder is creating a proxy instead of return Namespace instance.
|
|
12
|
+
* The reason is improving access to actions. e.g `.connect()` instead of `.run('connect')`
|
|
13
|
+
*/
|
|
14
|
+
export type ProxiedNamespace<T extends Actions<T>> = T &
|
|
15
|
+
Pick<Namespace<T>, (typeof allowedMethods)[number]> &
|
|
16
|
+
NamespacePublicValues;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* This is useful when you gave a list of namespaces and want to map a key to corresponding namespace.
|
|
20
|
+
*
|
|
21
|
+
* e.g:
|
|
22
|
+
* Type List = { evm: EvmActions, solana: SolanaActions};
|
|
23
|
+
* FindProxiedNamespace<"solana", List>
|
|
24
|
+
*/
|
|
25
|
+
export type FindProxiedNamespace<K extends keyof T, T> = T[K] extends Actions<
|
|
26
|
+
T[K]
|
|
27
|
+
>
|
|
28
|
+
? ProxiedNamespace<T[K]>
|
|
29
|
+
: never;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Note: This only works native async, if we are going to support for old transpilers like Babel.
|
|
3
|
+
*/
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
5
|
+
export function isAsync(fn: Function) {
|
|
6
|
+
return fn.constructor.name === 'AsyncFunction';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function generateStoreId(providerId: string, namespace: string) {
|
|
10
|
+
return `${providerId}$$${namespace}`;
|
|
11
|
+
}
|
package/src/hub/hub.ts
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { Namespace, State as NamespaceState } from './namespaces/mod.js';
|
|
2
|
+
import type { Provider, State as ProviderState } from './provider/mod.js';
|
|
3
|
+
import type { Store } from './store/mod.js';
|
|
4
|
+
|
|
5
|
+
type HubState = {
|
|
6
|
+
[key in string]: ProviderState & {
|
|
7
|
+
namespaces: NamespaceState[];
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
type RunAllResult = {
|
|
12
|
+
id: string;
|
|
13
|
+
provider: unknown;
|
|
14
|
+
namespaces: unknown[];
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
interface HubOptions {
|
|
18
|
+
store?: Store;
|
|
19
|
+
}
|
|
20
|
+
export class Hub {
|
|
21
|
+
#providers = new Map<string, Provider>();
|
|
22
|
+
#options: HubOptions;
|
|
23
|
+
|
|
24
|
+
constructor(options?: HubOptions) {
|
|
25
|
+
this.#options = options ?? {};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
init() {
|
|
29
|
+
this.runAll('init');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/*
|
|
33
|
+
* Running a specific action (e.g. init) on all namespaces and providers one by one.
|
|
34
|
+
*
|
|
35
|
+
* TODO: Some of methods may accepts args, with this implementation we only limit to those one without any argument.
|
|
36
|
+
*/
|
|
37
|
+
runAll(action: string): RunAllResult[] {
|
|
38
|
+
const output: RunAllResult[] = [];
|
|
39
|
+
|
|
40
|
+
// run action on all providers eagerConnect, disconnect
|
|
41
|
+
const providers = this.#providers.values();
|
|
42
|
+
|
|
43
|
+
for (const provider of providers) {
|
|
44
|
+
// Calling `action` on `Provider` if exists.
|
|
45
|
+
const providerOutput: RunAllResult = {
|
|
46
|
+
id: provider.id,
|
|
47
|
+
provider: undefined,
|
|
48
|
+
namespaces: [],
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const providerMethod = provider[action as keyof Provider];
|
|
52
|
+
if (typeof providerMethod === 'function') {
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
54
|
+
// @ts-ignore-next-line
|
|
55
|
+
providerOutput.provider = providerMethod.call(provider);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Namespace instances can have their own `action` as well. we will call them as well.
|
|
59
|
+
const namespaces = provider.getAll().values();
|
|
60
|
+
for (const namespace of namespaces) {
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
62
|
+
// @ts-ignore-next-line
|
|
63
|
+
const namespaceMethod = namespace[action];
|
|
64
|
+
if (typeof namespaceMethod === 'function') {
|
|
65
|
+
const result = namespaceMethod();
|
|
66
|
+
providerOutput.namespaces.push(result);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
output.push(providerOutput);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return output;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
add(id: string, provider: Provider) {
|
|
77
|
+
if (this.#options.store) {
|
|
78
|
+
provider.store(this.#options.store);
|
|
79
|
+
}
|
|
80
|
+
this.#providers.set(id, provider);
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
remove(id: string) {
|
|
84
|
+
const providerToRemove = this.#providers.get(id);
|
|
85
|
+
|
|
86
|
+
if (!providerToRemove) {
|
|
87
|
+
throw new Error(`Provider not found: No provider exists with ID "${id}"`);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
this.#options.store?.getState().providers.removeProvider(id);
|
|
91
|
+
this.#providers.delete(id);
|
|
92
|
+
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
get(providerId: string): Provider | undefined {
|
|
97
|
+
return this.#providers.get(providerId);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
getAll() {
|
|
101
|
+
return this.#providers;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
state(): HubState {
|
|
105
|
+
const output = this.runAll('state');
|
|
106
|
+
const res: HubState = {};
|
|
107
|
+
|
|
108
|
+
output.forEach((result) => {
|
|
109
|
+
const namespaces: NamespaceState[] = [];
|
|
110
|
+
result.namespaces.forEach((b) => {
|
|
111
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
112
|
+
const [getNamespaceState] = b as ReturnType<Namespace<any>['state']>;
|
|
113
|
+
|
|
114
|
+
namespaces.push(getNamespaceState());
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const [getProviderState] = result.provider as ReturnType<
|
|
118
|
+
Provider['state']
|
|
119
|
+
>;
|
|
120
|
+
|
|
121
|
+
res[result.id] = {
|
|
122
|
+
...(getProviderState() || {}),
|
|
123
|
+
namespaces: namespaces,
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
return res;
|
|
127
|
+
}
|
|
128
|
+
}
|
package/src/hub/mod.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
Subscriber,
|
|
3
|
+
SubscriberCleanUp,
|
|
4
|
+
Context,
|
|
5
|
+
} from './namespaces/mod.js';
|
|
6
|
+
export { Namespace } from './namespaces/mod.js';
|
|
7
|
+
|
|
8
|
+
export { Provider } from './provider/mod.js';
|
|
9
|
+
export type { CommonNamespaces, CommonNamespaceKeys } from './provider/mod.js';
|
|
10
|
+
|
|
11
|
+
export { Hub } from './hub.js';
|
|
12
|
+
export type { Store, State, ProviderMetadata } from './store/mod.js';
|
|
13
|
+
export {
|
|
14
|
+
createStore,
|
|
15
|
+
guessProviderStateSelector,
|
|
16
|
+
namespaceStateSelector,
|
|
17
|
+
} from './store/mod.js';
|
|
18
|
+
export { generateStoreId } from './helpers.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const ACTION_NOT_FOUND_ERROR = (name: string) =>
|
|
2
|
+
`Couldn't find "${name}" action. Are you sure you've added the action?`;
|
|
3
|
+
|
|
4
|
+
export const OR_ELSE_ACTION_FAILED_ERROR = (name: string) =>
|
|
5
|
+
`An error occurred during running ${name}`;
|
|
6
|
+
|
|
7
|
+
export const BEFORE_ACTION_FAILED_ERROR = (name: string) =>
|
|
8
|
+
`An error occurred during running before for "${name}" action`;
|
|
9
|
+
|
|
10
|
+
export const NO_STORE_FOUND_ERROR =
|
|
11
|
+
'For setup store, you should set `store` first.';
|