Skip to content

Commit fd77e1b

Browse files
committed
🐛 app: fix loan totals calculation
1 parent 863c75d commit fd77e1b

3 files changed

Lines changed: 17 additions & 22 deletions

File tree

.changeset/fiery-parents-burn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@exactly/mobile": patch
3+
---
4+
5+
🐛 fix loan totals calculation

src/components/loans/LoanSummary.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export default function LoanSummary({ loan }: { loan: Loan }) {
7575
<AssetLogo height={16} symbol={symbol} width={16} />
7676
<Text title3>
7777
{!isBorrow && installments
78-
? (Number(installments.amounts.reduce((a, b) => a + b, 0n)) / 1e6).toLocaleString(language, {
78+
? (Number(installments.installments.reduce((a, b) => a + b, 0n)) / 1e6).toLocaleString(language, {
7979
minimumFractionDigits: 2,
8080
maximumFractionDigits: 2,
8181
})

src/components/loans/Review.tsx

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,24 +86,17 @@ export default function Review() {
8686
marketAddress: market,
8787
});
8888

89-
const installmentsAmount = singleInstallment
89+
const totalAmount = singleInstallment
9090
? (borrow?.assets ?? 0n)
91-
: split
92-
? split.installments.reduce((accumulator, current) => accumulator + current, 0n) /
93-
BigInt(split.installments.length)
94-
: 0n;
91+
: (split?.installments.reduce((accumulator, current) => accumulator + current, 0n) ?? 0n);
9592

96-
const totalAmount = borrow
97-
? borrow.assets
93+
const installmentsAmount = singleInstallment
94+
? totalAmount
9895
: split
99-
? split.installments.reduce((accumulator, current) => accumulator + current, 0n)
96+
? totalAmount / BigInt(split.installments.length)
10097
: 0n;
10198

102-
const feeAmount = borrow
103-
? borrow.assets - (amount ?? 0n)
104-
: split
105-
? split.installments.reduce((accumulator, current) => accumulator + current, 0n) - (amount ?? 0n)
106-
: 0n;
99+
const feeAmount = totalAmount === 0n ? 0n : totalAmount - (amount ?? 0n);
107100

108101
const { mutateAsync: mutateSendCalls } = useSendCalls();
109102
const {
@@ -165,10 +158,10 @@ export default function Review() {
165158
}),
166159
[maturity, language],
167160
);
168-
const rate = borrow
169-
? Number(
170-
((borrow.assets - (amount ?? 0n)) * WAD * 31_536_000n) / ((amount ?? 0n) * (borrow.maturity - timestamp)),
171-
) / 1e18
161+
const rate = singleInstallment
162+
? borrow && amount
163+
? Number((feeAmount * WAD * 31_536_000n) / (amount * (borrow.maturity - timestamp))) / 1e18
164+
: 0
172165
: split
173166
? Number(split.effectiveRate) / 1e18
174167
: 0;
@@ -283,10 +276,7 @@ export default function Review() {
283276
<XStack alignItems="center" gap="$s2">
284277
<AssetLogo height={16} symbol={symbol} width={16} />
285278
<Text title3 color="$uiNeutralPrimary">
286-
{(
287-
Number(singleInstallment ? totalAmount : installmentsAmount) /
288-
10 ** (assetMarket?.decimals ?? 6)
289-
).toLocaleString(language, {
279+
{(Number(installmentsAmount) / 10 ** (assetMarket?.decimals ?? 6)).toLocaleString(language, {
290280
minimumFractionDigits: 2,
291281
maximumFractionDigits: 2,
292282
})}

0 commit comments

Comments
 (0)