@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.
- package/README.md +272 -0
- package/dist/config.cjs +21 -0
- package/dist/config.cjs.map +1 -0
- package/dist/config.d.cts +8 -0
- package/dist/config.d.cts.map +1 -0
- package/dist/config.d.mts +8 -0
- package/dist/config.d.mts.map +1 -0
- package/dist/config.mjs +20 -0
- package/dist/config.mjs.map +1 -0
- package/dist/index.cjs +7564 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +261 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +263 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +7529 -0
- package/dist/index.mjs.map +1 -0
- package/dist/metadata.cjs +22 -0
- package/dist/metadata.cjs.map +1 -0
- package/dist/metadata.d.cts +7 -0
- package/dist/metadata.d.cts.map +1 -0
- package/dist/metadata.d.mts +7 -0
- package/dist/metadata.d.mts.map +1 -0
- package/dist/metadata.mjs +21 -0
- package/dist/metadata.mjs.map +1 -0
- package/dist/networks-BrV516-R.d.cts +15 -0
- package/dist/networks-BrV516-R.d.cts.map +1 -0
- package/dist/networks-C0MmhJcu.d.mts +15 -0
- package/dist/networks-C0MmhJcu.d.mts.map +1 -0
- package/dist/networks-DgUFSTiC.cjs +76 -0
- package/dist/networks-DgUFSTiC.cjs.map +1 -0
- package/dist/networks-QbEPbaGT.mjs +46 -0
- package/dist/networks-QbEPbaGT.mjs.map +1 -0
- package/dist/networks.cjs +8 -0
- package/dist/networks.d.cts +2 -0
- package/dist/networks.d.mts +2 -0
- package/dist/networks.mjs +3 -0
- package/dist/vite-config.cjs +43 -0
- package/dist/vite-config.cjs.map +1 -0
- package/dist/vite-config.d.cts +35 -0
- package/dist/vite-config.d.cts.map +1 -0
- package/dist/vite-config.d.mts +35 -0
- package/dist/vite-config.d.mts.map +1 -0
- package/dist/vite-config.mjs +42 -0
- package/dist/vite-config.mjs.map +1 -0
- package/package.json +114 -0
- package/src/__tests__/getDefaultServiceConfig.test.ts +105 -0
- package/src/access-control/actions.ts +214 -0
- package/src/access-control/feature-detection.ts +238 -0
- package/src/access-control/index.ts +54 -0
- package/src/access-control/indexer-client.ts +1474 -0
- package/src/access-control/onchain-reader.ts +446 -0
- package/src/access-control/service.ts +1431 -0
- package/src/access-control/validation.ts +256 -0
- package/src/adapter.ts +659 -0
- package/src/config.ts +43 -0
- package/src/configuration/__tests__/explorer.test.ts +80 -0
- package/src/configuration/__tests__/rpc.test.ts +355 -0
- package/src/configuration/execution.ts +83 -0
- package/src/configuration/explorer.ts +105 -0
- package/src/configuration/index.ts +5 -0
- package/src/configuration/network-services.ts +210 -0
- package/src/configuration/rpc.ts +270 -0
- package/src/configuration.ts +2 -0
- package/src/contract/__tests__/complete-type-coverage.test.ts +78 -0
- package/src/contract/index.ts +3 -0
- package/src/contract/loader.ts +498 -0
- package/src/contract/transformer.ts +1 -0
- package/src/contract/type.ts +65 -0
- package/src/index.ts +23 -0
- package/src/mapping/constants.ts +89 -0
- package/src/mapping/enum-metadata.ts +237 -0
- package/src/mapping/field-generator.ts +296 -0
- package/src/mapping/index.ts +5 -0
- package/src/mapping/struct-fields.ts +106 -0
- package/src/mapping/tuple-components.ts +43 -0
- package/src/mapping/type-coverage-validator.ts +151 -0
- package/src/mapping/type-mapper.ts +203 -0
- package/src/metadata.ts +16 -0
- package/src/networks/README.md +84 -0
- package/src/networks/index.ts +19 -0
- package/src/networks/mainnet.ts +20 -0
- package/src/networks/testnet.ts +20 -0
- package/src/networks.ts +2 -0
- package/src/query/handler.ts +411 -0
- package/src/query/index.ts +4 -0
- package/src/query/view-checker.ts +32 -0
- package/src/sac/spec-cache.ts +68 -0
- package/src/sac/spec-source.ts +35 -0
- package/src/sac/xdr.ts +101 -0
- package/src/transaction/components/AdvancedInfo.tsx +34 -0
- package/src/transaction/components/FeeConfiguration.tsx +41 -0
- package/src/transaction/components/StellarRelayerOptions.tsx +60 -0
- package/src/transaction/components/TransactionTiming.tsx +77 -0
- package/src/transaction/components/index.ts +5 -0
- package/src/transaction/components/useStellarRelayerOptions.ts +114 -0
- package/src/transaction/eoa.ts +229 -0
- package/src/transaction/execution-strategy.ts +33 -0
- package/src/transaction/formatter.ts +296 -0
- package/src/transaction/index.ts +4 -0
- package/src/transaction/relayer.ts +575 -0
- package/src/transaction/sender.ts +156 -0
- package/src/transform/index.ts +4 -0
- package/src/transform/input-parser.ts +9 -0
- package/src/transform/output-formatter.ts +133 -0
- package/src/transform/parsers/complex-parser.ts +157 -0
- package/src/transform/parsers/generic-parser.ts +171 -0
- package/src/transform/parsers/index.ts +86 -0
- package/src/transform/parsers/primitive-parser.ts +123 -0
- package/src/transform/parsers/scval-converter.ts +405 -0
- package/src/transform/parsers/struct-parser.ts +324 -0
- package/src/transform/parsers/types.ts +35 -0
- package/src/types/__tests__/artifacts.test.ts +89 -0
- package/src/types/artifacts.ts +19 -0
- package/src/utils/__tests__/artifacts.test.ts +77 -0
- package/src/utils/artifacts.ts +30 -0
- package/src/utils/formatting.ts +122 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/input-parsing.ts +336 -0
- package/src/utils/safe-type-parser.ts +303 -0
- package/src/utils/stellar-types.ts +35 -0
- package/src/utils/type-detection.ts +163 -0
- package/src/utils/xdr-ordering.ts +36 -0
- package/src/validation/__tests__/address.test.ts +267 -0
- package/src/validation/address.ts +136 -0
- package/src/validation/eoa.ts +33 -0
- package/src/validation/index.ts +3 -0
- package/src/validation/relayer.ts +13 -0
- package/src/vite-config.ts +67 -0
- package/src/wallet/README.md +93 -0
- package/src/wallet/__tests__/connection.test.ts +72 -0
- package/src/wallet/components/StellarWalletUiRoot.tsx +161 -0
- package/src/wallet/components/account/AccountDisplay.tsx +50 -0
- package/src/wallet/components/connect/ConnectButton.tsx +100 -0
- package/src/wallet/components/connect/ConnectorDialog.tsx +125 -0
- package/src/wallet/components/index.ts +3 -0
- package/src/wallet/connection.ts +151 -0
- package/src/wallet/context/StellarWalletContext.ts +32 -0
- package/src/wallet/context/index.ts +4 -0
- package/src/wallet/context/useStellarWalletContext.ts +17 -0
- package/src/wallet/hooks/facade-hooks.ts +31 -0
- package/src/wallet/hooks/index.ts +7 -0
- package/src/wallet/hooks/useStellarAccount.ts +27 -0
- package/src/wallet/hooks/useStellarConnect.ts +60 -0
- package/src/wallet/hooks/useStellarDisconnect.ts +47 -0
- package/src/wallet/hooks/useUiKitConfig.ts +40 -0
- package/src/wallet/implementation/wallets-kit-implementation.ts +379 -0
- package/src/wallet/index.ts +11 -0
- package/src/wallet/services/__tests__/configResolutionService.test.ts +163 -0
- package/src/wallet/services/configResolutionService.ts +65 -0
- package/src/wallet/stellar-wallets-kit/StellarWalletsKitConnectButton.tsx +82 -0
- package/src/wallet/stellar-wallets-kit/__mocks__/@creit.tech/stellar-wallets-kit.ts +48 -0
- package/src/wallet/stellar-wallets-kit/__tests__/export-service.test.ts +93 -0
- package/src/wallet/stellar-wallets-kit/__tests__/stellarUiKitManager.test.ts +0 -0
- package/src/wallet/stellar-wallets-kit/config-generator.ts +75 -0
- package/src/wallet/stellar-wallets-kit/export-service.ts +19 -0
- package/src/wallet/stellar-wallets-kit/index.ts +3 -0
- package/src/wallet/stellar-wallets-kit/stellarUiKitManager.ts +235 -0
- package/src/wallet/types.ts +19 -0
- package/src/wallet/utils/__tests__/filterWalletComponents.test.ts +150 -0
- package/src/wallet/utils/__tests__/uiKitService.test.ts +189 -0
- package/src/wallet/utils/filterWalletComponents.ts +89 -0
- package/src/wallet/utils/index.ts +3 -0
- package/src/wallet/utils/stellarWalletImplementationManager.ts +118 -0
- package/src/wallet/utils/uiKitService.ts +74 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import type { Connector } from '@openzeppelin/ui-types';
|
|
2
|
+
import { logger } from '@openzeppelin/ui-utils';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
getInitializedStellarWalletImplementation,
|
|
6
|
+
getStellarWalletImplementation,
|
|
7
|
+
} from './utils/stellarWalletImplementationManager';
|
|
8
|
+
|
|
9
|
+
import { stellarUiKitManager } from './stellar-wallets-kit';
|
|
10
|
+
import { StellarConnectionStatusListener } from './types';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Indicates if this adapter supports wallet connection
|
|
14
|
+
* @returns Whether wallet connection is supported by this adapter
|
|
15
|
+
*/
|
|
16
|
+
export function supportsStellarWalletConnection(): boolean {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Get available Stellar wallet connectors
|
|
22
|
+
*/
|
|
23
|
+
export async function getStellarAvailableConnectors(): Promise<Connector[]> {
|
|
24
|
+
const impl = await getStellarWalletImplementation();
|
|
25
|
+
return impl.getAvailableConnectors();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Connect to a Stellar wallet
|
|
30
|
+
* @param connectorId - The ID of the wallet to connect to
|
|
31
|
+
*/
|
|
32
|
+
export async function connectStellarWallet(
|
|
33
|
+
connectorId: string
|
|
34
|
+
): Promise<{ connected: boolean; address?: string; error?: string }> {
|
|
35
|
+
const impl = await getStellarWalletImplementation();
|
|
36
|
+
return impl.connect(connectorId);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Disconnect from the current Stellar wallet
|
|
41
|
+
*/
|
|
42
|
+
export async function disconnectStellarWallet(): Promise<{
|
|
43
|
+
disconnected: boolean;
|
|
44
|
+
error?: string;
|
|
45
|
+
}> {
|
|
46
|
+
const impl = await getStellarWalletImplementation();
|
|
47
|
+
return impl.disconnect();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Get the current wallet connection status
|
|
52
|
+
* @inheritdoc
|
|
53
|
+
*/
|
|
54
|
+
export function getStellarWalletConnectionStatus(): {
|
|
55
|
+
isConnected: boolean;
|
|
56
|
+
address?: string;
|
|
57
|
+
chainId?: string;
|
|
58
|
+
walletId?: string;
|
|
59
|
+
} {
|
|
60
|
+
const impl = getInitializedStellarWalletImplementation();
|
|
61
|
+
if (!impl) {
|
|
62
|
+
logger.warn(
|
|
63
|
+
'getStellarWalletConnectionStatus',
|
|
64
|
+
'Wallet implementation not ready. Returning default disconnected state.'
|
|
65
|
+
);
|
|
66
|
+
return {
|
|
67
|
+
isConnected: false,
|
|
68
|
+
address: undefined,
|
|
69
|
+
chainId: stellarUiKitManager.getState().networkConfig?.id || 'stellar-testnet',
|
|
70
|
+
walletId: undefined,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const status = impl.getWalletConnectionStatus();
|
|
75
|
+
return {
|
|
76
|
+
isConnected: status.isConnected,
|
|
77
|
+
address: status.address,
|
|
78
|
+
chainId: typeof status.chainId === 'number' ? status.chainId.toString() : status.chainId,
|
|
79
|
+
walletId: status.walletId,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Update the cached Stellar wallet connection state.
|
|
85
|
+
* Used by provider code that derives the address directly from the kit.
|
|
86
|
+
*/
|
|
87
|
+
export function setStellarConnectedAddress(address: string | null, walletId?: string | null): void {
|
|
88
|
+
const impl = getInitializedStellarWalletImplementation();
|
|
89
|
+
if (impl) {
|
|
90
|
+
impl.updateConnectionStatus(address, walletId);
|
|
91
|
+
} else {
|
|
92
|
+
logger.warn(
|
|
93
|
+
'setStellarConnectedAddress',
|
|
94
|
+
'Wallet implementation not ready. Cannot update connection status.'
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// StellarConnectionStatusListener is now imported from the implementation file
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Subscribe to Stellar wallet connection status changes
|
|
103
|
+
* @param callback Function to call when connection status changes
|
|
104
|
+
* @returns Unsubscribe function
|
|
105
|
+
*/
|
|
106
|
+
export function onStellarWalletConnectionChange(
|
|
107
|
+
callback: StellarConnectionStatusListener
|
|
108
|
+
): () => void {
|
|
109
|
+
const impl = getInitializedStellarWalletImplementation();
|
|
110
|
+
if (!impl) {
|
|
111
|
+
logger.warn(
|
|
112
|
+
'onStellarWalletConnectionChange',
|
|
113
|
+
'Wallet implementation not ready. Returning no-op.'
|
|
114
|
+
);
|
|
115
|
+
return () => {};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Convert from implementation status format to connection format
|
|
119
|
+
return impl.onWalletConnectionChange((currentImplStatus, prevImplStatus) => {
|
|
120
|
+
const currentStatus = {
|
|
121
|
+
isConnected: currentImplStatus.isConnected,
|
|
122
|
+
address: currentImplStatus.address,
|
|
123
|
+
chainId: currentImplStatus.chainId,
|
|
124
|
+
walletId: currentImplStatus.walletId,
|
|
125
|
+
};
|
|
126
|
+
const previousStatus = {
|
|
127
|
+
isConnected: prevImplStatus.isConnected,
|
|
128
|
+
address: prevImplStatus.address,
|
|
129
|
+
chainId: prevImplStatus.chainId,
|
|
130
|
+
walletId: prevImplStatus.walletId,
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
callback(currentStatus, previousStatus);
|
|
135
|
+
} catch (error) {
|
|
136
|
+
logger.error('Error in Stellar connection status listener:', String(error));
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Sign a transaction using the connected wallet
|
|
143
|
+
* @internal
|
|
144
|
+
*/
|
|
145
|
+
export async function signTransaction(
|
|
146
|
+
xdr: string,
|
|
147
|
+
address: string
|
|
148
|
+
): Promise<{ signedTxXdr: string }> {
|
|
149
|
+
const impl = await getStellarWalletImplementation();
|
|
150
|
+
return impl.signTransaction(xdr, address);
|
|
151
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ISupportedWallet, StellarWalletsKit } from '@creit.tech/stellar-wallets-kit';
|
|
2
|
+
import { createContext } from 'react';
|
|
3
|
+
|
|
4
|
+
import type { StellarUiKitManagerState } from '../stellar-wallets-kit';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Stellar wallet context type
|
|
8
|
+
*/
|
|
9
|
+
export interface StellarWalletContextType {
|
|
10
|
+
// Connection state
|
|
11
|
+
address: string | null;
|
|
12
|
+
isConnected: boolean;
|
|
13
|
+
isConnecting: boolean;
|
|
14
|
+
|
|
15
|
+
// Available wallets
|
|
16
|
+
availableWallets: ISupportedWallet[];
|
|
17
|
+
|
|
18
|
+
// Connection methods
|
|
19
|
+
connect: (walletId: string) => Promise<void>;
|
|
20
|
+
disconnect: () => Promise<void>;
|
|
21
|
+
|
|
22
|
+
// UI Kit manager state
|
|
23
|
+
uiKitManagerState: StellarUiKitManagerState;
|
|
24
|
+
|
|
25
|
+
// Kit instance (for advanced usage)
|
|
26
|
+
kit: StellarWalletsKit | null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Create the context with undefined default value
|
|
31
|
+
*/
|
|
32
|
+
export const StellarWalletContext = createContext<StellarWalletContextType | undefined>(undefined);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
|
|
3
|
+
import { StellarWalletContext, type StellarWalletContextType } from './StellarWalletContext';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Hook to use the Stellar wallet context
|
|
7
|
+
* @throws Error if used outside of StellarWalletUiRoot
|
|
8
|
+
*/
|
|
9
|
+
export function useStellarWalletContext(): StellarWalletContextType {
|
|
10
|
+
const context = useContext(StellarWalletContext);
|
|
11
|
+
|
|
12
|
+
if (context === undefined) {
|
|
13
|
+
throw new Error('useStellarWalletContext must be used within a StellarWalletUiRoot');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return context;
|
|
17
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { EcosystemSpecificReactHooks } from '@openzeppelin/ui-types';
|
|
2
|
+
|
|
3
|
+
import { useStellarAccount } from './useStellarAccount';
|
|
4
|
+
import { useStellarConnect } from './useStellarConnect';
|
|
5
|
+
import { useStellarDisconnect } from './useStellarDisconnect';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Stellar-specific facade hooks following the EcosystemSpecificReactHooks interface
|
|
9
|
+
* These hooks provide a standardized interface for wallet operations in the Stellar ecosystem
|
|
10
|
+
*/
|
|
11
|
+
export const stellarFacadeHooks: EcosystemSpecificReactHooks = {
|
|
12
|
+
// Account management
|
|
13
|
+
useAccount: useStellarAccount,
|
|
14
|
+
|
|
15
|
+
// Connection management
|
|
16
|
+
useConnect: useStellarConnect,
|
|
17
|
+
useDisconnect: useStellarDisconnect,
|
|
18
|
+
|
|
19
|
+
// Stellar doesn't have the same network switching capabilities as EVM
|
|
20
|
+
// These are included for interface compatibility but may not be fully functional
|
|
21
|
+
useSwitchChain: () => ({ switchChain: undefined }),
|
|
22
|
+
useChainId: () => 'stellar',
|
|
23
|
+
useChains: () => [],
|
|
24
|
+
|
|
25
|
+
// Transaction and signing hooks - to be implemented as needed
|
|
26
|
+
useBalance: () => ({ data: undefined, isLoading: false }),
|
|
27
|
+
useSendTransaction: () => ({ sendTransaction: undefined }),
|
|
28
|
+
useWaitForTransactionReceipt: () => ({ data: undefined }),
|
|
29
|
+
useSignMessage: () => ({ signMessage: undefined }),
|
|
30
|
+
useSignTypedData: () => ({ signTypedData: undefined }),
|
|
31
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useStellarWalletContext } from '../context';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Account information returned by the hook
|
|
5
|
+
*/
|
|
6
|
+
export interface StellarAccountInfo {
|
|
7
|
+
/** The connected wallet address */
|
|
8
|
+
address: string | null;
|
|
9
|
+
/** Whether a wallet is currently connected */
|
|
10
|
+
isConnected: boolean;
|
|
11
|
+
/** Whether a connection is in progress */
|
|
12
|
+
isConnecting: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Hook to get the current Stellar account information
|
|
17
|
+
* @returns Account information including address and connection status
|
|
18
|
+
*/
|
|
19
|
+
export function useStellarAccount(): StellarAccountInfo {
|
|
20
|
+
const { address, isConnected, isConnecting } = useStellarWalletContext();
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
address,
|
|
24
|
+
isConnected,
|
|
25
|
+
isConnecting,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ISupportedWallet } from '@creit.tech/stellar-wallets-kit';
|
|
2
|
+
import { useCallback, useState } from 'react';
|
|
3
|
+
|
|
4
|
+
import type { Connector } from '@openzeppelin/ui-types';
|
|
5
|
+
|
|
6
|
+
import { useStellarWalletContext } from '../context';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Connect hook return type - matches what react-core expects
|
|
10
|
+
*/
|
|
11
|
+
export interface StellarConnectReturnType {
|
|
12
|
+
connect: (args: { connector: Connector }) => Promise<void>;
|
|
13
|
+
connectors: Connector[];
|
|
14
|
+
isLoading: boolean;
|
|
15
|
+
isPending: boolean;
|
|
16
|
+
error: Error | null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Hook to get the wallet connect function and status
|
|
21
|
+
* @returns An object with connect function and connection status
|
|
22
|
+
*/
|
|
23
|
+
export function useStellarConnect(): StellarConnectReturnType {
|
|
24
|
+
const { connect, isConnecting, availableWallets } = useStellarWalletContext();
|
|
25
|
+
const [error, setError] = useState<Error | null>(null);
|
|
26
|
+
|
|
27
|
+
const connectFunction = useCallback(
|
|
28
|
+
async ({ connector }: { connector: Connector }) => {
|
|
29
|
+
try {
|
|
30
|
+
// Clear any previous errors
|
|
31
|
+
setError(null);
|
|
32
|
+
await connect(connector.id);
|
|
33
|
+
} catch (err) {
|
|
34
|
+
// Store the error for access by the consumer
|
|
35
|
+
const connectError = err instanceof Error ? err : new Error(String(err));
|
|
36
|
+
setError(connectError);
|
|
37
|
+
// Re-throw to maintain the same behavior for error handling in UI components
|
|
38
|
+
throw connectError;
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
[connect]
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
// Convert ISupportedWallet[] to Connector[]
|
|
45
|
+
const connectors: Connector[] = availableWallets.map((wallet: ISupportedWallet) => ({
|
|
46
|
+
id: wallet.id,
|
|
47
|
+
name: wallet.name,
|
|
48
|
+
icon: wallet.icon,
|
|
49
|
+
installed: wallet.isAvailable,
|
|
50
|
+
type: (wallet.type as string) || 'browser',
|
|
51
|
+
}));
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
connect: connectFunction,
|
|
55
|
+
connectors,
|
|
56
|
+
isLoading: isConnecting,
|
|
57
|
+
isPending: isConnecting,
|
|
58
|
+
error,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useStellarWalletContext } from '../context';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Disconnect hook return type - matches what react-core expects
|
|
7
|
+
*/
|
|
8
|
+
export interface StellarDisconnectReturnType {
|
|
9
|
+
disconnect: () => Promise<void>;
|
|
10
|
+
isLoading: boolean;
|
|
11
|
+
isPending: boolean;
|
|
12
|
+
error: Error | null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Hook to get the wallet disconnect function and status
|
|
17
|
+
* @returns An object with disconnect function and disconnection status
|
|
18
|
+
*/
|
|
19
|
+
export function useStellarDisconnect(): StellarDisconnectReturnType {
|
|
20
|
+
const { disconnect } = useStellarWalletContext();
|
|
21
|
+
const [isDisconnecting, setIsDisconnecting] = useState(false);
|
|
22
|
+
const [error, setError] = useState<Error | null>(null);
|
|
23
|
+
|
|
24
|
+
const disconnectFunction = useCallback(async () => {
|
|
25
|
+
try {
|
|
26
|
+
// Clear any previous errors
|
|
27
|
+
setError(null);
|
|
28
|
+
setIsDisconnecting(true);
|
|
29
|
+
await disconnect();
|
|
30
|
+
} catch (err) {
|
|
31
|
+
// Store the error for access by the consumer
|
|
32
|
+
const disconnectError = err instanceof Error ? err : new Error(String(err));
|
|
33
|
+
setError(disconnectError);
|
|
34
|
+
// Re-throw to maintain the same behavior for error handling in UI components
|
|
35
|
+
throw disconnectError;
|
|
36
|
+
} finally {
|
|
37
|
+
setIsDisconnecting(false);
|
|
38
|
+
}
|
|
39
|
+
}, [disconnect]);
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
disconnect: disconnectFunction,
|
|
43
|
+
isLoading: isDisconnecting,
|
|
44
|
+
isPending: isDisconnecting,
|
|
45
|
+
error,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { UiKitConfiguration } from '@openzeppelin/ui-types';
|
|
2
|
+
import { appConfigService, logger } from '@openzeppelin/ui-utils';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Default configuration when no specific configuration is provided
|
|
6
|
+
*/
|
|
7
|
+
const defaultConfig: UiKitConfiguration = {
|
|
8
|
+
kitName: 'custom', // Default to using our custom implementation for Stellar
|
|
9
|
+
kitConfig: {},
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Loads the initial UI kit configuration from the AppConfigService
|
|
14
|
+
* @returns The UI kit configuration from app.config.local.json or defaults
|
|
15
|
+
*/
|
|
16
|
+
export function loadInitialConfigFromAppService(): UiKitConfiguration {
|
|
17
|
+
logger.debug(
|
|
18
|
+
'stellar:useUiKitConfig',
|
|
19
|
+
'Attempting to load initial config from AppConfigService...'
|
|
20
|
+
);
|
|
21
|
+
const configObj = appConfigService.getWalletUIConfig<UiKitConfiguration>('stellar');
|
|
22
|
+
|
|
23
|
+
if (configObj && configObj.kitName) {
|
|
24
|
+
logger.info(
|
|
25
|
+
'stellar:useUiKitConfig',
|
|
26
|
+
`Loaded initial config from AppConfigService: kitName=${configObj.kitName}`,
|
|
27
|
+
configObj.kitConfig
|
|
28
|
+
);
|
|
29
|
+
// Merge with defaults to ensure all base keys are present if AppConfigService only provides partial config
|
|
30
|
+
return {
|
|
31
|
+
kitName: configObj.kitName,
|
|
32
|
+
kitConfig: { ...defaultConfig.kitConfig, ...(configObj.kitConfig || {}) },
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
logger.debug(
|
|
36
|
+
'stellar:useUiKitConfig',
|
|
37
|
+
'No initial config found in AppConfigService, using module default.'
|
|
38
|
+
);
|
|
39
|
+
return { ...defaultConfig };
|
|
40
|
+
}
|