back/app/models/airdrop_mint.rb
def mint
    # Don't mint twice:
    return if self.minted

    referral = self.referral
    app = referral.app

    # Don't mint for apps that don't support on-chain interactions:
    return unless app.onchain_airdrop_enabled

    referred_user = referral.referred_user
    wallet_address = referred_user.wallet_address

    # Don't try to start minting if the user doesn't have a wallet yet.
    # The vault creation process should start minting all the pending rewards
    # when the user generates their vault:
    return unless wallet_address.present?

    contract_address = app.contract_address

    if app.is_erc721?
      contract = ERC721Contract.new(app.network, contract_address)
      token_id = contract.next_available_token_id
      raise "No ERC721 tokens left to airdrop. Unable to continue." unless token_id.present?
      contract.transfer(wallet_address, token_id)

      self.update(minted: true)
    elsif app.is_erc20?
      contract = ERC20Contract.new(app.network, contract_address)
      remaining_balance = contract.balance_available_for_airdrop
      raise "No ERC20 tokens left to airdrop. Unable to continue." unless remaining_balance > 1
      # XXX Give 1 coin? app.airdrop_amount?
      contract.transfer(wallet_address, 1)

      self.update(minted: true)
    else
      raise "Arbitrary contract type not yet implemented - must use ERC20 or ERC721."
    end
  end
#
# Push the reward to the blockchain
#
# TODO rename this (transfer?)
#
Push the reward to the blockchain
TODO rename this (transfer?)
Push the reward to the blockchain TODO rename this ( transfer? )
def mint
    return if self.minted
    referral = self.referral
    app = referral.app
    return unless app.onchain_airdrop_enabled
    referred_user = referral.referred_user
    wallet_address = referred_user.wallet_address
    return unless wallet_address.present?
    contract_address = app.contract_address
    if app.is_erc721?
      contract = ERC721Contract.new(app.network, contract_address)
      token_id = contract.next_available_token_id
      raise "No ERC721 tokens left to airdrop. Unable to continue." unless token_id.present?
      contract.transfer(wallet_address, token_id)
      self.update(minted: true)
    elsif app.is_erc20?
      contract = ERC20Contract.new(app.network, contract_address)
      remaining_balance = contract.balance_available_for_airdrop
      raise "No ERC20 tokens left to airdrop. Unable to continue." unless remaining_balance > 1
      contract.transfer(wallet_address, 1)
      self.update(minted: true)
    else
      raise "Arbitrary contract type not yet implemented - must use ERC20 or ERC721."
    end
  end
def mint return if self . minted referral = self . referral app = referral . app return unless app . onchain_airdrop_enabled referred_user = referral . referred_user wallet_address = referred_user . wallet_address return unless wallet_address . present? contract_address = app . contract_address if app . is_erc721? contract = ERC721Contract . new ( app . network , contract_address ) token_id = contract . next_available_token_id raise "No ERC721 tokens left to airdrop. Unable to continue." unless token_id . present? contract . transfer ( wallet_address , token_id ) self . update ( minted : true ) elsif app . is_erc20? contract = ERC20Contract . new ( app . network , contract_address ) remaining_balance = contract . balance_available_for_airdrop raise "No ERC20 tokens left to airdrop. Unable to continue." unless remaining_balance > 1 contract . transfer ( wallet_address , 1 ) self . update ( minted : true ) else raise "Arbitrary contract type not yet implemented - must use ERC20 or ERC721." end end
Push the reward to the blockchain
TODO rename this (transfer?)
Push the reward to the blockchain TODO rename this ( transfer? )
# Don't mint twice: # Don't mint for apps that don't support on-chain interactions: # Don't try to start minting if the user doesn't have a wallet yet. # The vault creation process should start minting all the pending rewards # when the user generates their vault: # XXX Give 1 coin? app.airdrop_amount?