From deee3e95438092dcb09a7b36bf03bbfa4fda38d9 Mon Sep 17 00:00:00 2001 From: noah Date: Thu, 5 Oct 2023 13:49:54 -0700 Subject: [PATCH] Save last nonce by API and not type. (#1398) (#1399) --- packages/stateful/hooks/useCfWorkerAuthPostRequest.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/stateful/hooks/useCfWorkerAuthPostRequest.ts b/packages/stateful/hooks/useCfWorkerAuthPostRequest.ts index 4e72f6ee8..2a41c48ff 100644 --- a/packages/stateful/hooks/useCfWorkerAuthPostRequest.ts +++ b/packages/stateful/hooks/useCfWorkerAuthPostRequest.ts @@ -9,7 +9,7 @@ import { useWallet } from './useWallet' // Cloudflare KV is slow to update, so keep track of the last successful nonce // that worked so we don't have to wait for the nonce query to update. Make this // a global variable so it persists across all hook uses. -const lastSuccessfulNonceForType: Record = {} +const lastSuccessfulNonceForApi: Record = {} export const useCfWorkerAuthPostRequest = ( apiBase: string, @@ -57,8 +57,7 @@ export const useCfWorkerAuthPostRequest = ( // If nonce was already used, manually increment. let nonce = nonceResponse.nonce - const lastSuccessfulNonce = - lastSuccessfulNonceForType[signatureType] ?? -1 + const lastSuccessfulNonce = lastSuccessfulNonceForApi[apiBase] ?? -1 if (nonce <= lastSuccessfulNonce) { nonce = lastSuccessfulNonce + 1 } @@ -134,7 +133,7 @@ export const useCfWorkerAuthPostRequest = ( } // If succeeded, store nonce. - lastSuccessfulNonceForType[signatureType] = nonce + lastSuccessfulNonceForApi[apiBase] = nonce // If response OK, return response body. return await response.json()