diff --git a/config/config.php b/config/config.php index 5bdcf0ac3..937109a22 100644 --- a/config/config.php +++ b/config/config.php @@ -44,6 +44,7 @@ use Bavix\Wallet\Services\DiscountService; use Bavix\Wallet\Services\EagerLoaderService; use Bavix\Wallet\Services\ExchangeService; +use Bavix\Wallet\Services\FormatterService; use Bavix\Wallet\Services\PrepareService; use Bavix\Wallet\Services\PurchaseService; use Bavix\Wallet\Services\RegulatorService; @@ -110,6 +111,7 @@ 'discount' => DiscountService::class, 'eager_loader' => EagerLoaderService::class, 'exchange' => ExchangeService::class, + 'formatter' => FormatterService::class, 'prepare' => PrepareService::class, 'purchase' => PurchaseService::class, 'tax' => TaxService::class, diff --git a/src/Traits/HasWalletFloat.php b/src/Traits/HasWalletFloat.php index 873691c5e..7dc1d5784 100644 --- a/src/Traits/HasWalletFloat.php +++ b/src/Traits/HasWalletFloat.php @@ -15,6 +15,7 @@ use Bavix\Wallet\Models\Transaction; use Bavix\Wallet\Models\Transfer; use Bavix\Wallet\Services\CastServiceInterface; +use Bavix\Wallet\Services\FormatterServiceInterface; use Illuminate\Database\RecordsNotFoundException; /** @@ -147,12 +148,12 @@ public function forceTransferFloat( public function getBalanceFloatAttribute(): string { - $math = app(MathServiceInterface::class); $wallet = app(CastServiceInterface::class)->getWallet($this); - $decimalPlacesValue = $wallet->decimal_places; - $decimalPlaces = $math->powTen($decimalPlacesValue); - return $math->div($wallet->getBalanceAttribute(), $decimalPlaces, $decimalPlacesValue); + return app(FormatterServiceInterface::class)->floatValue( + $wallet->getBalanceAttribute(), + $wallet->decimal_places, + ); } public function getBalanceFloatNumAttribute(): float diff --git a/src/WalletServiceProvider.php b/src/WalletServiceProvider.php index a7ae10136..bb121d86b 100644 --- a/src/WalletServiceProvider.php +++ b/src/WalletServiceProvider.php @@ -92,6 +92,8 @@ use Bavix\Wallet\Services\EagerLoaderServiceInterface; use Bavix\Wallet\Services\ExchangeService; use Bavix\Wallet\Services\ExchangeServiceInterface; +use Bavix\Wallet\Services\FormatterService; +use Bavix\Wallet\Services\FormatterServiceInterface; use Bavix\Wallet\Services\PrepareService; use Bavix\Wallet\Services\PrepareServiceInterface; use Bavix\Wallet\Services\PurchaseService; @@ -274,6 +276,7 @@ private function services(array $configure, array $cache): void $configure['eager_loader'] ?? EagerLoaderService::class ); $this->app->singleton(ExchangeServiceInterface::class, $configure['exchange'] ?? ExchangeService::class); + $this->app->singleton(FormatterServiceInterface::class, $configure['formatter'] ?? FormatterService::class); $this->app->singleton(PrepareServiceInterface::class, $configure['prepare'] ?? PrepareService::class); $this->app->singleton(PurchaseServiceInterface::class, $configure['purchase'] ?? PurchaseService::class); $this->app->singleton(TaxServiceInterface::class, $configure['tax'] ?? TaxService::class); @@ -466,6 +469,7 @@ private function servicesProviders(): array DiscountServiceInterface::class, EagerLoaderServiceInterface::class, ExchangeServiceInterface::class, + FormatterServiceInterface::class, PrepareServiceInterface::class, PurchaseServiceInterface::class, TaxServiceInterface::class,