diff --git a/faucet/constraints.py b/faucet/constraints.py new file mode 100644 index 00000000..e65009c1 --- /dev/null +++ b/faucet/constraints.py @@ -0,0 +1,26 @@ +from core.constraints import * +from .models import DonationReceipt, Chain, ClaimReceipt + +class DonationConstraint(ConstraintVerification): + _param_keys = [ + ConstraintParam.CHAIN + ] + + def is_observed(self, *args, **kwargs): + chain_pk = self._param_values[ConstraintParam.CHAIN] + return DonationReceipt.objects\ + .filter(chain__pk=chain_pk)\ + .filter(user_profile = self.user_profile)\ + .filter(status=ClaimReceipt.PROCESSED_FOR_TOKENTAP)\ + .exists() + +class OptimismDonationConstraint(DonationConstraint): + _param_keys = [] + + def is_observed(self, *args, **kwargs): + try: + chain = Chain.objects.get(chain_id=10) + except: + return False + self._param_values[ConstraintParam.CHAIN] = chain.pk + return super().is_observed(*args, **kwargs) \ No newline at end of file diff --git a/prizetap/migrations/0030_alter_constraint_name.py b/prizetap/migrations/0030_alter_constraint_name.py new file mode 100644 index 00000000..461c71e0 --- /dev/null +++ b/prizetap/migrations/0030_alter_constraint_name.py @@ -0,0 +1,18 @@ +# Generated by Django 4.0.4 on 2023-10-07 08:33 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('prizetap', '0029_constraint_icon_url'), + ] + + operations = [ + migrations.AlterField( + model_name='constraint', + name='name', + field=models.CharField(choices=[('BrightIDMeetVerification', 'BrightIDMeetVerification'), ('BrightIDAuraVerification', 'BrightIDAuraVerification'), ('HaveUnitapPass', 'HaveUnitapPass'), ('NotHaveUnitapPass', 'NotHaveUnitapPass'), ('OptimismDonationConstraint', 'OptimismDonationConstraint')], max_length=255, unique=True), + ), + ] diff --git a/prizetap/models.py b/prizetap/models.py index 3370e466..9eeefd45 100644 --- a/prizetap/models.py +++ b/prizetap/models.py @@ -1,5 +1,6 @@ from django.db import models from faucet.models import Chain +from faucet.constraints import OptimismDonationConstraint from django.utils import timezone from django.utils.translation import gettext_lazy as _ from authentication.models import NetworkTypes, UserProfile @@ -10,7 +11,11 @@ class Constraint(UserConstraint): - constraints = UserConstraint.constraints + [HaveUnitapPass, NotHaveUnitapPass] + constraints = UserConstraint.constraints + [ + HaveUnitapPass, + NotHaveUnitapPass, + OptimismDonationConstraint + ] name = UserConstraint.create_name_field(constraints) diff --git a/prizetap/views.py b/prizetap/views.py index c33fa467..3c697686 100644 --- a/prizetap/views.py +++ b/prizetap/views.py @@ -7,6 +7,7 @@ from rest_framework.views import APIView from faucet.models import Chain from faucet.serializers import SmallChainSerializer +from faucet.constraints import * from .models import Raffle, RaffleEntry, Constraint from .serializers import ( RaffleSerializer,