fix: cache web3Enable to prevent authorization flooding

Consolidated all web3Enable/web3FromAddress calls through getSigner helper.
Cached web3Enable promise so it only runs once per session.
This commit is contained in:
2026-02-23 08:24:41 +03:00
parent 80d8bbbcb1
commit b034954fd1
2 changed files with 17 additions and 19 deletions
+11 -1
View File
@@ -16,6 +16,16 @@ interface SignerResult {
signer: any; // Compatible with @pezkuwi/api Signer
}
// Cache web3Enable to avoid "Too many authorization requests" error
let enablePromise: Promise<unknown[]> | null = null;
async function ensureWeb3Enabled(): Promise<void> {
if (!enablePromise) {
enablePromise = web3Enable('PezkuwiChain');
}
await enablePromise;
}
export async function getSigner(
address: string,
walletSource: WalletSource,
@@ -34,7 +44,7 @@ export async function getSigner(
}
// Extension or native: use web3FromAddress
await web3Enable('PezkuwiChain');
await ensureWeb3Enabled();
const injector = await web3FromAddress(address);
return injector;
}