5 confirmations, then you can undo the transaction?
I think that's impossible. I don't think there's any wallet that can do this except for transactions with 0 confirmation. Electrum can cancel the transaction, but the process is by replacing the old transaction to send BTC back to your wallet with a higher TX fee.
NO, You can immediately undo the transaction, that is the entire idea, the fastest the better, you have until the 6th confirmation comes in, if the undo transaction was not issued/seen by the network by that time/block, the undo transaction is no longer valid/accepted and the transaction is permanent.
So the idea is you must submit the undo transaction before the usual/guidance/advise of waiting 6 confirmations before a bitcoin transaction can be considered valid/safe.