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

feat: /2 crosschain etc integration #5627

Merged
merged 6 commits into from
Jan 10, 2020
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: 4 additions & 3 deletions app/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@
# oauth2 provider
url('^o/', include('oauth2_provider.urls', namespace='oauth2_provider')),
path('jsi18n/', JavaScriptCatalog.as_view(), name='javascript-catalog'),
url('^api/v1/bounty/create', dashboard.views.create_bounty, name='create_bounty'),

url('^api/v1/bounty/create', dashboard.views.create_bounty_v1, name='create_bounty_v1'),
url('^api/v1/bounty/cancel', dashboard.views.cancel_bounty_v1, name='cancel_bounty_v1'),
url('^api/v1/bounty/fulfill', dashboard.views.fulfill_bounty_v1, name='fulfill_bounty_v1'),

# inbox
re_path(r'^inbox/?', include('inbox.urls', namespace='inbox')),
Expand Down Expand Up @@ -233,8 +236,6 @@
path('issue/cancel', dashboard.views.cancel_bounty, name='kill_bounty'),
path('issue/refund_request', dashboard.views.refund_request, name='refund_request'),
path('issue/cancel_reason', dashboard.views.cancel_reason, name='cancel_reason'),
path('issue/contribute', dashboard.views.contribute, name='contribute'),
path('issue/social_contribution', dashboard.views.social_contribution, name='social_contribution'),
path('modal/social_contribution', dashboard.views.social_contribution_modal, name='social_contribution_modal'),
path(
'<str:bounty_network>/<int:stdbounties_id>/modal/funder_payout_reminder/',
Expand Down
1 change: 0 additions & 1 deletion app/assets/v2/css/forms/input.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
background-color: #FFF;
border-radius: 2px;
border: 1px solid #D3D3D3;
font-size: 14px;
padding: 5px 7px;
width: 100%;
letter-spacing: -0.09px;
Expand Down
12 changes: 12 additions & 0 deletions app/assets/v2/css/submit_bounty.css
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,15 @@ input:read-only {
border: 1px solid red;
padding: 5px;
}

.fulfill_bounty .rating-container {
padding-left: 0 !important;
padding-right: 0 !important;
}

.fulfill_bounty .rating-container .rating {
font-size: 12px;
display: inline-block;
top: 3px;
position: relative;
}
26 changes: 13 additions & 13 deletions app/assets/v2/js/pages/bounty_details.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ var callbacks = {
}

const tokenDecimals = 3;
const dollarDecimals = 2;
const bountyTokenName = result['token_name'];
const bountyTokenAmount = token_value_to_display(result['value_in_token'], tokenDecimals);
const dateNow = new Date();
Expand Down Expand Up @@ -1058,16 +1057,17 @@ const is_funder_notifiable = (result) => {
};

var do_actions = function(result) {
var is_legacy = result['web3_type'] == 'legacy_gitcoin';
var is_status_expired = result['status'] == 'expired';
var is_status_done = result['status'] == 'done';
var is_status_cancelled = result['status'] == 'cancelled';
var can_submit_after_expiration_date = result['can_submit_after_expiration_date'];
var is_still_on_happy_path = result['status'] == 'reserved' || result['status'] == 'open' || result['status'] == 'started' || result['status'] == 'submitted' || (can_submit_after_expiration_date && result['status'] == 'expired');
var needs_review = result['needs_review'];
const is_legacy = result['web3_type'] == 'legacy_gitcoin';
const is_status_expired = result['status'] == 'expired';
const is_status_done = result['status'] == 'done';
const is_status_cancelled = result['status'] == 'cancelled';
const can_submit_after_expiration_date = result['can_submit_after_expiration_date'];
const is_still_on_happy_path = result['status'] == 'reserved' || result['status'] == 'open' || result['status'] == 'started' || result['status'] == 'submitted' || (can_submit_after_expiration_date && result['status'] == 'expired');
const needs_review = result['needs_review'];
const is_open = result['is_open'];
let bounty_path = result['network'] + '/' + result['standard_bounties_id'];
const is_bounties_network = document.is_bounties_network;

let bounty_path = result['network'] + '/' + result['standard_bounties_id'];

const is_interested = is_current_user_interested(result);

Expand Down Expand Up @@ -1096,10 +1096,10 @@ var do_actions = function(result) {
let show_submit_work = is_open && !has_fulfilled;
let show_kill_bounty = !is_status_done && !is_status_expired && !is_status_cancelled && isBountyOwner(result);
let show_job_description = result['attached_job_description'] && result['attached_job_description'].startsWith('http');
const show_increase_bounty = !is_status_done && !is_status_expired && !is_status_cancelled;
const show_increase_bounty = !is_status_done && !is_status_expired && !is_status_cancelled && is_bounties_network;
const submit_work_enabled = !isBountyOwner(result) && current_user_is_approved;
const notify_funder_enabled = is_funder_notifiable(result);
let show_payout = !is_status_expired && !is_status_done && isBountyOwner(result);
let show_payout = !is_status_expired && !is_status_done && isBountyOwner(result) && !is_status_cancelled;
let show_extend_deadline = isBountyOwner(result) && !is_status_expired && !is_status_done;
let show_invoice = isBountyOwner(result);
let show_notify_funder = is_open && has_fulfilled;
Expand Down Expand Up @@ -1210,8 +1210,8 @@ var do_actions = function(result) {
const enabled = true;
const _entry = {
enabled: enabled,
href: result['action_urls']['contribute'],
text: gettext('Contribute Funds'),
href: result['action_urls']['increase'],
text: isBountyOwner(result) ? gettext('Increase Funding') : gettext('Contribute Funds'),
parent: 'bounty_actions',
title: gettext('Help by funding or promoting this issue')
};
Expand Down
117 changes: 117 additions & 0 deletions app/assets/v2/js/pages/cancel_bounty/ETH.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/**
* Handles Bounty Cancellation for bounties funded in ETH/ERC20 tokens
* Data is stored on IPFS + the data is stored in
* standard bounties contract on the ethereum blockchain
*/
const ethCancelBounty = data => {

if (is_bounties_network) {
waitforWeb3(actions_page_warn_if_not_on_same_network);
}

try {
bounty_address();
} catch (exception) {
_alert(gettext('You are on an unsupported network. Please change your network to a supported network.'));
return;
}

const params = data.payload;

let account = web3.eth.accounts[0];
const sendForm = fetchData('cancel_reason', 'POST', params);

$.when(sendForm).then(function(payback) {
return payback;
});

loading_button($('.js-submit'));
const issueURL = data.issueURL;

let bounty = web3.eth.contract(bounty_abi).at(bounty_address());

const apiCallback = function(results, status) {
if (status != 'success') {
_alert({ message: gettext('Could not get bounty details') });
console.error(error);
unloading_button($('.submitBounty'));
return;
}
results = sanitizeAPIResults(results);
result = results[0];
if (result == null) {
_alert({
message: gettext('No active bounty found for this Github URL on ' + document.web3network + '.')
});
unloading_button($('.js-submit'));
return;
}

const bountyAmount = parseInt(result['value_in_token'], 10);
const fromAddress = result['bounty_owner_address'];
const is_open = result['is_open'];
const bountyId = result['standard_bounties_id'];

let errormsg = undefined;

if (bountyAmount > 0 && !is_open) {
errormsg = gettext(
'This bounty is already in progress, canceling the issue is no longer possible.'
);
} else if (bountyAmount == 0 || is_open == false) {
errormsg = gettext(
'No active funded issue found at this address. Are you sure this is an active funded issue?'
);
} else if (fromAddress != web3.eth.coinbase) {
errormsg = gettext(
'Only the address that submitted this funded issue may kill the bounty.'
);
}

if (errormsg) {
_alert({ message: errormsg });
unloading_button($('.js-submit'));
return;
}

const final_callback = function(error, result) {
indicateMetamaskPopup(true);
const next = function() {
// setup inter page state
localStorage[issueURL] = JSON.stringify({
timestamp: timestamp(),
dataHash: null,
issuer: account,
txid: result
});

_alert({ message: gettext('Cancel bounty submitted to web3.') }, 'info');
setTimeout(() => {
document.location.href = '/funding/details/?url=' + issueURL;
}, 1000);
};

if (error) {
console.error('err', error);
_alert({ message: gettext('There was an error') });
unloading_button($('.js-submit'));
} else {
next();
}
};

indicateMetamaskPopup();
bounty.killBounty(
bountyId,
{ gasPrice: web3.toHex($('#gasPrice').val() * Math.pow(10, 9)) },
final_callback
);

};

const uri = '/api/v0.1/bounties/?event_tag=all&github_url=' +
issueURL + '&network=' + $('input[name=network]').val() +
'&standard_bounties_id=' + $('input[name=standard_bounties_id]').val();

$.get(uri, apiCallback);
}
41 changes: 41 additions & 0 deletions app/assets/v2/js/pages/cancel_bounty/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* eslint-disable no-console */
window.onload = function() {

if (getParam('source')) {
$('input[name=issueURL]').val(getParam('source'));
}

$('#cancelBounty').validate({
submitHandler: function(form) {

let data = {};

$.each($(form).serializeArray(), function() {
if (this.value) {
data[this.name] = this.value;
}
});

const selectedRadio = $('input[name=canceled_bounty_reason]:checked').val();
const reasonCancel = selectedRadio == 'other' ? $('#reason_text').val() : selectedRadio;

if (!reasonCancel || reasonCancel == '') {
_alert('Please select a reason before cancelling the bounty');
return;
}

const payload = {
pk: $('input[name=pk]').val(),
canceled_bounty_reason: reasonCancel
};

data.payload = payload;

if (is_bounties_network) {
ethCancelBounty(data);
} else {
cancelBounty(data);
}
}
});
};
21 changes: 21 additions & 0 deletions app/assets/v2/js/pages/cancel_bounty/token.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Handles Bounty cancellation for crypto tokens
* Data is stored in the db
*/
cancelBounty = data => {

const url = '/api/v1/bounty/cancel';
params = data.payload;

$.post(url, params, function(response) {
if (200 <= response.status && response.status <= 204) {
// redirect to bounty page
console.log('success', response);
window.location.href = response.bounty_url;
} else {
_alert('Unable to cancel a bounty. Please try again later', 'error');
console.error(`error: bounty creation failed with status: ${response.status} and message: ${response.message}`);
}
});

}
Loading