mirror of
https://github.com/we-promise/sure.git
synced 2026-04-17 11:04:14 +00:00
* **Add Coinbase integration with item and account management** - Creates migrations for `coinbase_items` and `coinbase_accounts`. - Adds models, controllers, views, and background tasks to support account linking, syncing, and transaction handling. - Implements Coinbase API client and adapter for seamless integration. - Supports ActiveRecord encryption for secure credential storage. - Adds UI components for provider setup, account management, and synchronization. * Localize Coinbase-related UI strings, refine account linking for security, and add timeouts to Coinbase API requests. * Localize Coinbase account handling to support native currencies (USD, EUR, GBP, etc.) across balances, trades, holdings, and transactions. * Improve Coinbase processing with timezone-safe parsing, native currency support, and immediate holdings updates. * Improve trend percentage formatting and enhance race condition handling for Coinbase account linking. * Fix log message wording for orphan cleanup * Ensure `selected_accounts` parameter is sanitized by rejecting blank entries. * Add tests for Coinbase integration: account, item, and controller coverage - Adds unit tests for `CoinbaseAccount` and `CoinbaseItem` models. - Adds integration tests for `CoinbaseItemsController`. - Introduces Stimulus `select-all` controller for UI checkbox handling. - Localizes UI strings and logging for Coinbase integration. * Update test fixtures to use consistent placeholder API keys and secrets * Refine `coinbase_item` tests to ensure deterministic ordering and improve scope assertions. * Integrate `SyncStats::Collector` into Coinbase syncer to streamline statistics collection and enhance consistency. * Localize Coinbase sync status messages and improve sync summary test coverage. * Update `CoinbaseItem` encryption: use deterministic encryption for `api_key` and standard for `api_secret`. * fix schema drift * Beta labels to lower expectations --------- Co-authored-by: luckyPipewrench <luckypipewrench@proton.me> Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
144 lines
6.0 KiB
Plaintext
144 lines
6.0 KiB
Plaintext
<%# locals: (coinbase_item:) %>
|
|
|
|
<%= tag.div id: dom_id(coinbase_item) do %>
|
|
<details open class="group bg-container p-4 shadow-border-xs rounded-xl">
|
|
<summary class="flex items-center justify-between gap-2 focus-visible:outline-hidden">
|
|
<div class="flex items-center gap-2">
|
|
<%= icon "chevron-right", class: "group-open:transform group-open:rotate-90" %>
|
|
|
|
<div class="flex items-center justify-center h-8 w-8 rounded-full" style="background-color: rgba(0, 82, 255, 0.1);">
|
|
<div class="flex items-center justify-center">
|
|
<%= icon "bitcoin", size: "sm", class: "text-[#0052FF]" %>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="pl-1 text-sm">
|
|
<div class="flex items-center gap-2">
|
|
<%= tag.p coinbase_item.institution_display_name, class: "font-medium text-primary" %>
|
|
<% if coinbase_item.scheduled_for_deletion? %>
|
|
<p class="text-destructive text-sm animate-pulse"><%= t(".deletion_in_progress") %></p>
|
|
<% end %>
|
|
</div>
|
|
<p class="text-xs text-secondary"><%= t(".provider_name") %></p>
|
|
<% if coinbase_item.syncing? %>
|
|
<div class="text-secondary flex items-center gap-1">
|
|
<%= icon "loader", size: "sm", class: "animate-spin" %>
|
|
<%= tag.span t(".syncing") %>
|
|
</div>
|
|
<% elsif coinbase_item.requires_update? %>
|
|
<div class="text-warning flex items-center gap-1">
|
|
<%= icon "alert-triangle", size: "sm", color: "warning" %>
|
|
<%= tag.span t(".reconnect") %>
|
|
</div>
|
|
<% else %>
|
|
<p class="text-secondary">
|
|
<% if coinbase_item.last_synced_at %>
|
|
<% if coinbase_item.sync_status_summary %>
|
|
<%= t(".status_with_summary", timestamp: time_ago_in_words(coinbase_item.last_synced_at), summary: coinbase_item.sync_status_summary) %>
|
|
<% else %>
|
|
<%= t(".status", timestamp: time_ago_in_words(coinbase_item.last_synced_at)) %>
|
|
<% end %>
|
|
<% else %>
|
|
<%= t(".status_never") %>
|
|
<% end %>
|
|
</p>
|
|
<% end %>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="flex items-center gap-2">
|
|
<% if coinbase_item.requires_update? %>
|
|
<%= render DS::Link.new(
|
|
text: t(".update_credentials"),
|
|
icon: "refresh-cw",
|
|
variant: "secondary",
|
|
href: settings_providers_path,
|
|
frame: "_top"
|
|
) %>
|
|
<% elsif Rails.env.development? %>
|
|
<%= icon(
|
|
"refresh-cw",
|
|
as_button: true,
|
|
href: sync_coinbase_item_path(coinbase_item)
|
|
) %>
|
|
<% end %>
|
|
|
|
<%= render DS::Menu.new do |menu| %>
|
|
<% menu.with_item(
|
|
variant: "button",
|
|
text: t(".delete"),
|
|
icon: "trash-2",
|
|
href: coinbase_item_path(coinbase_item),
|
|
method: :delete,
|
|
confirm: CustomConfirm.for_resource_deletion(coinbase_item.institution_display_name, high_severity: true)
|
|
) %>
|
|
<% end %>
|
|
</div>
|
|
</summary>
|
|
|
|
<% unless coinbase_item.scheduled_for_deletion? %>
|
|
<div class="space-y-4 mt-4">
|
|
<% if coinbase_item.accounts.any? %>
|
|
<%= render "accounts/index/account_groups", accounts: coinbase_item.accounts %>
|
|
<% end %>
|
|
|
|
<%# Sync summary (collapsible) - using shared ProviderSyncSummary component %>
|
|
<% stats = if defined?(@coinbase_sync_stats_map) && @coinbase_sync_stats_map
|
|
@coinbase_sync_stats_map[coinbase_item.id] || {}
|
|
else
|
|
coinbase_item.syncs.ordered.first&.sync_stats || {}
|
|
end %>
|
|
<%= render ProviderSyncSummary.new(
|
|
stats: stats,
|
|
provider_item: coinbase_item
|
|
) %>
|
|
|
|
<%# Compute unlinked Coinbase accounts (no AccountProvider link) %>
|
|
<% unlinked_count = if defined?(@coinbase_unlinked_count_map) && @coinbase_unlinked_count_map
|
|
@coinbase_unlinked_count_map[coinbase_item.id] || 0
|
|
else
|
|
begin
|
|
coinbase_item.coinbase_accounts
|
|
.left_joins(:account_provider)
|
|
.where(account_providers: { id: nil })
|
|
.count
|
|
rescue => e
|
|
0
|
|
end
|
|
end %>
|
|
|
|
<% if unlinked_count.to_i > 0 && coinbase_item.accounts.empty? %>
|
|
<%# No accounts imported yet - show prominent setup prompt %>
|
|
<div class="p-4 flex flex-col gap-3 items-center justify-center">
|
|
<p class="text-primary font-medium text-sm"><%= t(".setup_needed") %></p>
|
|
<p class="text-secondary text-sm"><%= t(".setup_description") %></p>
|
|
<%= render DS::Link.new(
|
|
text: t(".setup_action"),
|
|
icon: "plus",
|
|
variant: "primary",
|
|
href: setup_accounts_coinbase_item_path(coinbase_item),
|
|
frame: :modal
|
|
) %>
|
|
</div>
|
|
<% elsif unlinked_count.to_i > 0 %>
|
|
<%# Some accounts imported, more available - show subtle link %>
|
|
<div class="pt-2 border-t border-primary">
|
|
<%= link_to setup_accounts_coinbase_item_path(coinbase_item),
|
|
data: { turbo_frame: :modal },
|
|
class: "flex items-center gap-2 text-sm text-secondary hover:text-primary transition-colors" do %>
|
|
<%= icon "plus", size: "sm" %>
|
|
<span><%= t(".more_wallets_available", count: unlinked_count) %></span>
|
|
<% end %>
|
|
</div>
|
|
<% elsif coinbase_item.accounts.empty? && coinbase_item.coinbase_accounts.none? %>
|
|
<%# No coinbase_accounts at all - waiting for sync %>
|
|
<div class="p-4 flex flex-col gap-3 items-center justify-center">
|
|
<p class="text-primary font-medium text-sm"><%= t(".no_accounts_title") %></p>
|
|
<p class="text-secondary text-sm"><%= t(".no_accounts_message") %></p>
|
|
</div>
|
|
<% end %>
|
|
</div>
|
|
<% end %>
|
|
</details>
|
|
<% end %>
|