mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-23 02:10:12 +01:00
88ae10418b
The `getProviderConfig` selector is now used anywhere the `provider` state was previously referenced directly. This was done to simplify renaming this state from `provider` to `providerConfig` in a later PR. Note that there are many opportunities left to use more-specific selectors (e.g. `getChainId()` over `getProviderConfig().chainId`), but that was intentionally omitted from this PR to reduce the size. I started going down this path and it quickly exploded in scope. Relates to #18902
37 lines
977 B
TypeScript
37 lines
977 B
TypeScript
import { useCallback } from 'react';
|
|
import { useSelector } from 'react-redux';
|
|
import type { Hex } from '@metamask/utils';
|
|
import { ChainId, CHAIN_IDS } from '../../../shared/constants/network';
|
|
import { getCurrentChainId } from '../../selectors';
|
|
|
|
interface IUseRamps {
|
|
openBuyCryptoInPdapp: VoidFunction;
|
|
getBuyURI: (chainId: ChainId) => string;
|
|
}
|
|
|
|
const portfolioUrl = process.env.PORTFOLIO_URL;
|
|
|
|
const useRamps = (): IUseRamps => {
|
|
const chainId = useSelector(getCurrentChainId);
|
|
|
|
const getBuyURI = useCallback((_chainId: Hex) => {
|
|
switch (_chainId) {
|
|
case CHAIN_IDS.SEPOLIA:
|
|
return 'https://faucet.sepolia.dev/';
|
|
default:
|
|
return `${portfolioUrl}/buy?metamaskEntry=ext_buy_button`;
|
|
}
|
|
}, []);
|
|
|
|
const openBuyCryptoInPdapp = useCallback(() => {
|
|
const buyUrl = getBuyURI(chainId);
|
|
global.platform.openTab({
|
|
url: buyUrl,
|
|
});
|
|
}, []);
|
|
|
|
return { openBuyCryptoInPdapp, getBuyURI };
|
|
};
|
|
|
|
export default useRamps;
|