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

airdrop_recipients.rb #4

Open geekelo opened 1 month ago

geekelo commented 1 month ago

FILE

ActiveAdmin.register AirdropRecipient do

  actions :all, except: :destroy

  includes :airdrop

  menu parent: 'Stores', label: 'Airdrop Recipients'

  # preserve_default_filters!
  filter :id_eq, as: :string, label: 'ID'
  filter :airdrop_id_eq, as: :string, label: 'Airdrop ID'
  filter :crypto_transfer_id_eq, as: :string, label: 'Crypto Transfer ID'
  filter :wallet_address_eq, as: :string, label: 'Wallet Address'
  filter :original_wallet_address_eq, as: :string, label: 'Original Wallet Address'
  filter :status, as: :select, collection: AirdropRecipient::AIRDROP_RECIPIENT_STATUS
  filter :active

  permit_params :airdrop, :crypto_transfer, :participation, :ref1, :balance, :wallet_address, :token_balance,
                :transaction_hash, :status, :sent_at, :active

  index do
    selectable_column
    id_column
    column :airdrop
    column :crypto_transfer
    column :user_email do |airdrop_recipient|
      airdrop_recipient.user_email
    end
    column :token_balance
    column :wallet_address

    column :status
    column :api_request_body do |airdrop_recipient|
      unless airdrop_recipient.crypto_transfer&.complete?
        wallet_id = airdrop_recipient.airdrop.store.default_crypto_api_wallet&.external_id
        token = airdrop_recipient.airdrop.token_symbol
        json_request_body = {
          walletId: "#{wallet_id}",
          amount: "#{airdrop_recipient.token_balance}",
          token: "#{token}",
          destinationAddress: "#{airdrop_recipient.wallet_address}",
          externalId: "#{airdrop_recipient.crypto_transfer&.id}",
          chainId: ENV.fetch('POLYGON_CHAIN_ID').to_i
        }.to_json
        "<code>#{json_request_body}</code>".html_safe
      end
    end
    column :participation
    column :balance
    column :ref1
    column :original_wallet_address
    column :created_at
    column :updated_at
  end

  csv do
    column :id
    column :airdrop
    column :crypto_transfer
    column :user_email do |airdrop_recipient|
      airdrop_recipient.user_email
    end
    column :participation
    column :balance
    column :ref1
    column :token_balance
    column :wallet_address
    column :original_wallet_address    
    column :status
    column :created_at
    column :updated_at
    column :api_request_body do |airdrop_recipient|
      unless airdrop_recipient.crypto_transfer&.complete?
        wallet_id = airdrop_recipient.airdrop.store.default_crypto_api_wallet&.external_id
        token = airdrop_recipient.airdrop.token_symbol
        {
          walletId: "#{wallet_id}",
          amount: "#{airdrop_recipient.token_balance}",
          token: "#{token}",
          destinationAddress: "#{airdrop_recipient.wallet_address}",
          externalId: "#{airdrop_recipient.crypto_transfer&.id}",
          chainId: ENV.fetch('POLYGON_CHAIN_ID').to_i
        }.to_json
      end
    end
  end

  show do
    default_main_content
    attributes_table do
      row 'User Email' do |airdrop_recipient|
        airdrop_recipient.user_email
      end
    end
  end
end
geekelo commented 1 month ago

This code configures the admin interface for managing AirdropRecipient records in an ActiveAdmin panel within a Ruby on Rails application. Here's a detailed breakdown of what this file does:

File: airdrop_recipient.rb

1. ActiveAdmin.register AirdropRecipient do

2. actions :all, except: :destroy

3. includes :airdrop

4. menu parent: 'Stores', label: 'Airdrop Recipients'

5. filter :...

6. permit_params :...

7. index do ... end

8. csv do ... end

9. show do ... end

Summary:

This setup provides a robust and customized interface for managing airdrop recipients in the application, with careful attention to security and performance.