UNPKG

@reservoir0x/relay-kit-ui

Version:

Relay is the Fastest and Cheapest Way to Bridge and Transact Across Chains.

56 lines 2.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const react_1 = require("react"); const useMoonPayCurrencies_js_1 = tslib_1.__importDefault(require("./useMoonPayCurrencies.js")); const useIpAddress_js_1 = tslib_1.__importDefault(require("./useIpAddress.js")); const useMoonPayGeolocation_js_1 = tslib_1.__importDefault(require("./useMoonPayGeolocation.js")); const moonPay_js_1 = require("../utils/moonPay.js"); function useIsPassthrough(token, apiKey) { const { data: ipAddressResponse } = (0, useIpAddress_js_1.default)({ staleTime: Infinity, gcTime: Infinity }); const { data: geolocationResponse } = (0, useMoonPayGeolocation_js_1.default)({ apiKey, ipAddress: ipAddressResponse?.ip }, { staleTime: Infinity, gcTime: Infinity }); const { data: moonPayCurrencies } = (0, useMoonPayCurrencies_js_1.default)({ apiKey }, { staleTime: 1000 * 60 * 60 * 24, retryDelay: 1000 * 60 * 60 * 10 }); return (0, react_1.useMemo)(() => { const supportedCurrencies = (0, moonPay_js_1.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]); } exports.default = useIsPassthrough; //# sourceMappingURL=useIsPassthrough.js.map