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

GITC-237: Alters matching pool contribution to be an "on-top" donation #9444

Merged
merged 2 commits into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 5 additions & 8 deletions app/assets/v2/js/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ Vue.component('grants-cart', {

// Amounts being donated to grants
donationsToGrants() {
return this.donationSummaryTotals(1 - this.gitcoinFactor);
return this.donationSummaryTotals(1);
},

// Amounts being donated to Gitcoin
Expand All @@ -226,7 +226,7 @@ Vue.component('grants-cart', {

// Total amounts being donated
donationsTotal() {
return this.donationSummaryTotals(1);
return this.donationSummaryTotals(1 + this.gitcoinFactor);
},

// String describing user's donations to grants
Expand All @@ -253,12 +253,9 @@ Vue.component('grants-cart', {
}

// Generate array of objects containing donation info from cart
let gitcoinFactor = String(100 - (100 * this.gitcoinFactor));
const donations = this.grantsByTenant.map((grant, index) => {
const tokenDetails = this.getTokenByName(grant.grant_donation_currency, isPolygon);
const amount = parseUnits(String(grant.grant_donation_amount || 0), tokenDetails?.decimals)
.mul(gitcoinFactor)
.div(100);
const amount = parseUnits(String(grant.grant_donation_amount || 0), tokenDetails?.decimals);

return {
token: tokenDetails?.addr,
Expand Down Expand Up @@ -735,8 +732,8 @@ Vue.component('grants-cart', {
this.grantsByTenant.forEach(grant => {
// Scale up number by 1e18 to use BigNumber, multiply by scaleFactor
const totalDonationAmount = parseEther(String(grant.grant_donation_amount || 0))
.mul(String(scaleFactor * 100))
.div('100');
.mul(String(Math.round(scaleFactor * 10000)))
.div('10000');

// Add the number to the totals object
// First time seeing this token, set the field and initial value
Expand Down
10 changes: 5 additions & 5 deletions app/grants/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ def amount_per_period_minus_gas_price(self):
if self.amount_per_period == self.amount_per_period_to_gitcoin:
return float(self.amount_per_period)

return float(self.amount_per_period) - float(self.amount_per_period_to_gitcoin)
return float(self.amount_per_period)

@property
def amount_per_period_to_gitcoin(self):
Expand Down Expand Up @@ -1449,7 +1449,7 @@ def get_converted_amount(self, ignore_gitcoin_fee=False, only_gitcoin_fee=False)
logger.info(no_conversion_e)
return None

def get_converted_monthly_amount(self, ignore_gitcoin_fee=False):
def get_converted_monthly_amount(self, ignore_gitcoin_fee=True):
converted_amount = self.get_converted_amount(ignore_gitcoin_fee=ignore_gitcoin_fee) or 0

total_sub_seconds = Decimal(self.real_period_seconds) * Decimal(self.num_tx_approved)
Expand Down Expand Up @@ -1485,7 +1485,7 @@ def successful_contribution(self, tx_id, include_for_clr=True, **kwargs):
contribution = Contribution.objects.create(**contribution_kwargs)
grant = self.grant

value_usdt = self.get_converted_amount(False)
value_usdt = self.get_converted_amount(True)
if value_usdt:
self.amount_per_period_usdt = value_usdt
grant.amount_received += Decimal(value_usdt)
Expand Down Expand Up @@ -1536,7 +1536,7 @@ def create_contribution(self, tx_id, is_successful_contribution=True):
contribution.save()
grant = self.grant

value_usdt = self.get_converted_amount(False)
value_usdt = self.get_converted_amount(True)
if value_usdt:
self.amount_per_period_usdt = value_usdt
grant.amount_received += Decimal(value_usdt)
Expand Down Expand Up @@ -1935,7 +1935,7 @@ def psave_contrib(sender, instance, **kwargs):
"from_profile":instance.subscription.contributor_profile,
"org_profile":instance.subscription.grant.org_profile,
"to_profile":instance.subscription.grant.admin_profile,
"value_usd":instance.subscription.amount_per_period_usdt if instance.subscription.amount_per_period_usdt else instance.subscription.get_converted_amount(False),
"value_usd":instance.subscription.amount_per_period_usdt if instance.subscription.amount_per_period_usdt else instance.subscription.get_converted_amount(True),
"url":instance.subscription.grant.url,
"network":instance.subscription.network,
"txid":instance.subscription.split_tx_id,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ why are making the changes here ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think is to ignore the gitcoin fee there as is already on the value ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah thats right @octavioamu! Passing ignore_gitcoin_fee=True will make sure we get the full contribution value (without deducting the matching pool contrib)

Expand Down
1 change: 1 addition & 0 deletions app/grants/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.core.paginator import EmptyPage, Paginator
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_control

import django_filters.rest_framework
from ratelimit.decorators import ratelimit
from rest_framework import generics, mixins, routers, viewsets
Expand Down
2 changes: 1 addition & 1 deletion app/grants/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def get_gitcoin_maintenance_amount(self, obj):

def get_grant_usd_value(self, obj):
subscription = obj.subscription
grant_usd_value = subscription.get_converted_amount(ignore_gitcoin_fee=False)
grant_usd_value = subscription.get_converted_amount(ignore_gitcoin_fee=True)
return grant_usd_value

def get_gitcoin_usd_value(self, obj):
Expand Down
4 changes: 2 additions & 2 deletions app/grants/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def update_grant_metadata(self, grant_id, retry: bool = True) -> None:
# recalculate usdt value
created_recently = subscription.created_on > (timezone.now() - timezone.timedelta(days=10))
if not value_usdt and created_recently:
value_usdt = subscription.get_converted_amount(False)
value_usdt = subscription.get_converted_amount(True)
if value_usdt:
subscription.amount_per_period_usdt = value_usdt
subscription.save()
Expand Down Expand Up @@ -209,7 +209,7 @@ def process_grant_contribution(self, grant_id, grant_slug, profile_id, package,
subscription.comments = package.get('comment', '')
subscription.save()

value_usdt = subscription.get_converted_amount(False)
value_usdt = subscription.get_converted_amount(True)
include_for_clr = package.get('include_for_clr')
if value_usdt < 1 or subscription.contributor_profile.shadowbanned:
include_for_clr = False
Expand Down
29 changes: 17 additions & 12 deletions app/grants/templates/grants/cart/eth.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,17 @@

</div>

<!-- Cart total -->
<div class="row justify-content-between text-left mt-5">
<div class="col-12 col-md-auto mr-3"><h4 class="gc-font-base text-dark pt-0">Total</h4></div>
<div class="col-12 col-md text-left"><h4 class="gc-font-base text-dark pt-0">[[donationsTotalString]]</h4></div>
{% comment %} <div class="col d-none d-md-block"></div>
<div class="col-auto d-none d-md-block"></div> {% endcomment %}
</div>

<hr class="my-5">

<!-- Preferences -->
<div>
<!-- Optional contribution to Gitcon -->
<div class="ml-1 mt-3">
{% trans "Contribute to" %}
<a href=" https://gitcoin.co/grants/12/gitcoin-grants-official-matching-pool-fund" target="_blank">Gitcoin Grants Official Matching Pool Fund</a>
{% trans "Give back to" %}
<a href=" https://gitcoin.co/grants/12/gitcoin-grants-official-matching-pool-fund" target="_blank">Gitcoin Matchpool Fund</a>
<i
class="fas fa-info-circle text-grey-400 mx-1 cursor-pointer"
v-b-tooltip.hover.top="'Contribute towards the Gitcoin Match Pool! These funds will be used for current and for future Grant rounds. The selected amount will be added on top of your grant contributions.'"
></i>
</div>
<div class="row justify-content-start align-items-center ml-1 mt-3">
<div class="col-5 col-md-auto cursor-pointer border rounded pr-5 pl-3 py-2 mr-2 my-2" :class="{ 'border-primary': gitcoinFactorRaw == 5 }" @click="gitcoinFactorRaw=5">5%</div>
Expand Down Expand Up @@ -123,13 +118,23 @@

<hr class="my-5">

<!-- Cart total -->
<div class="row justify-content-between text-left mt-5">
<div class="col-12 col-md-auto mr-3"><h4 class="gc-font-base text-dark pt-0">Total</h4></div>
<div class="col-12 col-md text-left"><h4 class="gc-font-base text-dark pt-0">[[donationsTotalString]]</h4></div>
{% comment %} <div class="col d-none d-md-block"></div>
<div class="col-auto d-none d-md-block"></div> {% endcomment %}
</div>

<hr class="my-5">

<!-- Summary -->
<div>
<h4 class="col gc-font-base text-dark p-0">Summary</h4>
<p>
<ul>
<li>You are contributing [[donationsToGrantsString]]</li>
<li>You are additionally contributing [[donationsToGitcoinString]] to the Gitcoin Maintainer Grant</li>
<li>You are contributing [[donationsToGitcoinString]] to the Gitcoin Match Pool Fund</li>
<li>
Note: The exact checkout flow will depend on whether you use Standard Checkout, Polygon, or zkSync.
<a href="https://github.com/gitcoinco/web/blob/master/docs/GRANTS.md" target="_blank">Read how this works</a>.
Expand Down
10 changes: 5 additions & 5 deletions app/grants/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
collection_thumbnail, contribute_to_grants_v1, contribution_addr_from_all_as_json,
contribution_addr_from_grant_as_json, contribution_addr_from_grant_during_round_as_json,
contribution_addr_from_round_as_json, contribution_info_from_grant_during_round_as_json, create_matching_pledge_v1,
flag, get_clr_sybil_input, get_collection, get_collections_list, get_ethereum_cart_data, get_grant_payload, get_grant_tags,
get_grants, get_interrupted_contributions, get_replaced_tx, get_trust_bonus, grant_activity, grant_details, grant_details_api,
grant_details_contributions, grant_details_contributors, grant_edit, grant_fund, grant_new, grants,
grants_addr_as_json, grants_bulk_add, grants_by_grant_type, grants_cart_view, grants_info, grants_landing,
grants_type_redirect, ingest_contributions, ingest_contributions_view, invoice, leaderboard,
flag, get_clr_sybil_input, get_collection, get_collections_list, get_ethereum_cart_data, get_grant_payload,
get_grant_tags, get_grants, get_interrupted_contributions, get_replaced_tx, get_trust_bonus, grant_activity,
grant_details, grant_details_api, grant_details_contributions, grant_details_contributors, grant_edit, grant_fund,
grant_new, grants, grants_addr_as_json, grants_bulk_add, grants_by_grant_type, grants_cart_view, grants_info,
grants_landing, grants_type_redirect, ingest_contributions, ingest_contributions_view, invoice, leaderboard,
manage_ethereum_cart_data, new_matching_partner, profile, quickstart, remove_grant_from_collection, save_collection,
toggle_grant_favorite, toggle_user_sybil, verify_grant,
)
Expand Down