@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.
Files changed (105) hide show
  1. package/README.md +33 -18
  2. package/dist/index.cjs +4651 -4448
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +12 -226
  5. package/dist/index.d.ts +12 -226
  6. package/dist/index.js +4737 -4535
  7. package/dist/index.js.map +1 -1
  8. package/package.json +7 -6
  9. package/src/__tests__/adapter-parsing.test.ts +4 -3
  10. package/src/__tests__/getDefaultServiceConfig.test.ts +185 -0
  11. package/src/__tests__/mocks/mock-network-configs.ts +1 -1
  12. package/src/__tests__/provenanceLinks.test.ts +6 -4
  13. package/src/__tests__/providerSelection.test.ts +5 -4
  14. package/src/__tests__/timeouts.test.ts +5 -3
  15. package/src/__tests__/wallet-connect.test.ts +2 -2
  16. package/src/adapter.ts +61 -107
  17. package/src/configuration/execution.ts +1 -52
  18. package/src/configuration/index.ts +2 -3
  19. package/src/configuration/network-services.ts +47 -60
  20. package/src/index.ts +22 -13
  21. package/src/networks/index.ts +2 -1
  22. package/src/networks/mainnet.ts +1 -1
  23. package/src/networks/testnet.ts +1 -1
  24. package/src/query/adapter-query.ts +72 -0
  25. package/src/query/index.ts +2 -2
  26. package/src/transaction/components/useEvmRelayerOptions.ts +5 -3
  27. package/src/transaction/index.ts +1 -5
  28. package/src/types/artifacts.ts +5 -30
  29. package/src/types/providers.ts +7 -18
  30. package/src/wallet/components/EvmWalletUiRoot.tsx +1 -1
  31. package/src/wallet/evmUiKitManager.ts +26 -129
  32. package/src/wallet/hooks/index.ts +0 -1
  33. package/src/wallet/implementation/wagmi-implementation.ts +45 -577
  34. package/src/wallet/index.ts +2 -3
  35. package/src/wallet/rainbowkit/__tests__/export-service.test.ts +1 -2
  36. package/src/wallet/rainbowkit/componentFactory.ts +10 -8
  37. package/src/wallet/rainbowkit/components.tsx +16 -133
  38. package/src/wallet/rainbowkit/index.ts +27 -5
  39. package/src/wallet/utils/__tests__/uiKitService.test.ts +5 -1
  40. package/src/wallet/utils/connection.ts +8 -52
  41. package/src/wallet/utils/index.ts +0 -2
  42. package/src/wallet/utils/uiKitService.ts +7 -3
  43. package/src/wallet/utils/walletImplementationManager.ts +5 -4
  44. package/src/wallet/utils.ts +1 -65
  45. package/src/abi/__tests__/etherscan-v2.test.ts +0 -117
  46. package/src/abi/__tests__/transformer.test.ts +0 -342
  47. package/src/abi/comparison.ts +0 -389
  48. package/src/abi/etherscan-v2.ts +0 -243
  49. package/src/abi/etherscan.ts +0 -158
  50. package/src/abi/index.ts +0 -7
  51. package/src/abi/loader.ts +0 -415
  52. package/src/abi/sourcify.ts +0 -75
  53. package/src/abi/transformer.ts +0 -163
  54. package/src/abi/types.ts +0 -101
  55. package/src/configuration/__tests__/explorer.test.ts +0 -174
  56. package/src/configuration/__tests__/rpc.test.ts +0 -176
  57. package/src/configuration/explorer.ts +0 -243
  58. package/src/configuration/rpc.ts +0 -257
  59. package/src/mapping/__tests__/field-generator.test.ts +0 -137
  60. package/src/mapping/__tests__/type-mapper.test.ts +0 -139
  61. package/src/mapping/constants.ts +0 -57
  62. package/src/mapping/field-generator.ts +0 -115
  63. package/src/mapping/index.ts +0 -4
  64. package/src/mapping/type-mapper.ts +0 -80
  65. package/src/proxy/detection.ts +0 -465
  66. package/src/query/handler.ts +0 -227
  67. package/src/query/view-checker.ts +0 -10
  68. package/src/transaction/eoa.ts +0 -98
  69. package/src/transaction/execution-strategy.ts +0 -33
  70. package/src/transaction/formatter.ts +0 -101
  71. package/src/transaction/relayer.ts +0 -380
  72. package/src/transaction/sender.ts +0 -185
  73. package/src/transform/index.ts +0 -3
  74. package/src/transform/input-parser.ts +0 -177
  75. package/src/transform/output-formatter.ts +0 -64
  76. package/src/types/__tests__/artifacts.test.ts +0 -105
  77. package/src/types.ts +0 -92
  78. package/src/utils/__tests__/artifacts.test.ts +0 -81
  79. package/src/utils/artifacts.ts +0 -30
  80. package/src/utils/formatting.ts +0 -25
  81. package/src/utils/gas.ts +0 -17
  82. package/src/utils/index.ts +0 -6
  83. package/src/utils/json.ts +0 -19
  84. package/src/utils/validation.ts +0 -10
  85. package/src/validation/eoa.ts +0 -33
  86. package/src/validation/index.ts +0 -2
  87. package/src/validation/relayer.ts +0 -13
  88. package/src/wallet/__tests__/utils.test.ts +0 -149
  89. package/src/wallet/components/account/AccountDisplay.tsx +0 -52
  90. package/src/wallet/components/connect/ConnectButton.tsx +0 -125
  91. package/src/wallet/components/connect/ConnectorDialog.tsx +0 -140
  92. package/src/wallet/components/index.ts +0 -4
  93. package/src/wallet/components/network/NetworkSwitcher.tsx +0 -90
  94. package/src/wallet/context/index.ts +0 -1
  95. package/src/wallet/context/wagmi-context.tsx +0 -7
  96. package/src/wallet/hooks/useIsWagmiProviderInitialized.ts +0 -11
  97. package/src/wallet/rainbowkit/config-generator.ts +0 -56
  98. package/src/wallet/rainbowkit/config-service.ts +0 -169
  99. package/src/wallet/rainbowkit/export-service.ts +0 -18
  100. package/src/wallet/rainbowkit/rainbowkitAssetManager.ts +0 -74
  101. package/src/wallet/rainbowkit/types.ts +0 -74
  102. package/src/wallet/rainbowkit/utils.ts +0 -96
  103. package/src/wallet/services/configResolutionService.ts +0 -65
  104. package/src/wallet/utils/SafeWagmiComponent.tsx +0 -72
  105. package/src/wallet/utils/filterWalletComponents.ts +0 -89
@@ -1,96 +0,0 @@
1
- import type { UiKitConfiguration } from '@openzeppelin/ui-types';
2
- import { logger } from '@openzeppelin/ui-utils';
3
-
4
- /**
5
- * RainbowKit configuration options definition
6
- */
7
-
8
- /**
9
- * Validates the RainbowKit configuration to ensure required fields are present.
10
- *
11
- * @param kitConfig - The RainbowKit configuration object
12
- * @returns Object containing the validation result and any missing fields or error message
13
- */
14
- export function validateRainbowKitConfig(kitConfig?: UiKitConfiguration['kitConfig']): {
15
- isValid: boolean;
16
- missingFields?: string[];
17
- error?: string;
18
- } {
19
- // Detailed log to inspect the received kitConfig
20
- logger.debug(
21
- 'validateRainbowKitConfig',
22
- 'Received kitConfig for validation:',
23
- JSON.stringify(kitConfig)
24
- );
25
-
26
- if (!kitConfig) {
27
- logger.warn('validateRainbowKitConfig', 'Validation failed: No kitConfig provided.');
28
- return { isValid: false, error: 'No kitConfig provided for RainbowKit' };
29
- }
30
-
31
- // kitConfig is the fully resolved configuration object which should contain wagmiParams and providerProps.
32
- // Access wagmiParams from within kitConfig.
33
- const wagmiParamsFromKitConfig = (kitConfig as Record<string, unknown>).wagmiParams as
34
- | Record<string, unknown>
35
- | undefined;
36
-
37
- if (
38
- !wagmiParamsFromKitConfig ||
39
- typeof wagmiParamsFromKitConfig !== 'object' ||
40
- wagmiParamsFromKitConfig === null
41
- ) {
42
- logger.warn(
43
- 'validateRainbowKitConfig',
44
- 'Validation failed: kitConfig.wagmiParams is missing or invalid.',
45
- { wagmiParamsFromKitConfig }
46
- );
47
- return { isValid: false, error: 'kitConfig.wagmiParams is missing or not a valid object' };
48
- }
49
-
50
- const missingFields: string[] = [];
51
- if (
52
- !('appName' in wagmiParamsFromKitConfig) ||
53
- typeof wagmiParamsFromKitConfig.appName !== 'string'
54
- ) {
55
- missingFields.push('wagmiParams.appName');
56
- }
57
- if (
58
- !('projectId' in wagmiParamsFromKitConfig) ||
59
- typeof wagmiParamsFromKitConfig.projectId !== 'string'
60
- ) {
61
- missingFields.push('wagmiParams.projectId');
62
- }
63
-
64
- if (missingFields.length > 0) {
65
- const errorMsg = `Missing or invalid required fields in wagmiParams: ${missingFields.join(', ')}`;
66
- logger.warn('validateRainbowKitConfig', 'Validation failed:', errorMsg, { missingFields });
67
- return {
68
- isValid: false,
69
- missingFields,
70
- error: errorMsg,
71
- };
72
- }
73
- logger.debug('validateRainbowKitConfig', 'Validation successful.');
74
- return { isValid: true };
75
- }
76
-
77
- /**
78
- * Extracts and type-guards a RainbowKit configuration from a UiKitConfiguration
79
- *
80
- * @param config The UI kit configuration
81
- * @returns The raw kitConfig Record<string, unknown> or undefined.
82
- */
83
- export function getRawUserNativeConfig(
84
- config: UiKitConfiguration
85
- ): Record<string, unknown> | undefined {
86
- if (config.kitName !== 'rainbowkit' || !config.kitConfig) {
87
- return undefined;
88
- }
89
- // kitConfig is already expected to be Record<string, unknown> or undefined by UiKitConfiguration type.
90
- // We just ensure it's not null and is an object here for safety if it were `any` somewhere up the chain.
91
- if (typeof config.kitConfig === 'object' && config.kitConfig !== null) {
92
- return config.kitConfig as Record<string, unknown>;
93
- }
94
- logger.warn('rainbowkit/utils', 'kitConfig for RainbowKit is not a valid object.');
95
- return undefined;
96
- }
@@ -1,65 +0,0 @@
1
- import type { NativeConfigLoader, UiKitConfiguration } from '@openzeppelin/ui-types';
2
- import { logger } from '@openzeppelin/ui-utils';
3
-
4
- import { resolveAndInitializeKitConfig } from '../utils';
5
-
6
- /**
7
- * Resolves the final, complete UiKitConfiguration by merging various sources.
8
- *
9
- * @param programmaticOverrides - Overrides passed directly to the configureUiKit call.
10
- * @param initialAppServiceKitName - The kitName noted from AppConfigService when the adapter instance was constructed.
11
- * @param currentAppServiceConfig - The full UiKitConfiguration from AppConfigService, re-fetched at the time of the call.
12
- * @param options - Options, including the callback to load user's native config file.
13
- * @returns A Promise resolving to the final UiKitConfiguration.
14
- */
15
- export async function resolveFullUiKitConfiguration(
16
- programmaticOverrides: Partial<UiKitConfiguration>,
17
- initialAppServiceKitName: UiKitConfiguration['kitName'],
18
- currentAppServiceConfig: UiKitConfiguration, // This is the result of loadInitialConfigFromAppService()
19
- options?: {
20
- loadUiKitNativeConfig?: NativeConfigLoader;
21
- }
22
- ): Promise<UiKitConfiguration> {
23
- logger.debug(
24
- 'configResolutionService:resolveFullUiKitConfiguration',
25
- 'Starting resolution with:',
26
- {
27
- programmaticOverrides,
28
- initialAppServiceKitName,
29
- currentAppServiceConfig,
30
- hasLoadNativeCallback: !!options?.loadUiKitNativeConfig,
31
- hasCustomCode: !!programmaticOverrides.customCode,
32
- }
33
- );
34
-
35
- const effectiveKitName: UiKitConfiguration['kitName'] =
36
- programmaticOverrides.kitName ||
37
- initialAppServiceKitName ||
38
- currentAppServiceConfig.kitName ||
39
- 'custom';
40
-
41
- // Resolve from native config file (if loader is provided)
42
- const resolvedUserNativeAndProgrammaticKitConfig = await resolveAndInitializeKitConfig(
43
- effectiveKitName,
44
- programmaticOverrides.kitConfig,
45
- options?.loadUiKitNativeConfig
46
- );
47
-
48
- const finalFullConfig: UiKitConfiguration = {
49
- kitName: effectiveKitName,
50
- kitConfig: {
51
- ...(currentAppServiceConfig.kitConfig || {}),
52
- ...(resolvedUserNativeAndProgrammaticKitConfig || {}),
53
- // customCode is NOT applied to runtime config
54
- },
55
- // Pass through customCode for export purposes only
56
- customCode: programmaticOverrides.customCode,
57
- };
58
-
59
- logger.debug(
60
- 'configResolutionService:resolveFullUiKitConfiguration',
61
- 'Resolved finalFullConfig:',
62
- finalFullConfig
63
- );
64
- return finalFullConfig;
65
- }
@@ -1,72 +0,0 @@
1
- import React, { useEffect, useState } from 'react';
2
-
3
- import { logger } from '@openzeppelin/ui-utils';
4
-
5
- import { useIsWagmiProviderInitialized } from '../hooks/useIsWagmiProviderInitialized';
6
-
7
- /**
8
- * A wrapper component that safely renders children that use wagmi hooks.
9
- * It handles errors and provider initialization state to prevent crashes.
10
- */
11
- export const SafeWagmiComponent = ({
12
- children,
13
- fallback = null,
14
- }: {
15
- children: React.ReactNode;
16
- fallback?: React.ReactNode;
17
- }) => {
18
- const isProviderInitialized = useIsWagmiProviderInitialized();
19
- const [hasError, setHasError] = useState(false);
20
-
21
- useEffect(() => {
22
- // Reset error state if provider initializes
23
- if (isProviderInitialized) {
24
- setHasError(false);
25
- }
26
- }, [isProviderInitialized]);
27
-
28
- // Setup global error handler for wagmi errors
29
- useEffect(() => {
30
- const handleError = (event: ErrorEvent) => {
31
- // Only handle wagmi-related errors
32
- if (
33
- event.error?.message?.includes('useConfig') ||
34
- event.error?.message?.includes('WagmiProvider')
35
- ) {
36
- logger.debug(
37
- 'SafeWagmiComponent',
38
- 'Caught wagmi error via window error event:',
39
- event.error
40
- );
41
- setHasError(true);
42
- event.preventDefault(); // Prevent the error from propagating
43
- }
44
- };
45
-
46
- window.addEventListener('error', handleError);
47
- return () => {
48
- window.removeEventListener('error', handleError);
49
- };
50
- }, []);
51
-
52
- // If provider isn't ready yet or we had an error, show fallback
53
- if (!isProviderInitialized || hasError) {
54
- return <>{fallback}</>;
55
- }
56
-
57
- try {
58
- return <>{children}</>;
59
- } catch (error) {
60
- // Only catch render errors related to wagmi hooks
61
- if (
62
- error instanceof Error &&
63
- (error.message.includes('useConfig') || error.message.includes('WagmiProvider'))
64
- ) {
65
- logger.debug('SafeWagmiComponent', 'Caught wagmi error:', error);
66
- setHasError(true);
67
- return <>{fallback}</>;
68
- }
69
- // Re-throw other errors
70
- throw error;
71
- }
72
- };
@@ -1,89 +0,0 @@
1
- import type { EcosystemWalletComponents, UiKitConfiguration } from '@openzeppelin/ui-types';
2
- import { ECOSYSTEM_WALLET_COMPONENT_KEYS } from '@openzeppelin/ui-types';
3
- import { logger } from '@openzeppelin/ui-utils';
4
-
5
- /**
6
- * Filters a set of wallet components based on an exclusion list.
7
- *
8
- * @param allPossibleComponents - An object containing all potential components for a kit.
9
- * @param exclusions - An array of component keys to exclude.
10
- * @param kitName - The name of the kit being filtered (for logging purposes).
11
- * @returns The filtered EcosystemWalletComponents object, or undefined if all components are excluded.
12
- */
13
- export function filterWalletComponents(
14
- allPossibleComponents: EcosystemWalletComponents,
15
- exclusions: Array<keyof EcosystemWalletComponents>,
16
- kitName: string = 'custom' // Default to custom for logging context
17
- ): EcosystemWalletComponents | undefined {
18
- logger.debug(
19
- 'filterWalletComponents',
20
- `Filtering components for kit: ${kitName}. Exclusions: ${exclusions.join(', ')}.`
21
- );
22
- if (!allPossibleComponents || Object.keys(allPossibleComponents).length === 0) {
23
- logger.debug('filterWalletComponents', `No components provided to filter for kit: ${kitName}.`);
24
- return undefined;
25
- }
26
-
27
- if (exclusions.length === 0) {
28
- logger.debug(
29
- 'filterWalletComponents',
30
- `Providing all components for kit: ${kitName}.`,
31
- allPossibleComponents
32
- );
33
- return allPossibleComponents;
34
- }
35
-
36
- const filteredComponents: Partial<EcosystemWalletComponents> = {};
37
- let componentCount = 0;
38
- for (const key in allPossibleComponents) {
39
- const componentKey = key as keyof EcosystemWalletComponents;
40
- if (!exclusions.includes(componentKey)) {
41
- if (allPossibleComponents[componentKey]) {
42
- // Ensure the component actually exists before adding
43
- filteredComponents[componentKey] = allPossibleComponents[componentKey];
44
- componentCount++;
45
- }
46
- }
47
- }
48
-
49
- if (componentCount > 0) {
50
- logger.debug(
51
- 'filterWalletComponents',
52
- `Providing filtered components for kit: ${kitName} after exclusions (${exclusions.join(', ')}).`,
53
- filteredComponents
54
- );
55
- return filteredComponents as EcosystemWalletComponents;
56
- }
57
-
58
- logger.debug('filterWalletComponents', `All components were excluded for kit: ${kitName}.`);
59
- return undefined;
60
- }
61
-
62
- /**
63
- * Extracts the component exclusion list from a UI kit configuration object.
64
- *
65
- * @param kitConfig - The `kitConfig` object from `UiKitConfiguration`.
66
- * @returns An array of component keys to exclude, or an empty array if none are specified or config is invalid.
67
- */
68
- export function getComponentExclusionsFromConfig(
69
- kitConfig: UiKitConfiguration['kitConfig']
70
- ): Array<keyof EcosystemWalletComponents> {
71
- if (kitConfig && typeof kitConfig === 'object' && 'components' in kitConfig) {
72
- const componentsCfg = kitConfig.components;
73
- if (
74
- componentsCfg &&
75
- typeof componentsCfg === 'object' &&
76
- 'exclude' in componentsCfg &&
77
- Array.isArray(componentsCfg.exclude)
78
- ) {
79
- // Ensure all elements are valid keys of EcosystemWalletComponents
80
- // This provides a bit more type safety at runtime if the config comes from an untyped source
81
- return componentsCfg.exclude.filter(
82
- (key): key is keyof EcosystemWalletComponents =>
83
- typeof key === 'string' &&
84
- (ECOSYSTEM_WALLET_COMPONENT_KEYS as readonly string[]).includes(key)
85
- ) as Array<keyof EcosystemWalletComponents>;
86
- }
87
- }
88
- return [];
89
- }