import React, { Component } from 'react'; import { FlatList, TouchableOpacity, ActivityIndicator, View } from 'react-native'; import { SafeBlueArea, BlueNavigationStyle, BlueListItem, BlueText, BlueCard } from '../../BlueComponents'; import PropTypes from 'prop-types'; import { Icon } from 'react-native-elements'; import { FiatUnit } from '../../models/fiatUnit'; let loc = require('../../loc'); let currency = require('../../currency'); export default class Currency extends Component { static navigationOptions = () => ({ ...BlueNavigationStyle(), title: loc.settings.currency, }); constructor(props) { super(props); this.state = { data: Object.values(FiatUnit), isSavingNewPreferredCurrency: false }; } async componentDidMount() { try { const preferredCurrency = await currency.getPreferredCurrency(); if (preferredCurrency === null) { throw Error(); } this.setState({ selectedCurrency: preferredCurrency }); } catch (_error) { this.setState({ selectedCurrency: FiatUnit.USD }); } } renderItem = ({ item }) => { return ( { this.setState({ isSavingNewPreferredCurrency: true, selectedCurrency: item }, async () => { await currency.setPrefferedCurrency(item); await currency.startUpdater(); this.setState({ isSavingNewPreferredCurrency: false }); }); }} > ) : ( ), } : { hideChevron: true })} /> ); }; render() { if (this.state.selectedCurrency !== null && this.state.selectedCurrency !== undefined) { return ( `${index}`} data={this.state.data} extraData={this.state.data} renderItem={this.renderItem} /> Prices are obtained from CoinDesk ); } return ( ); } } Currency.propTypes = { navigation: PropTypes.shape({ navigate: PropTypes.func, goBack: PropTypes.func, }), };