From 5d70e8ee5c2741b4356d2d309b51e246ce70e079 Mon Sep 17 00:00:00 2001 From: Alex Bakoushin Date: Fri, 16 Feb 2024 21:33:06 +0100 Subject: [PATCH] fix(jumpstart): correct jumpstart contracts `defaultValue` (#4923) ### Description 1) All possible dynamic config properties must be listed in `defaultValues` when declaring that config. Otherwise, they [won't be forwarded](https://github.com/valora-inc/wallet/blob/a0b4675774579822a6c2ac55e7de38f6658b45c2/src/statsig/index.ts#L29-L34). 2) In addition, it seems more appropriate to use `NetworkId` as network specifier instead of `Network` to enable jumpstart contracts on the testnet as well. ### Test plan * Updated unit tests ### Related issues - Related to RET-999 ### Backwards compatibility Jumpstart functionality is not fully released yet ### Network scalability If a new NetworkId and/or Network are added in the future, the changes in this PR will: - [x] Continue to work without code changes, OR trigger a compilation error (guaranteeing we find it when a new network is added) --- src/jumpstart/jumpstartLinkHandler.test.ts | 5 ++++- src/jumpstart/jumpstartLinkHandler.ts | 3 +-- src/statsig/constants.ts | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/jumpstart/jumpstartLinkHandler.test.ts b/src/jumpstart/jumpstartLinkHandler.test.ts index 7066832813d..5ae61f73ee8 100644 --- a/src/jumpstart/jumpstartLinkHandler.test.ts +++ b/src/jumpstart/jumpstartLinkHandler.test.ts @@ -1,6 +1,7 @@ import { getDynamicConfigParams } from 'src/statsig' import Logger from 'src/utils/Logger' import { fetchWithTimeout } from 'src/utils/fetchWithTimeout' +import networkConfig from 'src/web3/networkConfig' import { mockAccount, mockAccount2 } from 'test/values' import { jumpstartLinkHandler } from './jumpstartLinkHandler' @@ -43,7 +44,9 @@ describe('jumpstartLinkHandler', () => { ;(fetchWithTimeout as jest.Mock).mockImplementation(() => ({ ok: true, })) - jest.mocked(getDynamicConfigParams).mockReturnValue({ celo: { contractAddress: '0xTEST' } }) + jest.mocked(getDynamicConfigParams).mockReturnValue({ + jumpstartContracts: { [networkConfig.defaultNetworkId]: { contractAddress: '0xTEST' } }, + }) await jumpstartLinkHandler(privateKey, mockAccount2) diff --git a/src/jumpstart/jumpstartLinkHandler.ts b/src/jumpstart/jumpstartLinkHandler.ts index afa3ae136b3..4b3519b3e62 100644 --- a/src/jumpstart/jumpstartLinkHandler.ts +++ b/src/jumpstart/jumpstartLinkHandler.ts @@ -4,7 +4,6 @@ import jumpstartAbi from 'src/abis/WalletJumpStart.json' import { getDynamicConfigParams } from 'src/statsig' import { DynamicConfigs } from 'src/statsig/constants' import { StatsigDynamicConfigs } from 'src/statsig/types' -import { Network } from 'src/transactions/types' import Logger from 'src/utils/Logger' import { fetchWithTimeout } from 'src/utils/fetchWithTimeout' import { getWeb3Async } from 'src/web3/contracts' @@ -16,7 +15,7 @@ const TAG = 'WalletJumpstart' export async function jumpstartLinkHandler(privateKey: string, userAddress: string) { const contractAddress = getDynamicConfigParams( DynamicConfigs[StatsigDynamicConfigs.WALLET_JUMPSTART_CONFIG] - )?.[Network.Celo]?.contractAddress + ).jumpstartContracts?.[networkConfig.defaultNetworkId]?.contractAddress if (!contractAddress) { Logger.error(TAG, 'Contract address is not provided in dynamic config') diff --git a/src/statsig/constants.ts b/src/statsig/constants.ts index 58089f5c935..92c08ef7dca 100644 --- a/src/statsig/constants.ts +++ b/src/statsig/constants.ts @@ -1,5 +1,5 @@ import { StatsigDynamicConfigs, StatsigExperiments, StatsigFeatureGates } from 'src/statsig/types' -import { Network, NetworkId } from 'src/transactions/types' +import { NetworkId } from 'src/transactions/types' import networkConfig from 'src/web3/networkConfig' export const FeatureGates = { @@ -101,7 +101,9 @@ export const DynamicConfigs = { }, [StatsigDynamicConfigs.WALLET_JUMPSTART_CONFIG]: { configName: StatsigDynamicConfigs.WALLET_JUMPSTART_CONFIG, - defaultValues: {} as { [key in Network]?: { contractAddress?: string } }, + defaultValues: { + jumpstartContracts: {} as { [key in NetworkId]?: { contractAddress?: string } }, + }, }, [StatsigDynamicConfigs.NFT_CELEBRATION_CONFIG]: { configName: StatsigDynamicConfigs.NFT_CELEBRATION_CONFIG,