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

bounty/fee: fixes formula + css cleanup + makes fee editable #4244

Merged
merged 16 commits into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from 7 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
15 changes: 5 additions & 10 deletions app/assets/v2/css/submit_bounty.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,17 @@ h1, h2, h3, h4, h5 {
letter-spacing: 0;
}

input:-moz-read-only { /* For Firefox */
background-color: #eaeaea94;
input {
outline: none;
}

textarea:-moz-read-only,
input:-moz-read-only,
textarea:read-only,
input:read-only {
background-color: #eaeaea94;
}

textarea:-moz-read-only { /* For Firefox */
background-color: #eaeaea94;
}

textarea:read-only {
background-color: #eaeaea94;
}

#primary_form .revisions {
min-height: 37px;
padding: 0;
Expand Down
19 changes: 10 additions & 9 deletions app/assets/v2/js/pages/increase_bounty.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
load_tokens();

const FEE_PERCENTAGE = 10;
// Wait until page is loaded, then run the function
const FEE_PERCENTAGE = document.FEE_PERCENTAGE / 100.0;

const is_funder = function() {
return document.is_funder_github_user_same && $('input[name=bountyOwnerAddress]').val() == web3.eth.coinbase;
Expand Down Expand Up @@ -29,10 +28,6 @@ $(document).ready(function() {


$('input[name=amount]').on('change', function() {
const amount = $('input[name=amount]').val();

$('#summary-bounty-amount').html(amount);
$('#summary-fee-amount').html((amount / FEE_PERCENTAGE).toFixed(4));
populateBountyTotal();
});

Expand Down Expand Up @@ -213,7 +208,7 @@ $(document).ready(function() {
if (act_as_funder) {
const to_address = '0x00De4B13153673BCAE2616b67bf822500d325Fc3';
const gas_price = web3.toHex($('#gasPrice').val() * Math.pow(10, 9));
const fee = (Number($('#summary-bounty-amount').html()) / FEE_PERCENTAGE).toFixed(4);
const fee = (Number($('#summary-bounty-amount').html()) * FEE_PERCENTAGE).toFixed(4);

indicateMetamaskPopup();
if (isETH) {
Expand Down Expand Up @@ -257,10 +252,16 @@ $(document).ready(function() {
* Bounty Amount + Fee + Featured Bounty
*/
const populateBountyTotal = () => {
const amount = $('input[name=amount]').val();
const fee = (amount * FEE_PERCENTAGE).toFixed(4);

$('#summary-bounty-amount').html(amount);
$('#summary-fee-amount').html(fee);

const bountyToken = $('#summary-bounty-token').html();
const bountyAmount = Number($('#summary-bounty-amount').html());
const bountyFee = Number((bountyAmount / FEE_PERCENTAGE).toFixed(4));
const totalBounty = bountyAmount + bountyFee;
const bountyFee = Number(bountyAmount * FEE_PERCENTAGE).toFixed(4));
const totalBounty = (bountyAmount + bountyFee).toFixed(4);
const total = `${totalBounty} ${bountyToken}`;

$('#fee-percentage').html(FEE_PERCENTAGE);
Expand Down
42 changes: 35 additions & 7 deletions app/assets/v2/js/pages/new_bounty.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ load_tokens();
var localStorage;
var quickstartURL = document.location.origin + '/bounty/quickstart';

const FEE_PERCENTAGE = 10;
const FEE_PERCENTAGE = document.FEE_PERCENTAGE / 100.0;

var new_bounty = {
last_sync: new Date()
Expand Down Expand Up @@ -97,7 +97,7 @@ $('#last-synced').hide();
$(document).ready(function() {

$('#summary-bounty-amount').html($('input[name=amount]').val());
$('#summary-fee-amount').html(($('input[name=amount]').val() / FEE_PERCENTAGE).toFixed(4));
$('#summary-fee-amount').html(($('input[name=amount]').val() * FEE_PERCENTAGE).toFixed(4));
populateBountyTotal();

// Load sidebar radio buttons from localStorage
Expand Down Expand Up @@ -137,7 +137,7 @@ $(document).ready(function() {
const amount = $('input[name=amount]').val();

$('#summary-bounty-amount').html(amount);
$('#summary-fee-amount').html((amount / FEE_PERCENTAGE).toFixed(4));
$('#summary-fee-amount').html((amount * FEE_PERCENTAGE).toFixed(4));
populateBountyTotal();
});

Expand Down Expand Up @@ -498,7 +498,7 @@ $(document).ready(function() {
}

var do_bounty = function(callback) {
const fee = Number((Number(data.amount) / FEE_PERCENTAGE).toFixed(4));
const fee = Number((Number(data.amount) * FEE_PERCENTAGE).toFixed(4));
const to_address = '0x00De4B13153673BCAE2616b67bf822500d325Fc3';
const gas_price = web3.toHex($('#gasPrice').val() * Math.pow(10, 9));

Expand Down Expand Up @@ -624,6 +624,27 @@ $(window).on('load', function() {
});
});

var check_balance_and_alert_user_if_not_enough = function(tokenAddress, amount) {
Copy link
Member Author

Choose a reason for hiding this comment

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

should we try and reuse the one in shared.js @danlipert ?

Copy link
Contributor

Choose a reason for hiding this comment

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

@thelostone-mc yeah I think so, its just one line difference essentially

var token_contract = web3.eth.contract(token_abi).at(tokenAddress);
var from = web3.eth.coinbase;
var token_details = tokenAddressToDetails(tokenAddress);
var token_decimals = token_details['decimals'];
var token_name = token_details['name'];

token_contract.balanceOf.call(from, function(error, result) {
if (error) return;
var balance = result.toNumber() / Math.pow(10, token_decimals);
var balance_rounded = Math.round(balance * 10) / 10;
const total = parseFloat(amount) + parseFloat((parseFloat(amount) * FEE_PERCENTAGE).toFixed(4));

if (parseFloat(total) > balance) {
var msg = gettext('You do not have enough tokens to fund this bounty. You have ') + balance_rounded + ' ' + token_name + ' ' + gettext(' but you need ') + amount + ' ' + token_name;

_alert(msg, 'warning');
}
});
};

let usdFeaturedPrice = $('.featured-price-usd').text();
let ethFeaturedPrice;
let bountyFee;
Expand All @@ -639,11 +660,18 @@ getAmountEstimate(usdFeaturedPrice, 'ETH', (amountEstimate) => {
* Bounty Amount + Fee + Featured Bounty
*/
const populateBountyTotal = () => {

const amount = $('input[name=amount]').val();
const fee = ((amount / 100) * FEE_PERCENTAGE).toFixed(4);

$('#summary-bounty-amount').html(amount);
$('#summary-fee-amount').html(fee);

const bountyToken = $('#summary-bounty-token').html();
const bountyAmount = Number($('#summary-bounty-amount').html());
const bountyFee = Number((bountyAmount / FEE_PERCENTAGE).toFixed(4));
const bountyFee = Number((bountyAmount * FEE_PERCENTAGE).toFixed(4));
const isFeaturedBounty = $('input[name=featuredBounty]:checked').val();
let totalBounty = bountyAmount + bountyFee;
let totalBounty = (bountyAmount + bountyFee).toFixed(4);
let total = '';

if (isFeaturedBounty) {
Expand All @@ -659,7 +687,7 @@ const populateBountyTotal = () => {
total = `${totalBounty} ${bountyToken}`;
}

$('#fee-percentage').html(FEE_PERCENTAGE);
$('#fee-percentage').html(FEE_PERCENTAGE * 100);
$('#fee-amount').html(bountyFee);
$('#fee-token').html(bountyToken);
$('#summary-total-amount').html(total);
Expand Down
18 changes: 18 additions & 0 deletions app/dashboard/migrations/0029_profile_fee_percentage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.1.7 on 2019-03-29 16:47

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('dashboard', '0028_profile_actions_count'),
]

operations = [
migrations.AddField(
model_name='profile',
name='fee_percentage',
field=models.IntegerField(default=10),
),
]
1 change: 1 addition & 0 deletions app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1882,6 +1882,7 @@ class Profile(SuperModel):
linkedin_url = models.CharField(max_length=255, default='', blank=True, null=True)
resume = models.FileField(upload_to=get_upload_filename, null=True, blank=True, help_text=_('The profile resume.'))
actions_count = models.IntegerField(default=3)
fee_percentage = models.IntegerField(default=10)

objects = ProfileQuerySet.as_manager()

Expand Down
4 changes: 4 additions & 0 deletions app/dashboard/templates/bounty/increase.html
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ <h5 class="font-title-lg mb-0">{% trans "Total"%} </h5>
document.is_funder_github_user_same = {{ is_funder }};
</script>

<script>
document.FEE_PERCENTAGE = {{FEE_PERCENTAGE}};
</script>

<!-- jQuery -->
<script src="{% static "v2/js/ipfs-api.js" %}"></script>
<script src="{% static "v2/js/ipfs.js" %}"></script>
Expand Down
6 changes: 5 additions & 1 deletion app/dashboard/templates/bounty/new.html
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ <h5 class="font-subheader">{% trans "No Suprises" %}</h5>
<div class="fee-circle text-center">
<p class="font-title mb-0"><span id="fee-amount"></span> <span id="fee-token"></span></p>
<p class="font-body font-weight-semibold">
(<span class="fee-percentage">10</span>%)
(<span id="fee-percentage" class="fee-percentage">10</span>%)
</p>
</div>
</div>
Expand Down Expand Up @@ -305,6 +305,10 @@ <h5 class="font-title-lg mb-0">{% trans "Total"%} </h5>

{% include 'shared/current_profile.html' %}

<script>
document.FEE_PERCENTAGE = {{FEE_PERCENTAGE}};
</script>

<!-- jQuery -->
<script src="{% static "v2/js/ipfs-api.js" %}"></script>
<script src="{% static "v2/js/ipfs.js" %}"></script>
Expand Down
1 change: 1 addition & 0 deletions app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2219,6 +2219,7 @@ def new_bounty(request):
title=_('Create Funded Issue'),
update=bounty_params,
)
params['FEE_PERCENTAGE'] = request.user.profile.fee_percentage if request.user.is_authenticated else 10
return TemplateResponse(request, 'bounty/new.html', params)


Expand Down