66use Bavix \Wallet \Models \Transaction ;
77use Bavix \Wallet \Models \Transfer ;
88use Bavix \Wallet \Services \CommonService ;
9+ use Bavix \Wallet \Services \WalletService ;
910use function config ;
1011
1112/**
@@ -28,15 +29,8 @@ trait HasWalletFloat
2829 */
2930 public function forceWithdrawFloat (float $ amount , ?array $ meta = null , bool $ confirmed = true ): Transaction
3031 {
31- return $ this ->forceWithdraw ($ amount * $ this ->coefficient (), $ meta , $ confirmed );
32- }
33-
34- /**
35- * @return float
36- */
37- private function coefficient (): float
38- {
39- return config ('wallet.package.coefficient ' , 100. );
32+ $ decimalPlaces = app (WalletService::class)->decimalPlaces ($ this );
33+ return $ this ->forceWithdraw ($ amount * $ decimalPlaces , $ meta , $ confirmed );
4034 }
4135
4236 /**
@@ -48,7 +42,8 @@ private function coefficient(): float
4842 */
4943 public function depositFloat (float $ amount , ?array $ meta = null , bool $ confirmed = true ): Transaction
5044 {
51- return $ this ->deposit ($ amount * $ this ->coefficient (), $ meta , $ confirmed );
45+ $ decimalPlaces = app (WalletService::class)->decimalPlaces ($ this );
46+ return $ this ->deposit ($ amount * $ decimalPlaces , $ meta , $ confirmed );
5247 }
5348
5449 /**
@@ -60,7 +55,8 @@ public function depositFloat(float $amount, ?array $meta = null, bool $confirmed
6055 */
6156 public function withdrawFloat (float $ amount , ?array $ meta = null , bool $ confirmed = true ): Transaction
6257 {
63- return $ this ->withdraw ($ amount * $ this ->coefficient (), $ meta , $ confirmed );
58+ $ decimalPlaces = app (WalletService::class)->decimalPlaces ($ this );
59+ return $ this ->withdraw ($ amount * $ decimalPlaces , $ meta , $ confirmed );
6460 }
6561
6662 /**
@@ -69,7 +65,8 @@ public function withdrawFloat(float $amount, ?array $meta = null, bool $confirme
6965 */
7066 public function canWithdrawFloat (float $ amount ): bool
7167 {
72- return $ this ->canWithdraw ($ amount * $ this ->coefficient ());
68+ $ decimalPlaces = app (WalletService::class)->decimalPlaces ($ this );
69+ return $ this ->canWithdraw ($ amount * $ decimalPlaces );
7370 }
7471
7572 /**
@@ -81,7 +78,8 @@ public function canWithdrawFloat(float $amount): bool
8178 */
8279 public function transferFloat (Wallet $ wallet , float $ amount , ?array $ meta = null ): Transfer
8380 {
84- return $ this ->transfer ($ wallet , $ amount * $ this ->coefficient (), $ meta );
81+ $ decimalPlaces = app (WalletService::class)->decimalPlaces ($ this );
82+ return $ this ->transfer ($ wallet , $ amount * $ decimalPlaces , $ meta );
8583 }
8684
8785 /**
@@ -92,7 +90,8 @@ public function transferFloat(Wallet $wallet, float $amount, ?array $meta = null
9290 */
9391 public function safeTransferFloat (Wallet $ wallet , float $ amount , ?array $ meta = null ): ?Transfer
9492 {
95- return $ this ->safeTransfer ($ wallet , $ amount * $ this ->coefficient (), $ meta );
93+ $ decimalPlaces = app (WalletService::class)->decimalPlaces ($ this );
94+ return $ this ->safeTransfer ($ wallet , $ amount * $ decimalPlaces , $ meta );
9695 }
9796
9897 /**
@@ -103,15 +102,17 @@ public function safeTransferFloat(Wallet $wallet, float $amount, ?array $meta =
103102 */
104103 public function forceTransferFloat (Wallet $ wallet , float $ amount , ?array $ meta = null ): Transfer
105104 {
106- return $ this ->forceTransfer ($ wallet , $ amount * $ this ->coefficient (), $ meta );
105+ $ decimalPlaces = app (WalletService::class)->decimalPlaces ($ this );
106+ return $ this ->forceTransfer ($ wallet , $ amount * $ decimalPlaces , $ meta );
107107 }
108108
109109 /**
110110 * @return float
111111 */
112112 public function getBalanceFloatAttribute (): float
113113 {
114- return $ this ->balance / $ this ->coefficient ();
114+ $ decimalPlaces = app (WalletService::class)->decimalPlaces ($ this );
115+ return $ this ->balance / $ decimalPlaces ;
115116 }
116117
117118}
0 commit comments