-
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): [Wallet] add basic account form with icon and currency …
…input
- Loading branch information
Showing
36 changed files
with
1,931 additions
and
123 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { AddNewButton } from '@/components/common/add-new-button' | ||
import { Text } from '@/components/ui/text' | ||
import { WalletAccountItem } from '@/components/wallet/wallet-account-item' | ||
import { useWallets } from '@/queries/wallet' | ||
import { t } from '@lingui/macro' | ||
import { useLingui } from '@lingui/react' | ||
import { useRouter } from 'expo-router' | ||
import { FlatList } from 'react-native' | ||
|
||
export default function WalletAccountsScreen() { | ||
const { i18n } = useLingui() | ||
const { data: walletAccounts, isLoading, refetch } = useWallets() | ||
const router = useRouter() | ||
return ( | ||
<FlatList | ||
className="bg-card" | ||
contentContainerClassName="py-3" | ||
data={walletAccounts} | ||
renderItem={({ item }) => ( | ||
<WalletAccountItem | ||
// Date is typed as string in rpc output, not sure why | ||
// biome-ignore lint/suspicious/noExplicitAny: <explanation> | ||
data={item as any} | ||
/> | ||
)} | ||
keyExtractor={(item) => item.id} | ||
refreshing={isLoading} | ||
onRefresh={refetch} | ||
ListFooterComponent={ | ||
<AddNewButton | ||
label={t(i18n)`New account`} | ||
onPress={() => router.push('/wallet/new-account')} | ||
/> | ||
} | ||
ListEmptyComponent={ | ||
<Text className="font-sans text-muted-foreground text-center mt-6 mb-9"> | ||
{t(i18n)`empty`} | ||
</Text> | ||
} | ||
/> | ||
) | ||
} |
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,62 @@ | ||
import { AccountForm } from '@/components/wallet/account-form' | ||
import { createWallet } from '@/mutations/wallet' | ||
import { walletQueries } from '@/queries/wallet' | ||
import { useMutation, useQueryClient } from '@tanstack/react-query' | ||
import { useRouter } from 'expo-router' | ||
import { Alert, ScrollView } from 'react-native' | ||
|
||
export default function NewAccountScreen() { | ||
const queryClient = useQueryClient() | ||
const router = useRouter() | ||
const { mutateAsync } = useMutation({ | ||
mutationFn: createWallet, | ||
async onMutate(newWallet) { | ||
// Cancel any outgoing refetches | ||
// (so they don't overwrite our optimistic update) | ||
await queryClient.cancelQueries({ | ||
queryKey: walletQueries.list().queryKey, | ||
}) | ||
// Snapshot the previous value | ||
const previousWallets = queryClient.getQueryData( | ||
walletQueries.list().queryKey, | ||
) | ||
// Optimistically update to the new value | ||
// biome-ignore lint/suspicious/noExplicitAny: <explanation> | ||
queryClient.setQueryData(walletQueries.list().queryKey, (old: any) => [ | ||
...old, | ||
newWallet, | ||
]) | ||
// Return a context object with the snapshotted value | ||
return { previousWallets } | ||
}, | ||
onError(error, _, context) { | ||
Alert.alert(error.message) | ||
// use the context returned from onMutate to rollback | ||
queryClient.setQueryData( | ||
walletQueries.list().queryKey, | ||
context?.previousWallets, | ||
) | ||
}, | ||
onSuccess() { | ||
router.back() | ||
}, | ||
async onSettled() { | ||
// Always refetch after error or success: | ||
await queryClient.invalidateQueries({ | ||
queryKey: walletQueries._def, | ||
}) | ||
}, | ||
throwOnError: true, | ||
}) | ||
|
||
return ( | ||
<ScrollView | ||
className="bg-card flex-1" | ||
contentContainerClassName="gap-4 p-6" | ||
automaticallyAdjustKeyboardInsets | ||
keyboardShouldPersistTaps="handled" | ||
> | ||
<AccountForm onSubmit={mutateAsync} /> | ||
</ScrollView> | ||
) | ||
} |
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,45 @@ | ||
import { BackButton } from '@/components/common/back-button' | ||
import { useColorScheme } from '@/hooks/useColorScheme' | ||
import { theme } from '@/lib/theme' | ||
import { t } from '@lingui/macro' | ||
import { useLingui } from '@lingui/react' | ||
import { Stack } from 'expo-router' | ||
|
||
export default function AuxiliaryLayout() { | ||
const { colorScheme } = useColorScheme() | ||
const { i18n } = useLingui() | ||
return ( | ||
<Stack | ||
screenOptions={{ | ||
headerShown: true, | ||
headerBackTitleVisible: false, | ||
headerTintColor: theme[colorScheme ?? 'light'].primary, | ||
headerShadowVisible: false, | ||
headerTitleStyle: { | ||
fontFamily: 'Be Vietnam Pro Medium', | ||
fontSize: 16, | ||
color: theme[colorScheme ?? 'light'].primary, | ||
}, | ||
headerStyle: { | ||
backgroundColor: theme[colorScheme ?? 'light'].background, | ||
}, | ||
headerLeft: () => <BackButton />, | ||
}} | ||
> | ||
<Stack.Screen | ||
name="privacy-policy" | ||
options={{ | ||
presentation: 'modal', | ||
headerTitle: t(i18n)`Privacy Policy`, | ||
}} | ||
/> | ||
<Stack.Screen | ||
name="terms-of-service" | ||
options={{ | ||
presentation: 'modal', | ||
headerTitle: t(i18n)`Terms & Conditions`, | ||
}} | ||
/> | ||
</Stack> | ||
) | ||
} |
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,5 +1,9 @@ | ||
import { Text } from 'react-native' | ||
|
||
export default function PrivacyScreen() { | ||
return <Text className="font-sans m-4 mx-auto">Privacy Policy</Text> | ||
return ( | ||
<Text className="font-sans m-4"> | ||
lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. | ||
</Text> | ||
) | ||
} |
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
Oops, something went wrong.