Conversation
| const lastBatch = instructions[instructions.length - 1]; | ||
| lastBatch.unshift(createAtaIx); |
There was a problem hiding this comment.
🟡 Crash on undefined.unshift() if createTransferInterfaceInstructions returns empty array
The new code accesses instructions[instructions.length - 1] and calls .unshift(createAtaIx) on it without guarding against an empty instructions array. If createTransferInterfaceInstructions returns [], lastBatch is undefined and lastBatch.unshift(createAtaIx) throws a TypeError. The old code didn't have this crash path because it passed instructions directly to signAndSendBatches, which gracefully returns null for empty arrays (toolkits/sign-with-privy/react/src/hooks/signAndSendBatches.ts:43).
| const lastBatch = instructions[instructions.length - 1]; | |
| lastBatch.unshift(createAtaIx); | |
| if (instructions.length === 0) { | |
| throw new Error('Transfer returned no instructions'); | |
| } | |
| const lastBatch = instructions[instructions.length - 1]; | |
| lastBatch.unshift(createAtaIx); |
Was this helpful? React with 👍 or 👎 to provide feedback.
| const lastBatch = instructions[instructions.length - 1]; | ||
| lastBatch.unshift(createAtaIx); |
There was a problem hiding this comment.
🟡 Crash on undefined.unshift() if createTransferInterfaceInstructions returns empty array
Same issue as in the Privy variant: instructions[instructions.length - 1] is undefined when instructions is empty, and calling .unshift() on it throws a TypeError. The old code passed instructions directly to signAndSendBatches (toolkits/sign-with-wallet-adapter/react/src/hooks/signAndSendBatches.ts:32-33), which handles empty arrays gracefully by returning null.
| const lastBatch = instructions[instructions.length - 1]; | |
| lastBatch.unshift(createAtaIx); | |
| if (instructions.length === 0) { | |
| throw new Error('Transfer returned no instructions'); | |
| } | |
| const lastBatch = instructions[instructions.length - 1]; | |
| lastBatch.unshift(createAtaIx); |
Was this helpful? React with 👍 or 👎 to provide feedback.
breaking changes