Skip to content

Commit

Permalink
Prizetap: add optimism donation constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
ShayanShiravani committed Oct 7, 2023
1 parent 1f07489 commit 3b92067
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
26 changes: 26 additions & 0 deletions faucet/constraints.py
Original file line number Diff line number Diff line change
@@ -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)
18 changes: 18 additions & 0 deletions prizetap/migrations/0030_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 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),
),
]
7 changes: 6 additions & 1 deletion prizetap/models.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,7 +11,11 @@


class Constraint(UserConstraint):
constraints = UserConstraint.constraints + [HaveUnitapPass, NotHaveUnitapPass]
constraints = UserConstraint.constraints + [
HaveUnitapPass,
NotHaveUnitapPass,
OptimismDonationConstraint
]
name = UserConstraint.create_name_field(constraints)


Expand Down
1 change: 1 addition & 0 deletions prizetap/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3b92067

Please sign in to comment.