diff --git a/app/Support/Amount.php b/app/Support/Amount.php index a29381a460..3ffd96aaf4 100644 --- a/app/Support/Amount.php +++ b/app/Support/Amount.php @@ -224,23 +224,6 @@ class Amount return $this->getDefaultCurrencyByUser($user); } - /** - * @param string $value - * - * @return string - */ - private function tryDecrypt(string $value): string - { - try { - $value = Crypt::decrypt($value); - } catch (DecryptException $e) { - Log::debug(sprintf('Could not decrypt. %s', $e->getMessage())); - } - - return $value; - } - - /** * @param User $user * @@ -260,7 +243,13 @@ class Amount // at this point the currency preference could be encrypted, if coming from an old version. $currencyCode = $this->tryDecrypt((string)$currencyPreference->data); - $currency = TransactionCurrency::where('code', $currencyCode)->first(); + + // could still be json encoded: + if (\strlen($currencyCode) > 3) { + $currencyCode = null === json_decode($currencyCode) ? 'EUR' : $currencyCode; + } + + $currency = TransactionCurrency::where('code', $currencyCode)->first(); if (null === $currency) { throw new FireflyException(sprintf('No currency found with code "%s"', $currencyCode)); } @@ -288,4 +277,20 @@ class Amount 'zero' => $positive, ]; } + + /** + * @param string $value + * + * @return string + */ + private function tryDecrypt(string $value): string + { + try { + $value = Crypt::decrypt($value); + } catch (DecryptException $e) { + Log::debug(sprintf('Could not decrypt. %s', $e->getMessage())); + } + + return $value; + } }