-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathuseRampsCountries.ts
More file actions
47 lines (43 loc) · 1.21 KB
/
useRampsCountries.ts
File metadata and controls
47 lines (43 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { useSelector } from 'react-redux';
import { strings } from '../../../../../locales/i18n';
import { selectCountries } from '../../../../selectors/rampsController';
import { type Country } from '@metamask/ramps-controller';
import { parseUserFacingError } from '../utils/parseUserFacingError';
/**
* Result returned by the useRampsCountries hook.
*/
export interface UseRampsCountriesResult {
/**
* The list of countries available for ramp actions.
*/
countries: Country[];
/**
* Whether the countries request is currently loading.
*/
isLoading: boolean;
/**
* The error message if the request failed, or null.
*/
error: string | null;
}
/**
* Hook to get countries state from RampsController.
* This hook assumes Engine is already initialized.
*
* @returns Countries state.
*/
export function useRampsCountries(): UseRampsCountriesResult {
const countriesState = useSelector(selectCountries);
const { data: countries, isLoading, error } = countriesState;
return {
countries,
isLoading,
error: error
? parseUserFacingError(
countriesState,
strings('fiat_on_ramp.payment_error'),
)
: null,
};
}
export default useRampsCountries;