@openzeppelin/adapter-stellar 1.0.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 (165) hide show
  1. package/README.md +272 -0
  2. package/dist/config.cjs +21 -0
  3. package/dist/config.cjs.map +1 -0
  4. package/dist/config.d.cts +8 -0
  5. package/dist/config.d.cts.map +1 -0
  6. package/dist/config.d.mts +8 -0
  7. package/dist/config.d.mts.map +1 -0
  8. package/dist/config.mjs +20 -0
  9. package/dist/config.mjs.map +1 -0
  10. package/dist/index.cjs +7564 -0
  11. package/dist/index.cjs.map +1 -0
  12. package/dist/index.d.cts +261 -0
  13. package/dist/index.d.cts.map +1 -0
  14. package/dist/index.d.mts +263 -0
  15. package/dist/index.d.mts.map +1 -0
  16. package/dist/index.mjs +7529 -0
  17. package/dist/index.mjs.map +1 -0
  18. package/dist/metadata.cjs +22 -0
  19. package/dist/metadata.cjs.map +1 -0
  20. package/dist/metadata.d.cts +7 -0
  21. package/dist/metadata.d.cts.map +1 -0
  22. package/dist/metadata.d.mts +7 -0
  23. package/dist/metadata.d.mts.map +1 -0
  24. package/dist/metadata.mjs +21 -0
  25. package/dist/metadata.mjs.map +1 -0
  26. package/dist/networks-BrV516-R.d.cts +15 -0
  27. package/dist/networks-BrV516-R.d.cts.map +1 -0
  28. package/dist/networks-C0MmhJcu.d.mts +15 -0
  29. package/dist/networks-C0MmhJcu.d.mts.map +1 -0
  30. package/dist/networks-DgUFSTiC.cjs +76 -0
  31. package/dist/networks-DgUFSTiC.cjs.map +1 -0
  32. package/dist/networks-QbEPbaGT.mjs +46 -0
  33. package/dist/networks-QbEPbaGT.mjs.map +1 -0
  34. package/dist/networks.cjs +8 -0
  35. package/dist/networks.d.cts +2 -0
  36. package/dist/networks.d.mts +2 -0
  37. package/dist/networks.mjs +3 -0
  38. package/dist/vite-config.cjs +43 -0
  39. package/dist/vite-config.cjs.map +1 -0
  40. package/dist/vite-config.d.cts +35 -0
  41. package/dist/vite-config.d.cts.map +1 -0
  42. package/dist/vite-config.d.mts +35 -0
  43. package/dist/vite-config.d.mts.map +1 -0
  44. package/dist/vite-config.mjs +42 -0
  45. package/dist/vite-config.mjs.map +1 -0
  46. package/package.json +114 -0
  47. package/src/__tests__/getDefaultServiceConfig.test.ts +105 -0
  48. package/src/access-control/actions.ts +214 -0
  49. package/src/access-control/feature-detection.ts +238 -0
  50. package/src/access-control/index.ts +54 -0
  51. package/src/access-control/indexer-client.ts +1474 -0
  52. package/src/access-control/onchain-reader.ts +446 -0
  53. package/src/access-control/service.ts +1431 -0
  54. package/src/access-control/validation.ts +256 -0
  55. package/src/adapter.ts +659 -0
  56. package/src/config.ts +43 -0
  57. package/src/configuration/__tests__/explorer.test.ts +80 -0
  58. package/src/configuration/__tests__/rpc.test.ts +355 -0
  59. package/src/configuration/execution.ts +83 -0
  60. package/src/configuration/explorer.ts +105 -0
  61. package/src/configuration/index.ts +5 -0
  62. package/src/configuration/network-services.ts +210 -0
  63. package/src/configuration/rpc.ts +270 -0
  64. package/src/configuration.ts +2 -0
  65. package/src/contract/__tests__/complete-type-coverage.test.ts +78 -0
  66. package/src/contract/index.ts +3 -0
  67. package/src/contract/loader.ts +498 -0
  68. package/src/contract/transformer.ts +1 -0
  69. package/src/contract/type.ts +65 -0
  70. package/src/index.ts +23 -0
  71. package/src/mapping/constants.ts +89 -0
  72. package/src/mapping/enum-metadata.ts +237 -0
  73. package/src/mapping/field-generator.ts +296 -0
  74. package/src/mapping/index.ts +5 -0
  75. package/src/mapping/struct-fields.ts +106 -0
  76. package/src/mapping/tuple-components.ts +43 -0
  77. package/src/mapping/type-coverage-validator.ts +151 -0
  78. package/src/mapping/type-mapper.ts +203 -0
  79. package/src/metadata.ts +16 -0
  80. package/src/networks/README.md +84 -0
  81. package/src/networks/index.ts +19 -0
  82. package/src/networks/mainnet.ts +20 -0
  83. package/src/networks/testnet.ts +20 -0
  84. package/src/networks.ts +2 -0
  85. package/src/query/handler.ts +411 -0
  86. package/src/query/index.ts +4 -0
  87. package/src/query/view-checker.ts +32 -0
  88. package/src/sac/spec-cache.ts +68 -0
  89. package/src/sac/spec-source.ts +35 -0
  90. package/src/sac/xdr.ts +101 -0
  91. package/src/transaction/components/AdvancedInfo.tsx +34 -0
  92. package/src/transaction/components/FeeConfiguration.tsx +41 -0
  93. package/src/transaction/components/StellarRelayerOptions.tsx +60 -0
  94. package/src/transaction/components/TransactionTiming.tsx +77 -0
  95. package/src/transaction/components/index.ts +5 -0
  96. package/src/transaction/components/useStellarRelayerOptions.ts +114 -0
  97. package/src/transaction/eoa.ts +229 -0
  98. package/src/transaction/execution-strategy.ts +33 -0
  99. package/src/transaction/formatter.ts +296 -0
  100. package/src/transaction/index.ts +4 -0
  101. package/src/transaction/relayer.ts +575 -0
  102. package/src/transaction/sender.ts +156 -0
  103. package/src/transform/index.ts +4 -0
  104. package/src/transform/input-parser.ts +9 -0
  105. package/src/transform/output-formatter.ts +133 -0
  106. package/src/transform/parsers/complex-parser.ts +157 -0
  107. package/src/transform/parsers/generic-parser.ts +171 -0
  108. package/src/transform/parsers/index.ts +86 -0
  109. package/src/transform/parsers/primitive-parser.ts +123 -0
  110. package/src/transform/parsers/scval-converter.ts +405 -0
  111. package/src/transform/parsers/struct-parser.ts +324 -0
  112. package/src/transform/parsers/types.ts +35 -0
  113. package/src/types/__tests__/artifacts.test.ts +89 -0
  114. package/src/types/artifacts.ts +19 -0
  115. package/src/utils/__tests__/artifacts.test.ts +77 -0
  116. package/src/utils/artifacts.ts +30 -0
  117. package/src/utils/formatting.ts +122 -0
  118. package/src/utils/index.ts +6 -0
  119. package/src/utils/input-parsing.ts +336 -0
  120. package/src/utils/safe-type-parser.ts +303 -0
  121. package/src/utils/stellar-types.ts +35 -0
  122. package/src/utils/type-detection.ts +163 -0
  123. package/src/utils/xdr-ordering.ts +36 -0
  124. package/src/validation/__tests__/address.test.ts +267 -0
  125. package/src/validation/address.ts +136 -0
  126. package/src/validation/eoa.ts +33 -0
  127. package/src/validation/index.ts +3 -0
  128. package/src/validation/relayer.ts +13 -0
  129. package/src/vite-config.ts +67 -0
  130. package/src/wallet/README.md +93 -0
  131. package/src/wallet/__tests__/connection.test.ts +72 -0
  132. package/src/wallet/components/StellarWalletUiRoot.tsx +161 -0
  133. package/src/wallet/components/account/AccountDisplay.tsx +50 -0
  134. package/src/wallet/components/connect/ConnectButton.tsx +100 -0
  135. package/src/wallet/components/connect/ConnectorDialog.tsx +125 -0
  136. package/src/wallet/components/index.ts +3 -0
  137. package/src/wallet/connection.ts +151 -0
  138. package/src/wallet/context/StellarWalletContext.ts +32 -0
  139. package/src/wallet/context/index.ts +4 -0
  140. package/src/wallet/context/useStellarWalletContext.ts +17 -0
  141. package/src/wallet/hooks/facade-hooks.ts +31 -0
  142. package/src/wallet/hooks/index.ts +7 -0
  143. package/src/wallet/hooks/useStellarAccount.ts +27 -0
  144. package/src/wallet/hooks/useStellarConnect.ts +60 -0
  145. package/src/wallet/hooks/useStellarDisconnect.ts +47 -0
  146. package/src/wallet/hooks/useUiKitConfig.ts +40 -0
  147. package/src/wallet/implementation/wallets-kit-implementation.ts +379 -0
  148. package/src/wallet/index.ts +11 -0
  149. package/src/wallet/services/__tests__/configResolutionService.test.ts +163 -0
  150. package/src/wallet/services/configResolutionService.ts +65 -0
  151. package/src/wallet/stellar-wallets-kit/StellarWalletsKitConnectButton.tsx +82 -0
  152. package/src/wallet/stellar-wallets-kit/__mocks__/@creit.tech/stellar-wallets-kit.ts +48 -0
  153. package/src/wallet/stellar-wallets-kit/__tests__/export-service.test.ts +93 -0
  154. package/src/wallet/stellar-wallets-kit/__tests__/stellarUiKitManager.test.ts +0 -0
  155. package/src/wallet/stellar-wallets-kit/config-generator.ts +75 -0
  156. package/src/wallet/stellar-wallets-kit/export-service.ts +19 -0
  157. package/src/wallet/stellar-wallets-kit/index.ts +3 -0
  158. package/src/wallet/stellar-wallets-kit/stellarUiKitManager.ts +235 -0
  159. package/src/wallet/types.ts +19 -0
  160. package/src/wallet/utils/__tests__/filterWalletComponents.test.ts +150 -0
  161. package/src/wallet/utils/__tests__/uiKitService.test.ts +189 -0
  162. package/src/wallet/utils/filterWalletComponents.ts +89 -0
  163. package/src/wallet/utils/index.ts +3 -0
  164. package/src/wallet/utils/stellarWalletImplementationManager.ts +118 -0
  165. package/src/wallet/utils/uiKitService.ts +74 -0
@@ -0,0 +1,189 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
2
+
3
+ import type { UiKitConfiguration, UiKitName } from '@openzeppelin/ui-types';
4
+
5
+ import { CustomAccountDisplay, CustomConnectButton } from '../../components';
6
+ import { getResolvedWalletComponents } from '../uiKitService';
7
+
8
+ // Mock the stellar-wallets-kit before any imports that might use it
9
+ vi.mock('@creit.tech/stellar-wallets-kit', () => ({
10
+ StellarWalletsKit: vi.fn(),
11
+ WalletNetwork: {
12
+ PUBLIC: 'PUBLIC',
13
+ TESTNET: 'TESTNET',
14
+ },
15
+ allowAllModules: vi.fn(() => ({})),
16
+ }));
17
+
18
+ // Mock the filterWalletComponents module
19
+ vi.mock('../filterWalletComponents', () => ({
20
+ filterWalletComponents: vi.fn((components, exclusions) => {
21
+ // Simple mock implementation
22
+ if (!components || Object.keys(components).length === 0) return undefined;
23
+ if (exclusions.length === 0) return components;
24
+
25
+ const filtered: Record<string, unknown> = {};
26
+ for (const key in components) {
27
+ if (!exclusions.includes(key)) {
28
+ filtered[key] = components[key];
29
+ }
30
+ }
31
+ return Object.keys(filtered).length > 0 ? filtered : undefined;
32
+ }),
33
+ getComponentExclusionsFromConfig: vi.fn((config) => {
34
+ return config?.components?.exclude || [];
35
+ }),
36
+ }));
37
+
38
+ describe('uiKitService', () => {
39
+ beforeEach(() => {
40
+ vi.clearAllMocks();
41
+ });
42
+
43
+ describe('getResolvedWalletComponents', () => {
44
+ it('should return undefined for "none" kit', () => {
45
+ const config: UiKitConfiguration = {
46
+ kitName: 'none',
47
+ kitConfig: {},
48
+ };
49
+
50
+ const result = getResolvedWalletComponents(config);
51
+ expect(result).toBeUndefined();
52
+ });
53
+
54
+ it('should return custom components for "custom" kit', () => {
55
+ const config: UiKitConfiguration = {
56
+ kitName: 'custom',
57
+ kitConfig: {},
58
+ };
59
+
60
+ const result = getResolvedWalletComponents(config);
61
+
62
+ expect(result).toBeDefined();
63
+ expect(result?.ConnectButton).toBe(CustomConnectButton);
64
+ expect(result?.AccountDisplay).toBe(CustomAccountDisplay);
65
+ expect(result?.NetworkSwitcher).toBeUndefined(); // Stellar doesn't have NetworkSwitcher
66
+ });
67
+
68
+ it('should return built-in UI components for "stellar-wallets-kit" kit', () => {
69
+ const config: UiKitConfiguration = {
70
+ kitName: 'stellar-wallets-kit',
71
+ kitConfig: {},
72
+ };
73
+
74
+ const result = getResolvedWalletComponents(config);
75
+
76
+ expect(result).toBeDefined();
77
+ expect(result?.ConnectButton).toBeDefined();
78
+ expect(result?.ConnectButton?.name).toBe('StellarWalletsKitConnectButton');
79
+ expect(result?.AccountDisplay).toBeUndefined(); // Kit handles account display internally
80
+ expect(result?.NetworkSwitcher).toBeUndefined();
81
+ });
82
+
83
+ it('should apply component exclusions', () => {
84
+ const config: UiKitConfiguration = {
85
+ kitName: 'custom',
86
+ kitConfig: {
87
+ components: {
88
+ exclude: ['AccountDisplay'],
89
+ },
90
+ },
91
+ };
92
+
93
+ const result = getResolvedWalletComponents(config);
94
+
95
+ expect(result).toBeDefined();
96
+ expect(result?.ConnectButton).toBe(CustomConnectButton);
97
+ expect(result?.AccountDisplay).toBeUndefined();
98
+ });
99
+
100
+ it('should handle all components being excluded', () => {
101
+ const config: UiKitConfiguration = {
102
+ kitName: 'custom',
103
+ kitConfig: {
104
+ components: {
105
+ exclude: ['ConnectButton', 'AccountDisplay'],
106
+ },
107
+ },
108
+ };
109
+
110
+ const result = getResolvedWalletComponents(config);
111
+ expect(result).toBeUndefined();
112
+ });
113
+
114
+ it('should return undefined for unsupported kit name', () => {
115
+ const config: UiKitConfiguration = {
116
+ kitName: 'unsupported-kit' as UiKitName,
117
+ kitConfig: {},
118
+ };
119
+
120
+ const result = getResolvedWalletComponents(config);
121
+ expect(result).toBeUndefined();
122
+ });
123
+
124
+ it('should default to "custom" when kit name is not provided', () => {
125
+ const config: UiKitConfiguration = {
126
+ kitName: undefined as unknown as UiKitName,
127
+ kitConfig: {},
128
+ };
129
+
130
+ const result = getResolvedWalletComponents(config);
131
+
132
+ expect(result).toBeDefined();
133
+ expect(result?.ConnectButton).toBe(CustomConnectButton);
134
+ expect(result?.AccountDisplay).toBe(CustomAccountDisplay);
135
+ });
136
+
137
+ it('should handle empty kit config for stellar-wallets-kit', () => {
138
+ const config: UiKitConfiguration = {
139
+ kitName: 'stellar-wallets-kit',
140
+ kitConfig: undefined as Record<string, unknown> | undefined,
141
+ };
142
+
143
+ const result = getResolvedWalletComponents(config);
144
+
145
+ expect(result).toBeDefined();
146
+ expect(result?.ConnectButton).toBeDefined();
147
+ expect(result?.ConnectButton?.name).toBe('StellarWalletsKitConnectButton');
148
+ expect(result?.AccountDisplay).toBeUndefined();
149
+ });
150
+
151
+ it('should handle complex kit config with exclusions for custom kit', () => {
152
+ const config: UiKitConfiguration = {
153
+ kitName: 'custom',
154
+ kitConfig: {
155
+ showInjectedConnector: true,
156
+ appName: 'Test App',
157
+ components: {
158
+ exclude: ['ConnectButton'],
159
+ // Other potential component config
160
+ },
161
+ },
162
+ };
163
+
164
+ const result = getResolvedWalletComponents(config);
165
+
166
+ expect(result).toBeDefined();
167
+ expect(result?.ConnectButton).toBeUndefined();
168
+ expect(result?.AccountDisplay).toBe(CustomAccountDisplay);
169
+ });
170
+
171
+ it('should not apply exclusions to stellar-wallets-kit built-in components', () => {
172
+ const config: UiKitConfiguration = {
173
+ kitName: 'stellar-wallets-kit',
174
+ kitConfig: {
175
+ components: {
176
+ exclude: ['ConnectButton'], // Should be ignored
177
+ },
178
+ },
179
+ };
180
+
181
+ const result = getResolvedWalletComponents(config);
182
+
183
+ expect(result).toBeDefined();
184
+ // Built-in components are not affected by exclusions
185
+ expect(result?.ConnectButton).toBeDefined();
186
+ expect(result?.ConnectButton?.name).toBe('StellarWalletsKitConnectButton');
187
+ });
188
+ });
189
+ });
@@ -0,0 +1,89 @@
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
+ }
@@ -0,0 +1,3 @@
1
+ export * from './filterWalletComponents';
2
+ export * from './stellarWalletImplementationManager';
3
+ export * from './uiKitService';
@@ -0,0 +1,118 @@
1
+ import type { StellarNetworkConfig, UiKitConfiguration } from '@openzeppelin/ui-types';
2
+ import { appConfigService, logger } from '@openzeppelin/ui-utils';
3
+
4
+ import { WalletsKitImplementation } from '../implementation/wallets-kit-implementation';
5
+
6
+ let walletImplementationInstance: WalletsKitImplementation | undefined;
7
+ let walletImplementationPromise: Promise<WalletsKitImplementation> | undefined;
8
+
9
+ const LOG_SYSTEM = 'StellarWalletImplementationManager';
10
+
11
+ /**
12
+ * Get or create the singleton instance of WalletsKitImplementation.
13
+ * This function ensures that the initialization logic runs only once.
14
+ *
15
+ * @param networkConfig - Optional network configuration to use for initialization
16
+ * @returns A Promise resolving to the WalletsKitImplementation singleton
17
+ */
18
+ export async function getStellarWalletImplementation(
19
+ networkConfig?: StellarNetworkConfig
20
+ ): Promise<WalletsKitImplementation> {
21
+ if (walletImplementationInstance) {
22
+ // If network config is provided and different, update it
23
+ if (networkConfig) {
24
+ walletImplementationInstance.setNetworkConfig(networkConfig);
25
+ }
26
+ return walletImplementationInstance;
27
+ }
28
+
29
+ if (walletImplementationPromise) {
30
+ const instance = await walletImplementationPromise;
31
+ // If network config is provided and different, update it
32
+ if (networkConfig) {
33
+ instance.setNetworkConfig(networkConfig);
34
+ }
35
+ return instance;
36
+ }
37
+
38
+ walletImplementationPromise = (async () => {
39
+ try {
40
+ logger.info(LOG_SYSTEM, 'Initializing StellarWalletImplementation singleton (async)...');
41
+
42
+ // Get initial UI kit config from appConfigService
43
+ const initialUiKitConfig = appConfigService.getTypedNestedConfig<UiKitConfiguration>(
44
+ 'walletui',
45
+ 'config'
46
+ );
47
+
48
+ // Create instance with provided network config or undefined
49
+ const instance = new WalletsKitImplementation(networkConfig, initialUiKitConfig);
50
+
51
+ logger.info(LOG_SYSTEM, 'WalletsKitImplementation singleton created (async).');
52
+ walletImplementationInstance = instance;
53
+ return instance;
54
+ } catch (error) {
55
+ logger.error(LOG_SYSTEM, 'Failed to initialize WalletsKitImplementation (async):', error);
56
+
57
+ // Create fallback instance
58
+ const fallbackInstance = new WalletsKitImplementation(networkConfig);
59
+ walletImplementationInstance = fallbackInstance;
60
+ return fallbackInstance;
61
+ }
62
+ })();
63
+
64
+ return walletImplementationPromise;
65
+ }
66
+
67
+ /**
68
+ * A synchronous getter for cases where the instance is known to be initialized.
69
+ * Use with caution, prefer the async getter.
70
+ *
71
+ * This function is essential for cases where you need immediate access to the
72
+ * wallet implementation and know it has already been initialized.
73
+ *
74
+ * @returns The initialized WalletsKitImplementation instance or undefined
75
+ */
76
+ export function getInitializedStellarWalletImplementation(): WalletsKitImplementation | undefined {
77
+ if (!walletImplementationInstance) {
78
+ logger.warn(
79
+ LOG_SYSTEM,
80
+ 'getInitializedStellarWalletImplementation called before instance was ready.'
81
+ );
82
+ }
83
+ return walletImplementationInstance;
84
+ }
85
+
86
+ /**
87
+ * Updates the network configuration for the wallet implementation
88
+ * This is useful when the network changes but the implementation instance should remain the same
89
+ *
90
+ * @param networkConfig - The new network configuration
91
+ */
92
+ export function updateWalletImplementationNetworkConfig(networkConfig: StellarNetworkConfig): void {
93
+ logger.info(LOG_SYSTEM, 'Updating wallet implementation network config:', networkConfig.name);
94
+
95
+ if (walletImplementationInstance) {
96
+ walletImplementationInstance.setNetworkConfig(networkConfig);
97
+ } else {
98
+ logger.warn(
99
+ LOG_SYSTEM,
100
+ 'Cannot update network config - wallet implementation not initialized yet'
101
+ );
102
+ }
103
+ }
104
+
105
+ /**
106
+ * Resets the singleton instance (primarily for testing or cleanup)
107
+ * Use with extreme caution in production code
108
+ */
109
+ export function resetWalletImplementationInstance(): void {
110
+ logger.warn(LOG_SYSTEM, 'Resetting wallet implementation singleton instance');
111
+
112
+ if (walletImplementationInstance) {
113
+ walletImplementationInstance.cleanup();
114
+ }
115
+
116
+ walletImplementationInstance = undefined;
117
+ walletImplementationPromise = undefined;
118
+ }
@@ -0,0 +1,74 @@
1
+ import type { EcosystemWalletComponents, UiKitConfiguration } from '@openzeppelin/ui-types';
2
+ import { logger } from '@openzeppelin/ui-utils';
3
+
4
+ import { CustomAccountDisplay, CustomConnectButton } from '../components';
5
+ import { StellarWalletsKitConnectButton } from '../stellar-wallets-kit';
6
+ import { filterWalletComponents, getComponentExclusionsFromConfig } from './filterWalletComponents';
7
+
8
+ /**
9
+ * Determines the final set of wallet components to be provided by the Stellar adapter
10
+ * based on the UI kit configuration.
11
+ *
12
+ * @param uiKitConfiguration - The UiKitConfiguration from the adapter instance.
13
+ * @returns The EcosystemWalletComponents object or undefined.
14
+ */
15
+ export function getResolvedWalletComponents(
16
+ uiKitConfiguration: UiKitConfiguration
17
+ ): EcosystemWalletComponents | undefined {
18
+ logger.debug(
19
+ 'stellar:uiKitService:getResolvedWalletComponents',
20
+ 'Received uiKitConfiguration:',
21
+ JSON.stringify(uiKitConfiguration)
22
+ );
23
+
24
+ const currentKitName = uiKitConfiguration.kitName || 'custom';
25
+
26
+ if (currentKitName === 'none') {
27
+ logger.info(
28
+ 'stellar:uiKitService',
29
+ 'UI Kit set to "none" for getResolvedWalletComponents, not providing wallet components.'
30
+ );
31
+ return undefined;
32
+ }
33
+
34
+ const exclusions = getComponentExclusionsFromConfig(uiKitConfiguration.kitConfig);
35
+ logger.debug(
36
+ 'stellar:uiKitService',
37
+ `Extracted component exclusions for ${currentKitName}: ${exclusions.join(', ') || 'none'}.`
38
+ );
39
+
40
+ // For 'custom' kit, we provide our custom components
41
+ if (currentKitName === 'custom') {
42
+ const allCustomComponents: EcosystemWalletComponents = {
43
+ ConnectButton: CustomConnectButton,
44
+ AccountDisplay: CustomAccountDisplay,
45
+ // NetworkSwitcher is not included as Stellar doesn't support network switching
46
+ };
47
+
48
+ logger.info(
49
+ 'stellar:uiKitService',
50
+ `Providing custom Stellar wallet components for kit: ${currentKitName}`
51
+ );
52
+
53
+ return filterWalletComponents(allCustomComponents, exclusions, currentKitName);
54
+ }
55
+
56
+ // For 'stellar-wallets-kit', use the kit's native button with built-in UI
57
+ if (currentKitName === 'stellar-wallets-kit') {
58
+ const stellarKitComponents: EcosystemWalletComponents = {
59
+ ConnectButton: StellarWalletsKitConnectButton,
60
+ // The kit's native button handles account display internally
61
+ AccountDisplay: undefined,
62
+ };
63
+
64
+ logger.info('stellar:uiKitService', 'Using Stellar Wallets Kit native button');
65
+
66
+ return stellarKitComponents;
67
+ }
68
+
69
+ logger.warn(
70
+ 'stellar:uiKitService',
71
+ `UI Kit "${currentKitName}" for getResolvedWalletComponents not explicitly supported. No components provided.`
72
+ );
73
+ return undefined;
74
+ }