Repository navigation
fix: pay clicked batch instead of stale selection #234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -349,13 +349,30 @@ function ReceivedInvoice() { | |
| } | ||
| }; | ||
|
|
||
|
|
||
|
|
||
| const getGroupedInvoices = (ids = selectedInvoices) => { | ||
| const grouped = new Map(); | ||
| receivedInvoices.forEach((invoice) => { | ||
| if (!ids.has(invoice.id)) return; | ||
|
|
||
| const getGroupedInvoices = (selection = selectedInvoices) => { | ||
| const grouped = new Map(); | ||
| receivedInvoices.forEach((invoice) => { | ||
| if (!selection.has(invoice.id)) return; | ||
|
|
||
|
|
||
| const tokenAddress = invoice.paymentToken?.address || ethers.ZeroAddress; | ||
| const tokenKey = `${tokenAddress}_${invoice.paymentToken?.symbol || "ETH"}`; | ||
|
|
||
| const getGroupedInvoices = (invoices) => { | ||
| const grouped = new Map(); | ||
| invoices.forEach((invoice) => { | ||
| const { address: tokenAddress, symbol, logo, decimals } = | ||
| invoice.paymentToken; | ||
| const tokenKey = tokenAddress.toLowerCase(); | ||
|
|
||
|
|
||
| if (!grouped.has(tokenKey)) { | ||
| grouped.set(tokenKey, { | ||
| tokenAddress, | ||
|
|
@@ -445,14 +462,13 @@ function ReceivedInvoice() { | |
| return; | ||
| } | ||
|
|
||
| setSelectedInvoices(new Set(batchInvoices.map((inv) => inv.id))); | ||
| const batchIds = new Set(batchInvoices.map((inv) => inv.id)); | ||
| setSelectedInvoices(batchIds); | ||
| toast( | ||
| `Selected ${batchInvoices.length} invoices from batch #${batchId}` | ||
| ); | ||
|
|
||
| setTimeout(() => { | ||
| handleBatchPayment(); | ||
| }, 1000); | ||
| await handleBatchPayment(batchIds); | ||
| }; | ||
|
|
||
| // UNIFORM INDIVIDUAL PAYMENT | ||
|
|
@@ -579,6 +595,10 @@ function ReceivedInvoice() { | |
| }; | ||
|
|
||
| // UNIFORM BATCH PAYMENT | ||
|
|
||
| const handleBatchPayment = async (ids = selectedInvoices) => { | ||
| if (!walletClient || ids.size === 0) return; | ||
|
|
||
| const handleBatchPayment = async () => { | ||
| if (!walletClient || payableSelected.length === 0) return; | ||
| if (loading) { | ||
|
|
@@ -598,10 +618,13 @@ function ReceivedInvoice() { | |
| return; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| // Paid, cancelled and mismatched invoices can stay selected for export; | ||
| // the contract would revert the whole batch for any one of them. | ||
| const grouped = getGroupedInvoices(payableSelected); | ||
|
|
||
|
|
||
| setBatchLoading(true); | ||
| setPaymentError(""); | ||
| setShowPaymentError(false); | ||
|
|
@@ -619,6 +642,11 @@ function ReceivedInvoice() { | |
|
|
||
| const contract = new Contract(contractAddress, ChainvoiceABI, signer); | ||
|
|
||
|
|
||
| const grouped = getGroupedInvoices(ids); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Filter the selected IDs to payable invoices before payment. The normal Pay selected flow passes 🤖 Prompt for AI Agents |
||
|
|
||
|
|
||
|
|
||
| // BALANCE CHECK (same as individual) | ||
| toast("Checking balances..."); | ||
|
|
||
|
|
@@ -1426,7 +1454,7 @@ function ReceivedInvoice() { | |
| ))} | ||
| </Box> | ||
| <Button | ||
| onClick={handleBatchPayment} | ||
| onClick={() => handleBatchPayment()} | ||
| variant="contained" | ||
| color="success" | ||
| size="large" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: StabilityNexus/Chainvoice
Length of output: 7447
🏁 Script executed:
Repository: StabilityNexus/Chainvoice
Length of output: 5461
🏁 Script executed:
Repository: StabilityNexus/Chainvoice
Length of output: 42590
🏁 Script executed:
Repository: StabilityNexus/Chainvoice
Length of output: 2896
🏁 Script executed:
Repository: StabilityNexus/Chainvoice
Length of output: 792
Remove the duplicate function headers and use
idsthroughout batch payment.The added headers leave the existing implementations nested inside unfinished functions. The file now has a whole-file syntax error. The retained
handleBatchPaymentbody also checks and validatesselectedInvoicesinstead of itsidsargument.Keep one complete definition of each function. Update the existing grouping and batch-payment bodies to use
ids. Preserve the loaded-page validation, but apply it toids.🤖 Prompt for AI Agents