mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 18:00:18 +01:00
5998ae21aa
* feat: disable deposit popover and replace it with global redirect to onramp on pdapp * feat: remove legacy code for hardcoded onramp providers * fix: remove unused visuals and components related to legacy code of deposit popover * fix: remove unused messages * feat: use a custom hook for all onramps related methods and variables * fix: modify the custom hook implementation to include test networks * fix: remove deprecated file buy-url * fix: remove references for deleted deposit logos * fix: network-controller failing unit test * fix: snapshot loading-swaps-quotes-stories-metadata.test.js.snap * fix: storybook tests * fix: remove unused constatns related to buyable onramp chains * fix: remove unused variables and fix eslint * adding unit test for useRamps custom hook * feat: add comment on the proper usage of useRamps within confirm-page-container component * fix: add unit tests for buy button in token-overview page * fix: add unit test for open the buy crypto URL for a buyable chain ID in token page * feat: add unit test coverage for eth-overview page * fix: update locales
38 lines
1016 B
TypeScript
38 lines
1016 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.GOERLI:
|
|
return 'https://goerli-faucet.slock.it/';
|
|
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;
|