{"record":{"id":"2d2cd988460297bd","repo":"we-promise/sure","slug":"invalid-currency-code-currency-value-for-2d2cd9","errorCode":null,"errorMessage":"Invalid currency code '#{currency_value}' for <%= class_name %> account #{id}, defaulting to USD","messagePattern":"Invalid currency code '#(.+?)' for <%= class_name %> account #(.+?), defaulting to USD","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"lib/generators/provider/global/templates/global_account_model.rb.tt","lineNumber":50,"sourceCode":"        name: snapshot[:institution_name],\n        logo: snapshot[:institution_logo]\n      }.compact,\n      raw_payload: account_snapshot\n    )\n  end\n\n  def upsert_<%= file_name %>_transactions_snapshot!(transactions_snapshot)\n    assign_attributes(\n      raw_transactions_payload: transactions_snapshot\n    )\n\n    save!\n  end\n\n  private\n\n  def log_invalid_currency(currency_value)\n    Rails.logger.warn(\"Invalid currency code '#{currency_value}' for <%= class_name %> account #{id}, defaulting to USD\")\n  end\nend\n","sourceCodeStart":32,"sourceCodeEnd":53,"githubUrl":"https://github.com/we-promise/sure/blob/e69894adb92547273377398c15f45c979cd9416a/lib/generators/provider/global/templates/global_account_model.rb.tt#L32-L53","documentation":"Global (e.g. crypto) provider generator template. The generated account model includes CurrencyNormalizable and upsert_<provider>_snapshot! assigns currency: parse_currency(snapshot[:currency]) || \"USD\". parse_currency requires a 3-letter uppercase code recognized by the Money gem; when the snapshot's currency fails that check, the model's log_invalid_currency override emits this warning and the account silently persists with USD.","triggerScenarios":"Crypto/global providers returning non-ISO asset symbols that the Money gem does not know: \"USDT\", \"WBTC\", \"1INCH\" (starts with a digit, fails \\A[A-Z]{3}\\z), symbols with hyphens, or nil currency fields — failing either the 3-letter regex or Money::Currency.new in app/models/concerns/currency_normalizable.rb.","commonSituations":"Wallet/exchange APIs whose balances are denominated in tokens rather than fiat codes; stablecoin or wrapped-asset symbols treated as invalid; new listings the Money gem has never heard of — for these the USD fallback produces wrong valuations, so mapping matters more than in the family template.","solutions":["Check the account's raw_payload for the exact currency/symbol string the provider sent","Add a symbol-to-ISO mapping in the generated upsert (e.g. \"USDT\" -> \"USD\", \"WBTC\" -> \"BTC\") before parse_currency, and mirror it in lib/generators/provider/global/templates/global_account_model.rb.tt","For token-denominated balances that have no ISO code, decide an explicit conversion policy instead of relying on the silent USD default","If snapshot[:currency] is nil, require the provider field or default intentionally rather than via the Money-gem miss"],"exampleFix":"# generated global account model - before\ncurrency: parse_currency(snapshot[:currency]) || \"USD\",\n\n# after\nTOKEN_TO_ISO = { \"USDT\" => \"USD\", \"USDC\" => \"USD\", \"WBTC\" => \"BTC\" }.freeze\n\ncurrency: parse_currency(TOKEN_TO_ISO.fetch(snapshot[:currency].to_s.strip.upcase, snapshot[:currency])) || \"USD\",","handlingStrategy":"validation","validationCode":"# Validate/translate crypto symbols before persisting the snapshot\nTOKEN_TO_ISO = { \"USDT\" => \"USD\", \"USDC\" => \"USD\", \"WBTC\" => \"BTC\" }.freeze\n\nraw = snapshot[:currency].to_s.strip.upcase\ncandidate = TOKEN_TO_ISO.fetch(raw, raw)\nbegin\n  currency = Money::Currency.new(candidate).iso_code\nrescue Money::Currency::UnknownCurrencyError\n  currency = \"USD\" # or raise/report for token-denominated balances\nend","typeGuard":"def tradable_currency?(value)\n  return false if value.blank?\n\n  Money::Currency.new(value.to_s.strip.upcase)\n  true\nrescue Money::Currency::UnknownCurrencyError\n  false\nend","tryCatchPattern":null,"preventionTips":["For global/crypto providers, maintain an explicit token-to-ISO mapping instead of relying on the silent USD default — wrong-currency balances distort valuations","Log and alert when snapshot currency is nil separately from unknown-symbol cases; each needs a different fix","Re-check stored accounts with currency 'USD' against raw_payload after enabling a mapping to repair past fallbacks"],"tags":["currency","money-gem","crypto-assets","generator-template","fallback","provider-data"],"backgroundTag":"invalid-currency-code","analyzedSha":"e69894adb92547273377398c15f45c979cd9416a","analyzedAt":"2026-08-21T18:22:41.165Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}