@reown/appkit 1.5.3-k2f8w6.0 → 1.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/exports/constants.js +1 -1
- package/dist/esm/exports/constants.js.map +1 -1
- package/dist/esm/package.json +1 -1
- package/dist/esm/src/adapters/ChainAdapterBlueprint.js +1 -1
- package/dist/esm/src/adapters/ChainAdapterBlueprint.js.map +1 -1
- package/dist/esm/src/client.js +57 -48
- package/dist/esm/src/client.js.map +1 -1
- package/dist/esm/src/networks/bitcoin.js +14 -0
- package/dist/esm/src/networks/bitcoin.js.map +1 -1
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/exports/constants.d.ts +1 -1
- package/dist/types/src/adapters/ChainAdapterBlueprint.d.ts +1 -2
- package/dist/types/src/client.d.ts +2 -1
- package/dist/types/src/networks/bitcoin.d.ts +47 -0
- package/package.json +9 -9
- package/dist/esm/src/tests/appkit.test.js +0 -533
- package/dist/esm/src/tests/appkit.test.js.map +0 -1
- package/dist/esm/src/tests/mocks/Adapter.js +0 -30
- package/dist/esm/src/tests/mocks/Adapter.js.map +0 -1
- package/dist/esm/src/tests/mocks/AppKit.js +0 -24
- package/dist/esm/src/tests/mocks/AppKit.js.map +0 -1
- package/dist/esm/src/tests/mocks/Options.js +0 -14
- package/dist/esm/src/tests/mocks/Options.js.map +0 -1
- package/dist/esm/src/tests/mocks/UniversalProvider.js +0 -137
- package/dist/esm/src/tests/mocks/UniversalProvider.js.map +0 -1
- package/dist/esm/src/tests/siwe.test.js +0 -205
- package/dist/esm/src/tests/siwe.test.js.map +0 -1
- package/dist/esm/src/tests/universal-adapter.test.js +0 -115
- package/dist/esm/src/tests/universal-adapter.test.js.map +0 -1
- package/dist/esm/src/tests/utils/HelpersUtil.test.js +0 -195
- package/dist/esm/src/tests/utils/HelpersUtil.test.js.map +0 -1
- package/dist/esm/tsconfig.tsbuildinfo +0 -1
- package/dist/types/src/tests/appkit.test.d.ts +0 -1
- package/dist/types/src/tests/mocks/Adapter.d.ts +0 -3
- package/dist/types/src/tests/mocks/AppKit.d.ts +0 -3
- package/dist/types/src/tests/mocks/Options.d.ts +0 -18
- package/dist/types/src/tests/mocks/UniversalProvider.d.ts +0 -3
- package/dist/types/src/tests/siwe.test.d.ts +0 -1
- package/dist/types/src/tests/universal-adapter.test.d.ts +0 -1
- package/dist/types/src/tests/utils/HelpersUtil.test.d.ts +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PACKAGE_VERSION = "1.5.3
|
|
1
|
+
export declare const PACKAGE_VERSION = "1.5.3";
|
|
@@ -5,7 +5,7 @@ import type UniversalProvider from '@walletconnect/universal-provider';
|
|
|
5
5
|
import type { W3mFrameProvider } from '@reown/appkit-wallet';
|
|
6
6
|
import type { AppKitOptions } from '../utils/index.js';
|
|
7
7
|
import type { AppKit } from '../client.js';
|
|
8
|
-
type EventName = 'disconnect' | 'accountChanged' | 'switchNetwork'
|
|
8
|
+
type EventName = 'disconnect' | 'accountChanged' | 'switchNetwork';
|
|
9
9
|
type EventData = {
|
|
10
10
|
disconnect: () => void;
|
|
11
11
|
accountChanged: {
|
|
@@ -16,7 +16,6 @@ type EventData = {
|
|
|
16
16
|
address?: string;
|
|
17
17
|
chainId: number | string;
|
|
18
18
|
};
|
|
19
|
-
statusChanged: AccountControllerState['status'];
|
|
20
19
|
};
|
|
21
20
|
type EventCallback<T extends EventName> = (data: EventData[T]) => void;
|
|
22
21
|
/**
|
|
@@ -86,7 +86,7 @@ export declare class AppKit {
|
|
|
86
86
|
getCaipAddress: (chainNamespace?: ChainNamespace) => `eip155:${string}:${string}` | `eip155:${number}:${string}` | `solana:${string}:${string}` | `solana:${number}:${string}` | `polkadot:${string}:${string}` | `polkadot:${number}:${string}` | `bip122:${string}:${string}` | `bip122:${number}:${string}` | undefined;
|
|
87
87
|
getAddressByChainNamespace: (chainNamespace: ChainNamespace) => string | undefined;
|
|
88
88
|
getAddress: (chainNamespace?: ChainNamespace) => string | undefined;
|
|
89
|
-
getProvider: () =>
|
|
89
|
+
getProvider: () => Provider | UniversalProvider | import("@reown/appkit-core").CombinedProvider | undefined;
|
|
90
90
|
getPreferredAccountType: () => W3mFrameTypes.AccountType;
|
|
91
91
|
setCaipAddress: (typeof AccountController)['setCaipAddress'];
|
|
92
92
|
setProvider: (typeof AccountController)['setProvider'];
|
|
@@ -121,6 +121,7 @@ export declare class AppKit {
|
|
|
121
121
|
disconnect(): Promise<void>;
|
|
122
122
|
private initControllers;
|
|
123
123
|
private getDefaultMetaData;
|
|
124
|
+
private setUnsupportedNetwork;
|
|
124
125
|
private extendCaipNetworks;
|
|
125
126
|
private extendDefaultCaipNetwork;
|
|
126
127
|
private createClients;
|
|
@@ -45,3 +45,50 @@ export declare const bitcoin: {
|
|
|
45
45
|
imageUrl: string | undefined;
|
|
46
46
|
} | undefined;
|
|
47
47
|
};
|
|
48
|
+
export declare const bitcoinTestnet: {
|
|
49
|
+
blockExplorers?: {
|
|
50
|
+
[key: string]: {
|
|
51
|
+
name: string;
|
|
52
|
+
url: string;
|
|
53
|
+
apiUrl?: string | undefined;
|
|
54
|
+
};
|
|
55
|
+
default: {
|
|
56
|
+
name: string;
|
|
57
|
+
url: string;
|
|
58
|
+
apiUrl?: string | undefined;
|
|
59
|
+
};
|
|
60
|
+
} | undefined;
|
|
61
|
+
contracts?: {
|
|
62
|
+
[x: string]: import("viem").ChainContract | {
|
|
63
|
+
[sourceId: number]: import("viem").ChainContract | undefined;
|
|
64
|
+
} | undefined;
|
|
65
|
+
ensRegistry?: import("viem").ChainContract | undefined;
|
|
66
|
+
ensUniversalResolver?: import("viem").ChainContract | undefined;
|
|
67
|
+
multicall3?: import("viem").ChainContract | undefined;
|
|
68
|
+
universalSignatureVerifier?: import("viem").ChainContract | undefined;
|
|
69
|
+
} | undefined;
|
|
70
|
+
name: "Bitcoin Testnet";
|
|
71
|
+
nativeCurrency: {
|
|
72
|
+
readonly name: "Bitcoin";
|
|
73
|
+
readonly symbol: "BTC";
|
|
74
|
+
readonly decimals: 8;
|
|
75
|
+
};
|
|
76
|
+
rpcUrls: {
|
|
77
|
+
readonly default: {
|
|
78
|
+
readonly http: readonly ["https://rpc.walletconnect.org/v1"];
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
sourceId?: number | undefined;
|
|
82
|
+
testnet?: boolean | undefined;
|
|
83
|
+
custom?: Record<string, unknown> | undefined;
|
|
84
|
+
fees?: import("viem").ChainFees<undefined> | undefined;
|
|
85
|
+
formatters?: undefined;
|
|
86
|
+
serializers?: import("viem").ChainSerializers<undefined, import("viem").TransactionSerializable> | undefined;
|
|
87
|
+
id: "000000000933ea01ad0ee984209779ba";
|
|
88
|
+
chainNamespace: "bip122";
|
|
89
|
+
caipNetworkId: "bip122:000000000933ea01ad0ee984209779ba";
|
|
90
|
+
assets?: {
|
|
91
|
+
imageId: string | undefined;
|
|
92
|
+
imageUrl: string | undefined;
|
|
93
|
+
} | undefined;
|
|
94
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reown/appkit",
|
|
3
|
-
"version": "1.5.3
|
|
3
|
+
"version": "1.5.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/esm/exports/index.js",
|
|
6
6
|
"types": "./dist/types/exports/index.d.ts",
|
|
@@ -95,14 +95,14 @@
|
|
|
95
95
|
"bs58": "6.0.0",
|
|
96
96
|
"valtio": "1.11.2",
|
|
97
97
|
"viem": "2.x",
|
|
98
|
-
"@reown/appkit-common": "1.5.3
|
|
99
|
-
"@reown/appkit-core": "1.5.3
|
|
100
|
-
"@reown/appkit-polyfills": "1.5.3
|
|
101
|
-
"@reown/appkit-scaffold-ui": "1.5.3
|
|
102
|
-
"@reown/appkit-siwe": "1.5.3
|
|
103
|
-
"@reown/appkit-ui": "1.5.3
|
|
104
|
-
"@reown/appkit-utils": "1.5.3
|
|
105
|
-
"@reown/appkit-wallet": "1.5.3
|
|
98
|
+
"@reown/appkit-common": "1.5.3",
|
|
99
|
+
"@reown/appkit-core": "1.5.3",
|
|
100
|
+
"@reown/appkit-polyfills": "1.5.3",
|
|
101
|
+
"@reown/appkit-scaffold-ui": "1.5.3",
|
|
102
|
+
"@reown/appkit-siwe": "1.5.3",
|
|
103
|
+
"@reown/appkit-ui": "1.5.3",
|
|
104
|
+
"@reown/appkit-utils": "1.5.3",
|
|
105
|
+
"@reown/appkit-wallet": "1.5.3"
|
|
106
106
|
},
|
|
107
107
|
"devDependencies": {
|
|
108
108
|
"@types/react": "18.3.1",
|
|
@@ -1,533 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
2
|
-
import { AppKit } from '../client';
|
|
3
|
-
import { mainnet, polygon } from '../networks/index.js';
|
|
4
|
-
import { AccountController, ModalController, ThemeController, PublicStateController, SnackController, RouterController, OptionsController, BlockchainApiController, ConnectionController, EnsController, EventsController, AssetUtil, ConnectorController, ChainController, StorageUtil } from '@reown/appkit-core';
|
|
5
|
-
import { SafeLocalStorage, SafeLocalStorageKeys } from '@reown/appkit-common';
|
|
6
|
-
import { mockOptions } from './mocks/Options';
|
|
7
|
-
import { UniversalAdapter } from '../universal-adapter/client';
|
|
8
|
-
// Mock all controllers and UniversalAdapterClient
|
|
9
|
-
vi.mock('@reown/appkit-core');
|
|
10
|
-
vi.mock('../universal-adapter/client');
|
|
11
|
-
describe('Base', () => {
|
|
12
|
-
let appKit;
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
vi.resetAllMocks();
|
|
15
|
-
vi.mocked(ChainController).state = {
|
|
16
|
-
chains: new Map(),
|
|
17
|
-
activeChain: 'eip155'
|
|
18
|
-
};
|
|
19
|
-
vi.mocked(ConnectorController).getConnectors = vi.fn().mockReturnValue([]);
|
|
20
|
-
appKit = new AppKit(mockOptions);
|
|
21
|
-
});
|
|
22
|
-
describe('Base Initialization', () => {
|
|
23
|
-
it('should initialize controllers with required provided options', () => {
|
|
24
|
-
expect(OptionsController.setSdkVersion).toHaveBeenCalledWith(mockOptions.sdkVersion);
|
|
25
|
-
expect(OptionsController.setProjectId).toHaveBeenCalledWith(mockOptions.projectId);
|
|
26
|
-
expect(OptionsController.setMetadata).toHaveBeenCalledWith(mockOptions.metadata);
|
|
27
|
-
});
|
|
28
|
-
it('should initialize adapters in ChainController', () => {
|
|
29
|
-
expect(ChainController.initialize).toHaveBeenCalledWith(mockOptions.adapters);
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
describe('Base Public methods', () => {
|
|
33
|
-
it('should open modal', async () => {
|
|
34
|
-
await appKit.open();
|
|
35
|
-
expect(ModalController.open).toHaveBeenCalled();
|
|
36
|
-
});
|
|
37
|
-
it('should close modal', async () => {
|
|
38
|
-
await appKit.close();
|
|
39
|
-
expect(ModalController.close).toHaveBeenCalled();
|
|
40
|
-
});
|
|
41
|
-
it('should set loading state', () => {
|
|
42
|
-
appKit.setLoading(true);
|
|
43
|
-
expect(ModalController.setLoading).toHaveBeenCalledWith(true);
|
|
44
|
-
});
|
|
45
|
-
it('should get theme mode', () => {
|
|
46
|
-
vi.mocked(ThemeController).state = { themeMode: 'dark' };
|
|
47
|
-
expect(appKit.getThemeMode()).toBe('dark');
|
|
48
|
-
});
|
|
49
|
-
it('should set theme mode', () => {
|
|
50
|
-
appKit.setThemeMode('light');
|
|
51
|
-
expect(ThemeController.setThemeMode).toHaveBeenCalledWith('light');
|
|
52
|
-
});
|
|
53
|
-
it('should get theme variables', () => {
|
|
54
|
-
vi.mocked(ThemeController).state = {
|
|
55
|
-
themeVariables: { '--w3m-accent': '#000' }
|
|
56
|
-
};
|
|
57
|
-
expect(appKit.getThemeVariables()).toEqual({ '--w3m-accent': '#000' });
|
|
58
|
-
});
|
|
59
|
-
it('should set theme variables', () => {
|
|
60
|
-
const themeVariables = { '--w3m-accent': '#fff' };
|
|
61
|
-
appKit.setThemeVariables(themeVariables);
|
|
62
|
-
expect(ThemeController.setThemeVariables).toHaveBeenCalledWith(themeVariables);
|
|
63
|
-
});
|
|
64
|
-
it('should subscribe to theme changes', () => {
|
|
65
|
-
const callback = vi.fn();
|
|
66
|
-
appKit.subscribeTheme(callback);
|
|
67
|
-
expect(ThemeController.subscribe).toHaveBeenCalledWith(callback);
|
|
68
|
-
});
|
|
69
|
-
it('should get wallet info', () => {
|
|
70
|
-
vi.mocked(AccountController).state = { connectedWalletInfo: { name: 'Test Wallet' } };
|
|
71
|
-
expect(appKit.getWalletInfo()).toEqual({ name: 'Test Wallet' });
|
|
72
|
-
});
|
|
73
|
-
it('should subscribe to wallet info changes', () => {
|
|
74
|
-
const callback = vi.fn();
|
|
75
|
-
appKit.subscribeWalletInfo(callback);
|
|
76
|
-
expect(AccountController.subscribeKey).toHaveBeenCalledWith('connectedWalletInfo', callback);
|
|
77
|
-
});
|
|
78
|
-
it('should subscribe to address updates', () => {
|
|
79
|
-
const callback = vi.fn();
|
|
80
|
-
appKit.subscribeShouldUpdateToAddress(callback);
|
|
81
|
-
expect(AccountController.subscribeKey).toHaveBeenCalledWith('shouldUpdateToAddress', callback);
|
|
82
|
-
});
|
|
83
|
-
it('should subscribe to CAIP network changes', () => {
|
|
84
|
-
const callback = vi.fn();
|
|
85
|
-
appKit.subscribeCaipNetworkChange(callback);
|
|
86
|
-
expect(ChainController.subscribeKey).toHaveBeenCalledWith('activeCaipNetwork', callback);
|
|
87
|
-
});
|
|
88
|
-
it('should get state', () => {
|
|
89
|
-
vi.mocked(PublicStateController).state = { isConnected: true };
|
|
90
|
-
expect(appKit.getState()).toEqual({ isConnected: true });
|
|
91
|
-
});
|
|
92
|
-
it('should subscribe to state changes', () => {
|
|
93
|
-
const callback = vi.fn();
|
|
94
|
-
appKit.subscribeState(callback);
|
|
95
|
-
expect(PublicStateController.subscribe).toHaveBeenCalledWith(callback);
|
|
96
|
-
});
|
|
97
|
-
it('should show error message', () => {
|
|
98
|
-
appKit.showErrorMessage('Test error');
|
|
99
|
-
expect(SnackController.showError).toHaveBeenCalledWith('Test error');
|
|
100
|
-
});
|
|
101
|
-
it('should show success message', () => {
|
|
102
|
-
appKit.showSuccessMessage('Test success');
|
|
103
|
-
expect(SnackController.showSuccess).toHaveBeenCalledWith('Test success');
|
|
104
|
-
});
|
|
105
|
-
it('should get event', () => {
|
|
106
|
-
vi.mocked(EventsController).state = { name: 'test_event' };
|
|
107
|
-
expect(appKit.getEvent()).toEqual({ name: 'test_event' });
|
|
108
|
-
});
|
|
109
|
-
it('should subscribe to events', () => {
|
|
110
|
-
const callback = vi.fn();
|
|
111
|
-
appKit.subscribeEvents(callback);
|
|
112
|
-
expect(EventsController.subscribe).toHaveBeenCalledWith(callback);
|
|
113
|
-
});
|
|
114
|
-
it('should replace route', () => {
|
|
115
|
-
appKit.replace('Connect');
|
|
116
|
-
expect(RouterController.replace).toHaveBeenCalledWith('Connect');
|
|
117
|
-
});
|
|
118
|
-
it('should redirect to route', () => {
|
|
119
|
-
appKit.redirect('Networks');
|
|
120
|
-
expect(RouterController.push).toHaveBeenCalledWith('Networks');
|
|
121
|
-
});
|
|
122
|
-
it('should pop transaction stack', () => {
|
|
123
|
-
appKit.popTransactionStack(true);
|
|
124
|
-
expect(RouterController.popTransactionStack).toHaveBeenCalledWith(true);
|
|
125
|
-
});
|
|
126
|
-
it('should check if modal is open', () => {
|
|
127
|
-
vi.mocked(ModalController).state = { open: true };
|
|
128
|
-
expect(appKit.isOpen()).toBe(true);
|
|
129
|
-
});
|
|
130
|
-
it('should check if transaction stack is empty', () => {
|
|
131
|
-
vi.mocked(RouterController).state = { transactionStack: [] };
|
|
132
|
-
expect(appKit.isTransactionStackEmpty()).toBe(true);
|
|
133
|
-
});
|
|
134
|
-
it('should check if transaction should replace view', () => {
|
|
135
|
-
vi.mocked(RouterController).state = { transactionStack: [{ replace: true }] };
|
|
136
|
-
expect(appKit.isTransactionShouldReplaceView()).toBe(true);
|
|
137
|
-
});
|
|
138
|
-
it('should set status', () => {
|
|
139
|
-
appKit.setStatus('connected', 'eip155');
|
|
140
|
-
expect(AccountController.setStatus).toHaveBeenCalledWith('connected', 'eip155');
|
|
141
|
-
});
|
|
142
|
-
it('should set all accounts', () => {
|
|
143
|
-
const addresses = ['0x123', '0x456'];
|
|
144
|
-
appKit.setAllAccounts(addresses, 'eip155');
|
|
145
|
-
expect(AccountController.setAllAccounts).toHaveBeenCalledWith(addresses, 'eip155');
|
|
146
|
-
expect(OptionsController.setHasMultipleAddresses).toHaveBeenCalledWith(true);
|
|
147
|
-
});
|
|
148
|
-
it('should add address label', () => {
|
|
149
|
-
appKit.addAddressLabel('0x123', 'eip155 Address', 'eip155');
|
|
150
|
-
expect(AccountController.addAddressLabel).toHaveBeenCalledWith('0x123', 'eip155 Address', 'eip155');
|
|
151
|
-
});
|
|
152
|
-
it('should remove address label', () => {
|
|
153
|
-
appKit.removeAddressLabel('0x123', 'eip155');
|
|
154
|
-
expect(AccountController.removeAddressLabel).toHaveBeenCalledWith('0x123', 'eip155');
|
|
155
|
-
});
|
|
156
|
-
it('should get CAIP address', () => {
|
|
157
|
-
vi.mocked(ChainController).state = {
|
|
158
|
-
activeChain: 'eip155',
|
|
159
|
-
activeCaipAddress: 'eip155:1:0x123'
|
|
160
|
-
};
|
|
161
|
-
expect(appKit.getCaipAddress()).toBe('eip155:1:0x123');
|
|
162
|
-
});
|
|
163
|
-
it('should get address', () => {
|
|
164
|
-
vi.mocked(AccountController).state = { address: '0x123' };
|
|
165
|
-
expect(appKit.getAddress()).toBe('0x123');
|
|
166
|
-
});
|
|
167
|
-
it('should get provider', () => {
|
|
168
|
-
const mockProvider = { request: vi.fn() };
|
|
169
|
-
vi.mocked(AccountController).state = { provider: mockProvider };
|
|
170
|
-
expect(appKit.getProvider()).toBe(mockProvider);
|
|
171
|
-
});
|
|
172
|
-
it('should get preferred account type', () => {
|
|
173
|
-
vi.mocked(AccountController).state = { preferredAccountType: 'eoa' };
|
|
174
|
-
expect(appKit.getPreferredAccountType()).toBe('eoa');
|
|
175
|
-
});
|
|
176
|
-
it('should set CAIP address', () => {
|
|
177
|
-
// First mock AccountController.setCaipAddress to update ChainController state
|
|
178
|
-
vi.mocked(AccountController.setCaipAddress).mockImplementation(() => {
|
|
179
|
-
vi.mocked(ChainController).state = {
|
|
180
|
-
...vi.mocked(ChainController).state,
|
|
181
|
-
activeCaipAddress: 'eip155:1:0x123'
|
|
182
|
-
};
|
|
183
|
-
});
|
|
184
|
-
appKit.setCaipAddress('eip155:1:0x123', 'eip155');
|
|
185
|
-
expect(AccountController.setCaipAddress).toHaveBeenCalledWith('eip155:1:0x123', 'eip155');
|
|
186
|
-
expect(appKit.getIsConnectedState()).toBe(true);
|
|
187
|
-
});
|
|
188
|
-
it('should set provider', () => {
|
|
189
|
-
const mockProvider = {
|
|
190
|
-
request: vi.fn()
|
|
191
|
-
};
|
|
192
|
-
appKit.setProvider(mockProvider, 'eip155');
|
|
193
|
-
expect(AccountController.setProvider).toHaveBeenCalledWith(mockProvider, 'eip155');
|
|
194
|
-
});
|
|
195
|
-
it('should set balance', () => {
|
|
196
|
-
appKit.setBalance('1.5', 'ETH', 'eip155');
|
|
197
|
-
expect(AccountController.setBalance).toHaveBeenCalledWith('1.5', 'ETH', 'eip155');
|
|
198
|
-
});
|
|
199
|
-
it('should set profile name', () => {
|
|
200
|
-
appKit.setProfileName('John Doe', 'eip155');
|
|
201
|
-
expect(AccountController.setProfileName).toHaveBeenCalledWith('John Doe', 'eip155');
|
|
202
|
-
});
|
|
203
|
-
it('should set profile image', () => {
|
|
204
|
-
appKit.setProfileImage('https://example.com/image.png', 'eip155');
|
|
205
|
-
expect(AccountController.setProfileImage).toHaveBeenCalledWith('https://example.com/image.png', 'eip155');
|
|
206
|
-
});
|
|
207
|
-
it('should reset account', () => {
|
|
208
|
-
appKit.resetAccount('eip155');
|
|
209
|
-
expect(AccountController.resetAccount).toHaveBeenCalledWith('eip155');
|
|
210
|
-
});
|
|
211
|
-
it('should set CAIP network', () => {
|
|
212
|
-
const caipNetwork = { id: 'eip155:1', name: 'Ethereum' };
|
|
213
|
-
appKit.setCaipNetwork(caipNetwork);
|
|
214
|
-
expect(ChainController.setActiveCaipNetwork).toHaveBeenCalledWith(caipNetwork);
|
|
215
|
-
});
|
|
216
|
-
it('should get CAIP network', () => {
|
|
217
|
-
vi.mocked(ChainController).state = {
|
|
218
|
-
activeCaipNetwork: { id: 'eip155:1', name: 'Ethereum' }
|
|
219
|
-
};
|
|
220
|
-
expect(appKit.getCaipNetwork()).toEqual({ id: 'eip155:1', name: 'Ethereum' });
|
|
221
|
-
});
|
|
222
|
-
it('should set requested CAIP networks', () => {
|
|
223
|
-
const requestedNetworks = [{ id: 'eip155:1', name: 'Ethereum' }];
|
|
224
|
-
appKit.setRequestedCaipNetworks(requestedNetworks, 'eip155');
|
|
225
|
-
expect(ChainController.setRequestedCaipNetworks).toHaveBeenCalledWith(requestedNetworks, 'eip155');
|
|
226
|
-
});
|
|
227
|
-
it('should set connectors', () => {
|
|
228
|
-
const existingConnectors = [
|
|
229
|
-
{ id: 'phantom', name: 'Phantom', chain: 'eip155', type: 'INJECTED' }
|
|
230
|
-
];
|
|
231
|
-
// Mock getConnectors to return existing connectors
|
|
232
|
-
vi.mocked(ConnectorController.getConnectors).mockReturnValue(existingConnectors);
|
|
233
|
-
const newConnectors = [
|
|
234
|
-
{ id: 'metamask', name: 'MetaMask', chain: 'eip155', type: 'INJECTED' }
|
|
235
|
-
];
|
|
236
|
-
appKit.setConnectors(newConnectors);
|
|
237
|
-
// Verify that setConnectors was called with combined array
|
|
238
|
-
expect(ConnectorController.setConnectors).toHaveBeenCalledWith([
|
|
239
|
-
...existingConnectors,
|
|
240
|
-
...newConnectors
|
|
241
|
-
]);
|
|
242
|
-
});
|
|
243
|
-
it('should add connector', () => {
|
|
244
|
-
const connector = {
|
|
245
|
-
id: 'metamask',
|
|
246
|
-
name: 'MetaMask',
|
|
247
|
-
chain: 'eip155',
|
|
248
|
-
type: 'INJECTED'
|
|
249
|
-
};
|
|
250
|
-
appKit.addConnector(connector);
|
|
251
|
-
expect(ConnectorController.addConnector).toHaveBeenCalledWith(connector);
|
|
252
|
-
});
|
|
253
|
-
it('should get connectors', () => {
|
|
254
|
-
const mockConnectors = [
|
|
255
|
-
{ id: 'metamask', name: 'MetaMask', chain: 'eip155:1', type: 'INJECTED' }
|
|
256
|
-
];
|
|
257
|
-
vi.mocked(ConnectorController.getConnectors).mockReturnValue(mockConnectors);
|
|
258
|
-
expect(appKit.getConnectors()).toEqual(mockConnectors);
|
|
259
|
-
});
|
|
260
|
-
it('should get approved CAIP network IDs', () => {
|
|
261
|
-
vi.mocked(ChainController.getAllApprovedCaipNetworkIds).mockReturnValue(['eip155:1']);
|
|
262
|
-
expect(appKit.getApprovedCaipNetworkIds()).toEqual(['eip155:1']);
|
|
263
|
-
});
|
|
264
|
-
it('should set approved CAIP networks data', () => {
|
|
265
|
-
appKit.setApprovedCaipNetworksData('eip155');
|
|
266
|
-
expect(ChainController.setApprovedCaipNetworksData).toHaveBeenCalledWith('eip155');
|
|
267
|
-
});
|
|
268
|
-
it('should reset network', () => {
|
|
269
|
-
appKit.resetNetwork('eip155');
|
|
270
|
-
expect(ChainController.resetNetwork).toHaveBeenCalled();
|
|
271
|
-
});
|
|
272
|
-
it('should reset WC connection', () => {
|
|
273
|
-
appKit.resetWcConnection();
|
|
274
|
-
expect(ConnectionController.resetWcConnection).toHaveBeenCalled();
|
|
275
|
-
});
|
|
276
|
-
it('should fetch identity', async () => {
|
|
277
|
-
const mockRequest = { caipChainId: 'eip155:1', address: '0x123' };
|
|
278
|
-
vi.mocked(BlockchainApiController.fetchIdentity).mockResolvedValue({
|
|
279
|
-
name: 'John Doe',
|
|
280
|
-
avatar: null
|
|
281
|
-
});
|
|
282
|
-
const result = await appKit.fetchIdentity(mockRequest);
|
|
283
|
-
expect(BlockchainApiController.fetchIdentity).toHaveBeenCalledWith(mockRequest);
|
|
284
|
-
expect(result).toEqual({ name: 'John Doe', avatar: null });
|
|
285
|
-
});
|
|
286
|
-
it('should set address explorer URL', () => {
|
|
287
|
-
appKit.setAddressExplorerUrl('https://etherscan.io/address/0x123', 'eip155');
|
|
288
|
-
expect(AccountController.setAddressExplorerUrl).toHaveBeenCalledWith('https://etherscan.io/address/0x123', 'eip155');
|
|
289
|
-
});
|
|
290
|
-
it('should set smart account deployed', () => {
|
|
291
|
-
appKit.setSmartAccountDeployed(true, 'eip155');
|
|
292
|
-
expect(AccountController.setSmartAccountDeployed).toHaveBeenCalledWith(true, 'eip155');
|
|
293
|
-
});
|
|
294
|
-
it('should set connected wallet info', () => {
|
|
295
|
-
const walletInfo = { name: 'MetaMask', icon: 'icon-url' };
|
|
296
|
-
appKit.setConnectedWalletInfo(walletInfo, 'eip155');
|
|
297
|
-
expect(AccountController.setConnectedWalletInfo).toHaveBeenCalledWith(walletInfo, 'eip155');
|
|
298
|
-
});
|
|
299
|
-
it('should set smart account enabled networks', () => {
|
|
300
|
-
const networks = [1, 137];
|
|
301
|
-
appKit.setSmartAccountEnabledNetworks(networks, 'eip155');
|
|
302
|
-
expect(ChainController.setSmartAccountEnabledNetworks).toHaveBeenCalledWith(networks, 'eip155');
|
|
303
|
-
});
|
|
304
|
-
it('should set preferred account type', () => {
|
|
305
|
-
appKit.setPreferredAccountType('eoa', 'eip155');
|
|
306
|
-
expect(AccountController.setPreferredAccountType).toHaveBeenCalledWith('eoa', 'eip155');
|
|
307
|
-
});
|
|
308
|
-
it('should get Reown name', async () => {
|
|
309
|
-
vi.mocked(EnsController.getNamesForAddress).mockResolvedValue([
|
|
310
|
-
{
|
|
311
|
-
name: 'john.reown.id',
|
|
312
|
-
addresses: { eip155: { address: '0x123', created: '0' } },
|
|
313
|
-
attributes: [],
|
|
314
|
-
registered: 0,
|
|
315
|
-
updated: 0
|
|
316
|
-
}
|
|
317
|
-
]);
|
|
318
|
-
const result = await appKit.getReownName('john.reown.id');
|
|
319
|
-
expect(EnsController.getNamesForAddress).toHaveBeenCalledWith('john.reown.id');
|
|
320
|
-
expect(result).toEqual([
|
|
321
|
-
{
|
|
322
|
-
name: 'john.reown.id',
|
|
323
|
-
addresses: { eip155: { address: '0x123', created: '0' } },
|
|
324
|
-
attributes: [],
|
|
325
|
-
registered: 0,
|
|
326
|
-
updated: 0
|
|
327
|
-
}
|
|
328
|
-
]);
|
|
329
|
-
});
|
|
330
|
-
it('should set EIP6963 enabled', () => {
|
|
331
|
-
appKit.setEIP6963Enabled(true);
|
|
332
|
-
expect(OptionsController.setEIP6963Enabled).toHaveBeenCalledWith(true);
|
|
333
|
-
});
|
|
334
|
-
it('should set client ID', () => {
|
|
335
|
-
appKit.setClientId('client-123');
|
|
336
|
-
expect(BlockchainApiController.setClientId).toHaveBeenCalledWith('client-123');
|
|
337
|
-
});
|
|
338
|
-
it('should get connector image', () => {
|
|
339
|
-
vi.mocked(AssetUtil.getConnectorImage).mockReturnValue('connector-image-url');
|
|
340
|
-
const result = appKit.getConnectorImage({ id: 'metamask', type: 'INJECTED', chain: 'eip155' });
|
|
341
|
-
expect(AssetUtil.getConnectorImage).toHaveBeenCalledWith({
|
|
342
|
-
id: 'metamask',
|
|
343
|
-
type: 'INJECTED',
|
|
344
|
-
chain: 'eip155'
|
|
345
|
-
});
|
|
346
|
-
expect(result).toBe('connector-image-url');
|
|
347
|
-
});
|
|
348
|
-
it('should switch network when requested', async () => {
|
|
349
|
-
vi.mocked(ChainController.switchActiveNetwork).mockResolvedValue(undefined);
|
|
350
|
-
await appKit.switchNetwork(mainnet);
|
|
351
|
-
expect(ChainController.switchActiveNetwork).toHaveBeenCalledWith(expect.objectContaining({
|
|
352
|
-
id: mainnet.id,
|
|
353
|
-
name: mainnet.name
|
|
354
|
-
}));
|
|
355
|
-
await appKit.switchNetwork(polygon);
|
|
356
|
-
expect(ChainController.switchActiveNetwork).toHaveBeenCalledTimes(1);
|
|
357
|
-
});
|
|
358
|
-
it('should set connected wallet info when syncing account', async () => {
|
|
359
|
-
// Mock the connector data
|
|
360
|
-
const mockConnector = {
|
|
361
|
-
id: 'test-wallet'
|
|
362
|
-
};
|
|
363
|
-
vi.mocked(ConnectorController.getConnectors).mockReturnValue([mockConnector]);
|
|
364
|
-
const mockAccountData = {
|
|
365
|
-
address: '0x123',
|
|
366
|
-
chainId: '1',
|
|
367
|
-
chainNamespace: 'eip155'
|
|
368
|
-
};
|
|
369
|
-
vi.spyOn(SafeLocalStorage, 'getItem').mockImplementation((key) => {
|
|
370
|
-
if (key === SafeLocalStorageKeys.CONNECTED_CONNECTOR) {
|
|
371
|
-
return mockConnector.id;
|
|
372
|
-
}
|
|
373
|
-
return undefined;
|
|
374
|
-
});
|
|
375
|
-
await appKit['syncAccount'](mockAccountData);
|
|
376
|
-
expect(AccountController.setConnectedWalletInfo).toHaveBeenCalledWith(expect.objectContaining({
|
|
377
|
-
name: mockConnector.id
|
|
378
|
-
}), 'eip155');
|
|
379
|
-
});
|
|
380
|
-
it('should disconnect correctly', async () => {
|
|
381
|
-
vi.mocked(ChainController).state = {
|
|
382
|
-
chains: new Map([['eip155', { namespace: 'eip155' }]]),
|
|
383
|
-
activeChain: 'eip155'
|
|
384
|
-
};
|
|
385
|
-
const mockRemoveItem = vi.fn();
|
|
386
|
-
vi.spyOn(SafeLocalStorage, 'removeItem').mockImplementation(mockRemoveItem);
|
|
387
|
-
await appKit.disconnect();
|
|
388
|
-
expect(mockRemoveItem).toHaveBeenCalledWith(SafeLocalStorageKeys.CONNECTED_CONNECTOR);
|
|
389
|
-
expect(mockRemoveItem).toHaveBeenCalledWith(SafeLocalStorageKeys.ACTIVE_CAIP_NETWORK_ID);
|
|
390
|
-
expect(AccountController.resetAccount).toHaveBeenCalledWith('eip155');
|
|
391
|
-
expect(AccountController.setStatus).toHaveBeenCalledWith('disconnected', 'eip155');
|
|
392
|
-
});
|
|
393
|
-
it('should show unsupported chain UI when synced chainId is not supported', async () => {
|
|
394
|
-
vi.mocked(ChainController).state = {
|
|
395
|
-
chains: new Map([['eip155', { namespace: 'eip155' }]]),
|
|
396
|
-
activeChain: 'eip155'
|
|
397
|
-
};
|
|
398
|
-
appKit.caipNetworks = [{ id: 'eip155:1', chainNamespace: 'eip155' }];
|
|
399
|
-
const mockAdapter = {
|
|
400
|
-
syncConnection: vi.fn().mockResolvedValue({
|
|
401
|
-
chainId: 'eip155:999', // Unsupported chain
|
|
402
|
-
address: '0x123'
|
|
403
|
-
}),
|
|
404
|
-
getBalance: vi.fn().mockResolvedValue({ balance: '0', symbol: 'ETH' }),
|
|
405
|
-
getProfile: vi.fn().mockResolvedValue({}),
|
|
406
|
-
on: vi.fn(),
|
|
407
|
-
off: vi.fn(),
|
|
408
|
-
emit: vi.fn()
|
|
409
|
-
};
|
|
410
|
-
vi.spyOn(appKit, 'getAdapter').mockReturnValue(mockAdapter);
|
|
411
|
-
vi.spyOn(StorageUtil, 'setConnectedConnector').mockImplementation(vi.fn());
|
|
412
|
-
vi.spyOn(StorageUtil, 'setConnectedNamespace').mockImplementation(vi.fn());
|
|
413
|
-
vi.spyOn(SafeLocalStorage, 'getItem').mockImplementation((key) => {
|
|
414
|
-
if (key === SafeLocalStorageKeys.CONNECTED_CONNECTOR) {
|
|
415
|
-
return 'test-wallet';
|
|
416
|
-
}
|
|
417
|
-
if (key === SafeLocalStorageKeys.CONNECTED_NAMESPACE) {
|
|
418
|
-
return 'eip155';
|
|
419
|
-
}
|
|
420
|
-
return undefined;
|
|
421
|
-
});
|
|
422
|
-
vi.mocked(ChainController.showUnsupportedChainUI).mockImplementation(vi.fn());
|
|
423
|
-
await appKit.syncExistingConnection();
|
|
424
|
-
expect(ChainController.showUnsupportedChainUI).toHaveBeenCalled();
|
|
425
|
-
});
|
|
426
|
-
});
|
|
427
|
-
describe('Base Initialization', () => {
|
|
428
|
-
let appKit;
|
|
429
|
-
let mockAdapter;
|
|
430
|
-
let mockUniversalAdapter;
|
|
431
|
-
beforeEach(() => {
|
|
432
|
-
vi.resetAllMocks();
|
|
433
|
-
vi.mocked(ChainController).state = {
|
|
434
|
-
chains: new Map(),
|
|
435
|
-
activeChain: 'eip155'
|
|
436
|
-
};
|
|
437
|
-
vi.mocked(ConnectorController).getConnectors = vi.fn().mockReturnValue([]);
|
|
438
|
-
mockAdapter = {
|
|
439
|
-
namespace: 'eip155',
|
|
440
|
-
construct: vi.fn(),
|
|
441
|
-
setUniversalProvider: vi.fn(),
|
|
442
|
-
setAuthProvider: vi.fn(),
|
|
443
|
-
syncConnectors: vi.fn(),
|
|
444
|
-
connectors: [],
|
|
445
|
-
on: vi.fn(),
|
|
446
|
-
off: vi.fn(),
|
|
447
|
-
emit: vi.fn()
|
|
448
|
-
};
|
|
449
|
-
vi.mocked(UniversalAdapter).mockImplementation(() => mockUniversalAdapter);
|
|
450
|
-
appKit = new AppKit({
|
|
451
|
-
...mockOptions,
|
|
452
|
-
adapters: [mockAdapter]
|
|
453
|
-
});
|
|
454
|
-
vi.spyOn(appKit, 'getUniversalProvider').mockResolvedValue({
|
|
455
|
-
on: vi.fn(),
|
|
456
|
-
off: vi.fn(),
|
|
457
|
-
emit: vi.fn()
|
|
458
|
-
});
|
|
459
|
-
});
|
|
460
|
-
it('should call syncConnectors when initializing adapters', async () => {
|
|
461
|
-
const createAdapters = appKit.createAdapters.bind(appKit);
|
|
462
|
-
vi.spyOn(appKit, 'createUniversalProvider').mockResolvedValue(undefined);
|
|
463
|
-
await createAdapters([mockAdapter]);
|
|
464
|
-
expect(mockAdapter.syncConnectors).toHaveBeenCalledWith(expect.objectContaining({
|
|
465
|
-
projectId: mockOptions.projectId,
|
|
466
|
-
metadata: mockOptions.metadata
|
|
467
|
-
}), expect.any(Object));
|
|
468
|
-
});
|
|
469
|
-
it('should create UniversalAdapter when no blueprint is provided for namespace', async () => {
|
|
470
|
-
const createAdapters = appKit.createAdapters.bind(appKit);
|
|
471
|
-
vi.spyOn(appKit, 'createUniversalProvider').mockResolvedValue(undefined);
|
|
472
|
-
const mockUniversalAdapter = {
|
|
473
|
-
setUniversalProvider: vi.fn(),
|
|
474
|
-
setAuthProvider: vi.fn()
|
|
475
|
-
};
|
|
476
|
-
vi.mocked(UniversalAdapter).mockImplementation(() => mockUniversalAdapter);
|
|
477
|
-
const adapters = await createAdapters([]);
|
|
478
|
-
expect(adapters.eip155).toBeDefined();
|
|
479
|
-
expect(mockUniversalAdapter.setUniversalProvider).toHaveBeenCalled();
|
|
480
|
-
});
|
|
481
|
-
it('should initialize multiple adapters for different namespaces', async () => {
|
|
482
|
-
const createAdapters = appKit.createAdapters.bind(appKit);
|
|
483
|
-
const mockSolanaAdapter = {
|
|
484
|
-
namespace: 'solana',
|
|
485
|
-
construct: vi.fn(),
|
|
486
|
-
setUniversalProvider: vi.fn(),
|
|
487
|
-
setAuthProvider: vi.fn(),
|
|
488
|
-
syncConnectors: vi.fn(),
|
|
489
|
-
connectors: [],
|
|
490
|
-
on: vi.fn(),
|
|
491
|
-
off: vi.fn(),
|
|
492
|
-
emit: vi.fn()
|
|
493
|
-
};
|
|
494
|
-
vi.spyOn(appKit, 'createUniversalProvider').mockResolvedValue(undefined);
|
|
495
|
-
const adapters = await createAdapters([mockAdapter, mockSolanaAdapter]);
|
|
496
|
-
expect(mockAdapter.syncConnectors).toHaveBeenCalled();
|
|
497
|
-
expect(mockSolanaAdapter.syncConnectors).toHaveBeenCalled();
|
|
498
|
-
expect(adapters.eip155).toBeDefined();
|
|
499
|
-
expect(adapters.solana).toBeDefined();
|
|
500
|
-
});
|
|
501
|
-
it('should set universal provider and auth provider for each adapter', async () => {
|
|
502
|
-
const createAdapters = appKit.createAdapters.bind(appKit);
|
|
503
|
-
const mockUniversalProvider = {
|
|
504
|
-
on: vi.fn(),
|
|
505
|
-
off: vi.fn(),
|
|
506
|
-
emit: vi.fn()
|
|
507
|
-
};
|
|
508
|
-
vi.spyOn(appKit, 'createUniversalProvider').mockResolvedValue(undefined);
|
|
509
|
-
vi.spyOn(appKit, 'getUniversalProvider').mockResolvedValue(mockUniversalProvider);
|
|
510
|
-
await createAdapters([mockAdapter]);
|
|
511
|
-
expect(mockAdapter.setUniversalProvider).toHaveBeenCalledWith(expect.objectContaining({
|
|
512
|
-
on: expect.any(Function),
|
|
513
|
-
off: expect.any(Function),
|
|
514
|
-
emit: expect.any(Function)
|
|
515
|
-
}));
|
|
516
|
-
expect(mockAdapter.setAuthProvider).toHaveBeenCalled();
|
|
517
|
-
});
|
|
518
|
-
it('should update ChainController state with initialized adapters', async () => {
|
|
519
|
-
const createAdapters = appKit.createAdapters.bind(appKit);
|
|
520
|
-
vi.spyOn(appKit, 'createUniversalProvider').mockResolvedValue(undefined);
|
|
521
|
-
await createAdapters([mockAdapter]);
|
|
522
|
-
expect(ChainController.state.chains.get('eip155')).toEqual(expect.objectContaining({
|
|
523
|
-
namespace: 'eip155',
|
|
524
|
-
connectionControllerClient: expect.any(Object),
|
|
525
|
-
networkControllerClient: expect.any(Object),
|
|
526
|
-
networkState: expect.any(Object),
|
|
527
|
-
accountState: expect.any(Object),
|
|
528
|
-
caipNetworks: expect.any(Array)
|
|
529
|
-
}));
|
|
530
|
-
});
|
|
531
|
-
});
|
|
532
|
-
});
|
|
533
|
-
//# sourceMappingURL=appkit.test.js.map
|