Skip to content

Commit

Permalink
chore: support negative boolean test flags (#1225)
Browse files Browse the repository at this point in the history
  • Loading branch information
aforaleka authored Oct 28, 2024
1 parent 8778866 commit af2ba9e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/lib/abacus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
} from '@/constants/abacus';
import { Hdkey } from '@/constants/account';
import { DEFAULT_MARKETID } from '@/constants/markets';
import { CURRENT_ABACUS_DEPLOYMENT, isDev, type DydxNetwork } from '@/constants/networks';
import { CURRENT_ABACUS_DEPLOYMENT, type DydxNetwork } from '@/constants/networks';
import { StatsigFlags } from '@/constants/statsig';
import {
CLEARED_CLOSE_POSITION_INPUTS,
Expand Down Expand Up @@ -139,7 +139,7 @@ class AbacusStateManager {
);

const appConfigs = AbacusAppConfig.Companion.forWebAppWithIsolatedMargins;
appConfigs.staticTyping = testFlags.enableStaticTyping || isDev;
appConfigs.staticTyping = testFlags.enableStaticTyping;
appConfigs.metadataService = testFlags.pml;

this.stateManager = new AsyncAbacusStateManager(
Expand Down
24 changes: 16 additions & 8 deletions src/lib/testFlags.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { isDev, isTestnet } from '@/constants/networks';
import { isDev, isMainnet } from '@/constants/networks';

class TestFlags {
public queryParams: { [key: string]: string };

private isValueExplicitlyFalse = (value: string) =>
['false', '0', 'no', 'off'].includes(value.toLowerCase());

private booleanFlag = (value?: string, defaultTrue?: boolean) => {
if (!value) return defaultTrue ?? false;
return !this.isValueExplicitlyFalse(value);
};

constructor() {
this.queryParams = {};

Expand All @@ -27,43 +35,43 @@ class TestFlags {
}

get displayInitializingMarkets() {
return !!this.queryParams.displayinitializingmarkets;
return this.booleanFlag(this.queryParams.displayinitializingmarkets);
}

get addressOverride(): string | undefined {
return this.queryParams.address;
}

get enableVaults() {
return !!this.queryParams.vaults || isDev || isTestnet;
return this.booleanFlag(this.queryParams.vaults, !isMainnet);
}

get referrer() {
return this.queryParams.utm_source;
}

get enablePredictionMarketPerp() {
return !!this.queryParams.prediction || isDev;
return this.booleanFlag(this.queryParams.prediction, isDev);
}

get pml() {
return !!this.queryParams.pml || isDev || isTestnet;
return this.booleanFlag(this.queryParams.pml, !isMainnet);
}

get showLimitClose() {
return !!this.queryParams.limitclose;
return this.booleanFlag(this.queryParams.limitclose);
}

get referralCode() {
return this.queryParams.ref;
}

get enableStaticTyping() {
return !!this.queryParams.statictyping;
return this.booleanFlag(this.queryParams.statictyping, isDev);
}

get uiRefresh() {
return !!this.queryParams.uirefresh || isDev;
return this.booleanFlag(this.queryParams.uirefresh, isDev);
}

get onboardingRewrite() {
Expand Down

0 comments on commit af2ba9e

Please sign in to comment.