UNPKG

@reservoir0x/relay-kit-ui

Version:

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

65 lines 3.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const react_1 = require("react"); const useIpAddress_js_1 = tslib_1.__importDefault(require("./useIpAddress.js")); const useMoonPayCurrencies_js_1 = tslib_1.__importDefault(require("./useMoonPayCurrencies.js")); const useMoonPayGeolocation_js_1 = tslib_1.__importDefault(require("./useMoonPayGeolocation.js")); const moonPay_js_1 = require("../utils/moonPay.js"); function useSupportedMoonPayCurrencyCode(codes, apiKey, token) { 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 supportedCurrenciesMap = supportedCurrencies.reduce((map, currency) => { map[currency.code] = currency; return map; }, {}); let supportedMoonPayCurrencyCode; if (!geolocationResponse) { supportedMoonPayCurrencyCode = codes.find((code) => { const currency = supportedCurrenciesMap[code]; return token?.chainId ? currency && currency.chainId !== `${token.chainId}` : currency !== undefined; }); } else { supportedMoonPayCurrencyCode = codes.find((code) => { const currency = supportedCurrenciesMap[code]; 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 (!unsupportedCountry && !unsupportedState && (token?.chainId ? currency.chainId !== `${token.chainId}` : true)); } else { return false; } } }); } return supportedCurrenciesMap[supportedMoonPayCurrencyCode ?? 'eth']; }, [codes, moonPayCurrencies, geolocationResponse, token]); } exports.default = useSupportedMoonPayCurrencyCode; //# sourceMappingURL=useSupportedMoonPayCurrencyCode.js.map