-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: reorganize bridge controller
- Loading branch information
Showing
10 changed files
with
54 additions
and
50 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
app/scripts/controllers/bridge.test.ts → ...trollers/bridge/bridge-controller.test.ts
This file contains 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 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,23 @@ | ||
import { ObservableStore } from '@metamask/obs-store'; | ||
import { fetchBridgeFeatureFlags } from '../../../../ui/pages/bridge/bridge.util'; | ||
import { DEFAULT_BRIDGE_CONTROLLER_STATE } from './constants'; | ||
|
||
export default class BridgeController { | ||
store = new ObservableStore({ bridgeState: DEFAULT_BRIDGE_CONTROLLER_STATE }); | ||
|
||
resetState = () => { | ||
this.store.updateState({ | ||
bridgeState: { | ||
...DEFAULT_BRIDGE_CONTROLLER_STATE, | ||
}, | ||
}); | ||
}; | ||
|
||
setBridgeFeatureFlags = async () => { | ||
const { bridgeState } = this.store.getState(); | ||
const bridgeFeatureFlags = await fetchBridgeFeatureFlags(); | ||
this.store.updateState({ | ||
bridgeState: { ...bridgeState, bridgeFeatureFlags }, | ||
}); | ||
}; | ||
} |
This file contains 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,7 @@ | ||
import { BridgeControllerState, BridgeFeatureFlagsKey } from './types'; | ||
|
||
export const DEFAULT_BRIDGE_CONTROLLER_STATE: BridgeControllerState = { | ||
bridgeFeatureFlags: { | ||
[BridgeFeatureFlagsKey.EXTENSION_SUPPORT]: false, | ||
}, | ||
}; |
This file contains 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,16 @@ | ||
// Maps to BridgeController function names | ||
export enum BridgeBackgroundAction { | ||
SET_FEATURE_FLAGS = 'setBridgeFeatureFlags', | ||
} | ||
|
||
export enum BridgeFeatureFlagsKey { | ||
EXTENSION_SUPPORT = 'extensionSupport', | ||
} | ||
|
||
export type BridgeFeatureFlags = { | ||
[BridgeFeatureFlagsKey.EXTENSION_SUPPORT]: boolean; | ||
}; | ||
|
||
export type BridgeControllerState = { | ||
bridgeFeatureFlags: BridgeFeatureFlags; | ||
}; |
This file contains 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 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 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 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 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