-
Notifications
You must be signed in to change notification settings - Fork 38
chore(checkout): Additional overrides to facilitate the Immutable dev env #2607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a6d4759
chore(checkout): Add ability to override networkMap
keithbro-imx d4cdfe8
WIP
keithbro-imx bea3e1e
WIP
keithbro-imx 3d20ce7
WIP
keithbro-imx 6b9b184
WIP
keithbro-imx 8e9eb26
Consistent chain ID lookup
keithbro-imx f5f7938
Consistent chain ID lookup
keithbro-imx ca1185a
Fix remote config
keithbro-imx e00897b
Fix remote config test
keithbro-imx 9345706
Fix remote config test
keithbro-imx 94edde6
Filter out zero balance tokens
keithbro-imx 1743788
Remove overrides
keithbro-imx be6e863
Merge branch 'main' into task/ability-to-override-network-map
keithbro-imx f178666
Clean up
keithbro-imx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,17 @@ | ||
| import { Environment } from '@imtbl/config'; | ||
| import { CheckoutModuleConfiguration, ChainId, NetworkMap } from '../types'; | ||
| import { | ||
| CheckoutModuleConfiguration, ChainId, NetworkMap, ChainSlug, | ||
| } from '../types'; | ||
| import { RemoteConfigFetcher } from './remoteConfigFetcher'; | ||
| import { | ||
| CHECKOUT_CDN_BASE_URL, | ||
| DEFAULT_BRIDGE_ENABLED, | ||
| DEFAULT_ON_RAMP_ENABLED, | ||
| DEFAULT_SWAP_ENABLED, | ||
| DEV_CHAIN_ID_NETWORK_MAP, | ||
| ENV_DEVELOPMENT, | ||
| globalPackageVersion, | ||
| IMMUTABLE_API_BASE_URL, | ||
| PRODUCTION_CHAIN_ID_NETWORK_MAP, | ||
| SANDBOX_CHAIN_ID_NETWORK_MAP, | ||
| } from '../env'; | ||
|
|
@@ -28,12 +33,18 @@ const networkMap = (prod: boolean, dev: boolean) => { | |
| return SANDBOX_CHAIN_ID_NETWORK_MAP; | ||
| }; | ||
|
|
||
| // **************************************************** // | ||
| // This is duplicated in the widget-lib project. // | ||
| // We are not exposing these functions given that this // | ||
| // to keep the Checkout SDK interface as minimal as // | ||
| // possible. // | ||
| // **************************************************** // | ||
| const getBaseUrl = (prod: boolean, dev: boolean) => { | ||
| if (dev) return IMMUTABLE_API_BASE_URL[ENV_DEVELOPMENT]; | ||
| if (prod) return IMMUTABLE_API_BASE_URL[Environment.PRODUCTION]; | ||
| return IMMUTABLE_API_BASE_URL[Environment.SANDBOX]; | ||
| }; | ||
|
|
||
| const getChainSlug = (prod: boolean, dev: boolean) => { | ||
| if (dev) return ChainSlug.IMTBL_ZKEVM_DEVNET; | ||
| if (prod) return ChainSlug.IMTBL_ZKEVM_MAINNET; | ||
| return ChainSlug.IMTBL_ZKEVM_TESTNET; | ||
| }; | ||
|
|
||
| export const getL1ChainId = (config: CheckoutConfiguration): ChainId => { | ||
| // DevMode and Sandbox will both use Sepolia. | ||
| if (!config.isProduction) return ChainId.SEPOLIA; | ||
|
|
@@ -45,8 +56,12 @@ export const getL2ChainId = (config: CheckoutConfiguration): ChainId => { | |
| if (config.isProduction) return ChainId.IMTBL_ZKEVM_MAINNET; | ||
| return ChainId.IMTBL_ZKEVM_TESTNET; | ||
| }; | ||
| // **************************************************** // | ||
| // **************************************************** // | ||
|
|
||
| const getRemoteConfigEndpoint = (prod: boolean, dev: boolean) => { | ||
| if (dev) return CHECKOUT_CDN_BASE_URL[ENV_DEVELOPMENT]; | ||
| if (prod) return CHECKOUT_CDN_BASE_URL[Environment.PRODUCTION]; | ||
| return CHECKOUT_CDN_BASE_URL[Environment.SANDBOX]; | ||
| }; | ||
|
|
||
| export class CheckoutConfiguration { | ||
| // This is a hidden feature that is only available | ||
|
|
@@ -73,6 +88,10 @@ export class CheckoutConfiguration { | |
|
|
||
| readonly publishableKey: string; | ||
|
|
||
| readonly l1ChainId: ChainId; | ||
|
|
||
| readonly l2ChainId: ChainId; | ||
|
|
||
| readonly overrides: CheckoutModuleConfiguration['overrides']; | ||
|
|
||
| constructor(config: CheckoutModuleConfiguration, httpClient: HttpClient) { | ||
|
|
@@ -91,18 +110,23 @@ export class CheckoutConfiguration { | |
| this.isBridgeEnabled = config.bridge?.enable ?? DEFAULT_BRIDGE_ENABLED; | ||
| this.publishableKey = config.publishableKey ?? '<no-publishable-key>'; | ||
|
|
||
| this.networkMap = networkMap(this.isProduction, this.isDevelopment); | ||
| this.networkMap = config.overrides?.networkMap ?? networkMap(this.isProduction, this.isDevelopment); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These changes are mostly about reading from the overrides |
||
|
|
||
| const remoteConfigEndpoint = config.overrides?.remoteConfigEndpoint | ||
| ?? getRemoteConfigEndpoint(this.isProduction, this.isDevelopment); | ||
|
|
||
| this.remote = new RemoteConfigFetcher(httpClient, { | ||
| isDevelopment: this.isDevelopment, | ||
| isProduction: this.isProduction, | ||
| remoteConfigEndpoint, | ||
| }); | ||
|
|
||
| this.tokens = new TokensFetcher(httpClient, this.remote, { | ||
| isDevelopment: this.isDevelopment, | ||
| isProduction: this.isProduction, | ||
| baseUrl: config.overrides?.baseUrl ?? getBaseUrl(this.isProduction, this.isDevelopment), | ||
| chainSlug: config.overrides?.chainSlug ?? getChainSlug(this.isProduction, this.isDevelopment), | ||
| }); | ||
|
|
||
| this.l1ChainId = getL1ChainId(this); | ||
| this.l2ChainId = config.overrides?.l2ChainId ?? getL2ChainId(this); | ||
|
|
||
| this.overrides = config.overrides ?? {}; | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change here is to filter out any zero balances. When fetching balances from the RPC it returns all tokens, even zero balance ones. So we need to filter these out to maintain the same behaviour as when we use blockscout.