diff --git a/changelog.md b/changelog.md index d6475d3b4..f697e157b 100644 --- a/changelog.md +++ b/changelog.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [8.2.1] - 2022-04-14 +### Fixed +- Error in force transaction float #469 @EdX9 + ## [8.2.0] - 2022-04-03 ### Added - Add exception `TransactionStartException` @@ -819,7 +823,8 @@ The operation is now executed in the transaction and updates the new `refund` fi - Exceptions: AmountInvalid, BalanceIsEmpty. - Models: Transfer, Transaction. -[Unreleased]: https://github.com/bavix/laravel-wallet/compare/8.2.0...develop +[Unreleased]: https://github.com/bavix/laravel-wallet/compare/8.2.1...develop +[8.2.1]: https://github.com/bavix/laravel-wallet/compare/8.2.0...8.2.1 [8.2.0]: https://github.com/bavix/laravel-wallet/compare/8.1.1...8.2.0 [8.1.1]: https://github.com/bavix/laravel-wallet/compare/8.1.0...8.1.1 [8.1.0]: https://github.com/bavix/laravel-wallet/compare/8.0.6...8.1.0 diff --git a/src/Services/PrepareService.php b/src/Services/PrepareService.php index dccaa836d..357019cf6 100644 --- a/src/Services/PrepareService.php +++ b/src/Services/PrepareService.php @@ -83,10 +83,11 @@ public function transferLazy( ?array $meta = null ): TransferLazyDtoInterface { $discount = $this->personalDiscountService->getDiscount($from, $to); + $toWallet = $this->castService->getWallet($to); $from = $this->castService->getWallet($from); $fee = $this->taxService->getFee($to, $amount); - $amountWithoutDiscount = $this->mathService->sub($amount, $discount); + $amountWithoutDiscount = $this->mathService->sub($amount, $discount, $toWallet->decimal_places); $depositAmount = $this->mathService->compare($amountWithoutDiscount, 0) === -1 ? '0' : $amountWithoutDiscount; $withdrawAmount = $this->mathService->add($depositAmount, $fee, $from->decimal_places); diff --git a/tests/Units/Domain/WalletFloatTest.php b/tests/Units/Domain/WalletFloatTest.php index 4999b3afb..1bd6a4f68 100644 --- a/tests/Units/Domain/WalletFloatTest.php +++ b/tests/Units/Domain/WalletFloatTest.php @@ -304,6 +304,29 @@ public function testBitcoin(): void self::assertSame('256.00000256000000000000000000000001', $user->balanceFloat); } + /** + * Case from @EdX9. + * + * @see https://github.com/bavix/laravel-wallet/issues/469 + * + * @throws ExceptionInterface + */ + public function testBigFloat(): void + { + /** @var User[] $users */ + $users = UserFloatFactory::times(2)->create(); + + [$first, $second] = $users; + + self::assertSame(0, $first->balanceInt); + self::assertSame(0, $second->balanceInt); + + $first->forceTransferFloat($second, 6629944401); + + self::assertSame(-662994440100, $first->balanceInt); + self::assertSame(662994440100, $second->balanceInt); + } + /** * Case from @ucanbehack. *