mirror of
https://github.com/purrgrammer/grimoire.git
synced 2026-04-14 17:36:59 +02:00
fix: set connected status after initial wallet connection
createWalletFromURI was setting connectionStatus$ to "connecting" but never updating it to "connected" after the wallet was ready. This caused the UI to show a loading state even after balance and transactions had loaded. Changes: - Make createWalletFromURI async - Wait for support$ to emit before returning - Set connectionStatus$ to "connected" on success - Update ConnectWalletDialog to await the async function https://claude.ai/code/session_018fU3rYmjFPEKz3ot1itLZL
This commit is contained in:
@@ -56,9 +56,10 @@ export default function ConnectWalletDialog({
|
||||
|
||||
try {
|
||||
// Create wallet instance from connection string
|
||||
const wallet = createWalletFromURI(connectionString);
|
||||
// This waits for the wallet to be ready (support$ must emit)
|
||||
const wallet = await createWalletFromURI(connectionString);
|
||||
|
||||
// Test the connection by getting wallet info
|
||||
// Get wallet info (wallet is already ready at this point)
|
||||
const info = await wallet.getInfo();
|
||||
|
||||
// Get initial balance
|
||||
|
||||
@@ -222,16 +222,35 @@ export async function ensureWalletReady(): Promise<WalletConnect> {
|
||||
/**
|
||||
* Creates a new wallet connection from a NWC URI.
|
||||
* Used when user connects a new wallet.
|
||||
* Waits for wallet to be ready before returning.
|
||||
*/
|
||||
export function createWalletFromURI(connectionString: string): WalletConnect {
|
||||
export async function createWalletFromURI(
|
||||
connectionString: string,
|
||||
): Promise<WalletConnect> {
|
||||
connectionStatus$.next("connecting");
|
||||
lastError$.next(null);
|
||||
walletSupportReceived = false;
|
||||
|
||||
const wallet = WalletConnect.fromConnectURI(connectionString);
|
||||
wallet$.next(wallet);
|
||||
|
||||
// Subscribe to notifications to keep events$ alive
|
||||
subscribeToNotifications(wallet);
|
||||
refreshBalance(); // Fetch initial balance
|
||||
|
||||
// Wait for wallet to be ready (support$ must emit)
|
||||
try {
|
||||
await waitForSupport(wallet, 15000);
|
||||
connectionStatus$.next("connected");
|
||||
// Start fetching balance after wallet is ready
|
||||
refreshBalance();
|
||||
} catch (error) {
|
||||
console.error("[NWC] Wallet connection failed:", error);
|
||||
connectionStatus$.next("error");
|
||||
lastError$.next(
|
||||
error instanceof Error ? error : new Error("Connection failed"),
|
||||
);
|
||||
throw error; // Re-throw so the dialog can show the error
|
||||
}
|
||||
|
||||
return wallet;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user