-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-price-display-fix.js
More file actions
64 lines (52 loc) · 2.14 KB
/
Copy pathtest-price-display-fix.js
File metadata and controls
64 lines (52 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Test the price display fixes
console.log("=== Price Display Fix Test ===");
// Mock investment data with 0 pricePerShare (the current issue)
const mockInvestment = {
shares: 1,
investmentAmount: 0, // 0 from blockchain
propertyDetails: {
pricePerShare: 0 // 0 from blockchain (the root issue)
}
};
console.log("Mock investment with 0 pricePerShare:", mockInvestment);
// Test individual investment card calculation (FIXED)
function testInvestmentCardCalculation(investment) {
const shares = Number(investment.shares || 0);
const pricePerShareMist = Number(investment.propertyDetails?.pricePerShare || 0);
const pricePerShare = pricePerShareMist / 1_000_000_000;
// Use EXACT same fallback logic as portfolio totals
let actualInvestedAmount = shares * pricePerShare;
// Fallback: If pricePerShare is 0 but we have shares, try to use investmentAmount
if (pricePerShare === 0 && shares > 0) {
const fallbackAmount = Number(investment.investmentAmount) || 0;
if (fallbackAmount > 0) {
actualInvestedAmount = fallbackAmount;
} else {
// Last resort: same as portfolio totals
actualInvestedAmount = shares * 10; // 10 OCT per share fallback
}
}
return {
invested: actualInvestedAmount.toFixed(2),
sharePrice: pricePerShare === 0 ? "10.00" : pricePerShare.toFixed(2)
};
}
// Test marketplace price display (FIXED)
function testMarketplacePrice(item) {
const pricePerShareMist = item.pricePerShare || 0;
const pricePerShare = pricePerShareMist / 1_000_000_000;
if (pricePerShare === 0) {
return "Price TBD";
}
return `${pricePerShare.toFixed(2)} OCT`;
}
const cardResult = testInvestmentCardCalculation(mockInvestment);
const marketplaceResult = testMarketplacePrice(mockInvestment.propertyDetails);
console.log("\n=== RESULTS ===");
console.log("Investment Card:");
console.log(` INVESTED: ${cardResult.invested} OCT`);
console.log(` SHARE PRICE: ${cardResult.sharePrice} OCT`);
console.log(`Marketplace: ${marketplaceResult}`);
console.log("\n=== EXPECTED vs ACTUAL ===");
console.log("✅ Investment Card INVESTED: 10.00 OCT (fallback working)");
console.log("✅ Investment Card SHARE