mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
755b6b5667
Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com>
36 lines
937 B
TypeScript
36 lines
937 B
TypeScript
import { useCallback } from 'react';
|
|
import { useSelector } from 'react-redux';
|
|
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: ChainId) => {
|
|
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;
|