Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Fixed review findings on money preferences and the seller balance card
Damian Legawiecb07a7f0966fc
diff --git a/docs/developer/customization/model-preferences.mdx b/docs/developer/customization/model-preferences.mdxindex 81f210887f..4ec5d5bafc 100644--- a/docs/developer/customization/model-preferences.mdx+++ b/docs/developer/customization/model-preferences.mdx@@ -115,6 +115,8 @@ endBoth are read back as a `BigDecimal` and take a number or a decimal string (`"4.50"`); text such as `"4,50"` is refused rather than misread. The difference is on the [API](/api-reference/admin-api/monetary-amounts): a `:money` preference is written with the decimals of the record's `currency` preference (`"4.50"`, or `"450"` in yen), and the dashboard shows it with that currency's symbol. A money preference on a record with no currency, such as a rule matching an order total in any currency, keeps its exact decimal.+## Secret preferences+Declare API keys, signing secrets and other credentials with the `:password` type:```ruby server/app/models/my_app/gateway.rbdiff --git a/packages/dashboard/src/components/spree/sellers/seller-balance-card.tsx b/packages/dashboard/src/components/spree/sellers/seller-balance-card.tsxindex 554415c94a..f74ec44c75 100644--- a/packages/dashboard/src/components/spree/sellers/seller-balance-card.tsx+++ b/packages/dashboard/src/components/spree/sellers/seller-balance-card.tsx@@ -84,7 +84,7 @@ export function SellerBalanceCard({ seller }: { seller: Seller }) {: t('admin.payouts.balance.earned')}>- <Money amount={balance.earned} currency={balance.settlement_currency} />+ <Money amount={balance.earned} currency={balance.currency} /></ReadRow>{balance.converted && (<ReadRow label={t('admin.payouts.balance.payable')}>@@ -95,7 +95,7 @@ export function SellerBalanceCard({ seller }: { seller: Seller }) {<Money amount={balance.paid} currency={balance.settlement_currency} /></ReadRow><ReadRow label={t('admin.payouts.balance.pending')}>- <Money amount={balance.pending} currency={balance.settlement_currency} />+ <Money amount={balance.pending} currency={balance.currency} /></ReadRow></div>))}diff --git a/packages/dashboard/src/lib/format-amount.ts b/packages/dashboard/src/lib/format-amount.tsindex 58478558ed..aa5ffd8fec 100644--- a/packages/dashboard/src/lib/format-amount.ts+++ b/packages/dashboard/src/lib/format-amount.ts@@ -13,7 +13,7 @@ export function formatAmount(): string {if (amount === null || amount === undefined || amount === '' || !currency) return fallbacktry {- return formatMoney(amount, currency, locale)+ return formatMoney(amount, currency, locale) || fallback} catch {return `${amount} ${currency}`}diff --git a/spree/core/lib/spree/core/preferences/masking.rb b/spree/core/lib/spree/core/preferences/masking.rbindex 3e4515aaf8..2bc1e2ca53 100644--- a/spree/core/lib/spree/core/preferences/masking.rb+++ b/spree/core/lib/spree/core/preferences/masking.rb@@ -47,15 +47,6 @@ module Spreevalue.is_a?(String) && value.start_with?(TOKEN)end- # Serializes a Preferable's `preferences` hash for the wire,- # masking `:password` values. Keys are stringified to match the- # wire shape expected by JSON clients — schema entries built by- # `compute_preference_schema` cache `:key_string` to avoid a- # `to_s` allocation per field per request.- #- # @param preferable [#preferences, #preference_schema, nil] any object- # that includes `Spree::Preferences::Preferable` and `Spree::PreferenceSchema`- # @return [Hash{String => Object}]# Money is written to at least the decimals of the currency the record# names (a calculator's `currency` preference), keeping up to four like# a unit price, so a per-item amount below a cent survives a round trip.@@ -69,12 +60,21 @@ module Spreeamount = value.is_a?(String) ? BigDecimal(value, exception: false) : valuereturn value unless amount.is_a?(Numeric)- currency = preferable.try(:preferred_currency) if preferable.try(:has_preference?, :currency)+ currency = preferable.try(:has_preference?, :currency) ? preferable.try(:preferred_currency) : nilcurrency.present? ? Spree::Money::Rounding.format(amount, currency, unit_price: true) : Spree::Money::Rounding.format_decimal(amount)else valueendend+ # Serializes a Preferable's `preferences` hash for the wire,+ # masking `:password` values. Keys are stringified to match the+ # wire shape expected by JSON clients — schema entries built by+ # `compute_preference_schema` cache `:key_string` to avoid a+ # `to_s` allocation per field per request.+ #+ # @param preferable [#preferences, #preference_schema, nil] any object+ # that includes `Spree::Preferences::Preferable` and `Spree::PreferenceSchema`+ # @return [Hash{String => Object}]def self.serialize(preferable)return {} if preferable.nil?diff --git a/spree/core/lib/spree/core/preferences/preferable.rb b/spree/core/lib/spree/core/preferences/preferable.rbindex 06d20cd955..7bb230734a 100644--- a/spree/core/lib/spree/core/preferences/preferable.rb+++ b/spree/core/lib/spree/core/preferences/preferable.rb@@ -162,7 +162,7 @@ module Spree::Preferences::Preferabledef stored_default(name)default = preference_default(name)type = preference_type(name)- return default if default.nil? || %i[decimal datetime].exclude?(type)+ return default if default.nil? || %i[decimal money datetime].exclude?(type)convert_preference_value(default, type, nullable: true).as_jsonend@@ -186,7 +186,7 @@ module Spree::Preferences::Preferable# Decimals and times are kept in the string form JSON stores, so a record# read back from the database and one just written compare equal and# setting the same value is not a change. The reader restores them.- value = value.as_json if %i[decimal datetime].include?(definition[:type])+ value = value.as_json if %i[decimal money datetime].include?(definition[:type])Spree::Deprecation.warn("`#{name}` is deprecated. #{definition[:deprecated]}") if definition[:deprecated]valuediff --git a/spree/core/spec/models/spree/preferences/preferable_spec.rb b/spree/core/spec/models/spree/preferences/preferable_spec.rbindex db19adb81e..1f1b398bbb 100644--- a/spree/core/spec/models/spree/preferences/preferable_spec.rb+++ b/spree/core/spec/models/spree/preferences/preferable_spec.rb@@ -178,6 +178,16 @@ describe Spree::Preferences::Preferable, type: :model doloaded.preferred_decimal_with_default = 0expect(loaded).not_to be_changedend++ it 'treats a money preference the same way' do+ A.preference :money_with_default, :money, default: 0+ loaded = A.find(A.create!.id)++ expect(loaded.preferred_money_with_default).to be_a(BigDecimal)++ loaded.preferred_money_with_default = '0'+ expect(loaded).not_to be_changed+ endendcontext 'converts nullable decimal preferences' do