Skip to content

Commit

Permalink
Merge pull request #118 from spacemeshos/tweak-show-projected-balance
Browse files Browse the repository at this point in the history
Show projected balance when there is pending transactions
  • Loading branch information
brusherru authored Dec 19, 2024
2 parents 92a7516 + 32cced6 commit 5ad6fef
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 5 deletions.
76 changes: 71 additions & 5 deletions src/screens/WalletScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,26 @@ import {
Flex,
Icon,
IconButton,
keyframes,
Spacer,
Spinner,
Tab,
Table,
TabList,
TabPanels,
Tabs,
Tbody,
Td,
Text,
Tooltip,
Tr,
useBreakpointValue,
useDisclosure,
} from '@chakra-ui/react';
import { O, pipe } from '@mobily/ts-belt';
import {
IconHelp,
IconHourglassEmpty,
IconLockOpen2,
IconQrcode,
IconRefresh,
Expand Down Expand Up @@ -53,6 +61,11 @@ import useNetworks from '../store/useNetworks';
import { Transaction } from '../types/tx';
import { formatSmidge } from '../utils/smh';

const spin = keyframes`
85% {transform: rotate(0deg);}
100% {transform: rotate(360deg)}
`;

function WalletScreen(): JSX.Element {
const { isLoading, refreshData } = useDataRefresher();

Expand Down Expand Up @@ -85,8 +98,11 @@ function WalletScreen(): JSX.Element {
);
const balance = O.mapWithDefault(
accountData,
'0',
([account]) => account.state.current.balance
{ current: '0', projected: '0' },
([account]) => ({
current: account.state.current.balance,
projected: account.state.projected.balance,
})
);

const refreshIconSize = useBreakpointValue(
Expand All @@ -97,9 +113,11 @@ function WalletScreen(): JSX.Element {
const unlockedBalance = useVaultBalance(
currentAccount,
currentNetwork,
BigInt(balance)
BigInt(balance.current)
);

const pendingBalance = balance.projected !== balance.current;

return (
<Flex
direction="column"
Expand Down Expand Up @@ -171,9 +189,23 @@ function WalletScreen(): JSX.Element {
<Text
as="b"
fontSize={{ base: '32px', md: '40px' }}
title={`${balance} Smidge`}
title={`${
pendingBalance
? `Available balance: ${balance.projected} Smidge\n`
: ''
}Actual balance: ${balance.current} Smidge`}
color={pendingBalance ? 'orange' : 'white'}
>
{formatSmidge(balance)}
{pendingBalance ? (
<Icon
as={IconHourglassEmpty}
display="inline-block"
boxSize={{ base: 6, md: 7 }}
mb={{ base: '-1px', md: 0 }}
animation={`${spin} 4s linear infinite`}
/>
) : null}
{formatSmidge(balance.projected)}
</Text>
<IconButton
ml={4}
Expand All @@ -192,6 +224,40 @@ function WalletScreen(): JSX.Element {
verticalAlign="text-bottom"
/>
</Flex>
{pendingBalance && (
<Text fontSize="sm" color="orange" mt={-1} mb={2} mr={10}>
Pending transactions...
<Tooltip
maxW="80vw"
label={
<Table size="sm" variant="unstyled" whiteSpace="nowrap">
<Tbody>
<Tr>
<Td pl={0} pr={2} fontSize="xs">
Pending balance:
</Td>
<Td pl={2} pr={0}>
{balance.projected} Smidge
</Td>
</Tr>
<Tr>
<Td pl={0} pr={2} fontSize="xs">
Current balance:
</Td>
<Td pl={2} pr={0}>
{balance.current} Smidge
</Td>
</Tr>
</Tbody>
</Table>
}
>
<Text display="inline-block" ml={1}>
<IconHelp size={14} style={{ marginBottom: '-2px' }} />
</Text>
</Tooltip>
</Text>
)}
{O.mapWithDefault(
unlockedBalance,
// eslint-disable-next-line react/jsx-no-useless-fragment
Expand Down
2 changes: 2 additions & 0 deletions src/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import modalTheme from './theme/modal';
import radioTheme from './theme/radio';
import selectTheme from './theme/select';
import tabsTheme from './theme/tabs';
import tooltipTheme from './theme/tooltip';

const config: ThemeConfig = {
initialColorMode: 'dark',
Expand Down Expand Up @@ -51,6 +52,7 @@ const components = {
Input: inputTheme,
Select: selectTheme,
FormLabel: formLabelTheme,
Tooltip: tooltipTheme,
};
const theme = extendTheme({ config, colors, components, styles });

Expand Down
12 changes: 12 additions & 0 deletions src/theme/tooltip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineStyleConfig } from '@chakra-ui/react';

const tooltipTheme = defineStyleConfig({
baseStyle: {
borderRadius: 'md',
fontWeight: 'normal',
bg: 'brand.lightGray',
textColor: 'brand.darkGreen',
},
});

export default tooltipTheme;

0 comments on commit 5ad6fef

Please sign in to comment.