Skip to content

frontend: move web config access into config context/provider#3916

Open
smokyisthatyou wants to merge 4 commits intoBitBoxSwiss:masterfrom
smokyisthatyou:config-context-provider
Open

frontend: move web config access into config context/provider#3916
smokyisthatyou wants to merge 4 commits intoBitBoxSwiss:masterfrom
smokyisthatyou:config-context-provider

Conversation

@smokyisthatyou
Copy link
Copy Markdown
Contributor

Add ConfigContext + ConfigProvider in frontends/web and refactor React components/hooks to consume getConfig/setConfig through useConfig() instead of importing utils/config directly. Keep non-React config consumers on the shared utils/config implementation path, and update related hook dependency arrays.

Before asking for reviews, here is a check list of the most common things you might need to consider:

  • updating the Changelog
  • writing unit tests
  • checking if your changes affect other coins or tokens in unintended ways
  • testing on multiple environments (Qt, Android, ...)
  • having an AI review your changes

cc @thisconnect

@thisconnect
Copy link
Copy Markdown
Collaborator

nice, please make one more change/commit. Currently each component still does a get request when using getConfig.

Instead it could call getConfig once on startup and keep the "config" object in the context. getConfig could then either read out the local "config" object, or context could expose "config" object along with setConfig. I am not sure what is better.

With this all components that depend on "config" object can read from the context without doing an additional api call.

We want the source of truth still to be the backend, so in the context it should update the "config" object after setConfig and fetch from the api.

Also the api function in utils should be moved into frontends/web/src/api/config.ts

@thisconnect thisconnect requested a review from shonsirsha March 10, 2026 05:44
@shonsirsha
Copy link
Copy Markdown
Collaborator

concept ACK

@thisconnect thisconnect requested review from thisconnect and removed request for shonsirsha March 10, 2026 12:39
Comment thread frontends/web/src/hooks/bitsurance.ts
Comment thread frontends/web/src/api/config.ts Outdated
Comment thread frontends/web/src/api/config.ts
Comment thread frontends/web/src/components/banners/offline-error.tsx Outdated
Comment thread frontends/web/src/api/config.ts Outdated
Comment thread frontends/web/src/contexts/RatesProvider.tsx Outdated
Comment thread frontends/web/src/components/status/status.tsx Outdated
Comment thread frontends/web/src/contexts/DarkmodeProvider.tsx
Comment thread frontends/web/src/contexts/DarkmodeProvider.tsx Outdated
Comment thread frontends/web/src/hooks/bitsurance.ts
@smokyisthatyou smokyisthatyou force-pushed the config-context-provider branch from 30401e1 to ea60d60 Compare March 12, 2026 16:16
@smokyisthatyou smokyisthatyou force-pushed the config-context-provider branch from ea60d60 to 4da6264 Compare March 30, 2026 14:48
@smokyisthatyou smokyisthatyou marked this pull request as ready for review March 30, 2026 15:49
@smokyisthatyou
Copy link
Copy Markdown
Contributor Author

@thisconnect moving this from draft, rebased

Comment thread frontends/web/src/api/config.ts Outdated
Comment thread frontends/web/src/api/config.ts
Comment thread frontends/web/src/components/status/status.tsx Outdated
@smokyisthatyou
Copy link
Copy Markdown
Contributor Author

@thisconnect ptal whenever you have time 🙏

Copy link
Copy Markdown
Collaborator

@thisconnect thisconnect left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you I think we should merge this first step soon, as it reduces api calls to the config endpoint and is the base for further updates: like fully typing TConfig

Comment thread frontends/web/src/utils/config.ts Outdated
Comment thread frontends/web/src/utils/config.ts Outdated
};
export type { TConfig };

let pendingConfig: Partial<TConfig> = {};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about what it takes to move this into the react context.

The only place getConfig is used outside of react (component, hook, context) is in i18n/config.ts which is called once on app start. Here we could just use getConfig from api.

Similarly setConfig is used by i18n/i18n.ts, which is called once on startup (maybe not necessary) and when the user actively changes the language. Here I believe we cannot use setConfig from context, but there might be some workarounds (not 100% sure).

Other than for that we could move pendingConfig + the logic in setConfig into a context in the future.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should test/merge as is and in the future PR's:

  1. try to move this pending variable and logic into context.
  2. type config fully

both changes can be done independently

getConfig().then(({ backend }) => setUsesProxy(backend.proxy.useProxy));
}, []);
const { config } = useConfig();
const usesProxy = (config?.backend?.proxy as { useProxy?: boolean } | undefined)?.useProxy;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we have config object fully typed in a future PR, this type casting can be simplified a lot or even removed completely.

Comment thread frontends/web/src/components/status/status.tsx Outdated
const frontend = config?.frontend;
if (frontend && typeof frontend === 'object') {
if (frontend.guideShown !== undefined) {
setGuideShown(Boolean(frontend.guideShown));
Copy link
Copy Markdown
Collaborator

@thisconnect thisconnect Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we fully type TConfig in the future these safeguards can mostly be removed.

Comment thread frontends/web/src/contexts/AppProvider.tsx Outdated
Comment thread frontends/web/src/contexts/ConfigContext.tsx Outdated
@smokyisthatyou smokyisthatyou force-pushed the config-context-provider branch from e991fa0 to 8fb8728 Compare March 31, 2026 13:29
@smokyisthatyou smokyisthatyou force-pushed the config-context-provider branch 7 times, most recently from ed28dd9 to 925a212 Compare April 10, 2026 10:44
@smokyisthatyou
Copy link
Copy Markdown
Contributor Author

@jadzeidan while working on this pr i think i introduced an old behaviour of the app that was opening the guide on first run. i implemented the code thinking it was the current expected flow, but @thisconnect pointed out this was actually deprecated in v4.40.

personally i’m not a huge fan of the auto-opening guide for aesthetic reasons, though I can see the utility.
do you think we should reintroduce this or keep it as is?

@jadzeidan
Copy link
Copy Markdown
Contributor

thanks @smokyisthatyou for finding this 😄

I agree that guide shouldn't open automatically, so let's keep the "new" behaviour.

@smokyisthatyou smokyisthatyou force-pushed the config-context-provider branch from 96ad8f0 to d730016 Compare April 13, 2026 11:29
smokyisthatyou and others added 4 commits April 13, 2026 15:10
- Introduce ConfigProvider and ConfigContext and wrap app with
  provider
- Fetch config once when the app loads and expose config + setConfig
  via useConfig
- Refactor config consumers to read from context instead of calling
  getConfig per component
Stop auto-opening the guide when no frontend config is present.
This prevents the guide overlay from blocking interactions on fresh starts.
- Add TFrontendConfig with known frontend settings flags and keep index signature
- Update consumers to use typed config.frontend keys and drop casts/guards
- Add TBackendConfig and related types to api/config and use them in TConfig
- Introduce TConfigUpdate so setConfig can accept partial backend/frontend updates
- Update utils/config and ConfigProvider/Context to use TConfigUpdate merge + pendingConfig
- Drop remaining backend casts in offline-error, electrum-servers, and RatesProvider
@smokyisthatyou smokyisthatyou force-pushed the config-context-provider branch from d730016 to cacf20f Compare April 13, 2026 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants