@reservoir0x/relay-kit-ui
Version:
Relay is the Fastest and Cheapest Way to Bridge and Transact Across Chains.
53 lines • 2.15 kB
JavaScript
import { useMemo } from 'react';
import useMoonPayCurrencies from './useMoonPayCurrencies.js';
import useIpAddress from './useIpAddress.js';
import useMoonPayGeolocation from './useMoonPayGeolocation.js';
import _moonPayCurrencies from '../constants/moonPayCurrencies.js';
import { convertSupportedCurrencies } from '../utils/moonPay.js';
export default function useIsPassthrough(token, apiKey) {
const { data: ipAddressResponse } = useIpAddress({
staleTime: Infinity,
gcTime: Infinity
});
const { data: geolocationResponse } = useMoonPayGeolocation({
apiKey,
ipAddress: ipAddressResponse?.ip
}, {
staleTime: Infinity,
gcTime: Infinity
});
const { data: moonPayCurrencies } = useMoonPayCurrencies({ apiKey }, {
staleTime: 1000 * 60 * 60 * 24, //1 day
retryDelay: 1000 * 60 * 60 * 10 //10 minutes
});
return useMemo(() => {
const supportedCurrencies = convertSupportedCurrencies(moonPayCurrencies);
const currency = supportedCurrencies.find((currency) => currency.chainId === `${token.chainId}` &&
currency.contractAddress === token.address.toLowerCase());
if (currency) {
const countryCode = geolocationResponse?.alpha2;
const state = geolocationResponse?.state;
if (countryCode) {
const unsupportedCountry = currency.notAllowedCountries.includes(countryCode);
const unsupportedState = countryCode === 'US' &&
state &&
currency.notAllowedUSStates.includes(state);
return {
isPassthrough: !unsupportedCountry && !unsupportedState,
moonPayCurrency: currency
};
}
else {
return {
isPassthrough: false,
moonPayCurrency: null
};
}
}
return {
isPassthrough: false,
moonPayCurrency: null
};
}, [token, moonPayCurrencies, geolocationResponse]);
}
//# sourceMappingURL=useIsPassthrough.js.map