Skip to content

Commit

Permalink
Just use user cash balance for redeemable
Browse files Browse the repository at this point in the history
  • Loading branch information
IanPhilips committed Feb 12, 2025
1 parent 01082ae commit ca88ffd
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 14 deletions.
7 changes: 2 additions & 5 deletions mani/app/redeem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,8 @@ export default function CashoutPage() {
setSessionStatus(StatusMessage as string)
},
})
const redeemable = useAPIGetter('get-redeemable-prize-cash', {})
useEffect(() => {
redeemable?.refresh()
}, [user?.balance, user?.cashBalance])
const redeemableCash = redeemable?.data?.redeemablePrizeCash ?? 0

const redeemableCash = user?.cashBalance ?? 0

const roundedRedeemableCash = Math.floor(redeemableCash * 100) / 100
const {
Expand Down
3 changes: 1 addition & 2 deletions mani/components/profile/profile-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export function ProfileContent(props: { user: User }) {
const { user } = props
const currentUser = useUser()
const isCurrentUser = currentUser?.id === user.id
const { data: redeemable } = useAPIGetter('get-redeemable-prize-cash', {})
const [isSettingsOpen, setIsSettingsOpen] = useState(false)

const { data } = useAPIGetter('get-daily-changed-metrics-and-contracts', {
Expand Down Expand Up @@ -120,7 +119,7 @@ export function ProfileContent(props: { user: User }) {
<Button
onPress={() => router.push('/redeem')}
title={`Redeem ${formatMoneyVerbatim(
redeemable?.redeemablePrizeCash ?? 0,
user?.cashBalance ?? 0,
'CASH'
)}`}
variant="gray"
Expand Down
5 changes: 1 addition & 4 deletions web/pages/charity/[charitySlug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { FullscreenConfetti } from 'web/components/widgets/fullscreen-confetti'
import { Linkify } from 'web/components/widgets/linkify'
import { PaginationNextPrev } from 'web/components/widgets/pagination'
import { Title } from 'web/components/widgets/title'
import { useAPIGetter } from 'web/hooks/use-api-getter'
import { usePagination } from 'web/hooks/use-pagination'
import { useUser } from 'web/hooks/use-user'
import { api, APIError } from 'web/lib/api/api'
Expand Down Expand Up @@ -183,8 +182,7 @@ function DonationBox(props: {
}) {
const { user, charity, onDonated } = props

const { data, refresh } = useAPIGetter('get-redeemable-prize-cash', {})
const redeemableCash = data?.redeemablePrizeCash ?? 0
const redeemableCash = user?.cashBalance ?? 0

const [amount, setAmount] = useState<number | undefined>()
const [isSubmitting, setIsSubmitting] = useState(false)
Expand Down Expand Up @@ -219,7 +217,6 @@ function DonationBox(props: {
setAmount(undefined)
onDonated?.(user, Date.now(), amount)
track('donation', { charityId: charity.id, amount })
await refresh()
}

return (
Expand Down
4 changes: 1 addition & 3 deletions web/pages/redeem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ export default function CashoutPage() {
setSessionStatus(StatusMessage as string)
},
})
const redeemable = useAPIGetter('get-redeemable-prize-cash', {})
const redeemableCash = redeemable?.data?.redeemablePrizeCash
const redeemableCash = user?.cashBalance

const roundedRedeemableCash = Math.floor((redeemableCash ?? 0) * 100) / 100
const {
Expand Down Expand Up @@ -193,7 +192,6 @@ export default function CashoutPage() {
setError(message)
} else {
setPage('waiting')
redeemable.refresh()
}
} catch (err) {
if (err instanceof APIError) {
Expand Down

0 comments on commit ca88ffd

Please sign in to comment.