Skip to content

Commit

Permalink
update new platforms transactions page
Browse files Browse the repository at this point in the history
  • Loading branch information
pan-xiong committed Jan 6, 2024
1 parent 624b572 commit b77eb80
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 8 deletions.
6 changes: 4 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def transactions_table_headers
},
{
name: "币种投入/总投入",
sort: "none"
sort: "cost_ratio"
},
{
name: "预计收益 / 实际收益",
Expand Down Expand Up @@ -538,8 +538,10 @@ def get_list_url(source_type, params)
def get_origin_list_url(source_type, params)
if source_type == :public
origin_transactions_path(params)
else
elsif source_type == :users
users_origin_transactions_path(params)
else
new_platforms_origin_transactions_path(params)
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/jobs/generate_origin_transactions_snapshots_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def perform(date: Date.today)

def generate_snapshot(transactions_snapshot_info)
# 查找符合条件的原始交易记录
origin_transactions = OriginTransaction.where(trade_type: 'buy', user_id: nil)
origin_transactions = OriginTransaction.year_to_date.where(trade_type: 'buy', user_id: nil)

# 批量处理原始交易记录
origin_transactions.find_each(batch_size: 100) do |origin_transaction|
Expand Down
4 changes: 2 additions & 2 deletions app/models/origin_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ class OriginTransaction < ApplicationRecord
FILTER_SYMBOL = %w(USDC).freeze

def self.available
OriginTransaction.where.not(source: ['gate', 'bitget']).where('from_symbol NOT IN (?) and ((from_symbol IN (?) AND amount >= 50) OR from_symbol NOT IN (?))', FILTER_SYMBOL, SKIP_SYMBOLS, SKIP_SYMBOLS)
OriginTransaction.where('from_symbol NOT IN (?) and ((from_symbol IN (?) AND amount >= 50) OR from_symbol NOT IN (?))', FILTER_SYMBOL, SKIP_SYMBOLS, SKIP_SYMBOLS)
end

def self.year_to_date
OriginTransaction.where('event_time >= ?', DateTime.parse('2023-01-01'))
OriginTransaction.where.not(source: ['gate', 'bitget']).where.('event_time >= ?', DateTime.parse('2023-01-01'))
end

def self.total_summary(user_id=nil)
Expand Down
2 changes: 1 addition & 1 deletion app/models/user_spot_balance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class UserSpotBalance < ApplicationRecord

scope :available, -> { where("qty > 0") }

enum source: [:binance, :okx, :huobi]
enum source: [:binance, :okx, :huobi, :gate]

def current_price
OriginTransaction.find_by(original_symbol: origin_symbol, source: source)&.current_price
Expand Down
40 changes: 40 additions & 0 deletions app/views/origin_transactions/_new_list.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<table class="table">
<thead>
<tr class="table-container-tr">
<% transactions_table_headers.each do |h| %>
<% next if h[:sort].in?(['cost_ratio', 'revenue_ratio']) %>
<th scope="col">
<% if h[:sort] == "none" %>
<%= "#{h[:name]}" %>
<% else %>
<% url = get_origin_list_url(source_type, ch_remote_params(params, h[:sort])) %>
<%= link_to "#{h[:name]}", url, remote: true, class: "#{params[:sort] == h[:sort] ? 'text-primary' : ''}" %>
<% end %>
</th>
<% end %>
<th scope="col">Campaign</th>
<th></th>
</tr>
</thead>
<tbody>
<% @txs.each do |h| %>
<tr>
<td><%= h.event_time.strftime('%Y-%m-%d %H:%M:%S') rescue '' %></td>
<td><%= h.from_symbol %> / <%= h.to_symbol %></td>
<td class="<%= trade_type_style(h.trade_type) %>"><%= h.trade_type == 'buy' ? '买入' : '卖出' %></td>
<td data-bs-toggle="tooltip" title='<%= h.price %>'><%= h.price.round(4) %> <%= h.to_symbol %></td>
<td data-bs-toggle="tooltip" title='<%= h.cost %>'><%= h.cost.round(4) %> <%= h.to_symbol %></td>
<td data-bs-toggle="tooltip" title='<%= h.current_price %>'><%= h.current_price.round(4) %> <%= h.to_symbol %></td>
<td><%= h.qty.round(4) %></td>
<td><%= h.amount.round(4) %> <%= h.to_symbol %></td>
<td class="<%= h.revenue > 0 ? 'pos-num' : 'neg-num' %>"><%= display_spot_tx_revenue(h.revenue, h.to_symbol, h.trade_type) %></td>
<td class="<%= h.roi > 0 ? 'pos-num' : 'neg-num' %>" ><%= display_spot_tx_roi(h.roi, h.trade_type) %></td>
<td><%= h.source %></td>
</tr>
<% end %>
</tbody>
</table>

<div class="paginationBox p-4">
<%= paginate @txs %>
</div>
2 changes: 1 addition & 1 deletion app/views/origin_transactions/new_platforms.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<% end %>
</div>
<div id="trading-histories-container">
<%= render partial: "list", locals: { source_type: :public } %>
<%= render partial: "new_list", locals: { source_type: :new_platform } %>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion app/views/origin_transactions/new_platforms.js.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
$("#trading-histories-container").html("<%= j render partial: "list", locals: { source_type: :public } %>");
$("#trading-histories-container").html("<%= j render partial: "new_list", locals: { source_type: :new_platform } %>");
$('[data-bs-toggle="tooltip"]').tooltip();

0 comments on commit b77eb80

Please sign in to comment.