Do I have to convert to USD each transaction to determine the gain/loss or can I make the calcul in the foreign currency and then convert?

When calculating the gain/loss of a foreign sale, I'm wondering whether I have to make the calculations in the foreign currency and then convert the gain/loss in USD or I have to convert each transaction to USD when they happen and then make the calculations?

For example:

Let' say:

1) I buy 10 shares of stock A on 2010-01-01 (exchange rate: 1.43)

Cost basis €: 300€

Cost basis $: $429

2) on 2013-01-01, there is a return of capital of 2€ per share (exchange rate: 1.32)

Cost basis €: 300 - 10*2 = 280€

Cost basis $: 429 - 10*2*1.32 = $402

3) finally on 2015-12-01, I sell them all for 400€. (exchange rate 1.05)

Gain €: 400 - 280= +120€ => +$126

Gain $: 400*1.05 - 402 = +$18