Skip to content

Commit

Permalink
Merge pull request #266 from UnitapApp/feature/tokentap-contribution-hub
Browse files Browse the repository at this point in the history
Feature/tokentap contribution hub
  • Loading branch information
ShayanShiravani authored Jan 19, 2024
2 parents ca7bf33 + eff3469 commit a434b4f
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 13 deletions.
21 changes: 8 additions & 13 deletions core/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,14 @@ class ConstraintParam(Enum):
USERNAME = "username"
FROM_DATE = "from_date"
TO_DATE = "to_date"
WALLETS_CSV_FILE = "wallets_csv_file"
CSV_FILE = "csv_file"
COLLECTION_ADDRESS = "collection_address"
MINIMUM = "minimum"

@classmethod
def choices(cls):
return [(key.value, key.name) for key in cls]

@classmethod
def is_valid_wallets_csv_file(cls):
# TODO: fixme
pass


class ConstraintVerification(ABC):
_param_keys = []
Expand Down Expand Up @@ -159,19 +154,19 @@ def is_observed(self, *args, **kwargs):
# return token_count >= int(minimum)


class AllowList(ConstraintVerification):
_param_keys = [ConstraintParam.WALLETS_CSV_FILE]
class AllowListVerification(ConstraintVerification):
_param_keys = [ConstraintParam.CSV_FILE]

def __init__(self, user_profile, response: str = None) -> None:
super().__init__(user_profile, response)
def __init__(self, user_profile) -> None:
super().__init__(user_profile)

def is_observed(self, *args, **kwargs):
file_path = self._param_values[ConstraintParam.WALLETS_CSV_FILE]
file_path = self._param_values[ConstraintParam.CSV_FILE.name]
self.allow_list = []
with open(file_path, newline="") as f:
reader = csv.reader(f)
self.allow_list = list(reader)
self.allow_list = [a.lower() for a in self.allow_list]
data = list(reader)
self.allow_list = [a[0].lower() for a in data]
user_wallets = self.user_profile.wallets.values_list(
Lower("address"), flat=True
)
Expand Down
2 changes: 2 additions & 0 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from faucet.faucet_manager.lnpay_client import LNPayClient

from .constraints import (
AllowListVerification,
BrightIDAuraVerification,
BrightIDMeetVerification,
HasNFTVerification,
Expand Down Expand Up @@ -70,6 +71,7 @@ class Type(models.TextChoices):
BrightIDMeetVerification,
BrightIDAuraVerification,
HasNFTVerification,
AllowListVerification,
]

name = models.CharField(
Expand Down
22 changes: 22 additions & 0 deletions core/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import datetime
import logging
import os
import time
import uuid
from contextlib import contextmanager

import pytz
import web3.exceptions
from django.core.cache import cache
from django.core.files.storage import default_storage
from django.core.files.uploadedfile import UploadedFile
from eth_account.messages import encode_defunct
from solana.rpc.api import Client
from web3 import Account, Web3
Expand All @@ -14,6 +18,7 @@
from web3.middleware import geth_poa_middleware
from web3.types import TxParams, Type

from brightIDfaucet.settings import MEDIA_ROOT
from core.constants import ERC721_READ_METHODS


Expand Down Expand Up @@ -243,3 +248,20 @@ def get_number_of_tokens(self, address: str):

def to_checksum_address(self, address: str):
return self.web3_utils.w3.to_checksum_address(address)


class UploadFileStorage:
BASE_PATH = time.strftime("%Y%m%d") + "/"

def __init__(self, upload_to=None) -> None:
self.upload_to = upload_to or self.BASE_PATH

def save(self, file: UploadedFile):
_, file_extension = os.path.splitext(file.name)
milliseconds = round(time.time() * 1000)
time_str = time.strftime("%H%M%S") + "-" + str(milliseconds)
file_name = time_str + "-" + str(uuid.uuid4())
path = default_storage.save(
str(self.upload_to or "") + file_name + file_extension, file
)
return MEDIA_ROOT + "/" + path
18 changes: 18 additions & 0 deletions prizetap/migrations/0052_alter_constraint_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.0.4 on 2024-01-17 10:37

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('prizetap', '0051_alter_raffle_twitter_url'),
]

operations = [
migrations.AlterField(
model_name='constraint',
name='name',
field=models.CharField(choices=[('core.BrightIDMeetVerification', 'BrightIDMeetVerification'), ('core.BrightIDAuraVerification', 'BrightIDAuraVerification'), ('core.HasNFTVerification', 'HasNFTVerification'), ('core.AllowListVerification', 'AllowListVerification'), ('prizetap.HaveUnitapPass', 'HaveUnitapPass'), ('prizetap.NotHaveUnitapPass', 'NotHaveUnitapPass'), ('faucet.OptimismDonationConstraint', 'OptimismDonationConstraint'), ('faucet.OptimismClaimingGasConstraint', 'OptimismClaimingGasConstraint')], max_length=255, unique=True),
),
]
18 changes: 18 additions & 0 deletions tokenTap/migrations/0032_alter_constraint_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.0.4 on 2024-01-19 14:43

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('tokenTap', '0031_tokendistribution_constraint_params_and_more'),
]

operations = [
migrations.AlterField(
model_name='constraint',
name='name',
field=models.CharField(choices=[('core.BrightIDMeetVerification', 'BrightIDMeetVerification'), ('core.BrightIDAuraVerification', 'BrightIDAuraVerification'), ('core.HasNFTVerification', 'HasNFTVerification'), ('core.AllowListVerification', 'AllowListVerification'), ('tokenTap.OncePerMonthVerification', 'OncePerMonthVerification'), ('tokenTap.OnceInALifeTimeVerification', 'OnceInALifeTimeVerification'), ('faucet.OptimismHasClaimedGasInThisRound', 'OptimismHasClaimedGasInThisRound')], max_length=255, unique=True),
),
]

0 comments on commit a434b4f

Please sign in to comment.