diff --git a/app/models/ckb_transaction.rb b/app/models/ckb_transaction.rb index 4091e3cbc..964d5cda4 100644 --- a/app/models/ckb_transaction.rb +++ b/app/models/ckb_transaction.rb @@ -192,7 +192,11 @@ def cell_deps end def income(address) - outputs.where(address: address).sum(:capacity) - inputs.where(address: address).sum(:capacity) + if tx_pending? + cell_outputs.where(address: address).sum(:capacity) - input_cells.where(address: address).sum(:capacity) + else + outputs.where(address: address).sum(:capacity) - inputs.where(address: address).sum(:capacity) + end end def dao_transaction? diff --git a/app/serializers/ckb_transaction_serializer.rb b/app/serializers/ckb_transaction_serializer.rb index 7c8e742fb..b1c700eee 100644 --- a/app/serializers/ckb_transaction_serializer.rb +++ b/app/serializers/ckb_transaction_serializer.rb @@ -45,7 +45,8 @@ class CkbTransactionSerializer end attribute :display_inputs do |object, params| - Rails.cache.fetch("display_inputs_previews_#{params[:previews].present?}_#{object.id}", expires_in: 1.day) do + cache_key = "display_inputs_previews_#{params[:previews].present?}_#{object.id}_#{object.inputs.cache_key}" + Rails.cache.fetch(cache_key, expires_in: 1.day) do if params && params[:previews] object.display_inputs(previews: true) else @@ -55,7 +56,8 @@ class CkbTransactionSerializer end attribute :display_outputs do |object, params| - Rails.cache.fetch("display_outputs_previews_#{params[:previews].present?}_#{object.id}", expires_in: 1.day) do + cache_key = "display_outputs_previews_#{params[:previews].present?}_#{object.id}_#{object.outputs.cache_key}" + Rails.cache.fetch(cache_key, expires_in: 1.day) do if params && params[:previews] object.display_outputs(previews: true) else diff --git a/app/serializers/ckb_transactions_serializer.rb b/app/serializers/ckb_transactions_serializer.rb index 092895152..aba90613f 100644 --- a/app/serializers/ckb_transactions_serializer.rb +++ b/app/serializers/ckb_transactions_serializer.rb @@ -56,6 +56,6 @@ class CkbTransactionsSerializer end attribute :create_timestamp do |object| - (object.created_at.to_f * 1000).to_s + (object.created_at.to_f * 1000).to_i.to_s end end