-
-
Notifications
You must be signed in to change notification settings - Fork 775
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5627 from thelostone-mc/purge
feat: /2 crosschain etc integration
- Loading branch information
Showing
40 changed files
with
1,144 additions
and
940 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} | ||
}); | ||
|
||
} |
Oops, something went wrong.