-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mobile): allow user select default currency
- Loading branch information
Showing
13 changed files
with
239 additions
and
127 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
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
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
72 changes: 72 additions & 0 deletions
72
apps/mobile/components/setting/select-default-currency.tsx
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { BottomSheetBackdrop, BottomSheetModal } from '@gorhom/bottom-sheet' | ||
import { useRef } from 'react' | ||
|
||
import { useColorScheme } from '@/hooks/useColorScheme' | ||
import { theme } from '@/lib/theme' | ||
import { sleep } from '@/lib/utils' | ||
import { useDefaultCurrency } from '@/stores/user-settings/hooks' | ||
import { useUserSettingsStore } from '@/stores/user-settings/store' | ||
import { t } from '@lingui/macro' | ||
import { useLingui } from '@lingui/react' | ||
import { ChevronRightIcon, CurrencyIcon } from 'lucide-react-native' | ||
import { Keyboard, View } from 'react-native' | ||
import { FullWindowOverlay } from 'react-native-screens' | ||
import { CurrencySheetList } from '../common/currency-sheet' | ||
import { MenuItem } from '../common/menu-item' | ||
import { Text } from '../ui/text' | ||
|
||
export function SelectDefaultCurrency() { | ||
const { i18n } = useLingui() | ||
const sheetRef = useRef<BottomSheetModal>(null) | ||
const defaultCurrency = useDefaultCurrency() | ||
const setPreferredCurrency = useUserSettingsStore().setPreferredCurrency | ||
const { colorScheme } = useColorScheme() | ||
return ( | ||
<> | ||
<MenuItem | ||
label={t(i18n)`Default currency`} | ||
icon={CurrencyIcon} | ||
onPress={() => { | ||
Keyboard.dismiss() | ||
sheetRef.current?.present() | ||
}} | ||
rightSection={ | ||
<View className="flex flex-row items-center gap-2"> | ||
<Text className="text-muted-foreground font-sans"> | ||
{defaultCurrency} | ||
</Text> | ||
<ChevronRightIcon className="w-5 h-5 text-primary" /> | ||
</View> | ||
} | ||
/> | ||
<BottomSheetModal | ||
ref={sheetRef} | ||
index={0} | ||
snapPoints={['50%', '87%']} | ||
enablePanDownToClose | ||
backgroundStyle={{ backgroundColor: theme[colorScheme].background }} | ||
keyboardBehavior="extend" | ||
backdropComponent={(props) => ( | ||
<BottomSheetBackdrop | ||
{...props} | ||
appearsOnIndex={0} | ||
disappearsOnIndex={-1} | ||
enableTouchThrough | ||
/> | ||
)} | ||
containerComponent={(props) => ( | ||
<FullWindowOverlay>{props.children}</FullWindowOverlay> | ||
)} | ||
> | ||
<CurrencySheetList | ||
value={defaultCurrency} | ||
onSelect={async (currency) => { | ||
sheetRef.current?.close() | ||
await sleep(500) | ||
setPreferredCurrency?.(currency.code) | ||
}} | ||
/> | ||
</BottomSheetModal> | ||
</> | ||
) | ||
} |
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
Oops, something went wrong.