@openzeppelin/ui-builder-adapter-evm 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -18
- package/dist/index.cjs +4651 -4448
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -226
- package/dist/index.d.ts +12 -226
- package/dist/index.js +4737 -4535
- package/dist/index.js.map +1 -1
- package/package.json +7 -6
- package/src/__tests__/adapter-parsing.test.ts +4 -3
- package/src/__tests__/getDefaultServiceConfig.test.ts +185 -0
- package/src/__tests__/mocks/mock-network-configs.ts +1 -1
- package/src/__tests__/provenanceLinks.test.ts +6 -4
- package/src/__tests__/providerSelection.test.ts +5 -4
- package/src/__tests__/timeouts.test.ts +5 -3
- package/src/__tests__/wallet-connect.test.ts +2 -2
- package/src/adapter.ts +61 -107
- package/src/configuration/execution.ts +1 -52
- package/src/configuration/index.ts +2 -3
- package/src/configuration/network-services.ts +47 -60
- package/src/index.ts +22 -13
- package/src/networks/index.ts +2 -1
- package/src/networks/mainnet.ts +1 -1
- package/src/networks/testnet.ts +1 -1
- package/src/query/adapter-query.ts +72 -0
- package/src/query/index.ts +2 -2
- package/src/transaction/components/useEvmRelayerOptions.ts +5 -3
- package/src/transaction/index.ts +1 -5
- package/src/types/artifacts.ts +5 -30
- package/src/types/providers.ts +7 -18
- package/src/wallet/components/EvmWalletUiRoot.tsx +1 -1
- package/src/wallet/evmUiKitManager.ts +26 -129
- package/src/wallet/hooks/index.ts +0 -1
- package/src/wallet/implementation/wagmi-implementation.ts +45 -577
- package/src/wallet/index.ts +2 -3
- package/src/wallet/rainbowkit/__tests__/export-service.test.ts +1 -2
- package/src/wallet/rainbowkit/componentFactory.ts +10 -8
- package/src/wallet/rainbowkit/components.tsx +16 -133
- package/src/wallet/rainbowkit/index.ts +27 -5
- package/src/wallet/utils/__tests__/uiKitService.test.ts +5 -1
- package/src/wallet/utils/connection.ts +8 -52
- package/src/wallet/utils/index.ts +0 -2
- package/src/wallet/utils/uiKitService.ts +7 -3
- package/src/wallet/utils/walletImplementationManager.ts +5 -4
- package/src/wallet/utils.ts +1 -65
- package/src/abi/__tests__/etherscan-v2.test.ts +0 -117
- package/src/abi/__tests__/transformer.test.ts +0 -342
- package/src/abi/comparison.ts +0 -389
- package/src/abi/etherscan-v2.ts +0 -243
- package/src/abi/etherscan.ts +0 -158
- package/src/abi/index.ts +0 -7
- package/src/abi/loader.ts +0 -415
- package/src/abi/sourcify.ts +0 -75
- package/src/abi/transformer.ts +0 -163
- package/src/abi/types.ts +0 -101
- package/src/configuration/__tests__/explorer.test.ts +0 -174
- package/src/configuration/__tests__/rpc.test.ts +0 -176
- package/src/configuration/explorer.ts +0 -243
- package/src/configuration/rpc.ts +0 -257
- package/src/mapping/__tests__/field-generator.test.ts +0 -137
- package/src/mapping/__tests__/type-mapper.test.ts +0 -139
- package/src/mapping/constants.ts +0 -57
- package/src/mapping/field-generator.ts +0 -115
- package/src/mapping/index.ts +0 -4
- package/src/mapping/type-mapper.ts +0 -80
- package/src/proxy/detection.ts +0 -465
- package/src/query/handler.ts +0 -227
- package/src/query/view-checker.ts +0 -10
- package/src/transaction/eoa.ts +0 -98
- package/src/transaction/execution-strategy.ts +0 -33
- package/src/transaction/formatter.ts +0 -101
- package/src/transaction/relayer.ts +0 -380
- package/src/transaction/sender.ts +0 -185
- package/src/transform/index.ts +0 -3
- package/src/transform/input-parser.ts +0 -177
- package/src/transform/output-formatter.ts +0 -64
- package/src/types/__tests__/artifacts.test.ts +0 -105
- package/src/types.ts +0 -92
- package/src/utils/__tests__/artifacts.test.ts +0 -81
- package/src/utils/artifacts.ts +0 -30
- package/src/utils/formatting.ts +0 -25
- package/src/utils/gas.ts +0 -17
- package/src/utils/index.ts +0 -6
- package/src/utils/json.ts +0 -19
- package/src/utils/validation.ts +0 -10
- package/src/validation/eoa.ts +0 -33
- package/src/validation/index.ts +0 -2
- package/src/validation/relayer.ts +0 -13
- package/src/wallet/__tests__/utils.test.ts +0 -149
- package/src/wallet/components/account/AccountDisplay.tsx +0 -52
- package/src/wallet/components/connect/ConnectButton.tsx +0 -125
- package/src/wallet/components/connect/ConnectorDialog.tsx +0 -140
- package/src/wallet/components/index.ts +0 -4
- package/src/wallet/components/network/NetworkSwitcher.tsx +0 -90
- package/src/wallet/context/index.ts +0 -1
- package/src/wallet/context/wagmi-context.tsx +0 -7
- package/src/wallet/hooks/useIsWagmiProviderInitialized.ts +0 -11
- package/src/wallet/rainbowkit/config-generator.ts +0 -56
- package/src/wallet/rainbowkit/config-service.ts +0 -169
- package/src/wallet/rainbowkit/export-service.ts +0 -18
- package/src/wallet/rainbowkit/rainbowkitAssetManager.ts +0 -74
- package/src/wallet/rainbowkit/types.ts +0 -74
- package/src/wallet/rainbowkit/utils.ts +0 -96
- package/src/wallet/services/configResolutionService.ts +0 -65
- package/src/wallet/utils/SafeWagmiComponent.tsx +0 -72
- package/src/wallet/utils/filterWalletComponents.ts +0 -89
|
@@ -1,11 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
// Import from core package via barrel files
|
|
2
|
+
import {
|
|
3
|
+
EvmProviderKeys,
|
|
4
|
+
resolveExplorerApiKeyFromAppConfig,
|
|
5
|
+
type TypedEvmNetworkConfig,
|
|
6
|
+
} from '@openzeppelin/ui-builder-adapter-evm-core';
|
|
7
|
+
import type { EvmNetworkConfig, NetworkServiceForm } from '@openzeppelin/ui-types';
|
|
3
8
|
import { appConfigService, userNetworkServiceConfigService } from '@openzeppelin/ui-utils';
|
|
4
9
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Returns the default service configuration values for a given service ID.
|
|
12
|
+
* Used for proactive health checks when no user overrides are configured.
|
|
13
|
+
*
|
|
14
|
+
* @param networkConfig The network configuration
|
|
15
|
+
* @param serviceId The service identifier (e.g., 'rpc', 'explorer', 'contract-definitions')
|
|
16
|
+
* @returns The default configuration values, or null if not available
|
|
17
|
+
*/
|
|
18
|
+
export function getEvmDefaultServiceConfig(
|
|
19
|
+
networkConfig: EvmNetworkConfig,
|
|
20
|
+
serviceId: string
|
|
21
|
+
): Record<string, unknown> | null {
|
|
22
|
+
switch (serviceId) {
|
|
23
|
+
case 'rpc':
|
|
24
|
+
if (networkConfig.rpcUrl) {
|
|
25
|
+
return { rpcUrl: networkConfig.rpcUrl };
|
|
26
|
+
}
|
|
27
|
+
break;
|
|
28
|
+
case 'explorer': {
|
|
29
|
+
// For explorer service, we need to include the API key if available
|
|
30
|
+
// Use the shared helper from adapter-evm-core to resolve the API key
|
|
31
|
+
const typedConfig = networkConfig as TypedEvmNetworkConfig;
|
|
32
|
+
const apiKey = resolveExplorerApiKeyFromAppConfig(typedConfig);
|
|
33
|
+
|
|
34
|
+
// Return config if we have at least an explorer URL or an API key
|
|
35
|
+
if (networkConfig.explorerUrl || apiKey) {
|
|
36
|
+
return {
|
|
37
|
+
explorerUrl: networkConfig.explorerUrl,
|
|
38
|
+
apiUrl: networkConfig.apiUrl,
|
|
39
|
+
...(apiKey ? { apiKey } : {}),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
case 'contract-definitions':
|
|
45
|
+
// No connection test for contract definitions service
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
9
50
|
|
|
10
51
|
/**
|
|
11
52
|
* Returns the network service forms for EVM networks.
|
|
@@ -208,57 +249,3 @@ export function getEvmNetworkServiceForms(
|
|
|
208
249
|
},
|
|
209
250
|
];
|
|
210
251
|
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Validates a network service configuration for EVM networks.
|
|
214
|
-
*/
|
|
215
|
-
export async function validateEvmNetworkServiceConfig(
|
|
216
|
-
serviceId: string,
|
|
217
|
-
values: Record<string, unknown>
|
|
218
|
-
): Promise<boolean> {
|
|
219
|
-
if (serviceId === 'rpc') {
|
|
220
|
-
const cfg = { url: String(values.rpcUrl || ''), isCustom: true } as UserRpcProviderConfig;
|
|
221
|
-
return validateEvmRpcEndpoint(cfg);
|
|
222
|
-
}
|
|
223
|
-
if (serviceId === 'explorer') {
|
|
224
|
-
const cfg = {
|
|
225
|
-
explorerUrl: values.explorerUrl ? String(values.explorerUrl) : undefined,
|
|
226
|
-
apiUrl: values.apiUrl ? String(values.apiUrl) : undefined,
|
|
227
|
-
apiKey: values.apiKey ? String(values.apiKey) : undefined,
|
|
228
|
-
isCustom: true,
|
|
229
|
-
applyToAllNetworks: Boolean(values.applyToAllNetworks),
|
|
230
|
-
} as UserExplorerConfig;
|
|
231
|
-
return validateEvmExplorerConfig(cfg);
|
|
232
|
-
}
|
|
233
|
-
if (serviceId === 'contract-definitions') {
|
|
234
|
-
const raw = values.defaultProvider;
|
|
235
|
-
if (raw === undefined || raw === null || raw === '') return true;
|
|
236
|
-
return isEvmProviderKey(raw);
|
|
237
|
-
}
|
|
238
|
-
return true;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Tests a network service connection for EVM networks.
|
|
243
|
-
*/
|
|
244
|
-
export async function testEvmNetworkServiceConnection(
|
|
245
|
-
serviceId: string,
|
|
246
|
-
values: Record<string, unknown>,
|
|
247
|
-
networkConfig: TypedEvmNetworkConfig
|
|
248
|
-
): Promise<{ success: boolean; latency?: number; error?: string }> {
|
|
249
|
-
if (serviceId === 'rpc') {
|
|
250
|
-
const cfg = { url: String(values.rpcUrl || ''), isCustom: true } as UserRpcProviderConfig;
|
|
251
|
-
return testEvmRpcConnection(cfg);
|
|
252
|
-
}
|
|
253
|
-
if (serviceId === 'explorer') {
|
|
254
|
-
const cfg = {
|
|
255
|
-
explorerUrl: values.explorerUrl ? String(values.explorerUrl) : undefined,
|
|
256
|
-
apiUrl: values.apiUrl ? String(values.apiUrl) : undefined,
|
|
257
|
-
apiKey: values.apiKey ? String(values.apiKey) : undefined,
|
|
258
|
-
isCustom: true,
|
|
259
|
-
applyToAllNetworks: Boolean(values.applyToAllNetworks),
|
|
260
|
-
} as UserExplorerConfig;
|
|
261
|
-
return testEvmExplorerConnection(cfg, networkConfig);
|
|
262
|
-
}
|
|
263
|
-
return { success: true };
|
|
264
|
-
}
|
package/src/index.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
// Re-export the main adapter class
|
|
2
2
|
export { EvmAdapter } from './adapter';
|
|
3
3
|
|
|
4
|
-
// Export RainbowKit customization types
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
// Export RainbowKit customization types (re-exported from core via rainbowkit/index.ts)
|
|
5
|
+
export type {
|
|
6
|
+
AppInfo,
|
|
7
|
+
RainbowKitConnectButtonProps,
|
|
8
|
+
RainbowKitProviderProps,
|
|
9
|
+
RainbowKitKitConfig,
|
|
10
|
+
RainbowKitCustomizations,
|
|
11
|
+
} from './wallet/rainbowkit';
|
|
12
|
+
export { isRainbowKitCustomizations, extractRainbowKitCustomizations } from './wallet/rainbowkit';
|
|
9
13
|
|
|
14
|
+
// Export EVM networks
|
|
10
15
|
export {
|
|
11
16
|
evmNetworks,
|
|
12
17
|
evmMainnetNetworks,
|
|
@@ -40,12 +45,16 @@ export {
|
|
|
40
45
|
// Export adapter configuration
|
|
41
46
|
export { evmAdapterConfig } from './config';
|
|
42
47
|
|
|
43
|
-
export
|
|
44
|
-
export type {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
// Re-export core types for public API compatibility
|
|
49
|
+
export type {
|
|
50
|
+
TypedEvmNetworkConfig,
|
|
51
|
+
WriteContractParameters,
|
|
52
|
+
EvmContractArtifacts,
|
|
53
|
+
} from '@openzeppelin/ui-builder-adapter-evm-core';
|
|
54
|
+
export {
|
|
55
|
+
isEvmContractArtifacts,
|
|
56
|
+
abiComparisonService,
|
|
57
|
+
} from '@openzeppelin/ui-builder-adapter-evm-core';
|
|
49
58
|
|
|
50
|
-
// Export
|
|
51
|
-
export {
|
|
59
|
+
// Export adapter-specific types
|
|
60
|
+
export type { EvmRelayerTransactionOptions } from '@openzeppelin/ui-builder-adapter-evm-core';
|
package/src/networks/index.ts
CHANGED
package/src/networks/mainnet.ts
CHANGED
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
zksync as viemZkSync,
|
|
25
25
|
} from 'viem/chains';
|
|
26
26
|
|
|
27
|
-
import { TypedEvmNetworkConfig } from '
|
|
27
|
+
import type { TypedEvmNetworkConfig } from '@openzeppelin/ui-builder-adapter-evm-core';
|
|
28
28
|
|
|
29
29
|
export const ethereumMainnet: TypedEvmNetworkConfig = {
|
|
30
30
|
id: 'ethereum-mainnet',
|
package/src/networks/testnet.ts
CHANGED
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
zksyncSepoliaTestnet as viemZkSyncSepoliaTestnet,
|
|
27
27
|
} from 'viem/chains';
|
|
28
28
|
|
|
29
|
-
import { TypedEvmNetworkConfig } from '
|
|
29
|
+
import type { TypedEvmNetworkConfig } from '@openzeppelin/ui-builder-adapter-evm-core';
|
|
30
30
|
|
|
31
31
|
export const ethereumSepolia: TypedEvmNetworkConfig = {
|
|
32
32
|
id: 'ethereum-sepolia',
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapter-specific query wrapper
|
|
3
|
+
*
|
|
4
|
+
* Wraps the core queryEvmViewFunction with adapter-specific functionality:
|
|
5
|
+
* - Resolves RPC URL from network config (with user override support)
|
|
6
|
+
* - Supports loading contract schema for proxy implementations
|
|
7
|
+
*/
|
|
8
|
+
import {
|
|
9
|
+
queryEvmViewFunction as coreQueryEvmViewFunction,
|
|
10
|
+
resolveRpcUrl,
|
|
11
|
+
type TypedEvmNetworkConfig,
|
|
12
|
+
type WagmiWalletImplementation,
|
|
13
|
+
} from '@openzeppelin/ui-builder-adapter-evm-core';
|
|
14
|
+
import type { ContractSchema } from '@openzeppelin/ui-types';
|
|
15
|
+
import { logger } from '@openzeppelin/ui-utils';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Query a view function on an EVM contract.
|
|
19
|
+
*
|
|
20
|
+
* This adapter-specific version wraps the core queryEvmViewFunction to:
|
|
21
|
+
* 1. Resolve the RPC URL from network config (supporting user overrides)
|
|
22
|
+
* 2. Support optional wallet implementation for RPC context
|
|
23
|
+
* 3. Support loading proxy implementation schemas via callback
|
|
24
|
+
*
|
|
25
|
+
* @param contractAddress The contract address to query
|
|
26
|
+
* @param functionId The function ID to call
|
|
27
|
+
* @param networkConfig The network configuration
|
|
28
|
+
* @param params The parameters for the function call
|
|
29
|
+
* @param contractSchema Optional contract schema (if not provided, will use loadContractCallback)
|
|
30
|
+
* @param _walletImplementation Optional wallet implementation (reserved for future use)
|
|
31
|
+
* @param loadContractCallback Optional callback to load contract schema when not provided
|
|
32
|
+
* @returns The result of the view function call
|
|
33
|
+
*/
|
|
34
|
+
export async function queryEvmViewFunction(
|
|
35
|
+
contractAddress: string,
|
|
36
|
+
functionId: string,
|
|
37
|
+
networkConfig: TypedEvmNetworkConfig,
|
|
38
|
+
params: unknown[] = [],
|
|
39
|
+
contractSchema?: ContractSchema,
|
|
40
|
+
_walletImplementation?: WagmiWalletImplementation,
|
|
41
|
+
loadContractCallback?: (address: string) => Promise<ContractSchema>
|
|
42
|
+
): Promise<unknown> {
|
|
43
|
+
// Use provided schema or fall back to loading via callback
|
|
44
|
+
let schema = contractSchema;
|
|
45
|
+
if (!schema) {
|
|
46
|
+
if (loadContractCallback) {
|
|
47
|
+
logger.debug('adapter-query', `Loading contract schema for ${contractAddress} via callback`);
|
|
48
|
+
schema = await loadContractCallback(contractAddress);
|
|
49
|
+
} else {
|
|
50
|
+
throw new Error(
|
|
51
|
+
'Contract schema is required for view function query. ' +
|
|
52
|
+
'Provide either a contractSchema or a loadContractCallback.'
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Resolve RPC URL from network config (supports user overrides)
|
|
58
|
+
// Note: resolveRpcUrl throws if no valid URL can be resolved
|
|
59
|
+
const rpcUrl = resolveRpcUrl(networkConfig);
|
|
60
|
+
|
|
61
|
+
logger.debug('adapter-query', `Using RPC URL for query: ${rpcUrl}`);
|
|
62
|
+
|
|
63
|
+
// Call core function with resolved RPC URL
|
|
64
|
+
return coreQueryEvmViewFunction(
|
|
65
|
+
contractAddress,
|
|
66
|
+
functionId,
|
|
67
|
+
params,
|
|
68
|
+
schema,
|
|
69
|
+
rpcUrl,
|
|
70
|
+
networkConfig
|
|
71
|
+
);
|
|
72
|
+
}
|
package/src/query/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// Barrel file for query module
|
|
2
|
-
|
|
3
|
-
export
|
|
2
|
+
// Adapter-specific wrapper only - core query functionality (isEvmViewFunction) available from @openzeppelin/ui-builder-adapter-evm-core
|
|
3
|
+
export { queryEvmViewFunction } from './adapter-query';
|
|
@@ -2,9 +2,11 @@ import { useEffect, useRef } from 'react';
|
|
|
2
2
|
import { useForm } from 'react-hook-form';
|
|
3
3
|
|
|
4
4
|
import { Speed } from '@openzeppelin/relayer-sdk';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import {
|
|
6
|
+
gweiToWei,
|
|
7
|
+
weiToGwei,
|
|
8
|
+
type EvmRelayerTransactionOptions,
|
|
9
|
+
} from '@openzeppelin/ui-builder-adapter-evm-core';
|
|
8
10
|
|
|
9
11
|
export interface EvmRelayerFormData {
|
|
10
12
|
transactionOptions: EvmRelayerTransactionOptions & {
|
package/src/transaction/index.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
1
|
// Barrel file for transaction module
|
|
2
|
-
|
|
3
|
-
export * from './relayer';
|
|
4
|
-
export * from './sender';
|
|
5
|
-
export * from './formatter';
|
|
6
|
-
export * from './eoa';
|
|
2
|
+
// Adapter-specific UI components only - core transaction functionality available from @openzeppelin/ui-builder-adapter-evm-core
|
|
7
3
|
export { EvmRelayerOptions } from './components/EvmRelayerOptions';
|
package/src/types/artifacts.ts
CHANGED
|
@@ -1,33 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* EVM-specific contract artifacts interface
|
|
3
|
-
*
|
|
3
|
+
* Re-exports from core package for internal consumption
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
contractAddress: string;
|
|
10
|
-
|
|
11
|
-
/** Optional manual ABI JSON string (for unverified contracts) */
|
|
12
|
-
contractDefinition?: string;
|
|
13
|
-
|
|
14
|
-
/** Optional proxy detection configuration */
|
|
15
|
-
__proxyDetectionOptions?: {
|
|
16
|
-
/** Skip automatic proxy detection */
|
|
17
|
-
skipProxyDetection?: boolean;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/** Optional forced provider for this load attempt (session-scoped override) */
|
|
21
|
-
__forcedProvider?: EvmContractDefinitionProviderKey;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Type guard to check if an object matches EvmContractArtifacts structure
|
|
26
|
-
*/
|
|
27
|
-
export function isEvmContractArtifacts(obj: unknown): obj is EvmContractArtifacts {
|
|
28
|
-
return (
|
|
29
|
-
typeof obj === 'object' &&
|
|
30
|
-
obj !== null &&
|
|
31
|
-
typeof (obj as Record<string, unknown>).contractAddress === 'string'
|
|
32
|
-
);
|
|
33
|
-
}
|
|
5
|
+
export {
|
|
6
|
+
type EvmContractArtifacts,
|
|
7
|
+
isEvmContractArtifacts,
|
|
8
|
+
} from '@openzeppelin/ui-builder-adapter-evm-core';
|
package/src/types/providers.ts
CHANGED
|
@@ -1,21 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* EVM Contract Definition Provider keys and ordering
|
|
3
|
-
*
|
|
3
|
+
* Re-exports from core package for internal consumption
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export type EvmContractDefinitionProviderKey =
|
|
12
|
-
(typeof EvmProviderKeys)[keyof typeof EvmProviderKeys];
|
|
13
|
-
|
|
14
|
-
export const EVM_PROVIDER_ORDER_DEFAULT: readonly EvmContractDefinitionProviderKey[] = [
|
|
15
|
-
EvmProviderKeys.Etherscan,
|
|
16
|
-
EvmProviderKeys.Sourcify,
|
|
17
|
-
] as const;
|
|
18
|
-
|
|
19
|
-
export function isEvmProviderKey(value: unknown): value is EvmContractDefinitionProviderKey {
|
|
20
|
-
return value === EvmProviderKeys.Etherscan || value === EvmProviderKeys.Sourcify;
|
|
21
|
-
}
|
|
5
|
+
export {
|
|
6
|
+
EvmProviderKeys,
|
|
7
|
+
type EvmContractDefinitionProviderKey,
|
|
8
|
+
EVM_PROVIDER_ORDER_DEFAULT,
|
|
9
|
+
isEvmProviderKey,
|
|
10
|
+
} from '@openzeppelin/ui-builder-adapter-evm-core';
|
|
@@ -4,10 +4,10 @@ import { mainnet } from 'viem/chains';
|
|
|
4
4
|
import { WagmiProvider } from 'wagmi';
|
|
5
5
|
import React, { useEffect, useMemo, useState } from 'react';
|
|
6
6
|
|
|
7
|
+
import { WagmiProviderInitializedContext } from '@openzeppelin/ui-builder-adapter-evm-core';
|
|
7
8
|
import type { EcosystemReactUiProviderProps } from '@openzeppelin/ui-types';
|
|
8
9
|
import { logger } from '@openzeppelin/ui-utils';
|
|
9
10
|
|
|
10
|
-
import { WagmiProviderInitializedContext } from '../context/wagmi-context';
|
|
11
11
|
import { evmUiKitManager, type EvmUiKitManagerState } from '../evmUiKitManager';
|
|
12
12
|
import type { RainbowKitKitConfig, RainbowKitProviderProps } from '../rainbowkit';
|
|
13
13
|
|
|
@@ -1,132 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/**
|
|
2
|
+
* EVM UI Kit Manager
|
|
3
|
+
*
|
|
4
|
+
* Manages UI kit configuration for EVM networks using the shared factory from adapter-evm-core.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
createUiKitManager,
|
|
9
|
+
ensureRainbowKitAssetsLoaded,
|
|
10
|
+
type UiKitManagerState,
|
|
11
|
+
} from '@openzeppelin/ui-builder-adapter-evm-core';
|
|
6
12
|
|
|
7
13
|
import { getEvmWalletImplementation } from './utils/walletImplementationManager';
|
|
8
14
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
error: null,
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
let state: EvmUiKitManagerState = { ...initialState };
|
|
28
|
-
const listeners: Set<() => void> = new Set();
|
|
29
|
-
|
|
30
|
-
function notifyListeners(): void {
|
|
31
|
-
listeners.forEach((listener) => {
|
|
32
|
-
try {
|
|
33
|
-
listener();
|
|
34
|
-
} catch (error) {
|
|
35
|
-
logger.error('EvmUiKitManager', 'Error in listener:', error);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function subscribe(listener: () => void): () => void {
|
|
41
|
-
listeners.add(listener);
|
|
42
|
-
return () => {
|
|
43
|
-
listeners.delete(listener);
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function getState(): EvmUiKitManagerState {
|
|
48
|
-
return { ...state }; // Return a copy to prevent direct mutation
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async function configure(newFullUiKitConfig: UiKitConfiguration): Promise<void> {
|
|
52
|
-
logger.info('EvmUiKitManager:configure', 'Configuring UI kit. New config:', newFullUiKitConfig);
|
|
53
|
-
|
|
54
|
-
const oldKitName = state.currentFullUiKitConfig?.kitName;
|
|
55
|
-
const newKitName = newFullUiKitConfig.kitName;
|
|
56
|
-
const kitChanged = oldKitName !== newKitName;
|
|
57
|
-
|
|
58
|
-
state = {
|
|
59
|
-
...state,
|
|
60
|
-
isInitializing: true,
|
|
61
|
-
error: null,
|
|
62
|
-
currentFullUiKitConfig: newFullUiKitConfig,
|
|
63
|
-
kitProviderComponent: kitChanged ? null : state.kitProviderComponent,
|
|
64
|
-
isKitAssetsLoaded: kitChanged ? false : state.isKitAssetsLoaded,
|
|
65
|
-
};
|
|
66
|
-
notifyListeners();
|
|
67
|
-
|
|
68
|
-
let newWagmiConfigAttempt: WagmiConfig | null = null;
|
|
69
|
-
const evmImpl = await getEvmWalletImplementation();
|
|
70
|
-
try {
|
|
71
|
-
if (newKitName === 'rainbowkit') {
|
|
72
|
-
if (kitChanged || !state.kitProviderComponent || !state.isKitAssetsLoaded) {
|
|
73
|
-
logger.info('EvmUiKitManager:configure', 'Ensuring RainbowKit assets are loaded...');
|
|
74
|
-
const { ensureRainbowKitAssetsLoaded } = await import(
|
|
75
|
-
'./rainbowkit/rainbowkitAssetManager'
|
|
76
|
-
);
|
|
77
|
-
const rkAssets = await ensureRainbowKitAssetsLoaded();
|
|
78
|
-
state.kitProviderComponent = rkAssets.ProviderComponent;
|
|
79
|
-
state.isKitAssetsLoaded = rkAssets.cssLoaded && !!rkAssets.ProviderComponent;
|
|
80
|
-
if (!state.isKitAssetsLoaded) {
|
|
81
|
-
throw new Error('Failed to load critical RainbowKit assets.');
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
newWagmiConfigAttempt = await evmImpl.getConfigForRainbowKit(newFullUiKitConfig);
|
|
85
|
-
logger.info('EvmUiKitManager:configure', 'WagmiConfig for RainbowKit obtained.');
|
|
86
|
-
} else if (newKitName === 'custom' || !newKitName) {
|
|
87
|
-
newWagmiConfigAttempt = await evmImpl.getActiveConfigForManager(newFullUiKitConfig);
|
|
88
|
-
logger.info('EvmUiKitManager:configure', 'ActiveConfig for custom/default obtained.');
|
|
89
|
-
if (kitChanged) {
|
|
90
|
-
state.kitProviderComponent = null;
|
|
91
|
-
state.isKitAssetsLoaded = false;
|
|
92
|
-
}
|
|
93
|
-
} else {
|
|
94
|
-
logger.warn('EvmUiKitManager:configure', `Unsupported kitName: ${newKitName}.`);
|
|
95
|
-
state.kitProviderComponent = null;
|
|
96
|
-
state.isKitAssetsLoaded = false;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
state.wagmiConfig = newWagmiConfigAttempt;
|
|
100
|
-
evmImpl.setActiveWagmiConfig(state.wagmiConfig);
|
|
101
|
-
state.error = null;
|
|
102
|
-
if (!newWagmiConfigAttempt && newKitName && newKitName !== 'none' && newKitName !== 'custom') {
|
|
103
|
-
state.error = new Error(`Failed to obtain WagmiConfig for ${newKitName}`);
|
|
104
|
-
logger.error('EvmUiKitManager:configure', state.error.message);
|
|
105
|
-
}
|
|
106
|
-
} catch (err) {
|
|
107
|
-
logger.error('EvmUiKitManager:configure', 'Error during UI kit configuration process:', err);
|
|
108
|
-
state.error = err instanceof Error ? err : new Error(String(err));
|
|
109
|
-
state.wagmiConfig = null;
|
|
110
|
-
evmImpl.setActiveWagmiConfig(null);
|
|
111
|
-
} finally {
|
|
112
|
-
state.isInitializing = false;
|
|
113
|
-
logger.info(
|
|
114
|
-
'EvmUiKitManager:configure',
|
|
115
|
-
'Configuration attempt finished. Final wagmiConfig:',
|
|
116
|
-
state.wagmiConfig ? 'Set' : 'Null',
|
|
117
|
-
'Kit Provider Component:',
|
|
118
|
-
state.kitProviderComponent ? 'Set' : 'Null',
|
|
119
|
-
'Kit Assets Loaded:',
|
|
120
|
-
state.isKitAssetsLoaded,
|
|
121
|
-
'Error state:',
|
|
122
|
-
state.error ? state.error.message : 'None'
|
|
123
|
-
);
|
|
124
|
-
notifyListeners();
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export const evmUiKitManager = {
|
|
129
|
-
getState,
|
|
130
|
-
subscribe,
|
|
131
|
-
configure,
|
|
132
|
-
};
|
|
15
|
+
/**
|
|
16
|
+
* State interface for EVM UI Kit Manager.
|
|
17
|
+
* This is a type alias to the shared UiKitManagerState for backwards compatibility.
|
|
18
|
+
*/
|
|
19
|
+
export type EvmUiKitManagerState = UiKitManagerState;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* EVM UI Kit Manager instance.
|
|
23
|
+
* Provides state management for UI kit configuration in EVM adapters.
|
|
24
|
+
*/
|
|
25
|
+
export const evmUiKitManager = createUiKitManager({
|
|
26
|
+
getWalletImplementation: getEvmWalletImplementation,
|
|
27
|
+
loadRainbowKitAssets: ensureRainbowKitAssetsLoaded,
|
|
28
|
+
logPrefix: 'EvmUiKitManager',
|
|
29
|
+
});
|