-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'nonce_address_fix' of github.com:MetaMask/metamask-exte…
…nsion into nonce_address_fix
- Loading branch information
Showing
17 changed files
with
202 additions
and
57 deletions.
There are no files selected for viewing
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React, { ReactNode } from 'react'; | ||
import useCurrencyRatePolling from '../hooks/useCurrencyRatePolling'; | ||
import useTokenRatesPolling from '../hooks/useTokenRatesPolling'; | ||
|
||
// This provider is a step towards making controller polling fully UI based. | ||
// Eventually, individual UI components will call the use*Polling hooks to | ||
// poll and return particular data. This polls globally in the meantime. | ||
export const AssetPollingProvider = ({ children }: { children: ReactNode }) => { | ||
useCurrencyRatePolling(); | ||
useTokenRatesPolling(); | ||
|
||
return <>{children}</>; | ||
}; |
This file was deleted.
Oops, something went wrong.
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,57 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
type UseMultiPollingOptions<PollingInput> = { | ||
startPolling: (input: PollingInput) => Promise<string>; | ||
stopPollingByPollingToken: (pollingToken: string) => void; | ||
input: PollingInput[]; | ||
}; | ||
|
||
// A hook that manages multiple polling loops of a polling controller. | ||
// Callers provide an array of inputs, and the hook manages starting | ||
// and stopping polling loops for each input. | ||
const useMultiPolling = <PollingInput>( | ||
usePollingOptions: UseMultiPollingOptions<PollingInput>, | ||
) => { | ||
const [polls, setPolls] = useState(new Map()); | ||
|
||
useEffect(() => { | ||
// start new polls | ||
for (const input of usePollingOptions.input) { | ||
const key = JSON.stringify(input); | ||
if (!polls.has(key)) { | ||
usePollingOptions | ||
.startPolling(input) | ||
.then((token) => | ||
setPolls((prevPolls) => new Map(prevPolls).set(key, token)), | ||
); | ||
} | ||
} | ||
|
||
// stop existing polls | ||
for (const [inputKey, token] of polls.entries()) { | ||
const exists = usePollingOptions.input.some( | ||
(i) => inputKey === JSON.stringify(i), | ||
); | ||
|
||
if (!exists) { | ||
usePollingOptions.stopPollingByPollingToken(token); | ||
setPolls((prevPolls) => { | ||
const newPolls = new Map(prevPolls); | ||
newPolls.delete(inputKey); | ||
return newPolls; | ||
}); | ||
} | ||
} | ||
}, [usePollingOptions.input && JSON.stringify(usePollingOptions.input)]); | ||
|
||
// stop all polling on dismount | ||
useEffect(() => { | ||
return () => { | ||
for (const token of polls.values()) { | ||
usePollingOptions.stopPollingByPollingToken(token); | ||
} | ||
}; | ||
}, []); | ||
}; | ||
|
||
export default useMultiPolling; |
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,40 @@ | ||
import { useSelector } from 'react-redux'; | ||
import { | ||
getMarketData, | ||
getNetworkConfigurationsByChainId, | ||
getTokenExchangeRates, | ||
getTokensMarketData, | ||
getUseCurrencyRateCheck, | ||
} from '../selectors'; | ||
import { | ||
tokenRatesStartPolling, | ||
tokenRatesStopPollingByPollingToken, | ||
} from '../store/actions'; | ||
import useMultiPolling from './useMultiPolling'; | ||
|
||
const useTokenRatesPolling = ({ chainIds }: { chainIds?: string[] } = {}) => { | ||
// Selectors to determine polling input | ||
const useCurrencyRateCheck = useSelector(getUseCurrencyRateCheck); | ||
const networkConfigurations = useSelector(getNetworkConfigurationsByChainId); | ||
|
||
// Selectors returning state updated by the polling | ||
const tokenExchangeRates = useSelector(getTokenExchangeRates); | ||
const tokensMarketData = useSelector(getTokensMarketData); | ||
const marketData = useSelector(getMarketData); | ||
|
||
useMultiPolling({ | ||
startPolling: tokenRatesStartPolling, | ||
stopPollingByPollingToken: tokenRatesStopPollingByPollingToken, | ||
input: useCurrencyRateCheck | ||
? chainIds ?? Object.keys(networkConfigurations) | ||
: [], | ||
}); | ||
|
||
return { | ||
tokenExchangeRates, | ||
tokensMarketData, | ||
marketData, | ||
}; | ||
}; | ||
|
||
export default useTokenRatesPolling; |
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
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
Oops, something went wrong.