Skip to content

Commit

Permalink
Fix cache & loan repayment in place-bet
Browse files Browse the repository at this point in the history
  • Loading branch information
IanPhilips committed Dec 4, 2024
1 parent d06f08c commit 0e289a1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
9 changes: 4 additions & 5 deletions backend/api/src/get-next-loan-amount.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { type APIHandler } from './helpers/endpoint'
import { getNextLoanAmountResults } from 'api/request-loan'

export const getNextLoanAmount: APIHandler<'get-next-loan-amount'> = async (
_,
auth
) => {
export const getNextLoanAmount: APIHandler<'get-next-loan-amount'> = async ({
userId,
}) => {
try {
const { result } = await getNextLoanAmountResults(auth.uid)
const { result } = await getNextLoanAmountResults(userId)
return { amount: result.payout }
} catch (e) {
return { amount: 0 }
Expand Down
2 changes: 1 addition & 1 deletion backend/api/src/place-bet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ export const executeNewBetResult = async (
{
id: user.id,
[contract.token === 'CASH' ? 'cashBalance' : 'balance']:
-newBet.amount - apiFee,
-newBet.amount - apiFee + (newBet.loanAmount ?? 0),
},
]
const makersByTakerBetId: Record<string, maker[]> = {
Expand Down
6 changes: 4 additions & 2 deletions common/src/api/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1886,9 +1886,11 @@ export const API = (_apiTypeCheck = {
method: 'GET',
visibility: 'undocumented',
cache: DEFAULT_CACHE_STRATEGY,
authed: true,
authed: false,
returns: {} as { amount: number },
props: z.object({}),
props: z.object({
userId: z.string(),
}),
},
} as const)

Expand Down
3 changes: 2 additions & 1 deletion web/components/home/daily-loan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export function DailyLoan(props: {
)
const { receivedLoanToday: receivedTxnLoan, checkTxns } =
useHasReceivedLoanToday(user)
const { data } = useAPIGetter('get-next-loan-amount', {})
const { data } = useAPIGetter('get-next-loan-amount', { userId: user.id })
console.log('data', data)
const notEligibleForLoan = (data?.amount ?? 0) < 1

const receivedLoanToday = receivedTxnLoan || justReceivedLoan
Expand Down

0 comments on commit 0e289a1

Please sign in to comment.