-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
141 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Box, Link, Pressable, Text } from 'native-base'; | ||
|
||
type ActionButtonProps = { | ||
href?: string; | ||
text: string; | ||
bg: string; | ||
textColor: string; | ||
onPress?: any; | ||
buttonStyles?: any; | ||
}; | ||
|
||
const ActionButton = ({ href, text, bg, textColor, onPress, buttonStyles }: ActionButtonProps) => { | ||
const { buttonContainer, button, buttonText } = buttonStyles ?? {}; | ||
|
||
const content = ( | ||
<Pressable {...button} onPress={onPress} backgroundColor={bg}> | ||
<Text {...buttonText} color={textColor}> | ||
{text} | ||
</Text> | ||
</Pressable> | ||
); | ||
|
||
if (href) { | ||
return ( | ||
<Link {...buttonContainer} href={href} isExternal={true}> | ||
{content} | ||
</Link> | ||
); | ||
} | ||
|
||
return <Box {...buttonContainer}>{content}</Box>; | ||
}; | ||
|
||
export default ActionButton; |
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,38 @@ | ||
import { useMemo } from 'react'; | ||
|
||
import { useSubgraphTotalStats } from '../subgraph'; | ||
import { formatGoodDollarAmount } from '../lib/calculateGoodDollarAmounts'; | ||
|
||
type StatsFormatted = { | ||
amount: string; | ||
copy: string; | ||
}; | ||
type TotalStats = { | ||
totalDonations: StatsFormatted; | ||
totalPools: StatsFormatted; | ||
totalMembers: StatsFormatted; | ||
}; | ||
|
||
export const useTotalStats = (): TotalStats | undefined => { | ||
const stats = useSubgraphTotalStats(); | ||
|
||
return useMemo(() => { | ||
const totalDonations = stats?.collectives?.reduce((acc, collective) => acc + Number(collective.totalDonations), 0); | ||
const donationsFormatted = formatGoodDollarAmount(totalDonations?.toString() ?? '0'); | ||
|
||
return { | ||
totalPools: { | ||
amount: stats?.activeCollectives?.length.toString() ?? '0', | ||
copy: 'GoodCollective pools', | ||
}, | ||
totalDonations: { | ||
amount: 'G$ ' + donationsFormatted, | ||
copy: 'Total Donations', | ||
}, | ||
totalMembers: { | ||
amount: stats?.stewards?.length.toString() ?? '0', | ||
copy: 'GoodCollective Members Paid', | ||
}, | ||
}; | ||
}, [stats]); | ||
}; |
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,22 @@ | ||
import { gql } from '@apollo/client'; | ||
import { TotalStatsCollectivesResponse, useSubgraphData } from './useSubgraphData'; | ||
|
||
const collectivesTotalStats = gql` | ||
query COLLECTIVES_TOTAL_STATS { | ||
stewards(where: { or: [{ totalEarned_gt: 0 }, { totalUBIEarned_gt: 0 }] }) { | ||
id | ||
} | ||
collectives(where: { totalDonations_gt: 0 }) { | ||
totalDonations | ||
} | ||
activeCollectives: collectives { | ||
id | ||
} | ||
} | ||
`; | ||
|
||
export function useSubgraphTotalStats(): TotalStatsCollectivesResponse | undefined { | ||
const response = useSubgraphData(collectivesTotalStats); | ||
|
||
return response as TotalStatsCollectivesResponse; | ||
} |
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