44
55use Bavix \Wallet \Exceptions \AmountInvalid ;
66use Bavix \Wallet \Interfaces \MinimalTaxable ;
7+ use Bavix \Wallet \Interfaces \Storable ;
78use Bavix \Wallet \Interfaces \Taxable ;
89use Bavix \Wallet \Interfaces \Wallet ;
910use Bavix \Wallet \Models \Wallet as WalletModel ;
@@ -45,7 +46,7 @@ public function fee(Wallet $wallet, int $amount): int
4546 if ($ wallet instanceof MinimalTaxable) {
4647 $ minimal = $ wallet ->getMinimalFee ();
4748 if ($ fee < $ minimal ) {
48- $ fee = $ wallet -> getMinimalFee () ;
49+ $ fee = $ minimal ;
4950 }
5051 }
5152
@@ -94,16 +95,12 @@ public function getWallet(Wallet $object, bool $autoSave = true): WalletModel
9495 /**
9596 * @param Wallet $object
9697 * @return int
98+ * @deprecated use Storable::getBalance
9799 */
98100 public function getBalance (Wallet $ object ): int
99101 {
100- $ wallet = $ this ->getWallet ($ object );
101- $ proxy = app (ProxyService::class);
102- if (!$ proxy ->has ($ wallet ->getKey ())) {
103- $ proxy ->set ($ wallet ->getKey (), (int )$ wallet ->getOriginal ('balance ' , 0 ));
104- }
105-
106- return $ proxy [$ wallet ->getKey ()];
102+ return app (Storable::class)
103+ ->getBalance ($ object );
107104 }
108105
109106 /**
@@ -112,15 +109,13 @@ public function getBalance(Wallet $object): int
112109 */
113110 public function refresh (WalletModel $ wallet ): bool
114111 {
115- return app (LockService::class)->lock ($ this , __FUNCTION__ , function () use ($ wallet ) {
116- $ this ->getBalance ($ wallet );
112+ return app (LockService::class)->lock ($ this , __FUNCTION__ , static function () use ($ wallet ) {
113+ app (Storable::class) ->getBalance ($ wallet );
117114 $ balance = $ wallet ->getAvailableBalance ();
118115 $ wallet ->balance = $ balance ;
119116
120- $ proxy = app (ProxyService::class);
121- $ proxy ->set ($ wallet ->getKey (), $ balance );
122-
123- return $ wallet ->save ();
117+ return app (Storable::class)->setBalance ($ wallet , $ balance ) &&
118+ $ wallet ->save ();
124119 });
125120 }
126121
0 commit comments