From 7645fe6b236c9e1a5e0afdd9bbe21ea5c02f8071 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 31 Jul 2020 10:00:02 -0600 Subject: [PATCH] Update context transaction states --- .../views/dialogs/ServerOfflineDialog.tsx | 4 ++-- src/stores/local-echo/EchoContext.ts | 6 +++--- src/stores/local-echo/EchoTransaction.ts | 16 ++++++++-------- src/stores/local-echo/GenericEchoChamber.ts | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/components/views/dialogs/ServerOfflineDialog.tsx b/src/components/views/dialogs/ServerOfflineDialog.tsx index 6d2aa5ac27..f6767dcb8d 100644 --- a/src/components/views/dialogs/ServerOfflineDialog.tsx +++ b/src/components/views/dialogs/ServerOfflineDialog.tsx @@ -56,10 +56,10 @@ export default class ServerOfflineDialog extends React.PureComponent { ); const entries = c.transactions - .filter(t => t.status === TransactionStatus.DoneError || t.didPreviouslyFail) + .filter(t => t.status === TransactionStatus.Error || t.didPreviouslyFail) .map((t, j) => { let button = ; - if (t.status === TransactionStatus.DoneError) { + if (t.status === TransactionStatus.Error) { button = ( t.run()}>{_t("Resend")} ); diff --git a/src/stores/local-echo/EchoContext.ts b/src/stores/local-echo/EchoContext.ts index 9ed5cf387f..55d6e8020a 100644 --- a/src/stores/local-echo/EchoContext.ts +++ b/src/stores/local-echo/EchoContext.ts @@ -38,7 +38,7 @@ export abstract class EchoContext extends Whenable impl } public get firstFailedTime(): Date { - const failedTxn = this.transactions.find(t => t.didPreviouslyFail || t.status === TransactionStatus.DoneError); + const failedTxn = this.transactions.find(t => t.didPreviouslyFail || t.status === TransactionStatus.Error); if (failedTxn) return failedTxn.startTime; return null; } @@ -57,7 +57,7 @@ export abstract class EchoContext extends Whenable impl // We have no intent to call the transaction again if it succeeds (in fact, it'll // be really angry at us if we do), so call that the end of the road for the events. - txn.when(TransactionStatus.DoneSuccess, () => txn.destroy()); + txn.when(TransactionStatus.Success, () => txn.destroy()); return txn; } @@ -65,7 +65,7 @@ export abstract class EchoContext extends Whenable impl private checkTransactions = () => { let status = ContextTransactionState.AllSuccessful; for (const txn of this.transactions) { - if (txn.status === TransactionStatus.DoneError || txn.didPreviouslyFail) { + if (txn.status === TransactionStatus.Error || txn.didPreviouslyFail) { status = ContextTransactionState.PendingErrors; break; } else if (txn.status === TransactionStatus.Pending) { diff --git a/src/stores/local-echo/EchoTransaction.ts b/src/stores/local-echo/EchoTransaction.ts index 543c3b4ccd..2e372136d0 100644 --- a/src/stores/local-echo/EchoTransaction.ts +++ b/src/stores/local-echo/EchoTransaction.ts @@ -20,8 +20,8 @@ export type RunFn = () => Promise; export enum TransactionStatus { Pending, - DoneSuccess, - DoneError, + Success, + Error, } export class EchoTransaction extends Whenable { @@ -46,25 +46,25 @@ export class EchoTransaction extends Whenable { } public run() { - if (this.status === TransactionStatus.DoneSuccess) { + if (this.status === TransactionStatus.Success) { throw new Error("Cannot re-run a successful echo transaction"); } this.setStatus(TransactionStatus.Pending); this.runFn() - .then(() => this.setStatus(TransactionStatus.DoneSuccess)) - .catch(() => this.setStatus(TransactionStatus.DoneError)); + .then(() => this.setStatus(TransactionStatus.Success)) + .catch(() => this.setStatus(TransactionStatus.Error)); } public cancel() { // Success basically means "done" - this.setStatus(TransactionStatus.DoneSuccess); + this.setStatus(TransactionStatus.Success); } private setStatus(status: TransactionStatus) { this._status = status; - if (status === TransactionStatus.DoneError) { + if (status === TransactionStatus.Error) { this.didFail = true; - } else if (status === TransactionStatus.DoneSuccess) { + } else if (status === TransactionStatus.Success) { this.didFail = false; } this.notifyCondition(status); diff --git a/src/stores/local-echo/GenericEchoChamber.ts b/src/stores/local-echo/GenericEchoChamber.ts index 7bedc9bde8..f2d4648e81 100644 --- a/src/stores/local-echo/GenericEchoChamber.ts +++ b/src/stores/local-echo/GenericEchoChamber.ts @@ -84,7 +84,7 @@ export abstract class GenericEchoChamber extends Ev this.cacheVal(key, targetVal, txn); // set the cache now as it won't be updated by the .when() ladder below. txn.when(TransactionStatus.Pending, () => this.cacheVal(key, targetVal, txn)) - .when(TransactionStatus.DoneError, () => revertFn()); + .when(TransactionStatus.Error, () => revertFn()); txn.run(); }