BananaCrystal / email-templates

This repository contains in-house email templates that serve as structure for our emails. Each template can be updated and modified to fit requirements.
MIT License
0 stars 0 forks source link

master_wallet_crypto_transfer_fees.rb #30

Open geekelo opened 1 month ago

geekelo commented 1 month ago

FILE

ActiveAdmin.register MasterWalletCryptoTransferFee do
  actions :all, except: %i[destroy create new]

  includes :user, :wallet, :crypto_transfer

  config.sort_order = 'created_at_desc'

  menu parent: 'Transactions', label: 'Fees'

  scope('Completed Today', default: true) { |scope| scope.where(created_at: 1.day.ago..Time.zone.now, external_status: 'completed') }
  scope('Completed in The Last Week') { |scope| scope.where(created_at: 7.days.ago..Time.zone.now) }
  scope('Has_Fees') { |scope| scope.where('amount > ?', 0) }

  scope('Completed') { |scope| scope.where(external_status: 'completed') }
  scope('Pending') { |scope| scope.where(external_status: 'pending') }
  scope('Error') { |scope| scope.where(external_status: %w[error failed]) }
  scope('All') { |scope| scope.where.not(external_status: ['error']) }
  # See permitted parameters documentation:

  # See permitted parameters documentation:
  # https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
  #
  # Uncomment all parameters which should be permitted for assignment
  #
  # permit_params :transfer_type, :master_wallet_id, :source, :destination, :amount, :currency, :external_id, :external_status, :status, :error_code, :description, :user_id, :crypto_transfer_id, :wallet_id, :discarded_at
  #
  # or
  #
  # permit_params do
  #   permitted = [:transfer_type, :master_wallet_id, :source, :destination, :amount, :currency, :external_id, :external_status, :status, :error_code, :description, :user_id, :crypto_transfer_id, :wallet_id, :discarded_at]
  #   permitted << :other if params[:action] == 'create' && current_user.admin?
  #   permitted
  # end

  # preserve_default_filters!
  filter :user_email_cont, as: :string, label: 'Email'
  filter :id_eq, as: :string, label: 'ID'
  filter :external_id_eq, as: :string, label: 'External ID'
  filter :wallet_transfer_type
  filter :destination_type
  filter :status
  filter :fee_type, as: :select, collection: ['user_fee', 'store_fee', 'trade_fee']
  filter :fees
  filter :source
  filter :destination
  filter :source_currency
  filter :destination_currency

  index do
    selectable_column
    id_column
    column :fee_type
    column :transfer_type
    column :amount do |transfer|
      number_to_currency(transfer.amount, unit: "#{transfer.currency} ", precision: transfer.currency == 'USDT' ? 2 : 6, format: "%n %u")
    end
    column 'Crypto Transfer' do |transfer|
      link_to "#{transfer.crypto_transfer&.gross_amount} #{transfer.crypto_transfer.gross_amount_currency}", admin_crypto_transfer_path(transfer.crypto_transfer.id)
    end
    column :external_status
    column :status
    column :created_at
    column :updated_at
    actions
  end

  show do

    panel 'Fee Crypto Transfer' do
      if master_wallet_crypto_transfer_fee.crypto_transfer_for_fee

        table_for master_wallet_crypto_transfer_fee.crypto_transfer_for_fee do
          column :id do |crypto_transfer|
            link_to crypto_transfer.id, admin_crypto_transfer_path(crypto_transfer)
          end
          column '' do |transfer|
            from = transfer&.user&.name
            to =  transfer&.destination_wallet ? transfer&.destination_wallet&.user&.name : 'Blockchain'
            store = transfer&.destination_wallet&.store_wallet? ? transfer&.destination_wallet&.store&.name : ''

            "#{from} -><br> #{to} <br><strong>#{store}</strong>".html_safe
          end
          column 'Type' do |transfer|
            "#{transfer.source_type} -> #{transfer.destination_wallet ? 'wallet' : transfer.destination_type} <br>#{transfer.wallet_transfer_type} <br><strong>#{transfer.convert? ? 'convert' : ''}</strong>".html_safe
          end

          column :destination do |crypto_transfer|
            if crypto_transfer.destination
              Wallet.find_by(external_id: crypto_transfer.destination.split(":")[1]).user
            end
          end
          column :gross_amount do |transfer|
            "#{transfer.gross_amount} #{transfer.gross_amount_currency}"
          end
          column :fees do |transfer|
            "External Fees: #{transfer.external_fees.presence || '{}'} <br/>
            <strong>BananaCrystal Fees: #{BigDecimal(transfer.bananacrystal_fees ? transfer.bananacrystal_fees.to_s : '0.00').round(10)} #{transfer.fees_currency}</strong><br/>
            Fees: #{BigDecimal(transfer.fees ? transfer.fees.to_s : '0.00').round(10)} #{transfer.fees_currency}<br/>
            Total Fees: #{BigDecimal(transfer.total_fees ? transfer.total_fees.to_s : '0.00').round(10)} #{transfer.fees_currency}".html_safe
          end
          column :net_amount do |transfer|
            "<strong>#{transfer.net_amount} #{transfer.net_amount_currency}</strong>".html_safe
          end
          column :external_status
          column :status
          column :updated_at
        end
      end
    end

    panel 'Customer Crypto Transfer' do
      table_for master_wallet_crypto_transfer_fee.crypto_transfer do
        column :id do |crypto_transfer|
          link_to crypto_transfer.id, admin_crypto_transfer_path(crypto_transfer)
        end
        column '' do |crypto_transfer|
          from = crypto_transfer&.user&.name
          to =  crypto_transfer&.destination_wallet ? crypto_transfer&.destination_wallet&.user&.name : 'Blockchain'
          store = crypto_transfer&.destination_wallet&.store_wallet? ? crypto_transfer&.destination_wallet&.store&.name : ''

          "#{from} -><br> #{to} <br><strong>#{store}</strong>".html_safe
        end
        column 'Type' do |crypto_transfer|
          "#{crypto_transfer.source_type} -> #{crypto_transfer.destination_wallet ? 'wallet' : crypto_transfer.destination_type} <br>#{crypto_transfer.wallet_transfer_type} <br><strong>#{crypto_transfer.convert? ? 'convert' : ''}</strong>".html_safe
        end
        column :destination do |crypto_transfer|
          if crypto_transfer.destination
            if crypto_transfer.destination.split(":")[0] == 'wallet' 
              Wallet.find_by(external_id: crypto_transfer.destination.split(":")[1]).user
            else
              crypto_transfer.destination
            end
          end
        end
        column :gross_amount do |crypto_transfer|
          "#{crypto_transfer.gross_amount} #{crypto_transfer.source_currency}"
        end
        column :fees do |crypto_transfer|
          "External Fees: #{crypto_transfer.external_fees.presence || '{}'} <br/>
          <strong>BananaCrystal Fees: #{BigDecimal(crypto_transfer.bananacrystal_fees ? crypto_transfer.bananacrystal_fees.to_s : '0.00').round(10)} #{crypto_transfer.fees_currency}</strong><br/>
          Fees: #{BigDecimal(crypto_transfer.fees ? crypto_transfer.fees.to_s : '0.00').round(10)} #{crypto_transfer.fees_currency}<br/>
          Total Fees: #{BigDecimal(crypto_transfer.total_fees ? crypto_transfer.total_fees.to_s : '0.00').round(10)} #{crypto_transfer.fees_currency}".html_safe
        end
        column :net_amount do |crypto_transfer|
          "#{crypto_transfer.net_amount} #{crypto_transfer.destination_currency}"
        end
        column :external_status
        column :status
        column :updated_at
      end
    end

    default_main_content
  end
end
geekelo commented 1 month ago

This ActiveAdmin configuration sets up an interface for managing MasterWalletCryptoTransferFee records, which appear to involve fees associated with cryptocurrency transfers. Here's a breakdown of the configuration:

1. Actions Configuration

2. Includes

3. Sorting Configuration

4. Menu Configuration

5. Scopes

6. Permitted Parameters

7. Filters

8. Index Page Configuration

9. Show Page Configuration

Summary

This ActiveAdmin configuration provides a comprehensive interface for managing MasterWalletCryptoTransferFee records. It includes options for filtering, sorting, and viewing detailed information about transfer fees and associated records. The configurations are set to optimize performance and usability for admins, with a focus on displaying relevant details and allowing easy access to related records.