Doorbell transformer wiring to an electrical outlet?
The ac going to the transformer doesn’t matter because the low voltage on the other side is isolated.
However there are several issues as I see it
The high voltage between the transformer and metal box the wires are not in flex or rated for being in the open not a big deal but a code violation.
Next with the transformer not mounted to the metal it is not grounded so a fault could end up on the low voltage side and not tripping the circuit breaker.
Most door bell transformers are made to mount on a box and the 120v connections are made inside the box, this is the case with your new one
You will have knock out one of the slugs on the side of the box )make sure it will fit first)  you may have to add a spacer behind the box so the transformer can mount on the side but the mounting creates the ground path I mentioned as the fitting on the side of the box makes it very tight in a single gang box I would wrap electrical tape around the terminals after you connect the wires again the high side the colors don’t matter if they are the same color.
If the receptacle doesn’t look like it will fit you may need to change to a single receptacle and use one of the knockouts on the top side or bottom side (not the ends as the cover usually caused problems on the ends)
The good news is you now have the correct type of transformer to be mounted on the box.