Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fixed sgh current funding refresh issue
  • Loading branch information
JustinaMaryAtNomyx committed Mar 30, 2026
commit 1f911afe60e77d79e58921277fa8e2832c87048d
28 changes: 6 additions & 22 deletions src/components/projects/ProjectDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const ProjectDetails: React.FC<ProjectDetailsProps> = ({ project, onBack }) => {
const [withdrawAmount, setWithdrawAmount] = useState<number>(0);
const [currentFundingBalance, setCurrentFundingBalance] = useState<number | null>(null);
const [loadingCurrentFunding, setLoadingCurrentFunding] = useState(false);
const [refreshBalance, setRefreshBalance] = useState(0);

const safe = (obj: any) => JSON.parse(JSON.stringify(obj, (_, v) => (typeof v === "bigint" ? v.toString() : v)));

Expand Down Expand Up @@ -274,7 +275,7 @@ const ProjectDetails: React.FC<ProjectDetailsProps> = ({ project, onBack }) => {
};

fetchCurrentFunding();
}, [project.tradeDealId, project.industryTemplate]);
}, [project.tradeDealId, project.industryTemplate, refreshBalance]);

useEffect(() => {
// Function to handle window resize
Expand Down Expand Up @@ -1588,30 +1589,13 @@ const ProjectDetails: React.FC<ProjectDetailsProps> = ({ project, onBack }) => {
}
);

try {
const blockchainService = BlockchainService.getInstance();
if (blockchainService && project.tradeDealId != null) {
const updatedStatus = await blockchainService.getTradeDealFullStatus(project.tradeDealId);
const latestBalance = Number(updatedStatus.currentBalance);

setCurrentFundingBalance(latestBalance);
project.totalDepositAmount = latestBalance;
project.isWithdrawn = latestBalance === 0;
}
} catch (error) {
console.error("Failed to refresh funding balance:", error);
// Fallback to calculated value if blockchain fetch fails
const calculatedBalance = Number(tradeDealStatus.currentBalance) - withdrawAmount;
setCurrentFundingBalance(calculatedBalance);
project.totalDepositAmount = calculatedBalance;
project.isWithdrawn = calculatedBalance === 0;
}

// Clean up modal state
setIsWithdrawModalVisible(false);
setTradeDealStatus(null);
setWithdrawAmount(0);

// Refresh the page data
// Trigger currentFundingBalance re-fetch via the useEffect
setRefreshBalance((prev) => prev + 1);
// Refresh token list data
setRefresh(!refresh);
} catch (error) {
console.error("Withdrawal error:", error);
Expand Down