Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev -> Prod #121

Merged
merged 8 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@
AccountUpvotedListsAPI.as_view(),
name="accounts_api_upvoted_lists",
),
path(
"v1/accounts/<str:account_id>/rounds",
RoundsListAPI.as_view(),
name="accounts_api_rounds",
),
# donate contract config
path(
"v1/donate_contract_config",
Expand Down Expand Up @@ -149,7 +154,7 @@
name="rounds_applications_api",
),
path("v1/<str:account_id>/projects", AccountProjectListAPI.as_view(), name="user_projects_api"),
path("v1/<str:account_id>/<int:project_id>/project-stats", ProjectStatsAPI.as_view(), name="projects_api"),
path("v1/<str:account_id>/project-stats", ProjectStatsAPI.as_view(), name="projects_stat__api"),

path(
"v1/mpdao/voter-info",
Expand Down
4 changes: 2 additions & 2 deletions base/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
POTLOCK_TLA = "potlock.testnet" if ENVIRONMENT == "testnet" else ("staging.potlock.near" if ENVIRONMENT == "dev" else "potlock.near")
# NADABOT_TLA = "nadabot.testnet" if ENVIRONMENT == "testnet" else "nadabot.near"
NADABOT_TLA = "nadabot.testnet" if ENVIRONMENT == "testnet" else ("staging.nadabot.near" if ENVIRONMENT == "dev" else "nadabot.near")
STELLAR_CONTRACT_ID = "CBMCMOS3KX2R3AFOG3SZFPOFSX2ASMIC3TWF5FTIQTQSLZ6G3RUBQUM5" if ENVIRONMENT == "testnet" else ("" if ENVIRONMENT == "dev" else "")
STELLAR_PROJECTS_REGISTRY_CONTRACT = "CDOR6NBGSIE6ARJZHRAJAEDN2NG4QS67LSQRMJETVX6GHEJELLVPXWJQ" if ENVIRONMENT == "testnet" else ("" if ENVIRONMENT == "dev" else "")
STELLAR_CONTRACT_ID = "CBEW52FEWIFWK4LCSMX5FAAG2MYB36C2RLKS5YEIF5AOJEDMCGYU3ZGB" if ENVIRONMENT == "testnet" else ("" if ENVIRONMENT == "dev" else "")
STELLAR_PROJECTS_REGISTRY_CONTRACT = "CBG2JAGBYUAM3YLQFNFR3ZSWVR7XR5BEQHQ6XGUA3HCWVCHWO3RS3YUD" if ENVIRONMENT == "testnet" else ("" if ENVIRONMENT == "dev" else "")
NEAR_SOCIAL_CONTRACT_ADDRESS = (
"v1.social08.testnet" if ENVIRONMENT == "testnet" else "social.near"
)
Expand Down
39 changes: 23 additions & 16 deletions grantpicks/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class RoundsListAPI(APIView, CustomSizePageNumberPagination):

@extend_schema(
parameters=[
OpenApiParameter("account_id", str, OpenApiParameter.PATH, description="get rounds by this account"),
OpenApiParameter(
name="sort",
type=str,
Expand Down Expand Up @@ -84,7 +85,17 @@ class RoundsListAPI(APIView, CustomSizePageNumberPagination):
)
@method_decorator(cache_page(60 * 1))
def get(self, request: Request, *args, **kwargs):
rounds = Round.objects.all()
account_id = kwargs.get("account_id")
if account_id:
try:
account = Account.objects.get(id=account_id)
rounds = Round.objects.filter(owner=account)
except Account.DoesNotExist:
return Response(
{"message": f"Account with ID {account_id} not found."}, status=404
)
else:
rounds = Round.objects.all()
chain_param = request.query_params.get("chain")
if chain_param:
# chain = Chain.objects.get(name=chain_param)
Expand Down Expand Up @@ -335,16 +346,11 @@ def get(self, request: Request, *args, **kwargs):


class ProjectStatsAPI(APIView):
def dispatch(self, request, *args, **kwargs):
return super(ProjectStatsAPI, self).dispatch(request, *args, **kwargs)


@method_decorator(
cache_page(60 * 5)
)
@extend_schema(
parameters=[
OpenApiParameter("project_id", str, OpenApiParameter.PATH),
OpenApiParameter("account_id", str, OpenApiParameter.PATH),
*pagination_parameters,
],
Expand All @@ -369,24 +375,25 @@ def dispatch(self, request, *args, **kwargs):
}
)
def get(self, request: Request, *args, **kwargs):
project_id = kwargs.get("project_id")
owner_address = kwargs.get("account_id")
project = Project.objects.get(id=project_id)

total_donations_usd = (
Donation.objects.all().aggregate(Sum("total_amount_usd"))[
"total_amount_usd__sum"
]
or 0
)
# project = Project.objects.get(id=project_id)
account = Account.objects.get(id=owner_address)

# total_donations_usd = (
# Donation.objects.all().aggregate(Sum("total_amount_usd"))[
# "total_amount_usd__sum"
# ]
# or 0
# )
total_fund_received = (
PotPayout.objects.filter(paid_at__isnull=False, recipient_id=owner_address).aggregate(
Sum("amount_paid_usd")
)["amount_paid_usd__sum"]
or 0
)
rounds = project.rounds_approved_in.count()
total_votes = Vote.objects.filter(pairs__project=project).aggregate(total_votes=Count('id'))['total_votes']
rounds = account.rounds_approved_in.count()
total_votes = Vote.objects.filter(pairs__voted_project=account).aggregate(total_votes=Count('id'))['total_votes']

return Response(
{
Expand Down
7 changes: 7 additions & 0 deletions grantpicks/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Meta:
fields = [
"id", # Include the primary key
"on_chain_id",
"chain",
"factory_contract",
"deployed_at",
"owner",
Expand Down Expand Up @@ -105,6 +106,10 @@ class Meta:
admins = AccountSerializer(many=True)
remaining_dist_by = AccountSerializer()
contacts = ProjectContactSerializer(many=True, required=False)
chain = serializers.SerializerMethodField()

def get_chain(self, obj):
return obj.chain.name


class ApplicationReviewSerializer(ModelSerializer):
Expand Down Expand Up @@ -173,6 +178,8 @@ class Meta:
SIMPLE_ROUND_EXAMPLE = {
"id": 1,
"name": "InteractGrant TO Apply V1",
"on_chain_id": 13,
"chain": "stellar",
"owner": "GD4I4FXMIKKKVSGVCGNILRFFHDQHITMDW545SCLGEOKGBN6W44AV6367",
"contacts": [
{
Expand Down
4 changes: 2 additions & 2 deletions indexer_app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,7 @@ def get_pair_projects(pair_id: int, round_id: int, chain_id: str) -> Dict:
contract_id = settings.STELLAR_CONTRACT_ID
function_name = "get_pair_by_index"
parameters = [stellar_sdk.scval.to_uint128(round_id), stellar_sdk.scval.to_uint32(pair_id)]
public_key = "GDRZ47PQ43TA7GCBW22HHRM6FHN644KF23HFNZ76I46HPNBD5Q7YEYLJ"
public_key = "GAMFYFI7TIAPMLSAWIECFZCN52TR3NUIO74YM7ECBCPM6J743KENH367" # TODO: move to settings
acct = server.load_account(public_key)

pair_result = server.simulate_transaction(
Expand Down Expand Up @@ -1463,7 +1463,7 @@ def process_vote_event(event_data, tx_hash, chain_id="stellar"):
round_id, vote_data = event_data[0], event_data[1]
else:
# vote_event_data = event_data['vote']
round_id, vote_data = event_data.get("round_id", 2), event_data['vote']
round_id, vote_data = event_data.get("round_id"), event_data['vote']

chain = Chain.objects.get(name=chain_id)
round_obj = Round.objects.get(on_chain_id=round_id, chain=chain)
Expand Down
Loading