-
Notifications
You must be signed in to change notification settings - Fork 120
frontend: move web config access into config context/provider #3916
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
Open
smokyisthatyou
wants to merge
24
commits into
BitBoxSwiss:master
Choose a base branch
from
smokyisthatyou:config-context-provider
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
54a9ffd
frontend: add config context and fetch config once on startup
smokyisthatyou 5cd1bf7
frontend: keep guide hidden by default on first run
smokyisthatyou 2992d26
frontend: type frontend config keys in TConfig
smokyisthatyou 6f8a260
frontend: type backend config and add typed config updates
smokyisthatyou 4d19d28
frontend: complete TConfig typing
smokyisthatyou 7642796
frontend: migrate NewBadge to useConfig
smokyisthatyou 3f739db
frontend: remove duplicate onChangeConfig writes in advanced settings
smokyisthatyou 06fcb73
frontend: await bitsurance setConfig when clearing cancellation flag
smokyisthatyou 1e34610
frontend: address minor nits
smokyisthatyou 21682d8
fix: remove unused import
smokyisthatyou 24e6146
fix: export only config types that are imported in other files
smokyisthatyou fd60ec8
nit: add comment for deprecated coisn to match backend
smokyisthatyou c5b65e0
fix: drop redundant frontend/backend guards after config loads
smokyisthatyou 4a1496f
fix: drop redundant Boolean() on boolean config fields
smokyisthatyou b5dddcf
frontend: use useConfig in swap component
smokyisthatyou 9c56d5d
fix: move TConfigUpdate types to utils/config
smokyisthatyou d9f38ee
fix: type api getConfig as Promise<TConfig>
smokyisthatyou ca0308b
fix: prefix config types with TConfig
smokyisthatyou d0eb1d8
fix: drop config normalize-on-read
smokyisthatyou bb9cdc0
fix: remove cast utils setConfig merge
smokyisthatyou f30f894
fix: drop mock-config; inline TConfig casts in tests
smokyisthatyou 4037024
fix: read gap limit config from useConfig in CustomGapLimitSettings
smokyisthatyou aa6a5bf
fix: read auth setting from useConfig in EnableAuthSetting
smokyisthatyou c34305e
fix: stabilize export-logs Android e2e after config provider
smokyisthatyou 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 |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { apiGet, apiPost } from '@/utils/request'; | ||
| import type { Fiat } from '@/api/account'; | ||
| import type { BtcUnit } from '@/api/coins'; | ||
|
|
||
| type TElectrumServerInfo = Readonly<{ | ||
| server: string; | ||
| tls: boolean; | ||
| pemCert: string; | ||
| }>; | ||
|
|
||
| type TBtcCoinConfig = Readonly<{ | ||
| electrumServers: TElectrumServerInfo[]; | ||
| }>; | ||
|
|
||
| /** BTC-based coin keys in backend config (see backend/config/config.go). */ | ||
| export type TConfigBackendBtcCoinKey = 'btc' | 'tbtc' | 'ltc' | 'tltc'; | ||
|
|
||
| // Mirrors backend/config/config.go ethCoinConfig: DeprecatedActiveERC20Tokens (JSON key | ||
| // "activeERC20Tokens"). Deprecated — ERC20 activation is per-account in accounts config; kept | ||
| // for migration / compatibility with persisted app config. | ||
| type TEthCoinConfig = Readonly<{ | ||
| activeERC20Tokens: string[]; | ||
|
thisconnect marked this conversation as resolved.
|
||
| }>; | ||
|
|
||
| export type TConfigBackendProxy = Readonly<{ | ||
| useProxy: boolean; | ||
| proxyAddress: string; | ||
| }>; | ||
|
|
||
| /** Keys used by NewBadge to mark UI elements as seen. */ | ||
| export type TConfigFrontendBadgeKey = | ||
| | 'hasSeenMarketplaceNudge' | ||
| | 'hasSeenSwapMarketTab' | ||
| | 'hasSeenOtcMarketTab'; | ||
|
|
||
| /** Dynamic frontend keys written when dismissing Status banners. */ | ||
| type TConfigFrontendDismissibleDynamicKey = | ||
| | `update-${string}` | ||
| | `banner-backup-${string}` | ||
| | `banner-${string}-${string}`; | ||
|
|
||
| /** Known static frontend keys written when dismissing Status banners. */ | ||
| type TConfigFrontendDismissibleKnownKey = | ||
| | 'walletConnectDisclaimerDismissed' | ||
| | 'skipTestingWarning' | ||
| | 'mobile-data-warning'; | ||
|
|
||
| export type TConfigFrontendDismissibleKey = | ||
| | TConfigFrontendDismissibleKnownKey | ||
| | TConfigFrontendDismissibleDynamicKey; | ||
|
|
||
| export type TConfigFrontend = Readonly<{ | ||
| guideShown?: boolean; | ||
| hideAmounts?: boolean; | ||
| darkmode?: boolean; | ||
| expertFee?: boolean; | ||
| coinControl?: boolean; | ||
| selectedExchangeRegion?: string; | ||
| hideEnableRememberWalletDialog?: boolean; | ||
| hasUsedWalletConnect?: boolean; | ||
| bitsuranceNotifyCancellation?: string[]; | ||
|
|
||
| hasSeenMarketplaceNudge?: boolean; | ||
| hasSeenSwapMarketTab?: boolean; | ||
| hasSeenOtcMarketTab?: boolean; | ||
|
|
||
| skipBitrefillWidgetDisclaimer?: boolean; | ||
| skipBTCDirectWidgetDisclaimer?: boolean; | ||
| skipBTCDirectOTCDisclaimer?: boolean; | ||
| skipMoonpayDisclaimer?: boolean; | ||
| skipPocketDisclaimer?: boolean; | ||
| skipPocketOTCDisclaimer?: boolean; | ||
| skipBitsuranceDisclaimer?: boolean; | ||
| skipSwapkitDisclaimer?: boolean; | ||
|
|
||
| walletConnectDisclaimerDismissed?: boolean; | ||
| skipTestingWarning?: boolean; | ||
| 'mobile-data-warning'?: boolean; | ||
| }> & Readonly<{ | ||
| [key in TConfigFrontendDismissibleDynamicKey]?: boolean; | ||
| }>; | ||
|
|
||
| export type TConfigBackend = Readonly<{ | ||
| proxy: TConfigBackendProxy; | ||
| /** | ||
| * Deprecated global coin activation flags (backend/config/config.go: DeprecatedBitcoinActive, | ||
| * DeprecatedLitecoinActive, DeprecatedEthereumActive). Coins are configured per account now; | ||
| * kept for migration / compatibility with persisted app config. | ||
| */ | ||
| bitcoinActive: boolean; | ||
| litecoinActive: boolean; | ||
| ethereumActive: boolean; | ||
| authentication: boolean; | ||
| btc: TBtcCoinConfig; | ||
| tbtc: TBtcCoinConfig; | ||
| rbtc: TBtcCoinConfig; | ||
| ltc: TBtcCoinConfig; | ||
| tltc: TBtcCoinConfig; | ||
| eth: TEthCoinConfig; | ||
| teth: Record<string, never>; | ||
| reth: Record<string, never>; | ||
| fiatList: Fiat[]; | ||
| mainFiat: Fiat; | ||
| userLanguage: string; | ||
| btcUnit: BtcUnit; | ||
| startInTestnet: boolean; | ||
| gapLimitReceive: number; | ||
| gapLimitChange: number; | ||
| }>; | ||
|
|
||
| export type TConfig = { | ||
| readonly backend: TConfigBackend; | ||
| readonly frontend: TConfigFrontend; | ||
| }; | ||
|
thisconnect marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * Fetch config from the backend (see handlers.getAppConfig). | ||
| * Use setConfig from @/utils/config for partial merge-on-write updates. | ||
| */ | ||
| export const getConfig = (): Promise<TConfig> => apiGet('config'); | ||
|
|
||
| /** | ||
| * Post a config object to the backend. | ||
| */ | ||
| export const setConfig = (config: TConfig): Promise<void> => { | ||
| return apiPost('config', config); | ||
| }; | ||
|
thisconnect marked this conversation as resolved.
thisconnect marked this conversation as resolved.
|
||
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
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
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
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.
Please use
data-testidon the dialog component's overlay so you dont have to traverse the DOM here.The react testing library style would more be to find web accessible elements by role atc. https://testing-library.com/docs/queries/about/#priority
but refactoring the diaog/overlay seems a bit out of scope of this PR so best to just add
data-testidin this dialog.