From 003d181d1ff59d63e11a36b7d2e28f768adf5b33 Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Wed, 11 Dec 2024 20:46:33 +0700 Subject: [PATCH 1/2] feat: refresh balance --- pages/Home.tsx | 100 +++++++++++++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 40 deletions(-) diff --git a/pages/Home.tsx b/pages/Home.tsx index 10bdca5..4ab7d63 100644 --- a/pages/Home.tsx +++ b/pages/Home.tsx @@ -6,6 +6,8 @@ import React, { useState } from "react"; import { Platform, Pressable, + RefreshControl, + ScrollView, StyleSheet, TouchableOpacity, View, @@ -33,6 +35,7 @@ enum BalanceState { export function Home() { const { data: balance, mutate: reloadBalance } = useBalance(); + const [refreshingBalance, setRefreshingBalance] = useState(false); const getFiatAmount = useGetFiatAmount(); const [balanceState, setBalanceState] = useState( BalanceState.SATS, @@ -42,6 +45,12 @@ export function Home() { reloadBalance(); }); + const refreshBalance = async () => { + setRefreshingBalance(true); + await reloadBalance(); + setRefreshingBalance(false); + }; + function switchBalanceState(): void { if (balanceState === BalanceState.SATS) { setBalanceState(BalanceState.FIAT); @@ -65,50 +74,61 @@ export function Home() { )} /> - - - - {balance ? ( - <> - + + } + contentContainerClassName="flex-1" + > + + + + {balance && !refreshingBalance ? ( + <> + + {balanceState === BalanceState.SATS && + new Intl.NumberFormat().format( + Math.floor(balance.balance / 1000), + )} + {balanceState === BalanceState.FIAT && + getFiatAmount && + getFiatAmount(Math.floor(balance.balance / 1000))} + {balanceState === BalanceState.HIDDEN && "****"} + + + {balanceState === BalanceState.SATS && "sats"} + + + ) : ( + + )} + + + {balance && !refreshingBalance ? ( + {balanceState === BalanceState.SATS && - new Intl.NumberFormat().format( - Math.floor(balance.balance / 1000), - )} - {balanceState === BalanceState.FIAT && getFiatAmount && getFiatAmount(Math.floor(balance.balance / 1000))} - {balanceState === BalanceState.HIDDEN && "****"} - - - {balanceState === BalanceState.SATS && "sats"} + {balanceState === BalanceState.FIAT && + new Intl.NumberFormat().format( + Math.floor(balance.balance / 1000), + ) + " sats"} - - ) : ( - - )} - - - {balance ? ( - - {balanceState === BalanceState.SATS && - getFiatAmount && - getFiatAmount(Math.floor(balance.balance / 1000))} - {balanceState === BalanceState.FIAT && - new Intl.NumberFormat().format( - Math.floor(balance.balance / 1000), - ) + " sats"} - - ) : ( - - )} - - - {new Date().getDate() === 21 && } - + ) : ( + + )} + + + {new Date().getDate() === 21 && } + +