26 lines
763 B
TypeScript
26 lines
763 B
TypeScript
import type { Connector } from 'wagmi'
|
|
|
|
import { walletErrorLabel } from '@/lib/walletError'
|
|
|
|
export function walletConnectErrorLabel(err: unknown): string {
|
|
const msg = walletErrorLabel(err, 'Cancelled', 140)
|
|
if (/Provider not found/i.test(msg)) {
|
|
return 'No wallet provider found in this browser. Open Trump Alpha in a wallet-enabled browser.'
|
|
}
|
|
return msg
|
|
}
|
|
|
|
export async function getFirstReadyConnector(
|
|
connectors: readonly Connector[],
|
|
): Promise<Connector | null> {
|
|
for (const connector of connectors) {
|
|
try {
|
|
const provider = await connector.getProvider?.()
|
|
if (provider) return connector
|
|
} catch {
|
|
// Keep scanning — some connectors throw while probing availability.
|
|
}
|
|
}
|
|
return connectors[0] ?? null
|
|
}
|