Skip to content

Commit 3d08d7a

Browse files
committed
feat: improve pay/reimburse/execute flow
1 parent 1aba041 commit 3d08d7a

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

contracts/src/EscrowUniversal.sol

+14-6
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,19 @@ contract EscrowUniversal is IEscrow, IArbitrableV2 {
191191
if (transaction.status != Status.NoDispute) revert TransactionDisputed();
192192
if (_amount > transaction.amount) revert MaximumPaymentAmountExceeded();
193193

194+
emit Payment(_transactionID, _amount, msg.sender);
195+
194196
transaction.amount -= _amount;
197+
if (transaction.amount == 0) {
198+
transaction.status = Status.TransactionResolved;
199+
emit TransactionResolved(_transactionID, Resolution.TransactionExecuted);
200+
}
195201

196202
if (transaction.token == NATIVE) {
197203
transaction.seller.send(_amount); // It is the user responsibility to accept ETH.
198204
} else {
199205
if (!transaction.token.safeTransfer(transaction.seller, _amount)) revert TokenTransferFailed();
200206
}
201-
202-
emit Payment(_transactionID, _amount, msg.sender);
203207
}
204208

205209
/// @inheritdoc IEscrow
@@ -209,15 +213,19 @@ contract EscrowUniversal is IEscrow, IArbitrableV2 {
209213
if (transaction.status != Status.NoDispute) revert TransactionDisputed();
210214
if (_amountReimbursed > transaction.amount) revert MaximumPaymentAmountExceeded();
211215

216+
emit Payment(_transactionID, _amountReimbursed, msg.sender);
217+
212218
transaction.amount -= _amountReimbursed;
219+
if (transaction.amount == 0) {
220+
transaction.status = Status.TransactionResolved;
221+
emit TransactionResolved(_transactionID, Resolution.TransactionExecuted);
222+
}
213223

214224
if (transaction.token == NATIVE) {
215225
transaction.buyer.send(_amountReimbursed); // It is the user responsibility to accept ETH.
216226
} else {
217227
if (!transaction.token.safeTransfer(transaction.buyer, _amountReimbursed)) revert TokenTransferFailed();
218228
}
219-
220-
emit Payment(_transactionID, _amountReimbursed, msg.sender);
221229
}
222230

223231
/// @inheritdoc IEscrow
@@ -228,15 +236,15 @@ contract EscrowUniversal is IEscrow, IArbitrableV2 {
228236

229237
uint256 amount = transaction.amount;
230238
transaction.amount = 0;
239+
transaction.status = Status.TransactionResolved;
231240

232241
if (transaction.token == NATIVE) {
233242
transaction.seller.send(amount); // It is the user responsibility to accept ETH.
234243
} else {
235244
if (!transaction.token.safeTransfer(transaction.seller, amount)) revert TokenTransferFailed();
236245
}
237246

238-
transaction.status = Status.TransactionResolved;
239-
247+
emit Payment(_transactionID, amount, msg.sender);
240248
emit TransactionResolved(_transactionID, Resolution.TransactionExecuted);
241249
}
242250

0 commit comments

Comments
 (0)