diff options
author | Florian Dold <florian.dold@gmail.com> | 2019-12-07 22:02:11 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2019-12-07 22:02:11 +0100 |
commit | 396bb61db70f654599256e512bfec4c008ee8269 (patch) | |
tree | cfaba65d5d0c4782c7c64c28b68a41689cdbc07a /src/wallet-impl/refresh.ts | |
parent | b68b52e95c126e0d3b9788d6332c19144f9dc7e7 (diff) | |
download | wallet-core-396bb61db70f654599256e512bfec4c008ee8269.tar.xz |
reset retry counter when forcing operations
Diffstat (limited to 'src/wallet-impl/refresh.ts')
-rw-r--r-- | src/wallet-impl/refresh.ts | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/wallet-impl/refresh.ts b/src/wallet-impl/refresh.ts index 93be1435d..a23f34324 100644 --- a/src/wallet-impl/refresh.ts +++ b/src/wallet-impl/refresh.ts @@ -38,7 +38,11 @@ import { InternalWalletState } from "./state"; import { Logger } from "../util/logging"; import { getWithdrawDenomList } from "./withdraw"; import { updateExchangeFromUrl } from "./exchanges"; -import { getTimestampNow, OperationError, NotificationType } from "../walletTypes"; +import { + getTimestampNow, + OperationError, + NotificationType, +} from "../walletTypes"; import { guardOperationException } from "./errors"; const logger = new Logger("refresh.ts"); @@ -315,25 +319,41 @@ async function incrementRefreshRetry( ws.notify({ type: NotificationType.RefreshOperationError }); } - export async function processRefreshSession( ws: InternalWalletState, refreshSessionId: string, + forceNow: boolean = false, ) { return ws.memoProcessRefresh.memo(refreshSessionId, async () => { const onOpErr = (e: OperationError) => incrementRefreshRetry(ws, refreshSessionId, e); return guardOperationException( - () => processRefreshSessionImpl(ws, refreshSessionId), + () => processRefreshSessionImpl(ws, refreshSessionId, forceNow), onOpErr, ); }); } +async function resetRefreshSessionRetry( + ws: InternalWalletState, + refreshSessionId: string, +) { + await oneShotMutate(ws.db, Stores.refresh, refreshSessionId, (x) => { + if (x.retryInfo.active) { + x.retryInfo = initRetryInfo(); + } + return x; + }); +} + async function processRefreshSessionImpl( ws: InternalWalletState, refreshSessionId: string, + forceNow: boolean, ) { + if (forceNow) { + await resetRefreshSessionRetry(ws, refreshSessionId); + } const refreshSession = await oneShotGet( ws.db, Stores.refresh, @@ -413,7 +433,7 @@ export async function refresh( x.status = CoinStatus.Dormant; return x; }); - ws.notify( { type: NotificationType.RefreshRefused }); + ws.notify({ type: NotificationType.RefreshRefused }); return; } @@ -450,7 +470,7 @@ export async function refresh( }, ); logger.info(`created refresh session ${refreshSession.refreshSessionId}`); - ws.notify( { type: NotificationType.RefreshStarted }); + ws.notify({ type: NotificationType.RefreshStarted }); await processRefreshSession(ws, refreshSession.refreshSessionId); } |