@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,173 @@
|
|
|
1
|
+
import type { Actions } from '../../../hub/namespaces/types.js';
|
|
2
|
+
import type { AutoImplementedActionsByRecommended } from '../types.js';
|
|
3
|
+
|
|
4
|
+
import { waitFor } from '@testing-library/dom';
|
|
5
|
+
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { createStore, Namespace } from '../../../mod.js';
|
|
8
|
+
|
|
9
|
+
import { ChangeAccountSubscriberBuilder } from './changeAccountSubscriber.js';
|
|
10
|
+
|
|
11
|
+
interface TestNamespaceActions {
|
|
12
|
+
disconnect: () => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe('check changeAccountSubscriber', () => {
|
|
16
|
+
const garbageProvider = { name: 'garbage provider' };
|
|
17
|
+
|
|
18
|
+
const garbageFormatter = async (
|
|
19
|
+
_instance: typeof garbageProvider,
|
|
20
|
+
accounts: string[]
|
|
21
|
+
) => accounts.map((account) => `Formatted: ${account}`);
|
|
22
|
+
|
|
23
|
+
const garbageAddEventListener = (
|
|
24
|
+
_instance: typeof garbageProvider,
|
|
25
|
+
callback: (event: string[]) => void
|
|
26
|
+
) => {
|
|
27
|
+
callback(['0']);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const garbageRemoveEventListener = (
|
|
31
|
+
_: typeof garbageProvider,
|
|
32
|
+
__: (event: string[]) => void
|
|
33
|
+
) => {};
|
|
34
|
+
|
|
35
|
+
let builder: ChangeAccountSubscriberBuilder<
|
|
36
|
+
string[],
|
|
37
|
+
typeof garbageProvider,
|
|
38
|
+
Actions<AutoImplementedActionsByRecommended>
|
|
39
|
+
>;
|
|
40
|
+
|
|
41
|
+
const setupNamespace = () => {
|
|
42
|
+
const actions = new Map();
|
|
43
|
+
const disconnectAction = vi.fn();
|
|
44
|
+
actions.set('disconnect', disconnectAction);
|
|
45
|
+
|
|
46
|
+
const store = createStore();
|
|
47
|
+
const ns = new Namespace<TestNamespaceActions>('evm', 'garbage provider', {
|
|
48
|
+
actions,
|
|
49
|
+
store,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const context = { action: ns.run.bind(ns), state: ns.state.bind(ns) };
|
|
53
|
+
|
|
54
|
+
return { ns, context, disconnectAction };
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
beforeEach(() => {
|
|
58
|
+
builder = new ChangeAccountSubscriberBuilder();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('throws error if required operators are not set', () => {
|
|
62
|
+
expect(() => builder.build()).toThrow(
|
|
63
|
+
`Required "getInstance" operation has not been set for "changeAccountSubscriber"`
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
builder.getInstance(() => garbageProvider);
|
|
67
|
+
expect(() => builder.build()).toThrow(
|
|
68
|
+
`Required "format" operation has not been set for "changeAccountSubscriber"`
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
builder.format(garbageFormatter);
|
|
72
|
+
expect(() => builder.build()).toThrow(
|
|
73
|
+
`Required "addEventListener" operation has not been set for "changeAccountSubscriber"`
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
builder.addEventListener(garbageAddEventListener);
|
|
77
|
+
expect(() => builder.build()).toThrow(
|
|
78
|
+
`Required "removeEventListener" operation has not been set for "changeAccountSubscriber"`
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
builder.removeEventListener(garbageRemoveEventListener);
|
|
82
|
+
|
|
83
|
+
// should not throw now
|
|
84
|
+
builder.build();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('calls addEventListener and formats accounts correctly', async () => {
|
|
88
|
+
const { context } = setupNamespace();
|
|
89
|
+
const spiedAddEventListener = vi.fn(garbageAddEventListener);
|
|
90
|
+
|
|
91
|
+
builder
|
|
92
|
+
.getInstance(() => garbageProvider)
|
|
93
|
+
.format(garbageFormatter)
|
|
94
|
+
.addEventListener(spiedAddEventListener)
|
|
95
|
+
.removeEventListener(garbageRemoveEventListener);
|
|
96
|
+
|
|
97
|
+
const [subscriber] = builder.build();
|
|
98
|
+
|
|
99
|
+
expect(spiedAddEventListener).toHaveBeenCalledTimes(0);
|
|
100
|
+
subscriber(context);
|
|
101
|
+
expect(spiedAddEventListener).toHaveBeenCalledTimes(1);
|
|
102
|
+
|
|
103
|
+
const [getState] = context.state();
|
|
104
|
+
await waitFor(() => {
|
|
105
|
+
expect(getState('accounts')?.[0]).toBe('Formatted: 0');
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('wont update accounts if preventDefault called', async () => {
|
|
110
|
+
const { context } = setupNamespace();
|
|
111
|
+
const spiedAddEventListener = vi.fn(garbageAddEventListener);
|
|
112
|
+
const [getState, setState] = context.state();
|
|
113
|
+
setState('accounts', ['Initial State']);
|
|
114
|
+
builder
|
|
115
|
+
.getInstance(() => garbageProvider)
|
|
116
|
+
.format(garbageFormatter)
|
|
117
|
+
.addEventListener(spiedAddEventListener)
|
|
118
|
+
.onSwitchAccount((event) => {
|
|
119
|
+
event.preventDefault();
|
|
120
|
+
})
|
|
121
|
+
.removeEventListener(garbageRemoveEventListener);
|
|
122
|
+
|
|
123
|
+
const [subscriber] = builder.build();
|
|
124
|
+
|
|
125
|
+
subscriber(context);
|
|
126
|
+
await waitFor(() => {
|
|
127
|
+
expect(getState('accounts')?.[0]).toBe('Initial State');
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test('calls removeEventListener', () => {
|
|
132
|
+
const { context } = setupNamespace();
|
|
133
|
+
const spiedRemoveEventListener = vi.fn(garbageRemoveEventListener);
|
|
134
|
+
|
|
135
|
+
builder
|
|
136
|
+
.getInstance(() => garbageProvider)
|
|
137
|
+
.format(garbageFormatter)
|
|
138
|
+
.addEventListener(garbageAddEventListener)
|
|
139
|
+
.removeEventListener(spiedRemoveEventListener);
|
|
140
|
+
|
|
141
|
+
const [, clearSubscriber] = builder.build();
|
|
142
|
+
|
|
143
|
+
expect(spiedRemoveEventListener).toHaveBeenCalledTimes(0);
|
|
144
|
+
clearSubscriber(context);
|
|
145
|
+
expect(spiedRemoveEventListener).toHaveBeenCalledTimes(1);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test('calls addEventListener returned function', () => {
|
|
149
|
+
const { context } = setupNamespace();
|
|
150
|
+
const unsubscribe = vi.fn();
|
|
151
|
+
|
|
152
|
+
const addEventListenerWithReturn = (
|
|
153
|
+
_: typeof garbageProvider,
|
|
154
|
+
__: (event: string[]) => void
|
|
155
|
+
) => {
|
|
156
|
+
return unsubscribe;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
builder
|
|
160
|
+
.getInstance(() => garbageProvider)
|
|
161
|
+
.format(garbageFormatter)
|
|
162
|
+
.addEventListener(addEventListenerWithReturn)
|
|
163
|
+
.removeEventListener(garbageRemoveEventListener);
|
|
164
|
+
|
|
165
|
+
const [subscriber, clearSubscriber] = builder.build();
|
|
166
|
+
|
|
167
|
+
subscriber(context);
|
|
168
|
+
expect(unsubscribe).toHaveBeenCalledTimes(0);
|
|
169
|
+
|
|
170
|
+
clearSubscriber(context);
|
|
171
|
+
expect(unsubscribe).toHaveBeenCalledTimes(1);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Actions,
|
|
3
|
+
Context,
|
|
4
|
+
SubscriberCleanUp,
|
|
5
|
+
} from '../../../hub/namespaces/types.js';
|
|
6
|
+
import type { Subscriber } from '../../../mod.js';
|
|
7
|
+
import type { AutoImplementedActionsByRecommended } from '../types.js';
|
|
8
|
+
|
|
9
|
+
type OnSwitchAccountEvent<EventType> = {
|
|
10
|
+
payload: EventType;
|
|
11
|
+
preventDefault: () => void;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export class ChangeAccountSubscriberBuilder<
|
|
15
|
+
EventType,
|
|
16
|
+
ProviderAPI,
|
|
17
|
+
ActionsType extends Actions<ActionsType> &
|
|
18
|
+
Actions<AutoImplementedActionsByRecommended>
|
|
19
|
+
> {
|
|
20
|
+
#getInstance: (() => ProviderAPI) | null = null;
|
|
21
|
+
#format:
|
|
22
|
+
| ((instance: ProviderAPI, event: EventType) => Promise<string[]>)
|
|
23
|
+
| null = null;
|
|
24
|
+
#onSwitchAccount:
|
|
25
|
+
| ((
|
|
26
|
+
event: OnSwitchAccountEvent<EventType>,
|
|
27
|
+
context: Context<ActionsType>
|
|
28
|
+
) => void)
|
|
29
|
+
| null = null;
|
|
30
|
+
|
|
31
|
+
#addEventListener:
|
|
32
|
+
| ((
|
|
33
|
+
instance: ProviderAPI,
|
|
34
|
+
callback: (event: EventType) => void
|
|
35
|
+
) => (() => void) | void)
|
|
36
|
+
| null = null;
|
|
37
|
+
#removeEventListener:
|
|
38
|
+
| ((instance: ProviderAPI, callback: (event: EventType) => void) => void)
|
|
39
|
+
| null = null;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Sets the function that provides the provider API instance.
|
|
43
|
+
*
|
|
44
|
+
* @param operator - Function that returns the provider API instance
|
|
45
|
+
* @returns The builder instance for method chaining
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* builder.getInstance(() => window.ethereum)
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
public getInstance(operator: () => ProviderAPI) {
|
|
52
|
+
this.#getInstance = operator;
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Sets the formatter function that converts provider events to account strings.
|
|
58
|
+
*
|
|
59
|
+
* @param operator - Function that takes a provider instance and event, returns array of account strings
|
|
60
|
+
* @returns The builder instance for method chaining
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* builder.format(async (instance, event) => event.accounts || [])
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
public format(
|
|
67
|
+
operator: (instance: ProviderAPI, event: EventType) => Promise<string[]>
|
|
68
|
+
) {
|
|
69
|
+
this.#format = operator;
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Set a handler that runs whenever a **switch-account** event occurs.
|
|
75
|
+
*
|
|
76
|
+
* The provided operator is called with:
|
|
77
|
+
* - `event`: An object containing:
|
|
78
|
+
* - `payload`: The event payload associated with the account switch.
|
|
79
|
+
* - `preventDefault`: A function that prevents the default switch-account
|
|
80
|
+
* behavior (e.g., updating the active accounts list).
|
|
81
|
+
* - `context`: The execution context of the current flow or action.
|
|
82
|
+
*
|
|
83
|
+
* Calling `event.preventDefault()` inside the handler cancels the built-in
|
|
84
|
+
* account switching logic.
|
|
85
|
+
*
|
|
86
|
+
* @param operator - A function invoked on each switch-account event.
|
|
87
|
+
* It receives `(event, context)` and can call `event.preventDefault()` to
|
|
88
|
+
* stop the default behavior.
|
|
89
|
+
*
|
|
90
|
+
* @returns The builder instance for method chaining.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* builder.onSwitchAccount((event, context) => {
|
|
95
|
+
* if (!event.payload.userConfirmed) {
|
|
96
|
+
* event.preventDefault(); // cancel default account switch
|
|
97
|
+
* }
|
|
98
|
+
*
|
|
99
|
+
* console.log("Switching account:", event.payload.accountId);
|
|
100
|
+
* });
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
public onSwitchAccount(
|
|
104
|
+
operator: (
|
|
105
|
+
event: OnSwitchAccountEvent<EventType>,
|
|
106
|
+
context: Context<ActionsType>
|
|
107
|
+
) => void
|
|
108
|
+
) {
|
|
109
|
+
this.#onSwitchAccount = operator;
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Sets the event listener attachment function.
|
|
115
|
+
*
|
|
116
|
+
* @param operator - Function that attaches an event listener and optionally returns a cleanup function
|
|
117
|
+
* @returns The builder instance for method chaining
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* builder.addEventListener((instance, callback) => {
|
|
121
|
+
* return instance.on('accountsChanged', callback);
|
|
122
|
+
* })
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
public addEventListener(
|
|
126
|
+
operator: (
|
|
127
|
+
instance: ProviderAPI,
|
|
128
|
+
callback: (event: EventType) => void
|
|
129
|
+
) => (() => void) | void
|
|
130
|
+
) {
|
|
131
|
+
this.#addEventListener = operator;
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Sets the event listener removal function.
|
|
137
|
+
*
|
|
138
|
+
* @param operator - Function that removes an event listener from the provider
|
|
139
|
+
* @returns The builder instance for method chaining
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* builder.removeEventListener((instance, callback) => instance.off('accountsChanged', callback))
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
public removeEventListener(
|
|
146
|
+
operator: (
|
|
147
|
+
instance: ProviderAPI,
|
|
148
|
+
callback: (event: EventType) => void
|
|
149
|
+
) => void
|
|
150
|
+
) {
|
|
151
|
+
this.#removeEventListener = operator;
|
|
152
|
+
return this;
|
|
153
|
+
}
|
|
154
|
+
public build(): [Subscriber<ActionsType>, SubscriberCleanUp<ActionsType>] {
|
|
155
|
+
if (this.#getInstance === null) {
|
|
156
|
+
throw new Error(this.#getErrorMessage('getInstance'));
|
|
157
|
+
}
|
|
158
|
+
if (this.#format === null) {
|
|
159
|
+
throw new Error(this.#getErrorMessage('format'));
|
|
160
|
+
}
|
|
161
|
+
if (this.#addEventListener === null) {
|
|
162
|
+
throw new Error(this.#getErrorMessage('addEventListener'));
|
|
163
|
+
}
|
|
164
|
+
if (this.#removeEventListener === null) {
|
|
165
|
+
throw new Error(this.#getErrorMessage('removeEventListener'));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Capture current operator state at build time to ensure immutability.
|
|
170
|
+
*
|
|
171
|
+
* This creates a snapshot of all operators, preventing the built subscriber
|
|
172
|
+
* from being affected by subsequent changes to the builder instance.
|
|
173
|
+
* Each call to build() gets its own isolated set of operators, allowing
|
|
174
|
+
* the builder to be reused for creating multiple independent subscribers.
|
|
175
|
+
*/
|
|
176
|
+
const getInstance = this.#getInstance;
|
|
177
|
+
const format = this.#format;
|
|
178
|
+
const addEventListener = this.#addEventListener;
|
|
179
|
+
const removeEventListener = this.#removeEventListener;
|
|
180
|
+
const onSwitchAccount = this.#onSwitchAccount;
|
|
181
|
+
|
|
182
|
+
let subscriber: (event: EventType) => void;
|
|
183
|
+
let unsubscribe: (() => void) | void;
|
|
184
|
+
return [
|
|
185
|
+
async (context) => {
|
|
186
|
+
const [, setState] = context.state();
|
|
187
|
+
const instance = getInstance();
|
|
188
|
+
|
|
189
|
+
if (!instance) {
|
|
190
|
+
throw new Error(
|
|
191
|
+
'Trying to subscribe to your wallet, but seems its instance is not available.'
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
subscriber = async (event) => {
|
|
195
|
+
let shouldProceedWithDefault = true;
|
|
196
|
+
onSwitchAccount?.(
|
|
197
|
+
{
|
|
198
|
+
payload: event,
|
|
199
|
+
preventDefault: () => {
|
|
200
|
+
shouldProceedWithDefault = false;
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
context
|
|
204
|
+
);
|
|
205
|
+
if (!shouldProceedWithDefault) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
setState('accounts', await format(instance, event));
|
|
209
|
+
};
|
|
210
|
+
unsubscribe = addEventListener(instance, subscriber);
|
|
211
|
+
},
|
|
212
|
+
(_, err) => {
|
|
213
|
+
/**
|
|
214
|
+
* Call the cleanup function if addEventListener returned one.
|
|
215
|
+
* This handles providers that return an unsubscribe function from their event listeners.
|
|
216
|
+
*/
|
|
217
|
+
if (unsubscribe && typeof unsubscribe === 'function') {
|
|
218
|
+
unsubscribe();
|
|
219
|
+
}
|
|
220
|
+
const instance = getInstance();
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Always call removeEventListener as well to handle the on/off pattern.
|
|
224
|
+
* This ensures cleanup works regardless of which pattern the provider uses.
|
|
225
|
+
*/
|
|
226
|
+
removeEventListener(instance, subscriber);
|
|
227
|
+
|
|
228
|
+
// subscriber can be passed to `or`, it will get the error and should rethrow error to pass the error to next `or` or throw error.
|
|
229
|
+
return err;
|
|
230
|
+
},
|
|
231
|
+
];
|
|
232
|
+
}
|
|
233
|
+
#getErrorMessage(operatorName: string) {
|
|
234
|
+
return `Required "${operatorName}" operation has not been set for "changeAccountSubscriber"`;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export * as actions from './actions.js';
|
|
2
|
+
export * as builders from './builders.js';
|
|
3
|
+
export { standardizeAndThrowError } from './or.js';
|
|
4
|
+
export { parseErrorAndThrowStandardizeError } from './utils.js';
|
|
5
|
+
export {
|
|
6
|
+
intoConnectionFinished,
|
|
7
|
+
recommended as afterRecommended,
|
|
8
|
+
} from './after.js';
|
|
9
|
+
export { ChangeAccountSubscriberBuilder } from './hooks/changeAccountSubscriber.js';
|
|
10
|
+
export {
|
|
11
|
+
connectAndUpdateStateForMultiNetworks,
|
|
12
|
+
connectAndUpdateStateForSingleNetwork,
|
|
13
|
+
recommended as andRecommended,
|
|
14
|
+
} from './and.js';
|
|
15
|
+
export { intoConnecting, recommended as beforeRecommended } from './before.js';
|
|
16
|
+
|
|
17
|
+
export type {
|
|
18
|
+
CaipAccount,
|
|
19
|
+
Accounts,
|
|
20
|
+
AccountsWithActiveChain,
|
|
21
|
+
} from '../../types/accounts.js';
|
|
22
|
+
|
|
23
|
+
export type { Namespace } from './types.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Context } from '../../hub/namespaces/mod.js';
|
|
2
|
+
|
|
3
|
+
import { parseErrorAndThrowStandardizeError } from './utils.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Standardizes an unknown error into an Error object and throws it.
|
|
7
|
+
* If the input is already an Error, it's thrown directly.
|
|
8
|
+
* Otherwise, a new Error is created with the input's message or string representation.
|
|
9
|
+
* Note: The parseErrorAndThrowStandardizeError function is defined as a separate function, so that it can be used independently.
|
|
10
|
+
*
|
|
11
|
+
* @param _context - The context.
|
|
12
|
+
* @param e - The unknown error object.
|
|
13
|
+
* @throws {Error} - The standardized Error object.
|
|
14
|
+
*/
|
|
15
|
+
export function standardizeAndThrowError(_context: Context, e: unknown): never {
|
|
16
|
+
parseErrorAndThrowStandardizeError(e);
|
|
17
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* These are supported namespaces in Rango that we want to officially support.
|
|
3
|
+
* This should be private and don't make it public since core can support more namespaces and should be extendable.
|
|
4
|
+
*/
|
|
5
|
+
type RangoNamespace =
|
|
6
|
+
| 'EVM'
|
|
7
|
+
| 'Solana'
|
|
8
|
+
| 'Cosmos'
|
|
9
|
+
| 'UTXO'
|
|
10
|
+
| 'Starknet'
|
|
11
|
+
| 'Tron'
|
|
12
|
+
| 'Ton'
|
|
13
|
+
| 'Sui';
|
|
14
|
+
|
|
15
|
+
export type Namespace = RangoNamespace | (string & {});
|
|
16
|
+
|
|
17
|
+
export interface CommonActions {
|
|
18
|
+
init: () => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface AutoImplementedActionsByRecommended {
|
|
22
|
+
disconnect: () => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type Provider = Map<string, unknown>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standardizes an unknown error into an Error object and throws it.
|
|
3
|
+
* If the input is already an Error, it's thrown directly.
|
|
4
|
+
* Otherwise, a new Error is created with the input's message or string representation.
|
|
5
|
+
*
|
|
6
|
+
* @param e - The unknown error object.
|
|
7
|
+
* @throws {Error} - The standardized Error object.
|
|
8
|
+
*/
|
|
9
|
+
export function parseErrorAndThrowStandardizeError(e: unknown): never {
|
|
10
|
+
if (e instanceof Error) {
|
|
11
|
+
throw e;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let errorMessage: string;
|
|
15
|
+
if (
|
|
16
|
+
typeof e === 'object' &&
|
|
17
|
+
e !== null &&
|
|
18
|
+
'message' in e &&
|
|
19
|
+
typeof e.message === 'string'
|
|
20
|
+
) {
|
|
21
|
+
errorMessage = e.message;
|
|
22
|
+
} else if (typeof e === 'string') {
|
|
23
|
+
errorMessage = e;
|
|
24
|
+
} else {
|
|
25
|
+
errorMessage = String(e);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const err = new Error(errorMessage) as Error & {
|
|
29
|
+
code?: unknown;
|
|
30
|
+
data?: unknown;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
if (typeof e === 'object' && e !== null) {
|
|
34
|
+
if ('code' in e) {
|
|
35
|
+
err.code = e.code;
|
|
36
|
+
}
|
|
37
|
+
if ('data' in e) {
|
|
38
|
+
err.data = e.data;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
throw err;
|
|
43
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CosmosActions } from './types.js';
|
|
2
|
+
|
|
3
|
+
import { ActionBuilder } from '../../mod.js';
|
|
4
|
+
import {
|
|
5
|
+
connectAndUpdateStateForSingleNetwork,
|
|
6
|
+
intoConnecting,
|
|
7
|
+
intoConnectionFinished,
|
|
8
|
+
} from '../common/mod.js';
|
|
9
|
+
|
|
10
|
+
// Actions
|
|
11
|
+
export const connect = () =>
|
|
12
|
+
new ActionBuilder<CosmosActions, 'connect'>('connect')
|
|
13
|
+
.and(connectAndUpdateStateForSingleNetwork)
|
|
14
|
+
.before(intoConnecting)
|
|
15
|
+
.after(intoConnectionFinished);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const CAIP_NAMESPACE = 'cosmos';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type { CosmosActions, ProviderAPI } from './types.js';
|
|
2
|
+
export * as actions from './actions.js';
|
|
3
|
+
export * as after from './after.js';
|
|
4
|
+
export * as and from './and.js';
|
|
5
|
+
export * as before from './before.js';
|
|
6
|
+
export * as utils from './utils.js';
|
|
7
|
+
export * as builders from './builders.js';
|
|
8
|
+
|
|
9
|
+
export { CAIP_NAMESPACE } from './constants.js';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Accounts } from '../common/mod.js';
|
|
2
|
+
import type {
|
|
3
|
+
AutoImplementedActionsByRecommended,
|
|
4
|
+
CommonActions,
|
|
5
|
+
} from '../common/types.js';
|
|
6
|
+
|
|
7
|
+
export interface CosmosActions
|
|
8
|
+
extends AutoImplementedActionsByRecommended,
|
|
9
|
+
CommonActions {
|
|
10
|
+
connect: (options?: ConnectOptions) => Promise<Accounts>;
|
|
11
|
+
canEagerConnect: () => Promise<boolean>;
|
|
12
|
+
}
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
+
export type ProviderAPI = Record<string, any>;
|
|
15
|
+
export type CosmosChainAccounts = {
|
|
16
|
+
accounts: string[];
|
|
17
|
+
chainId: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type ConnectOptions = {
|
|
21
|
+
chainIds: string[];
|
|
22
|
+
/**
|
|
23
|
+
* For chains that may not be natively supported by the provider.
|
|
24
|
+
*/
|
|
25
|
+
customChainIds?: string[];
|
|
26
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { CosmosChainAccounts } from './types.js';
|
|
2
|
+
import type { CaipAccount } from '../common/mod.js';
|
|
3
|
+
|
|
4
|
+
import { AccountId } from 'caip';
|
|
5
|
+
|
|
6
|
+
import { CAIP_NAMESPACE } from './constants.js';
|
|
7
|
+
|
|
8
|
+
export function formatAccountsToCAIP(accounts: CosmosChainAccounts[]) {
|
|
9
|
+
return accounts.flatMap((networkAccounts) =>
|
|
10
|
+
networkAccounts.accounts.map(
|
|
11
|
+
(networkAccount) =>
|
|
12
|
+
AccountId.format({
|
|
13
|
+
address: networkAccount,
|
|
14
|
+
chainId: {
|
|
15
|
+
namespace: CAIP_NAMESPACE,
|
|
16
|
+
reference: networkAccounts.chainId,
|
|
17
|
+
},
|
|
18
|
+
}) as CaipAccount
|
|
19
|
+
)
|
|
20
|
+
);
|
|
21
|
+
}
|