-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: fiat currency picker * fix: replace data source with npm package * fix: remove save button --------- Co-authored-by: Roland Bewick <roland.bewick@gmail.com>
- Loading branch information
Showing
4 changed files
with
51 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,53 @@ | ||
import { router } from "expo-router"; | ||
import React from "react"; | ||
import { Keyboard, TouchableWithoutFeedback, View } from "react-native"; | ||
import Toast from "react-native-toast-message"; | ||
import { Button } from "~/components/ui/button"; | ||
import { Input } from "~/components/ui/input"; | ||
import { View, FlatList, TouchableOpacity } from "react-native"; | ||
import { Text } from "~/components/ui/text"; | ||
import { useAppStore } from "~/lib/state/appStore"; | ||
import Screen from "~/components/Screen"; | ||
import { cn } from "~/lib/utils"; | ||
import CurrencyList from 'currency-list'; | ||
import { router } from "expo-router"; | ||
import Toast from "react-native-toast-message"; | ||
|
||
const currencies: [string, string][] = Object.entries(CurrencyList.getAll("en_US")).map(([code, details]) => [code, details.name]); | ||
|
||
export function FiatCurrency() { | ||
const [fiatCurrency, setFiatCurrency] = React.useState( | ||
useAppStore.getState().fiatCurrency, | ||
); | ||
|
||
function select(iso: string) { | ||
setFiatCurrency(iso); | ||
useAppStore.getState().setFiatCurrency(fiatCurrency); | ||
Toast.show({ | ||
type: "success", | ||
text1: "Fiat currency updated", | ||
}); | ||
router.back(); | ||
} | ||
|
||
const renderCurrencyItem = ({ item }: { item: [string, string] }) => ( | ||
<TouchableOpacity | ||
className={cn("p-4 flex flex-row gap-2 border-b border-input", item[0] === fiatCurrency && "bg-muted")} | ||
onPress={() => select(item[0])} | ||
> | ||
<Text className={cn("text-lg", item[0] === fiatCurrency && "font-bold2")}> | ||
{item[1]} | ||
</Text> | ||
<Text className="text-lg text-muted-foreground"> | ||
({item[0]}) | ||
</Text> | ||
</TouchableOpacity> | ||
); | ||
|
||
return ( | ||
<View className="flex-1 flex flex-col p-6 gap-3"> | ||
<Screen | ||
title="Units & Currency" | ||
<View className="flex-1 flex flex-col p-6"> | ||
<Screen title="Fiat Currency" /> | ||
<FlatList | ||
data={currencies} | ||
renderItem={renderCurrencyItem} | ||
keyExtractor={(item) => item[0]} | ||
className="flex-1 mb-4" | ||
/> | ||
<TouchableWithoutFeedback | ||
onPress={() => { | ||
Keyboard.dismiss(); | ||
}} | ||
> | ||
<View className="flex-1"> | ||
<Input | ||
autoFocus | ||
className="w-full text-center" | ||
placeholder="USD" | ||
value={fiatCurrency} | ||
onChangeText={setFiatCurrency} | ||
returnKeyType="done" | ||
// aria-errormessage="inputError" | ||
/> | ||
</View> | ||
</TouchableWithoutFeedback> | ||
<Button | ||
size="lg" | ||
onPress={() => { | ||
useAppStore.getState().setFiatCurrency(fiatCurrency); | ||
Toast.show({ | ||
type: "success", | ||
text1: "Fiat currency updated", | ||
}); | ||
router.back(); | ||
}} | ||
> | ||
<Text>Save</Text> | ||
</Button> | ||
</View> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters