Skip to content

Commit

Permalink
feat: evm swap deposits [OTE-700]
Browse files Browse the repository at this point in the history
add test + comments and filter invalid flags
  • Loading branch information
yogurtandjam committed Aug 16, 2024
1 parent f128fc0 commit 388ff1d
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"@cosmjs/proto-signing": "^0.32.1",
"@cosmjs/stargate": "^0.32.1",
"@cosmjs/tendermint-rpc": "^0.32.1",
"@dydxprotocol/v4-abacus": "1.8.85",
"@dydxprotocol/v4-abacus": "1.8.89",
"@dydxprotocol/v4-client-js": "^1.1.27",
"@dydxprotocol/v4-localization": "^1.1.174",
"@emotion/is-prop-valid": "^1.3.0",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/hooks/useStatsig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,5 @@ export const useAllStatsigGateValues = () => {
return { ...acc, [gate]: checkGate(gate) };
}, {} as StatsigConfigType);
}, []);

return allGateValues;
};
16 changes: 16 additions & 0 deletions src/lib/__test__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { describe, expect, it } from "vitest"

Check failure on line 1 in src/lib/__test__/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `"vitest"` with `'vitest';⏎`
import { StatsigConfig } from '../../constants/abacus'

Check failure on line 2 in src/lib/__test__/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `;`
import { StatSigFlags } from "../../types/statsig"

Check failure on line 3 in src/lib/__test__/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `"../../types/statsig"` with `'../../types/statsig';`
import abacusStateManager from "../abacus"

Check failure on line 4 in src/lib/__test__/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `"../abacus"` with `'../abacus';`

describe('setStatsigConfigs', () => {
it('only sets properties that exist in the kotlin object', () => {

Check failure on line 7 in src/lib/__test__/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
abacusStateManager.setStatsigConfigs({

Check failure on line 8 in src/lib/__test__/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `····`
[StatSigFlags.ffEnableEvmSwaps]: true,

Check failure on line 9 in src/lib/__test__/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `······`
'nonexistent_flag': true,

Check failure on line 10 in src/lib/__test__/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `············'nonexistent_flag'` with `······nonexistent_flag`
})

Check failure on line 11 in src/lib/__test__/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `········})` with `····});`
expect(StatsigConfig.ff_enable_evm_swaps).toBe(true)

Check failure on line 12 in src/lib/__test__/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `········expect(StatsigConfig.ff_enable_evm_swaps).toBe(true)` with `····expect(StatsigConfig.ff_enable_evm_swaps).toBe(true);`
// @ts-ignore
expect(StatsigConfig.nonexistent_flag).toBeUndefined()
})
})
15 changes: 9 additions & 6 deletions src/lib/abacus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,16 +446,19 @@ class AbacusStateManager {
/**
*
* Updates Abacus' global StatsigConfig object.
* You must destructure the new flag you want to use from the config and set
* the relevant property on the StatsigConfig object.
* You must define the property in abacus first, and then add to the enum.
*
* TODO: establish standardized naming conventions between
* statsig FF name and boolean propery in abacus StatsigConfig
* https://linear.app/dydx/project/feature-experimentation-6853beb333d7/overview
*/
setStatsigConfigs = (statsigConfig: { [key in StatSigFlags]?: boolean }) => {
const { [StatSigFlags.ffSkipMigration]: useSkip = false } = statsigConfig;
const { [StatSigFlags.ffSkipMigration]: useSkip = false, ...rest } = statsigConfig;
StatsigConfig.useSkip = useSkip;
Object.entries(rest).forEach(([k, v]) => {
// This filters out any feature flags in the enum that are not part of the
// kotlin statsig config object
if (k in StatsigConfig) {
StatsigConfig[k] = v;
}
});
};
}

Expand Down
6 changes: 6 additions & 0 deletions src/types/statsig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
export type StatsigConfigType = Record<StatSigFlags, boolean>;

/**
* !README!:
* If you are using a flag in abacus, you must add it to the abacus
* StatsigConfig object first! Otherwise it won't be set in the StatsigConfig object
*/
export enum StatSigFlags {
ffSkipMigration = 'ff_skip_migration',
ffShowPredictionMarketsUi = 'ff_show_prediction_markets_ui',
ffEnableEvmSwaps = 'ff_enable_evm_swaps',
}

0 comments on commit 388ff1d

Please sign in to comment.