From 112ce260f1ad2d5e3057a690b65f41819a4aac3d Mon Sep 17 00:00:00 2001 From: tyleroooo Date: Fri, 20 Dec 2024 15:21:46 -0500 Subject: [PATCH] chore: flag for disabling abacus (#1394) --- src/lib/abacus/index.ts | 12 +++++++++--- src/lib/abacus/stateNotification.ts | 17 +++++++++++++++++ src/lib/testFlags.ts | 4 ++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/lib/abacus/index.ts b/src/lib/abacus/index.ts index eac186d7d..337c807d5 100644 --- a/src/lib/abacus/index.ts +++ b/src/lib/abacus/index.ts @@ -2,6 +2,7 @@ import type { LocalWallet, SelectedGasDenom } from '@dydxprotocol/v4-client-js'; import type { + AbacusStateNotificationProtocol, AdjustIsolatedMarginInputFields, ClosePositionInputFields, HistoricalPnlPeriods, @@ -64,6 +65,7 @@ import { getTransferInputs } from '@/state/inputsSelectors'; import { assertNever } from '../assertNever'; import { LocaleSeparators } from '../numbers'; +import { testFlags } from '../testFlags'; import AbacusAnalytics from './analytics'; import AbacusChainTransaction from './dydxChainTransactions'; import AbacusFileSystem from './filesystem'; @@ -71,7 +73,7 @@ import AbacusFormatter from './formatter'; import AbacusLocalizer from './localizer'; import AbacusLogger from './logger'; import AbacusRest from './rest'; -import AbacusStateNotifier from './stateNotification'; +import AbacusStateNotifier, { NoOpAbacusStateNotifier } from './stateNotification'; import AbacusThreading from './threading'; import AbacusWebsocket from './websocket'; @@ -102,7 +104,7 @@ class AbacusStateManager { websocket: AbacusWebsocket; - stateNotifier: AbacusStateNotifier; + stateNotifier: AbacusStateNotificationProtocol & { setStore: (store: RootStore) => void }; analytics: AbacusAnalytics; @@ -113,7 +115,9 @@ class AbacusStateManager { constructor() { this.store = undefined; this.currentMarket = undefined; - this.stateNotifier = new AbacusStateNotifier(); + this.stateNotifier = testFlags.disableAbacus + ? new NoOpAbacusStateNotifier() + : new AbacusStateNotifier(); this.analytics = new AbacusAnalytics(); this.websocket = new AbacusWebsocket(); this.abacusFormatter = new AbacusFormatter(); @@ -153,6 +157,7 @@ class AbacusStateManager { } start = ({ network }: { network?: DydxNetwork } = {}) => { + if (testFlags.disableAbacus) return; if (network) { this.stateManager.environmentId = network; } @@ -162,6 +167,7 @@ class AbacusStateManager { }; restart = ({ network }: { network?: DydxNetwork } = {}) => { + if (testFlags.disableAbacus) return; this.stateManager.readyToConnect = false; this.start({ network }); }; diff --git a/src/lib/abacus/stateNotification.ts b/src/lib/abacus/stateNotification.ts index d35ed69f0..f3f4d9769 100644 --- a/src/lib/abacus/stateNotification.ts +++ b/src/lib/abacus/stateNotification.ts @@ -1,3 +1,4 @@ +// eslint-disable-next-line max-classes-per-file import { kollections } from '@dydxprotocol/v4-abacus'; import { fromPairs, throttle } from 'lodash'; @@ -286,3 +287,19 @@ class AbacusStateNotifier implements AbacusStateNotificationProtocol { } export default AbacusStateNotifier; + +export class NoOpAbacusStateNotifier implements AbacusStateNotificationProtocol { + environmentsChanged(): void {} + + notificationsChanged(): void {} + + stateChanged(): void {} + + lastOrderChanged() {} + + errorsEmitted() {} + + apiStateChanged() {} + + setStore = () => {}; +} diff --git a/src/lib/testFlags.ts b/src/lib/testFlags.ts index dc4499797..1fc92cf6b 100644 --- a/src/lib/testFlags.ts +++ b/src/lib/testFlags.ts @@ -66,6 +66,10 @@ class TestFlags { return isDev; } + get disableAbacus() { + return this.booleanFlag(this.queryParams.disable_abacus); + } + get showNewDepositFlow() { return !!this.queryParams.deposit_rewrite; }