diff --git a/CHANGELOG.md b/CHANGELOG.md index 46975545a..80d18adcf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Ability to disable public account creation - Updated caniuse db - Optimized the load time of the payment schedules list +- Fix a bug: do not load Stripe if no keys were defined - [TODO DEPLOY] `rails db:seed` # v5.3.0 2021 December 29 diff --git a/app/frontend/src/javascript/components/payment/stripe/stripe-elements.tsx b/app/frontend/src/javascript/components/payment/stripe/stripe-elements.tsx index c9252b3ab..68a912733 100644 --- a/app/frontend/src/javascript/components/payment/stripe/stripe-elements.tsx +++ b/app/frontend/src/javascript/components/payment/stripe/stripe-elements.tsx @@ -1,6 +1,6 @@ import React, { memo, useEffect, useState } from 'react'; import { Elements } from '@stripe/react-stripe-js'; -import { loadStripe } from '@stripe/stripe-js'; +import { loadStripe, Stripe } from '@stripe/stripe-js'; import { SettingName } from '../../../models/setting'; import SettingAPI from '../../../api/setting'; @@ -8,15 +8,17 @@ import SettingAPI from '../../../api/setting'; * This component initializes the stripe's Elements tag with the API key */ export const StripeElements: React.FC = memo(({ children }) => { - const [stripe, setStripe] = useState(undefined); + const [stripe, setStripe] = useState>(undefined); /** * When this component is mounted, we initialize the tag with the Stripe's public key */ useEffect(() => { SettingAPI.get(SettingName.StripePublicKey).then(key => { - const promise = loadStripe(key.value); - setStripe(promise); + if (key?.value) { + const promise = loadStripe(key.value); + setStripe(promise); + } }); }, []); diff --git a/yarn.lock b/yarn.lock index 02f139434..ab6efaa72 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2605,9 +2605,9 @@ caniuse-api@^3.0.0: lodash.uniq "^4.5.0" caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001219, caniuse-lite@^1.0.30001261: - version "1.0.30001295" - resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001295.tgz" - integrity sha512-lSP16vcyC0FEy0R4ECc9duSPoKoZy+YkpGkue9G4D81OfPnliopaZrU10+qtPdT8PbGXad/PNx43TIQrOmJZSQ== + version "1.0.30001296" + resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001296.tgz" + integrity sha512-WfrtPEoNSoeATDlf4y3QvkwiELl9GyPLISV5GejTbbQRtQx4LhsXmc9IQ6XCL2d7UxCyEzToEZNMeqR79OUw8Q== case-sensitive-paths-webpack-plugin@^2.4.0: version "2.4.0"