This repository was archived by the owner on Nov 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 360
Instantiate contracts via chainId from loaded config
#3313
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fb01de6
fix: Use chain id from chains config
2411c00
build: init Safe contracts with chains + id set
4a95fd1
build: Set chain id + contract init in middleware
27d445b
fix: Remove unnecessary contract init
0c1da16
fix: Dispatch chain id setting with App init
e0a873f
build: Move contract init to provider watcher
e90fc54
build: Separate local `chainId` from store
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,13 @@ | ||
| import { instantiateSafeContracts } from 'src/logic/contracts/safeContracts' | ||
| import closeSnackbar from 'src/logic/notifications/store/actions/closeSnackbar' | ||
| import { getProviderInfo, getWeb3 } from 'src/logic/wallets/getWeb3' | ||
| import { fetchProvider } from 'src/logic/wallets/store/actions' | ||
| import { ADD_PROVIDER } from 'src/logic/wallets/store/actions/addProvider' | ||
| import { REMOVE_PROVIDER } from 'src/logic/wallets/store/actions/removeProvider' | ||
|
|
||
| import { loadFromStorage, removeFromStorage, saveToStorage } from 'src/utils/storage' | ||
| import { store as reduxStore } from 'src/store' | ||
| import { Dispatch } from 'redux' | ||
| import { ProviderState } from '../reducer/provider' | ||
|
|
||
| const watchedActions = [ADD_PROVIDER, REMOVE_PROVIDER] | ||
|
|
||
|
|
@@ -16,50 +19,60 @@ export const loadLastUsedProvider = async (): Promise<string | undefined> => { | |
| return lastUsedProvider | ||
| } | ||
|
|
||
| let watcherInterval | ||
| const providerWatcherMware = (store) => (next) => async (action) => { | ||
| const handledAction = next(action) | ||
| type ProviderWatcherAction = { | ||
| type: string | ||
| payload: ProviderState | ||
| } | ||
|
|
||
| if (watchedActions.includes(action.type)) { | ||
| switch (action.type) { | ||
| case ADD_PROVIDER: { | ||
| const currentProviderProps = action.payload.toJS() | ||
| let watcherInterval: NodeJS.Timer | ||
| const providerWatcherMware = | ||
| (store: typeof reduxStore) => | ||
| (next: Dispatch) => | ||
| async (action: ProviderWatcherAction): Promise<ProviderWatcherAction> => { | ||
| const handledAction = next(action) | ||
|
|
||
| if (watcherInterval) { | ||
| clearInterval(watcherInterval) | ||
| } | ||
| if (watchedActions.includes(action.type)) { | ||
| switch (action.type) { | ||
| case ADD_PROVIDER: { | ||
| const currentProviderProps = action.payload.toJS() | ||
|
|
||
| saveToStorage(LAST_USED_PROVIDER_KEY, currentProviderProps.name) | ||
| if (watcherInterval) { | ||
| clearInterval(watcherInterval) | ||
| } | ||
|
|
||
| watcherInterval = setInterval(async () => { | ||
| const web3 = getWeb3() | ||
| const providerInfo = await getProviderInfo(web3) | ||
| instantiateSafeContracts() | ||
|
Member
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. 👍 |
||
|
|
||
| const networkChanged = currentProviderProps.network !== providerInfo.network | ||
| saveToStorage(LAST_USED_PROVIDER_KEY, currentProviderProps.name) | ||
|
|
||
| if (networkChanged) { | ||
| store.dispatch(closeSnackbar({ dismissAll: true })) | ||
| } | ||
| watcherInterval = setInterval(async () => { | ||
| const web3 = getWeb3() | ||
| const providerInfo = await getProviderInfo(web3) | ||
|
|
||
| if (currentProviderProps.account !== providerInfo.account || networkChanged) { | ||
| store.dispatch(fetchProvider(currentProviderProps.name)) | ||
| } | ||
| }, 2000) | ||
| const networkChanged = currentProviderProps.network !== providerInfo.network | ||
|
|
||
| break | ||
| } | ||
| case REMOVE_PROVIDER: | ||
| clearInterval(watcherInterval) | ||
| if (!action.payload?.keepStorageKey) { | ||
| removeFromStorage(LAST_USED_PROVIDER_KEY) | ||
| if (networkChanged) { | ||
| store.dispatch(closeSnackbar({ dismissAll: true })) | ||
| } | ||
|
|
||
| if (currentProviderProps.account !== providerInfo.account || networkChanged) { | ||
| store.dispatch(fetchProvider(currentProviderProps.name)) | ||
| } | ||
| }, 2000) | ||
|
|
||
| break | ||
| } | ||
| break | ||
| default: | ||
| break | ||
| case REMOVE_PROVIDER: | ||
| clearInterval(watcherInterval) | ||
| if (!action.payload?.keepStorageKey) { | ||
| removeFromStorage(LAST_USED_PROVIDER_KEY) | ||
| } | ||
| break | ||
| default: | ||
| break | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return handledAction | ||
| } | ||
| return handledAction | ||
| } | ||
|
|
||
| export default providerWatcherMware | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.