@reown/appkit-controllers
Version:
The full stack toolkit to build onchain app UX.
102 lines • 3.7 kB
JavaScript
import { ConnectorController } from '../ConnectorController.js';
import { Connection } from './entities/Connection/index.js';
// -- Controller Implementation -------------------------- //
class ConnectionController {
constructor() {
this.state = this.initializeState();
}
initializeState() {
return {
isSwitchingConnection: false,
connections: new Map(),
recentConnections: new Map(),
walletConnectManager: this.createWalletConnectManager()
};
}
createWalletConnectManager() {
// Placeholder for WC manager - will be implemented later
return {
connectWalletConnect: async () => {
// WalletConnect connection logic will be implemented here
},
resetWcConnection: () => {
// WC connection reset logic will be implemented here
},
resetUri: () => {
// URI reset logic will be implemented here
},
finalizeWcConnection: () => {
// WC connection finalization logic will be implemented here
},
setWcBasic: () => {
// WC basic setting logic will be implemented here
},
setUri: () => {
// URI setting logic will be implemented here
},
setWcLinking: () => {
// WC linking logic will be implemented here
},
setWcError: () => {
// WC error setting logic will be implemented here
},
setRecentWallet: () => {
// Recent wallet setting logic will be implemented here
},
setBuffering: () => {
// Buffering setting logic will be implemented here
},
setStatus: () => {
// Status setting logic will be implemented here
}
};
}
// -- Public API ------------------------------------- //
subscribe(_callback) {
// Placeholder for subscription logic - will be implemented with state management
return () => {
// Unsubscribe logic will be implemented here
};
}
subscribeKey(_key, _callback) {
// Placeholder for subscription logic - will be implemented with state management
return () => {
// Unsubscribe logic will be implemented here
};
}
async connect(_params) {
// Connection logic will be implemented here
return Promise.resolve();
}
async disconnect(_params) {
// Disconnection logic will be implemented here
return Promise.resolve();
}
async reconnect(_params) {
// Reconnection logic will be implemented here
return Promise.resolve();
}
async switchConnection(_params) {
// Connection switching logic will be implemented here
return Promise.resolve();
}
getConnectors() {
return ConnectorController.getConnectors();
}
getConnections(namespace) {
if (!namespace) {
return Array.from(this.state.connections.values()).flat();
}
return this.state.connections.get(namespace) || [];
}
getActiveConnection(namespace) {
const connections = this.getConnections(namespace);
return connections.find(conn => conn.status === 'connected');
}
hasAnyConnection() {
return Array.from(this.state.connections.values()).some(connections => connections.length > 0);
}
}
// -- Export -------------------------------------------- //
export { ConnectionController };
//# sourceMappingURL=index.js.map