From b50556a589711459b9fa739bccccf913d96b071b Mon Sep 17 00:00:00 2001 From: Derek Guenther Date: Tue, 20 Aug 2024 16:20:55 -0400 Subject: [PATCH] Add support for setting an account as active --- packages/mobile-app/app/(tabs)/index.tsx | 34 ++++-- packages/mobile-app/app/account-select.tsx | 20 +++- .../app/account-settings/remove-account.tsx | 6 +- .../mobile-app/app/add-account/create.tsx | 6 +- .../app/add-account/import-encoded.tsx | 6 +- packages/mobile-app/app/onboarding/create.tsx | 47 ++++++++ .../app/onboarding/import-encoded.tsx | 75 ++++++++++++ packages/mobile-app/app/onboarding/index.tsx | 8 +- .../data/facades/wallet/demoHandlers.ts | 20 +++- .../data/facades/wallet/handlers.ts | 18 ++- .../mobile-app/data/facades/wallet/types.ts | 4 +- packages/mobile-app/data/wallet/db.ts | 111 +++++++++++++++++- packages/mobile-app/data/wallet/wallet.ts | 12 ++ 13 files changed, 333 insertions(+), 34 deletions(-) create mode 100644 packages/mobile-app/app/onboarding/create.tsx create mode 100644 packages/mobile-app/app/onboarding/import-encoded.tsx diff --git a/packages/mobile-app/app/(tabs)/index.tsx b/packages/mobile-app/app/(tabs)/index.tsx index 7d7bda4..e9efde3 100644 --- a/packages/mobile-app/app/(tabs)/index.tsx +++ b/packages/mobile-app/app/(tabs)/index.tsx @@ -1,5 +1,11 @@ import { StatusBar } from "expo-status-bar"; -import { ScrollView, StyleSheet, Text, View } from "react-native"; +import { + ActivityIndicator, + ScrollView, + StyleSheet, + Text, + View, +} from "react-native"; import { useFacade } from "../../data/facades"; import { useEffect, useState } from "react"; import { LinkButton } from "../../components/LinkButton"; @@ -17,23 +23,37 @@ export default function Balances() { ); const getAccountResult = facade.getAccount.useQuery( - { name: account }, + {}, { refetchInterval: 1000, }, ); - const getAccountsResult = facade.getAccounts.useQuery(); - const getWalletStatusResult = facade.getWalletStatus.useQuery(undefined, { refetchInterval: 1000, }); useEffect(() => { - if (getAccountsResult.data?.[0]) { - setAccount(getAccountsResult.data[0].name); + if (getAccountResult.data) { + setAccount(getAccountResult.data.name); } - }, [getAccountsResult.data]); + }, [getAccountResult.data]); + + if (getAccountResult.isLoading) { + return ( + + + + ); + } + + if (getAccountResult.data === null) { + return ( + + + + ); + } return ( diff --git a/packages/mobile-app/app/account-select.tsx b/packages/mobile-app/app/account-select.tsx index cbb4534..785a620 100644 --- a/packages/mobile-app/app/account-select.tsx +++ b/packages/mobile-app/app/account-select.tsx @@ -2,23 +2,41 @@ import { StatusBar } from "expo-status-bar"; import { Button, StyleSheet, Text, View } from "react-native"; import { useRouter } from "expo-router"; import { LinkButton } from "../components/LinkButton"; +import { useQueryClient } from "@tanstack/react-query"; import { useFacade } from "../data/facades"; export default function AccountSelect() { const router = useRouter(); const facade = useFacade(); + const qc = useQueryClient(); const getAccountsResult = facade.getAccounts.useQuery(undefined, { refetchInterval: 1000, }); + const setActiveAccount = facade.setActiveAccount.useMutation({ + onSuccess: async () => { + await qc.invalidateQueries(); + }, + }); + return (