Skip to content

Commit

Permalink
fix(jumpstart): correct jumpstart contracts defaultValue (#4923)
Browse files Browse the repository at this point in the history
### 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)
  • Loading branch information
bakoushin committed Feb 16, 2024
1 parent 81e998c commit 5d70e8e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/jumpstart/jumpstartLinkHandler.test.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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)

Expand Down
3 changes: 1 addition & 2 deletions src/jumpstart/jumpstartLinkHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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')
Expand Down
6 changes: 4 additions & 2 deletions src/statsig/constants.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 5d70e8e

Please sign in to comment.