Skip to content

Commit

Permalink
Merge pull request #2177 from nervosnetwork/develop
Browse files Browse the repository at this point in the history
Deploy to testnet
  • Loading branch information
rabbitz authored Sep 4, 2024
2 parents 405ec8f + ca8faea commit b841bb7
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions app/interactions/addresses/ckb_transactions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ def execute
raise AddressNotFoundError if address.is_a?(NullAddress)

address_id = address.map(&:id)

order_by, asc_or_desc = account_books_ordering
records = CkbTransaction.tx_committed.joins(:account_books).where(
account_books: { address_id: },
).order(order_by => asc_or_desc, "ckb_transactions.tx_index" => "desc").distinct.page(page).per(page_size)

account_books = AccountBook.joins(:ckb_transaction).
where(account_books: { address_id: }, ckb_transactions: { tx_status: :committed }).
order(transactions_ordering).
select("DISTINCT account_books.ckb_transaction_id, ckb_transactions.block_timestamp, ckb_transactions.tx_index").
page(page).per(page_size)
records = CkbTransaction.where(id: account_books.map(&:ckb_transaction_id)).order(transactions_ordering)
options = paginate_options(records, address_id)
options.merge!(params: { previews: true, address: })

Expand All @@ -28,13 +28,12 @@ def execute

private

def account_books_ordering
def transactions_ordering
sort_by = "ckb_transactions.block_timestamp"
_, sort_order = sort.split(".", 2)

sort_order = "asc" unless sort_order&.match?(/^(asc|desc)$/i)

[sort_by, sort_order]
"#{sort_by} #{sort_order}, ckb_transactions.tx_index desc"
end

def paginate_options(records, address_id)
Expand Down

0 comments on commit b841bb7

Please sign in to comment.