1313use Bavix \Wallet \Internal \Exceptions \RecordNotFoundException ;
1414use Bavix \Wallet \Internal \Exceptions \TransactionFailedException ;
1515use Bavix \Wallet \Internal \Service \DatabaseServiceInterface ;
16- use Bavix \Wallet \Internal \Service \MathServiceInterface ;
1716use Bavix \Wallet \Models \Transaction ;
1817use Bavix \Wallet \Models \Transfer ;
1918use Bavix \Wallet \Models \Wallet as WalletModel ;
@@ -30,7 +29,6 @@ final class CommonServiceLegacy
3029 private RegulatorServiceInterface $ regulatorService ;
3130 private TransferDtoAssemblerInterface $ transferDtoAssembler ;
3231 private StateServiceInterface $ stateService ;
33- private MathServiceInterface $ mathService ;
3432
3533 public function __construct (
3634 CastServiceInterface $ castService ,
@@ -40,8 +38,7 @@ public function __construct(
4038 TransferDtoAssemblerInterface $ transferDtoAssembler ,
4139 RegulatorServiceInterface $ regulatorService ,
4240 StateServiceInterface $ stateService ,
43- AtmServiceInterface $ atmService ,
44- MathServiceInterface $ mathService
41+ AtmServiceInterface $ atmService
4542 ) {
4643 $ this ->atmService = $ atmService ;
4744 $ this ->castService = $ castService ;
@@ -51,7 +48,6 @@ public function __construct(
5148 $ this ->regulatorService = $ regulatorService ;
5249 $ this ->transferDtoAssembler = $ transferDtoAssembler ;
5350 $ this ->stateService = $ stateService ;
54- $ this ->mathService = $ mathService ;
5551 }
5652
5753 /**
@@ -147,11 +143,11 @@ public function addBalance(Wallet $wallet, $amount): bool
147143 ->whereKey ($ walletObject ->getKey ())
148144 ->update (['balance ' => $ balance ])
149145 ;
150-
151- $ walletObject ->fill (['balance ' => $ balance ])->syncOriginalAttribute ('balance ' );
152146 } finally {
153147 if ($ result === 0 ) {
154- $ this ->regulatorService ->increase ($ walletObject , $ this ->mathService ->negative ($ amount ));
148+ $ this ->regulatorService ->decrease ($ walletObject , $ amount );
149+ } else {
150+ $ walletObject ->fill (['balance ' => $ balance ])->syncOriginalAttribute ('balance ' );
155151 }
156152 }
157153
0 commit comments