mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-26 20:39:08 +01:00
37af04374a
Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com>
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
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, getMetaMetricsId } from '../../selectors';
|
|
|
|
interface IUseRamps {
|
|
openBuyCryptoInPdapp: VoidFunction;
|
|
getBuyURI: (chainId: ChainId) => string;
|
|
}
|
|
|
|
const portfolioUrl = process.env.PORTFOLIO_URL;
|
|
|
|
const useRamps = (): IUseRamps => {
|
|
const chainId = useSelector(getCurrentChainId);
|
|
const metaMetricsId = useSelector(getMetaMetricsId);
|
|
|
|
const getBuyURI = useCallback((_chainId: Hex) => {
|
|
switch (_chainId) {
|
|
case CHAIN_IDS.SEPOLIA:
|
|
return 'https://faucet.sepolia.dev/';
|
|
default: {
|
|
const params = new URLSearchParams();
|
|
params.set('metamaskEntry', 'ext_buy_button');
|
|
if (metaMetricsId) {
|
|
params.set('metametricsId', metaMetricsId);
|
|
}
|
|
return `${portfolioUrl}/buy?${params.toString()}`;
|
|
}
|
|
}
|
|
}, []);
|
|
|
|
const openBuyCryptoInPdapp = useCallback(() => {
|
|
const buyUrl = getBuyURI(chainId);
|
|
global.platform.openTab({
|
|
url: buyUrl,
|
|
});
|
|
}, []);
|
|
|
|
return { openBuyCryptoInPdapp, getBuyURI };
|
|
};
|
|
|
|
export default useRamps;
|