Skip to content

Commit

Permalink
feat: custom chain in dashboard (#620)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-schultz authored Jun 20, 2024
1 parent f734f0c commit a7a2f03
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
8 changes: 7 additions & 1 deletion api/account/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
Customization,
AddressList,
AddressListMember,
IncludedChainId,
)


Expand Down Expand Up @@ -210,11 +211,16 @@ class AllowListInline(admin.TabularInline):
extra = 0


class IncludedChainIdInline(admin.TabularInline):
model = IncludedChainId
extra = 0


@admin.register(Customization)
class CustomizationAdmin(ScorerModelAdmin):
form = CustomizationForm
raw_id_fields = ["scorer"]
inlines = [AllowListInline]
inlines = [AllowListInline, IncludedChainIdInline]
fieldsets = [
(
None,
Expand Down
5 changes: 5 additions & 0 deletions api/account/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,10 @@ def get_account_customization(request, dashboard_path: str):

weights.update(customization.get_customization_dynamic_weights())

included_chain_ids = list(
customization.included_chain_ids.values_list("chain_id", flat=True)
)

return dict(
key=customization.path,
useCustomDashboardPanel=customization.use_custom_dashboard_panel,
Expand Down Expand Up @@ -644,6 +648,7 @@ def get_account_customization(request, dashboard_path: str):
"weights": weights,
"id": customization.scorer.id,
},
includedChainIds=included_chain_ids,
)

except Customization.DoesNotExist:
Expand Down
39 changes: 39 additions & 0 deletions api/account/migrations/0030_includedchainid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Generated by Django 4.2.6 on 2024-06-20 18:56

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
dependencies = [
("account", "0029_alter_addresslist_name"),
]

operations = [
migrations.CreateModel(
name="IncludedChainId",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("chain_id", models.CharField(max_length=200)),
(
"customization",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="included_chain_ids",
to="account.customization",
),
),
],
options={
"unique_together": {("chain_id", "customization")},
},
),
]
10 changes: 10 additions & 0 deletions api/account/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,16 @@ async def aget_customization_dynamic_weights(self) -> dict:
return weights


class IncludedChainId(models.Model):
chain_id = models.CharField(max_length=200, blank=False, null=False)
customization = models.ForeignKey(
Customization, on_delete=models.CASCADE, related_name="included_chain_ids"
)

class Meta:
unique_together = ["chain_id", "customization"]


class AllowList(models.Model):
address_list = models.ForeignKey(
AddressList, on_delete=models.PROTECT, related_name="allow_lists"
Expand Down

0 comments on commit a7a2f03

Please sign in to comment.