Skip to content

Commit

Permalink
get remote config of custom wallets on firebase
Browse files Browse the repository at this point in the history
  • Loading branch information
ltminhthu committed Aug 15, 2024
1 parent 2f50ebc commit 12c0f06
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion apps/wallet/src/state/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { widgetState } from './widget';

export const bootstrap = async (): Promise<void> => {
const startTime = new Date();
appState.remoteConfig = loadRemoteConfig();
appState.remoteConfig = await loadRemoteConfig();

await configure(storage);
await migrateDatabase(storage, 'app', appMigrations).then(async () => {
Expand Down
17 changes: 11 additions & 6 deletions apps/wallet/src/utils/firebase/index.web.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { getAnalytics, logEvent } from '@firebase/analytics';
import {
activate,
fetchConfig,
fetchAndActivate,
getAll,
getRemoteConfig,
} from '@firebase/remote-config';
import type { RemoteConfig } from '@walless/core';
import type { CustomWalletMetadata, RemoteConfig } from '@walless/core';
import { defaultRemoteConfig } from 'utils/constants';

import { app } from './index.ext';
Expand All @@ -18,15 +17,21 @@ export const remoteConfig = getRemoteConfig(app);
remoteConfig.settings.minimumFetchIntervalMillis = __DEV__ ? 10000 : 3600000;
remoteConfig.defaultConfig = defaultRemoteConfig as never;

export const loadRemoteConfig = (): RemoteConfig => {
activate(remoteConfig);
fetchConfig(remoteConfig);
export const loadRemoteConfig = async (): Promise<RemoteConfig> => {
await fetchAndActivate(remoteConfig);
const allConfig = getAll(remoteConfig);

const customWalletsString = allConfig.customWallets?.asString();
const customWallets = JSON.parse(customWalletsString) as Record<
string,
CustomWalletMetadata
>;

return {
experimentalEnabled: allConfig.experimentalEnabled?.asBoolean(),
deepAnalyticsEnabled: allConfig.deepAnalyticsEnabled?.asBoolean(),
minimalVersion: allConfig.minimalVersion?.asString() || '1.0.0',
customWallets: customWallets,
};
};

Expand Down

0 comments on commit 12c0f06

Please sign in to comment.