From 590b37c08560768cf84798640820b5408b35b5c4 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Wed, 24 Aug 2022 23:12:02 +0000 Subject: [PATCH] Show Protocoin total circulation --- apiserver/apiserver/api/serializers.py | 6 ++++++ webclient/src/Paymaster.js | 2 ++ 2 files changed, 8 insertions(+) diff --git a/apiserver/apiserver/api/serializers.py b/apiserver/apiserver/api/serializers.py index a6ddb51..e77d648 100644 --- a/apiserver/apiserver/api/serializers.py +++ b/apiserver/apiserver/api/serializers.py @@ -214,6 +214,7 @@ class MemberSerializer(serializers.ModelSerializer): email = fields.UserEmailField(serializers.EmailField) phone = serializers.CharField() protocoin = serializers.SerializerMethodField() + total_protocoin = serializers.SerializerMethodField() class Meta: model = models.Member @@ -257,6 +258,11 @@ class MemberSerializer(serializers.ModelSerializer): total = transactions.aggregate(Sum('protocoin'))['protocoin__sum'] or 0 return total + def get_total_protocoin(self, obj): + transactions = models.Transaction.objects + total = transactions.aggregate(Sum('protocoin'))['protocoin__sum'] or 0 + return total + def update(self, instance, validated_data): instance.user.email = validated_data.get('email', instance.user.email) instance.user.save() diff --git a/webclient/src/Paymaster.js b/webclient/src/Paymaster.js index 46e98e4..63cd02e 100644 --- a/webclient/src/Paymaster.js +++ b/webclient/src/Paymaster.js @@ -94,6 +94,8 @@ export function Paymaster(props) {

Current balance: ₱ {user.member.protocoin.toFixed(2)}

+

Total circulation: ₱ {user.member.total_protocoin.toFixed(2)}

+ Buy any amount of Protocoin: