From 13cd974c50ffbca26f2d89efda18078cfd536531 Mon Sep 17 00:00:00 2001 From: sirpy Date: Mon, 16 Dec 2024 15:21:55 +0200 Subject: [PATCH] add: consolidate components into one --- .../app/src/components/GoodDollarAmount.tsx | 5 +- .../WalletDetails/BothWalletDetails.tsx | 117 ++++++++++-------- .../WalletDetails/DonorWalletDetails.tsx | 71 ----------- .../WalletDetails/StewardWalletDetails.tsx | 54 -------- .../WalletDetails/WalletDetails.tsx | 8 +- 5 files changed, 74 insertions(+), 181 deletions(-) delete mode 100644 packages/app/src/components/WalletDetails/DonorWalletDetails.tsx delete mode 100644 packages/app/src/components/WalletDetails/StewardWalletDetails.tsx diff --git a/packages/app/src/components/GoodDollarAmount.tsx b/packages/app/src/components/GoodDollarAmount.tsx index 429e47d9..f348a2ef 100644 --- a/packages/app/src/components/GoodDollarAmount.tsx +++ b/packages/app/src/components/GoodDollarAmount.tsx @@ -6,10 +6,11 @@ import { formatGoodDollarAmount } from '../lib/calculateGoodDollarAmounts'; interface FlowingBalanceProps extends TextProps { amount: string; lastDigitsProps?: TextProps; + decimals?: number; } -export const GoodDollarAmount: FC = ({ amount, lastDigitsProps, ...props }) => { - const formatted = formatGoodDollarAmount(amount); +export const GoodDollarAmount: FC = ({ amount, lastDigitsProps, decimals = 4, ...props }) => { + const formatted = formatGoodDollarAmount(amount, decimals); return ( <> diff --git a/packages/app/src/components/WalletDetails/BothWalletDetails.tsx b/packages/app/src/components/WalletDetails/BothWalletDetails.tsx index 4f21c89e..3a6c0b98 100644 --- a/packages/app/src/components/WalletDetails/BothWalletDetails.tsx +++ b/packages/app/src/components/WalletDetails/BothWalletDetails.tsx @@ -9,81 +9,100 @@ import { useCountPeopleSupported } from '../../hooks/useCountPeopleSupported'; import { GoodDollarAmount } from '../GoodDollarAmount'; interface BothWalletDetailsProps { - donor: Donor; - steward: Steward; + donor?: Donor; + steward?: Steward; tokenPrice?: number; + firstName: string; } -function BothWalletDetails({ donor, steward, tokenPrice }: BothWalletDetailsProps) { +function BothWalletDetails({ donor, steward, tokenPrice, firstName }: BothWalletDetailsProps) { const { wei: formattedDonations, usdValue: donationsUsdValue } = useDonorCollectivesFlowingBalances( - donor.collectives, + donor?.collectives || [], tokenPrice ); const { formatted: formattedRewards, usdValue: rewardsUsdValue } = calculateGoodDollarAmounts( - steward.totalEarned, - tokenPrice, - 2 + steward?.totalEarned || '0', + tokenPrice ); - const peopleSupported = useCountPeopleSupported(donor.collectives) ?? 0; + const peopleSupported = useCountPeopleSupported(donor?.collectives || []) ?? 0; const nCollectives = countUniqueValuesInTwoArrays( - steward.collectives.map((c) => c.collective), - donor.collectives.map((d) => d.collective) + steward?.collectives.map((c) => c.collective) || [], + donor?.collectives.map((d) => d.collective) || [] ); return ( - - - - This wallet has donated a total of + {donor && ( + <> - G$ - + + + {firstName} has donated a total of + + G$ + + + = {donationsUsdValue} USD + - = {donationsUsdValue} USD - - - - - - Since - {formatTime(donor.joined)} - - - - - - - This wallet's funding supported - {peopleSupported} - people + + + Since + {formatTime(donor.joined)} + - - - - - - And received - G$ - {formattedRewards} + + + {firstName}'s funding supported + + {peopleSupported} + people + + + + + )} + {steward && ( + <> + + + + {firstName} has performed + + {steward?.actions} + actions + + - = {rewardsUsdValue} USD - - + + + + And has received + + G$ + {formattedRewards} + + = {rewardsUsdValue} USD + + + + )} - + in the following diff --git a/packages/app/src/components/WalletDetails/DonorWalletDetails.tsx b/packages/app/src/components/WalletDetails/DonorWalletDetails.tsx deleted file mode 100644 index 01b347f9..00000000 --- a/packages/app/src/components/WalletDetails/DonorWalletDetails.tsx +++ /dev/null @@ -1,71 +0,0 @@ -import { Text, View } from 'react-native'; -import { Donor } from '../../models/models'; -import { styles } from './styles'; -import { formatTime } from '../../lib/formatTime'; -import { useDonorCollectivesFlowingBalances } from '../../hooks/useFlowingBalance'; -import { useCountPeopleSupported } from '../../hooks/useCountPeopleSupported'; -import { GoodDollarAmount } from '../GoodDollarAmount'; - -interface DonorWalletDetailsProps { - firstName: string; - donor: Donor; - tokenPrice?: number; -} - -function DonorWalletDetails({ firstName, donor, tokenPrice }: DonorWalletDetailsProps) { - const { wei: formattedDonations, usdValue } = useDonorCollectivesFlowingBalances(donor.collectives, tokenPrice); - - const peopleSupported = useCountPeopleSupported(donor.collectives) ?? 0; - - return ( - - - - - {firstName} has donated a total of - - G$ - - - = {usdValue} USD - - - - - - - Since - {formatTime(donor.joined)} - - - - - - - {firstName}'s funding supported - - {peopleSupported} - people - - - - - - - - in the following - - {donor.collectives.length} - collectives - - - - - ); -} - -export default DonorWalletDetails; diff --git a/packages/app/src/components/WalletDetails/StewardWalletDetails.tsx b/packages/app/src/components/WalletDetails/StewardWalletDetails.tsx deleted file mode 100644 index 359af860..00000000 --- a/packages/app/src/components/WalletDetails/StewardWalletDetails.tsx +++ /dev/null @@ -1,54 +0,0 @@ -import { Text, View } from 'react-native'; -import { Steward } from '../../models/models'; -import { styles } from './styles'; -import { calculateGoodDollarAmounts } from '../../lib/calculateGoodDollarAmounts'; - -interface StewardWalletDetailsProps { - firstName: string; - steward: Steward; - tokenPrice?: number; -} - -function StewardWalletDetails({ firstName, steward, tokenPrice }: StewardWalletDetailsProps) { - const { formatted: formattedRewards, usdValue } = calculateGoodDollarAmounts(steward.totalEarned, tokenPrice, 2); - - return ( - - - - - {firstName} has performed - - {steward?.actions} - actions - - - - - - - - And has received - - G$ - {formattedRewards} - - = {usdValue} USD - - - - - - - from the following - - {steward.collectives.length} - Collectives - - - - - ); -} - -export default StewardWalletDetails; diff --git a/packages/app/src/components/WalletDetails/WalletDetails.tsx b/packages/app/src/components/WalletDetails/WalletDetails.tsx index 9805157b..08bf8ac8 100644 --- a/packages/app/src/components/WalletDetails/WalletDetails.tsx +++ b/packages/app/src/components/WalletDetails/WalletDetails.tsx @@ -1,8 +1,6 @@ import EmptyProfile from './EmptyProfile'; import { Donor, Steward } from '../../models/models'; -import StewardWalletDetails from './StewardWalletDetails'; import BothWalletDetails from './BothWalletDetails'; -import DonorWalletDetails from './DonorWalletDetails'; interface WalletDetailsProps { firstName: string; @@ -12,9 +10,9 @@ interface WalletDetailsProps { } function WalletDetails({ firstName, donor, steward, tokenPrice }: WalletDetailsProps) { - if (!!donor && !!steward) return ; - else if (donor) return ; - else if (steward) return ; + if (!!donor || !!steward) + return ; + return ; }